Compare commits

...

5 commits

Author SHA1 Message Date
29420f40f8 Updated project.godot
Added Input Action for debugging the switch between pokemon.
2025-06-13 17:11:31 -05:00
af766236c1 Added WildPokemon Scene
Started work on Wild Poke`mon Scene for capturing wild pokemon.
2025-06-13 17:11:08 -05:00
538f3b68df Commited Missing UUID 2025-06-13 17:10:31 -05:00
93f5b3dec9 Fixed GIF Manager
Fixed fetching of GifManager from singelton, instead of as a node.
2025-06-13 17:10:17 -05:00
8f1d66da1b Created Generations Class
Added Generations to track the generations of Poke`mon, and pick random based upon unlocked level of Generation.
2025-06-13 17:09:45 -05:00
7 changed files with 102 additions and 2 deletions

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
namespace PokePurple.Library.Singletons;
public class Generations
{
private List<Range> _generations =
[
new Range(1,151),
new Range(152, 251),
new Range(252, 386),
new Range(387, 493),
new Range(494, 649),
new Range(650, 721),
new Range(722, 809),
new Range(810, 905),
new Range(906, 1025)
];
public int Generation = 1;
public int PickRandomPokemon()
{
var maxRange = _generations[Generation].End.Value;
var random = new Random();
var id = random.Next(1, maxRange);
return id;
}
}

View file

@ -0,0 +1 @@
uid://dbfww8rxe1kj2

View file

@ -7,11 +7,12 @@ public class GifManager
private static GifManager? _instance;
public static GifManager Instance => _instance ?? (_instance = new GifManager());
private Node _gifManager;
private GodotObject _gifManager;
public GifManager()
{
_gifManager = ((SceneTree)Engine.GetMainLoop()).GetRoot().GetNode("GifManager");
_gifManager = Engine.GetSingleton("GifManager");
//_gifManager = ((SceneTree)Engine.GetMainLoop()).GetRoot().GetNode("GifManager");
}
public AnimatedTexture AnimatedTextureFromBuffer(byte[] data, int max_frames = 0) => _gifManager.Call("animated_texture_from_buffer", data, max_frames).As<AnimatedTexture>();

49
Scenes/WildPokemon.cs Normal file
View file

@ -0,0 +1,49 @@
using Godot;
using System;
using System.ComponentModel;
using System.Text;
using Godot.Sharp.Extras;
using PokeApiNet;
using PokePurple.Library.Singletons;
public partial class WildPokemon : Node2D
{
private Generations _generations = new();
private Pokemon _pokemon;
private PokeApiClient _apiClient;
private System.Net.Http.HttpClient _http;
[NodePath] private AnimatedSprite2D _pokemonSprite;
private String _animatedUrl =
"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/showdown/{0}.gif";
public override void _Ready()
{
this.OnReady();
_apiClient = new();
_http = new();
_generations.Generation = 8;
InitPokemon();
}
public override void _Input(InputEvent @event)
{
if (Input.IsActionJustPressed("debug_pokemon"))
{
InitPokemon();
}
}
private async void InitPokemon()
{
var pokeId = _generations.PickRandomPokemon();
_pokemon = await _apiClient.GetResourceAsync<Pokemon>(pokeId);
GD.Print(_pokemon.Name);
var url = String.Format(_animatedUrl, pokeId);
GD.Print(url);
var data = await _http.GetByteArrayAsync(url);
var frames = GifManager.Instance.SpriteFramesFromBuffer(data);
_pokemonSprite.SpriteFrames = frames;
_pokemonSprite.Play();
}
}

View file

@ -0,0 +1 @@
uid://cfn824p8fcutm

10
Scenes/WildPokemon.tscn Normal file
View file

@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://k73x3ho8t1x1"]
[ext_resource type="Script" uid="uid://cfn824p8fcutm" path="res://Scenes/WildPokemon.cs" id="1_3f6p2"]
[node name="WildPokemon" type="Node2D"]
script = ExtResource("1_3f6p2")
[node name="PokemonSprite" type="AnimatedSprite2D" parent="."]
position = Vector2(180, 180)
scale = Vector2(2, 2)

View file

@ -27,6 +27,14 @@ project/assembly_name="PokePurple"
enabled=PackedStringArray("res://addons/twitcher/plugin.cfg")
[input]
debug_pokemon={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":80,"key_label":0,"unicode":112,"location":0,"echo":false,"script":null)
]
}
[twitcher]
editor/game_oauth_token="res://addons/twitcher/default_oauth_token.tres"