From 46fcf8130d3e490e9de7d0cc8151a1d61c6edada Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Mon, 12 Oct 2026 10:16:01 +0200 Subject: [PATCH] Add temporary colors to pokemon capsules in overworld --- game/pokemon/sent_pokemon.gd | 38 ++++++++++++++++++----- game/pokemon/type_colors.gd | 54 +++++++++++++++++++++++++++++++++ game/pokemon/type_colors.gd.uid | 1 + 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 game/pokemon/type_colors.gd create mode 100644 game/pokemon/type_colors.gd.uid diff --git a/game/pokemon/sent_pokemon.gd b/game/pokemon/sent_pokemon.gd index 239fefc..4d1dc4d 100644 --- a/game/pokemon/sent_pokemon.gd +++ b/game/pokemon/sent_pokemon.gd @@ -58,21 +58,43 @@ func _build_model() -> void: add_child(model) static func create_model(p : PokemonInstance) -> Node3D: - #modele 3D de l'espece ; capsule de remplacement s'il n'y en a pas + #modele 3D de l'espece ; capsule coloree selon le type s'il n'y en a pas var result : Node3D = null var scene : PackedScene = p.species.model_scene if scene: result = scene.instantiate() as Node3D if result == null: - var mesh_instance := MeshInstance3D.new() - var capsule := CapsuleMesh.new() - capsule.radius = 0.3 - capsule.height = 1.0 - mesh_instance.mesh = capsule - mesh_instance.position.y = 0.5 - result = mesh_instance + result = _create_placeholder(p) return result +static func _create_placeholder(p : PokemonInstance) -> Node3D: + var colors : Array[Color] = TypeColors.for_species(p.species) + + var body := MeshInstance3D.new() + var capsule := CapsuleMesh.new() + capsule.radius = 0.3 + capsule.height = 1.0 + body.mesh = capsule + body.position.y = 0.5 + body.material_override = _make_material(colors[0]) + + #deuxieme type : anneau autour de la capsule + if colors.size() > 1: + var ring := MeshInstance3D.new() + var torus := TorusMesh.new() + torus.inner_radius = 0.29 + torus.outer_radius = 0.36 + ring.mesh = torus + ring.material_override = _make_material(colors[1]) + body.add_child(ring) + return body + +static func _make_material(color : Color) -> StandardMaterial3D: + var mat := StandardMaterial3D.new() + mat.albedo_color = color + mat.roughness = 0.8 + return mat + func recall() -> void: recalled.emit() queue_free() diff --git a/game/pokemon/type_colors.gd b/game/pokemon/type_colors.gd new file mode 100644 index 0000000..ab05252 --- /dev/null +++ b/game/pokemon/type_colors.gd @@ -0,0 +1,54 @@ +class_name TypeColors +extends RefCounted + +#couleurs de remplacement par type, en attendant les modeles 3D + +const FALLBACK : Color = Color(0.62, 0.62, 0.62) + +static var COLORS : Dictionary = { + "normal": Color.html("a8a77a"), + "fire": Color.html("ee8130"), + "water": Color.html("6390f0"), + "electric": Color.html("f7d02c"), + "grass": Color.html("7ac74c"), + "ice": Color.html("96d9d6"), + "fighting": Color.html("c22e28"), + "poison": Color.html("a33ea1"), + "ground": Color.html("e2bf65"), + "flying": Color.html("a98ff3"), + "psychic": Color.html("f95587"), + "bug": Color.html("a6b91a"), + "rock": Color.html("b6a136"), + "ghost": Color.html("735797"), + "dragon": Color.html("6f35fc"), + "dark": Color.html("705746"), + "steel": Color.html("b7b7ce"), + "fairy": Color.html("d685ad"), +} + +static func for_species(species : PokemonData) -> Array[Color]: + #[couleur du type principal] ou [type principal, type secondaire] ; gris si le type est inconnu + var result : Array[Color] = [] + if species != null: + for type_data : TypeData in species.types: + if type_data != null and result.size() < 2: + var color : Color = COLORS.get(type_data.api_name.to_lower(), FALLBACK) + result.append(color) + + if result.is_empty(): result.append(FALLBACK) + return result + +static func _type_key(type_data : Resource) -> String: + #adapte ici si TypeData utilise un autre champ : on essaie plusieurs noms, puis le nom du fichier .tres + var candidates : Array[String] = [] + for prop in ["api_name", "identifier", "id", "name"]: + var value : Variant = type_data.get(prop) + if value is String: candidates.append(value) + candidates.append(type_data.resource_path.get_file().get_basename()) + + for candidate in candidates: + var key : String = candidate.to_lower() + if COLORS.has(key): return key + for known : String in COLORS: + if key.ends_with(known): return known #ex. "10_fire" -> "fire" + return "" diff --git a/game/pokemon/type_colors.gd.uid b/game/pokemon/type_colors.gd.uid new file mode 100644 index 0000000..93c0697 --- /dev/null +++ b/game/pokemon/type_colors.gd.uid @@ -0,0 +1 @@ +uid://dfqyotue8i5kh