Add temporary colors to pokemon capsules in overworld
This commit is contained in:
parent
c4c2bf5f7b
commit
46fcf8130d
|
|
@ -58,20 +58,42 @@ func _build_model() -> void:
|
||||||
add_child(model)
|
add_child(model)
|
||||||
|
|
||||||
static func create_model(p : PokemonInstance) -> Node3D:
|
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 result : Node3D = null
|
||||||
var scene : PackedScene = p.species.model_scene
|
var scene : PackedScene = p.species.model_scene
|
||||||
if scene:
|
if scene:
|
||||||
result = scene.instantiate() as Node3D
|
result = scene.instantiate() as Node3D
|
||||||
if result == null:
|
if result == null:
|
||||||
var mesh_instance := MeshInstance3D.new()
|
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()
|
var capsule := CapsuleMesh.new()
|
||||||
capsule.radius = 0.3
|
capsule.radius = 0.3
|
||||||
capsule.height = 1.0
|
capsule.height = 1.0
|
||||||
mesh_instance.mesh = capsule
|
body.mesh = capsule
|
||||||
mesh_instance.position.y = 0.5
|
body.position.y = 0.5
|
||||||
result = mesh_instance
|
body.material_override = _make_material(colors[0])
|
||||||
return result
|
|
||||||
|
#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:
|
func recall() -> void:
|
||||||
recalled.emit()
|
recalled.emit()
|
||||||
|
|
|
||||||
54
game/pokemon/type_colors.gd
Normal file
54
game/pokemon/type_colors.gd
Normal file
|
|
@ -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 ""
|
||||||
1
game/pokemon/type_colors.gd.uid
Normal file
1
game/pokemon/type_colors.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dfqyotue8i5kh
|
||||||
Loading…
Reference in a new issue