Add spirit and affinity transition effects
This commit is contained in:
@@ -13,6 +13,8 @@ var hi_root: Node3D = null
|
||||
var pathfinder: Pathfinder = null
|
||||
var cursor_highlight_ref: MeshInstance3D = null
|
||||
var hover_team_overlay_ref: MeshInstance3D = null
|
||||
var affinity_transition_shader: Shader = null
|
||||
var tile_materialize_shader: Shader = null
|
||||
|
||||
|
||||
func build_board(board: Dictionary) -> void:
|
||||
@@ -53,6 +55,7 @@ func add_tile(x: int, y: int, affinity: String) -> void:
|
||||
body.position = wp + Vector3(0, y_base + h * 0.5, 0)
|
||||
body.set_meta("tile_coord", Vector2i(x, y))
|
||||
body.set_meta("tile_height", h) # used by bottom-model loader
|
||||
body.set_meta("affinity", affinity)
|
||||
|
||||
var shape: CollisionShape3D = CollisionShape3D.new()
|
||||
var mi: MeshInstance3D = MeshInstance3D.new()
|
||||
@@ -130,12 +133,16 @@ func try_load_tile_model(body: StaticBody3D, affinity: String) -> void:
|
||||
# Remove any existing mesh (placeholder or previously loaded model),
|
||||
# but leave the CollisionShape3D so click detection still works.
|
||||
for child in b.get_children():
|
||||
if not (child is CollisionShape3D):
|
||||
if not (child is CollisionShape3D) and not bool(child.get_meta("tile_fx", false)):
|
||||
child.queue_free()
|
||||
|
||||
b.add_child(model_node)
|
||||
# Scale so the XZ footprint fits the 0.98-unit tile square.
|
||||
fit_model_to_tile(model_node, 0.98)
|
||||
if str(b.get_meta("affinity_transition_affinity", "")) == affinity:
|
||||
var transition_color: Color = GameConstants.AFFINITY_COLORS.get(affinity, Color(0.8, 0.8, 0.9))
|
||||
_play_tile_materialize_shader(model_node, transition_color, 1.25)
|
||||
b.set_meta("affinity_transition_model_materialized", affinity)
|
||||
# Update the visual-top cache so highlights land just above the model surface,
|
||||
# not the collision box top (the two can differ when model height ≠ box height).
|
||||
var tc: Vector2i = b.get_meta("tile_coord", Vector2i(-1, -1))
|
||||
@@ -191,7 +198,7 @@ func try_load_tile_bottom(body_ref: Variant, url: String) -> void:
|
||||
func apply_tile_texture(body: StaticBody3D, tex_url: String) -> void:
|
||||
var mi: MeshInstance3D = null
|
||||
for child in body.get_children():
|
||||
if child is MeshInstance3D:
|
||||
if child is MeshInstance3D and not bool(child.get_meta("tile_fx", false)):
|
||||
mi = child as MeshInstance3D
|
||||
break
|
||||
if mi == null or tex_url.is_empty():
|
||||
@@ -265,12 +272,414 @@ func model_local_aabb(root: Node3D) -> AABB:
|
||||
func update_tile_affinity(x: int, y: int, affinity: String) -> void:
|
||||
var body: StaticBody3D = tile_bodies.get("%d,%d" % [x, y]) as StaticBody3D
|
||||
if body == null: return
|
||||
var prev_affinity: String = str(body.get_meta("affinity", ""))
|
||||
var changed: bool = prev_affinity != affinity
|
||||
var prev_color: Color = GameConstants.AFFINITY_COLORS.get(prev_affinity, Color(0.25, 0.25, 0.3))
|
||||
var color: Color = GameConstants.AFFINITY_COLORS.get(affinity, Color(0.8, 0.8, 0.9))
|
||||
var shape_key: String = "Hex" if pathfinder.grid_type == "Hexagon" else "Square"
|
||||
var expects_model: bool = not ContentCache.get_tile_model_url(affinity, shape_key).is_empty()
|
||||
if changed:
|
||||
body.set_meta("affinity_transition_affinity", affinity)
|
||||
var outgoing_snapshot: Node3D = _make_outgoing_tile_snapshot(body)
|
||||
if outgoing_snapshot != null:
|
||||
_play_tile_dissolve_shader(outgoing_snapshot, prev_color, 1.1)
|
||||
get_tree().create_timer(1.3).timeout.connect(func() -> void:
|
||||
if is_instance_valid(outgoing_snapshot):
|
||||
outgoing_snapshot.queue_free()
|
||||
, CONNECT_ONE_SHOT)
|
||||
body.set_meta("affinity", affinity)
|
||||
|
||||
# Update the placeholder colour in case there is no model for this affinity.
|
||||
for child in body.get_children():
|
||||
if child is MeshInstance3D:
|
||||
if child is MeshInstance3D and not bool(child.get_meta("tile_fx", false)):
|
||||
var mat: StandardMaterial3D = child.material_override as StandardMaterial3D
|
||||
if mat: mat.albedo_color = GameConstants.AFFINITY_COLORS.get(affinity, Color(0.2, 0.2, 0.2))
|
||||
if mat: mat.albedo_color = color
|
||||
|
||||
# Attempt to swap in a real 3D model.
|
||||
try_load_tile_model(body, affinity)
|
||||
if changed:
|
||||
var body_ref: WeakRef = weakref(body)
|
||||
if not expects_model:
|
||||
get_tree().create_timer(0.14).timeout.connect(func() -> void:
|
||||
var b: StaticBody3D = body_ref.get_ref() as StaticBody3D
|
||||
if is_instance_valid(b) \
|
||||
and str(b.get_meta("affinity_transition_affinity", "")) == affinity \
|
||||
and str(b.get_meta("affinity_transition_model_materialized", "")) != affinity:
|
||||
_play_tile_materialize_shader(b, color, 1.25)
|
||||
, CONNECT_ONE_SHOT)
|
||||
play_affinity_change_effect(body, prev_affinity, affinity)
|
||||
get_tree().create_timer(4.0 if expects_model else 2.2).timeout.connect(func() -> void:
|
||||
var b: StaticBody3D = body_ref.get_ref() as StaticBody3D
|
||||
if is_instance_valid(b) and str(b.get_meta("affinity_transition_affinity", "")) == affinity:
|
||||
_apply_direct_tile_placeholder_color(b, color)
|
||||
b.remove_meta("affinity_transition_affinity")
|
||||
if str(b.get_meta("affinity_transition_model_materialized", "")) == affinity:
|
||||
b.remove_meta("affinity_transition_model_materialized")
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func play_affinity_change_effect(body: StaticBody3D, prev_affinity: String, affinity: String) -> void:
|
||||
if not is_instance_valid(body):
|
||||
return
|
||||
var prev_color: Color = GameConstants.AFFINITY_COLORS.get(prev_affinity, Color(0.25, 0.25, 0.3))
|
||||
var color: Color = GameConstants.AFFINITY_COLORS.get(affinity, Color(0.8, 0.8, 0.9))
|
||||
var root: Node3D = Node3D.new()
|
||||
root.name = "AffinityTransition"
|
||||
root.set_meta("tile_fx", true)
|
||||
root.position = Vector3(0.0, _tile_effect_local_y(body), 0.0)
|
||||
body.add_child(root)
|
||||
|
||||
var outgoing: MeshInstance3D = _make_affinity_transition_mesh(prev_color)
|
||||
outgoing.name = "OutgoingDissolve"
|
||||
outgoing.position.y = 0.006
|
||||
root.add_child(outgoing)
|
||||
|
||||
var incoming: MeshInstance3D = _make_affinity_transition_mesh(color)
|
||||
incoming.name = "IncomingMaterialize"
|
||||
incoming.position.y = 0.028
|
||||
root.add_child(incoming)
|
||||
|
||||
var motes: CPUParticles3D = _make_affinity_motes(color)
|
||||
motes.position = Vector3.ZERO
|
||||
root.add_child(motes)
|
||||
motes.emitting = true
|
||||
|
||||
var outgoing_mat: ShaderMaterial = outgoing.material_override as ShaderMaterial
|
||||
var incoming_mat: ShaderMaterial = incoming.material_override as ShaderMaterial
|
||||
if outgoing_mat != null:
|
||||
outgoing_mat.set_shader_parameter("reveal", 1.0)
|
||||
outgoing_mat.set_shader_parameter("alpha_scale", 0.72)
|
||||
if incoming_mat != null:
|
||||
incoming_mat.set_shader_parameter("reveal", 0.0)
|
||||
incoming_mat.set_shader_parameter("alpha_scale", 0.0)
|
||||
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(root, "position:x", 0.025, 0.045).set_trans(Tween.TRANS_SINE)
|
||||
tween.tween_property(root, "position:z", -0.018, 0.045).set_trans(Tween.TRANS_SINE)
|
||||
tween.chain().tween_property(root, "position:x", -0.022, 0.055).set_trans(Tween.TRANS_SINE)
|
||||
tween.parallel().tween_property(root, "position:z", 0.022, 0.055).set_trans(Tween.TRANS_SINE)
|
||||
tween.chain().tween_property(root, "position", Vector3(0.0, _tile_effect_local_y(body), 0.0), 0.08)
|
||||
tween.parallel().tween_property(root, "scale", Vector3(1.08, 1.0, 1.08), 0.82)\
|
||||
.set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
|
||||
if outgoing_mat != null:
|
||||
tween.parallel().tween_method(func(value: float) -> void:
|
||||
outgoing_mat.set_shader_parameter("reveal", value)
|
||||
, 1.0, 0.0, 0.46).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN)
|
||||
tween.parallel().tween_method(func(value: float) -> void:
|
||||
outgoing_mat.set_shader_parameter("alpha_scale", value)
|
||||
, 0.72, 0.0, 0.5).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
|
||||
if incoming_mat != null:
|
||||
tween.parallel().tween_method(func(value: float) -> void:
|
||||
incoming_mat.set_shader_parameter("alpha_scale", value)
|
||||
, 0.0, 0.88, 0.18).set_delay(0.08).set_trans(Tween.TRANS_SINE)
|
||||
tween.parallel().tween_method(func(value: float) -> void:
|
||||
incoming_mat.set_shader_parameter("reveal", value)
|
||||
, 0.0, 1.0, 0.68).set_delay(0.08).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
|
||||
tween.parallel().tween_method(func(value: float) -> void:
|
||||
incoming_mat.set_shader_parameter("alpha_scale", value)
|
||||
, 0.88, 0.0, 0.32).set_delay(0.72).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
|
||||
tween.finished.connect(func() -> void:
|
||||
if is_instance_valid(root):
|
||||
root.queue_free()
|
||||
)
|
||||
|
||||
|
||||
func _tile_effect_local_y(body: StaticBody3D) -> float:
|
||||
var coord: Vector2i = body.get_meta("tile_coord", Vector2i(-1, -1))
|
||||
var visual_top: float = tile_visual_tops.get(
|
||||
"%d,%d" % [coord.x, coord.y],
|
||||
body.position.y + float(body.get_meta("tile_height", 1.0)) * 0.5)
|
||||
return visual_top - body.position.y + 0.055
|
||||
|
||||
|
||||
func _apply_direct_tile_placeholder_color(body: StaticBody3D, color: Color) -> void:
|
||||
for child in body.get_children():
|
||||
if child is MeshInstance3D and not bool(child.get_meta("tile_fx", false)):
|
||||
var mat: StandardMaterial3D = child.material_override as StandardMaterial3D
|
||||
if mat != null:
|
||||
mat.albedo_color = color
|
||||
|
||||
|
||||
func _make_outgoing_tile_snapshot(body: StaticBody3D) -> Node3D:
|
||||
var root: Node3D = Node3D.new()
|
||||
root.name = "OutgoingAffinityModel"
|
||||
root.set_meta("tile_fx", true)
|
||||
root.set_meta("tile_shader_fx", true)
|
||||
|
||||
for child in body.get_children():
|
||||
if child is CollisionShape3D or bool(child.get_meta("tile_fx", false)):
|
||||
continue
|
||||
var duplicate_child: Node = child.duplicate(Node.DUPLICATE_SIGNALS | Node.DUPLICATE_GROUPS | Node.DUPLICATE_SCRIPTS)
|
||||
if duplicate_child == null:
|
||||
continue
|
||||
root.add_child(duplicate_child)
|
||||
|
||||
if root.get_child_count() <= 0:
|
||||
root.queue_free()
|
||||
return null
|
||||
body.add_child(root)
|
||||
return root
|
||||
|
||||
|
||||
func _make_affinity_transition_mesh(color: Color) -> MeshInstance3D:
|
||||
var mi: MeshInstance3D = MeshInstance3D.new()
|
||||
if pathfinder.grid_type == "Hexagon":
|
||||
var hex_mesh: CylinderMesh = CylinderMesh.new()
|
||||
hex_mesh.height = 0.012
|
||||
hex_mesh.radial_segments = 6
|
||||
var radius: float = GameConstants.HEX_TILE_RADIUS * GameConstants.HEX_TILE_SPACING * 0.94
|
||||
hex_mesh.top_radius = radius
|
||||
hex_mesh.bottom_radius = radius
|
||||
mi.mesh = hex_mesh
|
||||
else:
|
||||
var box_mesh: BoxMesh = BoxMesh.new()
|
||||
box_mesh.size = Vector3(0.92, 0.012, 0.92)
|
||||
mi.mesh = box_mesh
|
||||
|
||||
var mat: ShaderMaterial = ShaderMaterial.new()
|
||||
mat.shader = _get_affinity_transition_shader()
|
||||
mat.set_shader_parameter("affinity_color", Color(color.r, color.g, color.b, 1.0))
|
||||
mat.set_shader_parameter("reveal", 0.0)
|
||||
mat.set_shader_parameter("alpha_scale", 0.0)
|
||||
mi.material_override = mat
|
||||
return mi
|
||||
|
||||
|
||||
func _get_affinity_transition_shader() -> Shader:
|
||||
if affinity_transition_shader != null:
|
||||
return affinity_transition_shader
|
||||
var shader: Shader = Shader.new()
|
||||
shader.code = """
|
||||
shader_type spatial;
|
||||
render_mode blend_mix, cull_disabled, unshaded;
|
||||
|
||||
uniform vec4 affinity_color : source_color = vec4(1.0, 0.85, 0.35, 1.0);
|
||||
uniform float reveal : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform float alpha_scale : hint_range(0.0, 1.0) = 1.0;
|
||||
|
||||
varying vec3 local_pos;
|
||||
|
||||
float hash21(vec2 p) {
|
||||
p = fract(p * vec2(123.34, 456.21));
|
||||
p += dot(p, p + 45.32);
|
||||
return fract(p.x * p.y);
|
||||
}
|
||||
|
||||
float value_noise(vec2 p) {
|
||||
vec2 i = floor(p);
|
||||
vec2 f = fract(p);
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
float a = hash21(i);
|
||||
float b = hash21(i + vec2(1.0, 0.0));
|
||||
float c = hash21(i + vec2(0.0, 1.0));
|
||||
float d = hash21(i + vec2(1.0, 1.0));
|
||||
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
local_pos = VERTEX;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 p = local_pos.xz * 5.5;
|
||||
float n = value_noise(p) * 0.62 + value_noise(p * 2.15 + vec2(7.1, 3.4)) * 0.38;
|
||||
float radial = smoothstep(0.74, 0.08, length(local_pos.xz));
|
||||
float threshold = clamp(reveal, 0.001, 0.999);
|
||||
if (n > threshold) {
|
||||
discard;
|
||||
}
|
||||
float edge = 1.0 - smoothstep(0.0, 0.11, abs(n - threshold));
|
||||
float body_alpha = alpha_scale * (0.28 + edge * 0.58) * radial;
|
||||
ALBEDO = affinity_color.rgb * (0.55 + edge * 0.45);
|
||||
EMISSION = affinity_color.rgb * (1.2 + edge * 3.8);
|
||||
ALPHA = body_alpha;
|
||||
}
|
||||
"""
|
||||
affinity_transition_shader = shader
|
||||
return affinity_transition_shader
|
||||
|
||||
|
||||
func _play_tile_materialize_shader(visual: Node, color: Color, duration: float) -> void:
|
||||
if not is_instance_valid(visual):
|
||||
return
|
||||
var surfaces: Array[Dictionary] = []
|
||||
_collect_tile_materialize_surfaces(visual, surfaces)
|
||||
if surfaces.is_empty():
|
||||
return
|
||||
|
||||
var reveal_mats: Array[ShaderMaterial] = []
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if not is_instance_valid(mi):
|
||||
continue
|
||||
var mat: ShaderMaterial = ShaderMaterial.new()
|
||||
mat.shader = _get_tile_materialize_shader()
|
||||
mat.set_shader_parameter("reveal", 0.0)
|
||||
mat.set_shader_parameter("team_color", Color(color.r, color.g, color.b, 1.0))
|
||||
mi.material_override = mat
|
||||
reveal_mats.append(mat)
|
||||
|
||||
var target_scale: Vector3 = Vector3.ONE
|
||||
var visual_3d: Node3D = visual as Node3D
|
||||
if visual_3d != null and not (visual_3d is StaticBody3D):
|
||||
target_scale = visual_3d.scale
|
||||
visual_3d.scale = target_scale * 0.96
|
||||
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
if visual_3d != null and not (visual_3d is StaticBody3D):
|
||||
tween.parallel().tween_property(visual_3d, "scale", target_scale, duration)
|
||||
tween.parallel().tween_method(func(value: float) -> void:
|
||||
for mat: ShaderMaterial in reveal_mats:
|
||||
if mat != null:
|
||||
mat.set_shader_parameter("reveal", value)
|
||||
, 0.0, 1.0, duration)
|
||||
tween.tween_callback(func() -> void:
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if is_instance_valid(mi):
|
||||
mi.material_override = entry["override"]
|
||||
)
|
||||
|
||||
|
||||
func _play_tile_dissolve_shader(visual: Node, color: Color, duration: float) -> void:
|
||||
if not is_instance_valid(visual):
|
||||
return
|
||||
var surfaces: Array[Dictionary] = []
|
||||
_collect_tile_materialize_surfaces(visual, surfaces)
|
||||
if surfaces.is_empty():
|
||||
return
|
||||
|
||||
var dissolve_mats: Array[ShaderMaterial] = []
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if not is_instance_valid(mi):
|
||||
continue
|
||||
var mat: ShaderMaterial = ShaderMaterial.new()
|
||||
mat.shader = _get_tile_materialize_shader()
|
||||
mat.set_shader_parameter("reveal", 1.0)
|
||||
mat.set_shader_parameter("team_color", Color(color.r, color.g, color.b, 1.0))
|
||||
mi.material_override = mat
|
||||
dissolve_mats.append(mat)
|
||||
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
tween.tween_method(func(value: float) -> void:
|
||||
for mat: ShaderMaterial in dissolve_mats:
|
||||
if mat != null:
|
||||
mat.set_shader_parameter("reveal", value)
|
||||
, 1.0, 0.0, duration)
|
||||
tween.tween_callback(func() -> void:
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if is_instance_valid(mi):
|
||||
mi.material_override = entry["override"]
|
||||
)
|
||||
|
||||
|
||||
func _collect_tile_materialize_surfaces(node: Node, surfaces: Array[Dictionary]) -> void:
|
||||
if bool(node.get_meta("tile_fx", false)) and not bool(node.get_meta("tile_shader_fx", false)):
|
||||
return
|
||||
if node is MeshInstance3D:
|
||||
var mi: MeshInstance3D = node as MeshInstance3D
|
||||
surfaces.append({
|
||||
"mesh_ref": weakref(mi),
|
||||
"override": mi.material_override
|
||||
})
|
||||
for child: Node in node.get_children():
|
||||
_collect_tile_materialize_surfaces(child, surfaces)
|
||||
|
||||
|
||||
func _get_tile_materialize_shader() -> Shader:
|
||||
if tile_materialize_shader != null:
|
||||
return tile_materialize_shader
|
||||
var shader: Shader = Shader.new()
|
||||
shader.code = """
|
||||
shader_type spatial;
|
||||
render_mode blend_mix, cull_disabled, depth_draw_opaque;
|
||||
|
||||
uniform float reveal : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform vec4 team_color : source_color = vec4(0.35, 0.5, 1.0, 1.0);
|
||||
|
||||
varying vec3 local_pos;
|
||||
|
||||
float hash13(vec3 p) {
|
||||
p = fract(p * 0.1031);
|
||||
p += dot(p, p.yzx + 33.33);
|
||||
return fract((p.x + p.y) * p.z);
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
local_pos = VERTEX;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec3 cell = floor((local_pos + vec3(0.0, TIME * 0.08, 0.0)) * 9.0);
|
||||
float bubble_noise = hash13(cell);
|
||||
float fine_noise = hash13(floor((local_pos + vec3(TIME * 0.12, 0.0, 0.0)) * 23.0));
|
||||
float threshold = clamp(reveal * 1.18 - 0.08, 0.0, 1.0);
|
||||
|
||||
if (bubble_noise > threshold) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float edge = 1.0 - smoothstep(0.0, 0.16, abs(bubble_noise - threshold));
|
||||
float shimmer = smoothstep(0.72, 1.0, fine_noise) * (1.0 - reveal * 0.45);
|
||||
vec3 dark_affinity = team_color.rgb * 0.12;
|
||||
vec3 final_tint = mix(team_color.rgb * 0.45, team_color.rgb, reveal);
|
||||
vec3 color = mix(dark_affinity, final_tint, smoothstep(0.25, 1.0, reveal));
|
||||
color += team_color.rgb * (edge * 1.8 + shimmer * 0.9);
|
||||
|
||||
ALBEDO = color;
|
||||
EMISSION = team_color.rgb * (edge * 1.5 + shimmer);
|
||||
ROUGHNESS = 0.35;
|
||||
ALPHA = 1.0;
|
||||
}
|
||||
"""
|
||||
tile_materialize_shader = shader
|
||||
return tile_materialize_shader
|
||||
|
||||
|
||||
func _make_affinity_motes(color: Color) -> CPUParticles3D:
|
||||
var particles: CPUParticles3D = CPUParticles3D.new()
|
||||
particles.name = "AffinityMotes"
|
||||
particles.amount = 80
|
||||
particles.lifetime = 0.8
|
||||
particles.one_shot = true
|
||||
particles.explosiveness = 0.7
|
||||
particles.randomness = 0.82
|
||||
particles.lifetime_randomness = 0.35
|
||||
particles.local_coords = true
|
||||
particles.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
|
||||
particles.emission_sphere_radius = 0.36
|
||||
particles.direction = Vector3.UP
|
||||
particles.spread = 110.0
|
||||
particles.gravity = Vector3(0.0, 0.05, 0.0)
|
||||
particles.initial_velocity_min = 0.04
|
||||
particles.initial_velocity_max = 0.42
|
||||
particles.scale_amount_min = 0.012
|
||||
particles.scale_amount_max = 0.045
|
||||
particles.color = Color(color.r, color.g, color.b, 0.82)
|
||||
|
||||
var mote_mesh: SphereMesh = SphereMesh.new()
|
||||
mote_mesh.radius = 0.035
|
||||
mote_mesh.height = 0.07
|
||||
mote_mesh.radial_segments = 10
|
||||
mote_mesh.rings = 5
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.72)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = Color(color.r, color.g, color.b)
|
||||
mat.emission_energy_multiplier = 2.6
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mote_mesh.material = mat
|
||||
particles.mesh = mote_mesh
|
||||
return particles
|
||||
|
||||
@@ -570,6 +570,13 @@ func play_damage_animations(state: Dictionary) -> bool:
|
||||
for iid: String in dying_iids:
|
||||
show_hitsplats_once(hitsplats_shown, iid, int(defense_hits.get(iid, 0)), int(health_hits.get(iid, 0)))
|
||||
play_unit_anim(iid, "dying")
|
||||
var death_iid: String = iid
|
||||
var death_anim_time: float = unit_action_duration(death_iid, "dying", 0.85)
|
||||
var dissolve_delay: float = clampf(death_anim_time * 0.62, 0.45, 0.95)
|
||||
var death_fx_tween: Tween = create_tween()
|
||||
death_fx_tween.tween_callback(func() -> void:
|
||||
mesh_builder.play_dissolve_effect(death_iid)
|
||||
).set_delay(dissolve_delay)
|
||||
SFX.play(sfx_for_unit(iid, "deathSoundUrl"))
|
||||
|
||||
return true
|
||||
|
||||
@@ -28,6 +28,10 @@ var oneshot_callbacks: Dictionary = {} # iid → Callable (animation_finished
|
||||
var model_base_angles: Dictionary = {} # iid → float (base facing angle, radians)
|
||||
var needs_face_rot: Dictionary = {} # iid → bool (team-based 180° flip flag)
|
||||
var unit_model_retries: Dictionary = {} # iid → int (attempt number, 1-based, capped at 10)
|
||||
var turn_glows: Dictionary = {} # iid → CPUParticles3D
|
||||
var turn_glow_rings: Dictionary = {} # iid → MeshInstance3D
|
||||
var materialize_until: Dictionary = {} # iid → Time.get_ticks_msec deadline
|
||||
var unit_owner_ids: Dictionary = {} # iid → accountId
|
||||
|
||||
# ── Incremental rebuild ───────────────────────────────────────────────────────
|
||||
|
||||
@@ -74,17 +78,48 @@ func rebuild_units(state: Dictionary) -> void:
|
||||
var iid: String = str(unit.get("instanceId", ""))
|
||||
if iid.is_empty():
|
||||
continue
|
||||
desired[iid] = {"unit": unit, "color": color, "is_enemy": is_enemy}
|
||||
desired[iid] = {
|
||||
"unit": unit,
|
||||
"color": color,
|
||||
"is_enemy": is_enemy,
|
||||
"owner_id": pid,
|
||||
"card_type": str(unit.get("cardType", ""))
|
||||
}
|
||||
unit_owner_ids[iid] = pid
|
||||
|
||||
# 2. Remove units that are no longer on the board.
|
||||
var arch_replacements: Dictionary = {}
|
||||
for iid: String in desired:
|
||||
var d: Dictionary = desired[iid] as Dictionary
|
||||
if unit_bodies.has(iid):
|
||||
continue
|
||||
if str(d.get("card_type", "")) != "ArchSpirit":
|
||||
continue
|
||||
var owner_id: String = str(d.get("owner_id", ""))
|
||||
if not owner_id.is_empty():
|
||||
arch_replacements[owner_id] = iid
|
||||
|
||||
var to_remove: Array[String] = []
|
||||
for iid: String in unit_bodies:
|
||||
if not desired.has(iid):
|
||||
to_remove.append(iid)
|
||||
for iid: String in to_remove:
|
||||
var body: StaticBody3D = unit_bodies[iid] as StaticBody3D
|
||||
var owner_id: String = str(body.get_meta("owner_id", "")) if is_instance_valid(body) else str(unit_owner_ids.get(iid, ""))
|
||||
if owner_id.is_empty():
|
||||
owner_id = str(unit_owner_ids.get(iid, ""))
|
||||
var card_type: String = str(body.get_meta("card_type", "")) if is_instance_valid(body) else ""
|
||||
var is_ascend_departure: bool = card_type == "ArchSpirit" and arch_replacements.has(owner_id)
|
||||
if is_instance_valid(body):
|
||||
body.queue_free()
|
||||
if is_ascend_departure:
|
||||
play_ascend_departure_effect(iid)
|
||||
body.set_meta("unit_id", "")
|
||||
get_tree().create_timer(1.55).timeout.connect(func() -> void:
|
||||
if is_instance_valid(body):
|
||||
body.queue_free()
|
||||
, CONNECT_ONE_SHOT)
|
||||
else:
|
||||
body.queue_free()
|
||||
unit_bodies.erase(iid)
|
||||
unit_meshes.erase(iid)
|
||||
anim_players.erase(iid)
|
||||
@@ -96,12 +131,25 @@ func rebuild_units(state: Dictionary) -> void:
|
||||
needs_face_rot.erase(iid)
|
||||
unit_registry.unit_team_idx.erase(iid)
|
||||
unit_model_retries.erase(iid)
|
||||
turn_glows.erase(iid)
|
||||
turn_glow_rings.erase(iid)
|
||||
materialize_until.erase(iid)
|
||||
unit_owner_ids.erase(iid)
|
||||
|
||||
# 3. Add units not yet present (newly played, or first render after connect).
|
||||
for iid: String in desired:
|
||||
if not unit_bodies.has(iid):
|
||||
var d: Dictionary = desired[iid] as Dictionary
|
||||
add_unit_mesh(d["unit"] as Dictionary, d["color"] as Color, d["is_enemy"] as bool)
|
||||
var owner_id: String = str(d.get("owner_id", ""))
|
||||
var is_ascend_arrival: bool = str(d.get("card_type", "")) == "ArchSpirit" \
|
||||
and arch_replacements.get(owner_id, "") == iid
|
||||
add_unit_mesh(
|
||||
d["unit"] as Dictionary,
|
||||
d["color"] as Color,
|
||||
d["is_enemy"] as bool,
|
||||
is_ascend_arrival)
|
||||
|
||||
_sync_turn_glows(desired, state)
|
||||
|
||||
# 4. Refresh idle rotation for all units — nearest enemy may have changed.
|
||||
for iid: String in unit_meshes:
|
||||
@@ -112,7 +160,8 @@ func rebuild_units(state: Dictionary) -> void:
|
||||
m.rotation.y = idle_rotation(iid)
|
||||
|
||||
|
||||
func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false) -> void:
|
||||
func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false,
|
||||
ascend_arrival: bool = false) -> void:
|
||||
var pd: Dictionary = unit.get("position", {})
|
||||
if pd.is_empty():
|
||||
return
|
||||
@@ -124,9 +173,15 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
||||
var card_type: String = unit.get("cardType", "Spirit")
|
||||
var iid: String = unit.get("instanceId", "")
|
||||
var exhausted: bool = unit.get("isExhausted", false)
|
||||
var owner_id: String = _owner_id_for_unit(iid, Game.state)
|
||||
|
||||
var body: StaticBody3D = StaticBody3D.new()
|
||||
body.set_meta("unit_id", iid)
|
||||
body.set_meta("owner_id", owner_id)
|
||||
body.set_meta("card_type", card_type)
|
||||
body.set_meta("team_color", team_color)
|
||||
if not owner_id.is_empty():
|
||||
unit_owner_ids[iid] = owner_id
|
||||
|
||||
var shape: CollisionShape3D = CollisionShape3D.new()
|
||||
var mi: MeshInstance3D = MeshInstance3D.new()
|
||||
@@ -176,6 +231,12 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
||||
units_root.add_child(body)
|
||||
unit_meshes[iid] = mi
|
||||
unit_bodies[iid] = body
|
||||
if card_type != "Ruin":
|
||||
materialize_until[iid] = Time.get_ticks_msec() + 1800
|
||||
if ascend_arrival:
|
||||
_play_ascend_arrival_effect(body, mi, above_tile, team_color)
|
||||
else:
|
||||
_play_materialize_effect(body, mi, above_tile, team_color)
|
||||
|
||||
# ── Try to load the real 3D model from the card definition ──────────────
|
||||
var def_id: String = str(unit.get("cardDefinitionId", ""))
|
||||
@@ -223,13 +284,15 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
||||
return
|
||||
|
||||
# Remove the placeholder MeshInstance3D.
|
||||
var placeholder: Node3D = unit_meshes.get(iid) as Node3D
|
||||
for child in b.get_children():
|
||||
if child is MeshInstance3D:
|
||||
if child == placeholder:
|
||||
child.queue_free()
|
||||
|
||||
# Apply uniform scale if configured.
|
||||
var target_scale: Vector3 = Vector3.ONE * model_scale
|
||||
if not is_equal_approx(model_scale, 1.0):
|
||||
model_node.scale = Vector3.ONE * model_scale
|
||||
model_node.scale = target_scale
|
||||
|
||||
# Facing config was already stored above; no need to repeat.
|
||||
|
||||
@@ -248,17 +311,607 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
||||
# body-local Y=0 is the tile top; feet target = -above_tile.
|
||||
var m_aabb: AABB = model_local_aabb(model_node)
|
||||
if m_aabb.size != Vector3.ZERO:
|
||||
model_node.position.y = -above_tile - model_node.scale.y * m_aabb.position.y
|
||||
model_node.position.y = -above_tile - target_scale.y * m_aabb.position.y
|
||||
unit_meshes[iid] = model_node
|
||||
if Time.get_ticks_msec() <= int(materialize_until.get(iid, 0)):
|
||||
if ascend_arrival:
|
||||
_play_ascend_arrival_shader(model_node, team_color)
|
||||
else:
|
||||
_play_materialize_shader(model_node, team_color)
|
||||
|
||||
# Find and store the AnimationPlayer, then start the Idle loop.
|
||||
var ap: AnimationPlayer = find_animation_player(model_node)
|
||||
anim_players[iid] = ap
|
||||
if ap != null:
|
||||
_request_play_anim(iid, "idle", true)
|
||||
materialize_until.erase(iid)
|
||||
, model_etag)
|
||||
|
||||
|
||||
func _sync_turn_glows(desired: Dictionary, state: Dictionary) -> void:
|
||||
var active_id: String = str(state.get("activePlayerAccountId", "")).to_lower()
|
||||
var phase: String = str(state.get("phase", ""))
|
||||
var show_glows: bool = not active_id.is_empty() and phase != "Placement" and phase != "GameOver"
|
||||
|
||||
for iid: String in desired:
|
||||
var d: Dictionary = desired[iid] as Dictionary
|
||||
var unit: Dictionary = d.get("unit", {}) as Dictionary
|
||||
var owner_id: String = str(unit.get("ownerAccountId", "")).to_lower()
|
||||
if owner_id.is_empty():
|
||||
owner_id = _owner_id_for_unit(iid, state)
|
||||
var is_ruin: bool = str(unit.get("cardType", "")).to_lower() == "ruin"
|
||||
var should_show: bool = show_glows and owner_id == active_id and not is_ruin
|
||||
if should_show:
|
||||
var glow_color: Color = d.get("color", Color.WHITE)
|
||||
_ensure_turn_glow(iid, glow_color)
|
||||
else:
|
||||
_clear_turn_glow(iid)
|
||||
|
||||
var stale_ids: Array[String] = []
|
||||
for iid: String in turn_glows:
|
||||
if not desired.has(iid):
|
||||
stale_ids.append(iid)
|
||||
for iid: String in stale_ids:
|
||||
_clear_turn_glow(iid)
|
||||
|
||||
|
||||
func _owner_id_for_unit(iid: String, state: Dictionary) -> String:
|
||||
for player: Dictionary in state.get("players", []):
|
||||
var account_id: String = str(player.get("accountId", "")).to_lower()
|
||||
var arch: Dictionary = unit_registry.safe_arch(player)
|
||||
if str(arch.get("instanceId", "")) == iid:
|
||||
return account_id
|
||||
for unit: Dictionary in player.get("field", []):
|
||||
if str(unit.get("instanceId", "")) == iid:
|
||||
return account_id
|
||||
return ""
|
||||
|
||||
|
||||
func _ensure_turn_glow(iid: String, color: Color) -> void:
|
||||
var body: StaticBody3D = unit_bodies.get(iid) as StaticBody3D
|
||||
if not is_instance_valid(body):
|
||||
return
|
||||
|
||||
var ring: MeshInstance3D = turn_glow_rings.get(iid) as MeshInstance3D
|
||||
if not is_instance_valid(ring):
|
||||
ring = _make_turn_glow_ring(color)
|
||||
body.add_child(ring)
|
||||
turn_glow_rings[iid] = ring
|
||||
else:
|
||||
var ring_mat: StandardMaterial3D = ring.material_override as StandardMaterial3D
|
||||
if ring_mat != null:
|
||||
ring_mat.albedo_color = Color(color.r, color.g, color.b, 0.16)
|
||||
ring_mat.emission = Color(color.r, color.g, color.b)
|
||||
|
||||
var particles: CPUParticles3D = turn_glows.get(iid) as CPUParticles3D
|
||||
if not is_instance_valid(particles):
|
||||
particles = _make_turn_glow_particles(color)
|
||||
body.add_child(particles)
|
||||
turn_glows[iid] = particles
|
||||
else:
|
||||
particles.color = Color(color.r, color.g, color.b, 0.58)
|
||||
var dot_mesh: SphereMesh = particles.mesh as SphereMesh
|
||||
if dot_mesh != null:
|
||||
var mat: StandardMaterial3D = dot_mesh.material as StandardMaterial3D
|
||||
if mat != null:
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.48)
|
||||
mat.emission = Color(color.r, color.g, color.b)
|
||||
|
||||
var above_tile: float = float(body.get_meta("above_tile", 0.28))
|
||||
ring.position = Vector3(0.0, -above_tile + 0.045, 0.0)
|
||||
particles.position = Vector3(0.0, -above_tile + 0.18, 0.0)
|
||||
particles.emitting = true
|
||||
|
||||
|
||||
func _clear_turn_glow(iid: String) -> void:
|
||||
var particles: CPUParticles3D = turn_glows.get(iid) as CPUParticles3D
|
||||
if is_instance_valid(particles):
|
||||
particles.queue_free()
|
||||
turn_glows.erase(iid)
|
||||
var ring: MeshInstance3D = turn_glow_rings.get(iid) as MeshInstance3D
|
||||
if is_instance_valid(ring):
|
||||
ring.queue_free()
|
||||
turn_glow_rings.erase(iid)
|
||||
|
||||
|
||||
func _make_turn_glow_particles(color: Color) -> CPUParticles3D:
|
||||
var particles: CPUParticles3D = CPUParticles3D.new()
|
||||
particles.name = "TurnGlow"
|
||||
particles.amount = 90
|
||||
particles.lifetime = 2.6
|
||||
particles.preprocess = 2.6
|
||||
particles.randomness = 0.82
|
||||
particles.lifetime_randomness = 0.42
|
||||
particles.local_coords = true
|
||||
particles.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
|
||||
particles.emission_sphere_radius = 0.72
|
||||
particles.direction = Vector3.UP
|
||||
particles.spread = 48.0
|
||||
particles.gravity = Vector3(0.0, 0.035, 0.0)
|
||||
particles.initial_velocity_min = 0.035
|
||||
particles.initial_velocity_max = 0.16
|
||||
particles.scale_amount_min = 0.045
|
||||
particles.scale_amount_max = 0.16
|
||||
particles.color = Color(color.r, color.g, color.b, 0.58)
|
||||
|
||||
var dot_mesh: SphereMesh = SphereMesh.new()
|
||||
dot_mesh.radius = 0.08
|
||||
dot_mesh.height = 0.16
|
||||
dot_mesh.radial_segments = 12
|
||||
dot_mesh.rings = 6
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.48)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = Color(color.r, color.g, color.b)
|
||||
mat.emission_energy_multiplier = 2.2
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
dot_mesh.material = mat
|
||||
particles.mesh = dot_mesh
|
||||
return particles
|
||||
|
||||
|
||||
func _make_turn_glow_ring(color: Color) -> MeshInstance3D:
|
||||
var ring: MeshInstance3D = MeshInstance3D.new()
|
||||
ring.name = "TurnGlowRing"
|
||||
var mesh: CylinderMesh = CylinderMesh.new()
|
||||
mesh.top_radius = 0.37
|
||||
mesh.bottom_radius = 0.37
|
||||
mesh.height = 0.012
|
||||
mesh.radial_segments = 40
|
||||
ring.mesh = mesh
|
||||
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.16)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = Color(color.r, color.g, color.b)
|
||||
mat.emission_energy_multiplier = 1.25
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
ring.material_override = mat
|
||||
return ring
|
||||
|
||||
|
||||
func _play_materialize_effect(body: StaticBody3D, visual: Node3D,
|
||||
above_tile: float, team_color: Color) -> void:
|
||||
_play_materialize_shader(visual, team_color)
|
||||
|
||||
var dark_bubbles: CPUParticles3D = _make_materialize_bubbles(team_color, true)
|
||||
dark_bubbles.position = Vector3(0.0, -above_tile + 0.18, 0.0)
|
||||
body.add_child(dark_bubbles)
|
||||
dark_bubbles.emitting = true
|
||||
|
||||
var sparks: CPUParticles3D = _make_materialize_bubbles(team_color, false)
|
||||
sparks.position = Vector3(0.0, -above_tile + 0.12, 0.0)
|
||||
body.add_child(sparks)
|
||||
sparks.emitting = true
|
||||
|
||||
get_tree().create_timer(2.4).timeout.connect(func() -> void:
|
||||
if is_instance_valid(dark_bubbles):
|
||||
dark_bubbles.queue_free()
|
||||
if is_instance_valid(sparks):
|
||||
sparks.queue_free()
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func play_dissolve_effect(iid: String) -> void:
|
||||
var body: StaticBody3D = unit_bodies.get(iid) as StaticBody3D
|
||||
var visual: Node3D = unit_meshes.get(iid) as Node3D
|
||||
if not is_instance_valid(body) or not is_instance_valid(visual):
|
||||
return
|
||||
|
||||
_clear_turn_glow(iid)
|
||||
var team_color: Color = _team_color_for_unit(iid)
|
||||
var above_tile: float = float(body.get_meta("above_tile", 0.28))
|
||||
_play_dissolve_shader(visual, team_color)
|
||||
|
||||
var burst: CPUParticles3D = _make_dissolve_burst(team_color, true)
|
||||
burst.position = Vector3(0.0, -above_tile + 0.25, 0.0)
|
||||
body.add_child(burst)
|
||||
|
||||
var sparks: CPUParticles3D = _make_dissolve_burst(team_color, false)
|
||||
sparks.position = Vector3(0.0, -above_tile + 0.2, 0.0)
|
||||
body.add_child(sparks)
|
||||
|
||||
get_tree().create_timer(0.48).timeout.connect(func() -> void:
|
||||
if is_instance_valid(burst):
|
||||
burst.emitting = true
|
||||
if is_instance_valid(sparks):
|
||||
sparks.emitting = true
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
get_tree().create_timer(1.18).timeout.connect(func() -> void:
|
||||
if is_instance_valid(burst):
|
||||
burst.queue_free()
|
||||
if is_instance_valid(sparks):
|
||||
sparks.queue_free()
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func play_ascend_departure_effect(iid: String) -> void:
|
||||
var body: StaticBody3D = unit_bodies.get(iid) as StaticBody3D
|
||||
var visual: Node3D = unit_meshes.get(iid) as Node3D
|
||||
if not is_instance_valid(body) or not is_instance_valid(visual):
|
||||
return
|
||||
|
||||
_clear_turn_glow(iid)
|
||||
var team_color: Color = _team_color_for_unit(iid)
|
||||
var ascend_color: Color = _ascend_color(team_color)
|
||||
var above_tile: float = float(body.get_meta("above_tile", 0.4))
|
||||
_play_dissolve_shader_timed(visual, ascend_color, 1.05)
|
||||
|
||||
var beams: Node3D = _make_ascend_beams(ascend_color)
|
||||
beams.position = Vector3(0.0, -above_tile + 1.1, 0.0)
|
||||
body.add_child(beams)
|
||||
|
||||
var motes: CPUParticles3D = _make_ascend_particles(team_color, true)
|
||||
motes.position = Vector3(0.0, -above_tile + 0.35, 0.0)
|
||||
body.add_child(motes)
|
||||
motes.emitting = true
|
||||
|
||||
get_tree().create_timer(1.45).timeout.connect(func() -> void:
|
||||
if is_instance_valid(beams):
|
||||
beams.queue_free()
|
||||
if is_instance_valid(motes):
|
||||
motes.queue_free()
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func _play_ascend_arrival_effect(body: StaticBody3D, visual: Node3D,
|
||||
above_tile: float, team_color: Color) -> void:
|
||||
var ascend_color: Color = _ascend_color(team_color)
|
||||
_play_ascend_arrival_shader(visual, team_color)
|
||||
|
||||
var beams: Node3D = _make_ascend_beams(ascend_color)
|
||||
beams.position = Vector3(0.0, -above_tile + 1.1, 0.0)
|
||||
body.add_child(beams)
|
||||
|
||||
var motes: CPUParticles3D = _make_ascend_particles(team_color, false)
|
||||
motes.position = Vector3(0.0, -above_tile + 0.2, 0.0)
|
||||
body.add_child(motes)
|
||||
motes.emitting = true
|
||||
|
||||
get_tree().create_timer(2.25).timeout.connect(func() -> void:
|
||||
if is_instance_valid(beams):
|
||||
beams.queue_free()
|
||||
if is_instance_valid(motes):
|
||||
motes.queue_free()
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func _play_ascend_arrival_shader(visual: Node3D, team_color: Color) -> void:
|
||||
_play_materialize_shader_timed(visual, _ascend_color(team_color), 1.35)
|
||||
|
||||
|
||||
func _play_materialize_shader(visual: Node3D, team_color: Color) -> void:
|
||||
_play_materialize_shader_timed(visual, team_color, 0.95)
|
||||
|
||||
|
||||
func _play_materialize_shader_timed(visual: Node3D, team_color: Color, duration: float) -> void:
|
||||
if not is_instance_valid(visual):
|
||||
return
|
||||
var surfaces: Array[Dictionary] = []
|
||||
_collect_materialize_surfaces(visual, surfaces)
|
||||
if surfaces.is_empty():
|
||||
return
|
||||
|
||||
var reveal_mats: Array[ShaderMaterial] = []
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if not is_instance_valid(mi):
|
||||
continue
|
||||
var mat: ShaderMaterial = ShaderMaterial.new()
|
||||
mat.shader = _materialize_shader()
|
||||
mat.set_shader_parameter("reveal", 0.0)
|
||||
mat.set_shader_parameter("team_color", Color(team_color.r, team_color.g, team_color.b, 1.0))
|
||||
mi.material_override = mat
|
||||
reveal_mats.append(mat)
|
||||
|
||||
var target_scale: Vector3 = visual.scale
|
||||
visual.scale = target_scale * 0.92
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.parallel().tween_property(visual, "scale", target_scale, duration)
|
||||
tween.parallel().tween_method(func(v: float) -> void:
|
||||
for mat: ShaderMaterial in reveal_mats:
|
||||
if mat != null:
|
||||
mat.set_shader_parameter("reveal", v)
|
||||
, 0.0, 1.0, duration)
|
||||
tween.tween_callback(func() -> void:
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if is_instance_valid(mi):
|
||||
mi.material_override = entry["override"]
|
||||
)
|
||||
|
||||
|
||||
func _play_dissolve_shader(visual: Node3D, team_color: Color) -> void:
|
||||
_play_dissolve_shader_timed(visual, team_color, 0.72)
|
||||
|
||||
|
||||
func _play_dissolve_shader_timed(visual: Node3D, team_color: Color, duration: float) -> void:
|
||||
if not is_instance_valid(visual):
|
||||
return
|
||||
var surfaces: Array[Dictionary] = []
|
||||
_collect_materialize_surfaces(visual, surfaces)
|
||||
if surfaces.is_empty():
|
||||
return
|
||||
|
||||
var dissolve_mats: Array[ShaderMaterial] = []
|
||||
for entry: Dictionary in surfaces:
|
||||
var mesh_ref: WeakRef = entry["mesh_ref"] as WeakRef
|
||||
var mi: MeshInstance3D = mesh_ref.get_ref() as MeshInstance3D if mesh_ref != null else null
|
||||
if not is_instance_valid(mi):
|
||||
continue
|
||||
var mat: ShaderMaterial = ShaderMaterial.new()
|
||||
mat.shader = _materialize_shader()
|
||||
mat.set_shader_parameter("reveal", 1.0)
|
||||
mat.set_shader_parameter("team_color", Color(team_color.r, team_color.g, team_color.b, 1.0))
|
||||
mi.material_override = mat
|
||||
dissolve_mats.append(mat)
|
||||
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
tween.tween_method(func(v: float) -> void:
|
||||
for mat: ShaderMaterial in dissolve_mats:
|
||||
if mat != null:
|
||||
mat.set_shader_parameter("reveal", v)
|
||||
, 1.0, 0.0, duration)
|
||||
|
||||
|
||||
func _collect_materialize_surfaces(node: Node, surfaces: Array[Dictionary]) -> void:
|
||||
if node is MeshInstance3D:
|
||||
var mi: MeshInstance3D = node as MeshInstance3D
|
||||
surfaces.append({
|
||||
"mesh_ref": weakref(mi),
|
||||
"override": mi.material_override
|
||||
})
|
||||
for child: Node in node.get_children():
|
||||
_collect_materialize_surfaces(child, surfaces)
|
||||
|
||||
|
||||
func _materialize_shader() -> Shader:
|
||||
if has_meta("_materialize_shader"):
|
||||
return get_meta("_materialize_shader") as Shader
|
||||
var shader: Shader = Shader.new()
|
||||
shader.code = """
|
||||
shader_type spatial;
|
||||
render_mode blend_mix, cull_disabled, depth_draw_opaque;
|
||||
|
||||
uniform float reveal : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform vec4 team_color : source_color = vec4(0.35, 0.5, 1.0, 1.0);
|
||||
|
||||
varying vec3 local_pos;
|
||||
|
||||
float hash13(vec3 p) {
|
||||
p = fract(p * 0.1031);
|
||||
p += dot(p, p.yzx + 33.33);
|
||||
return fract((p.x + p.y) * p.z);
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
local_pos = VERTEX;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec3 cell = floor((local_pos + vec3(0.0, TIME * 0.08, 0.0)) * 9.0);
|
||||
float bubble_noise = hash13(cell);
|
||||
float fine_noise = hash13(floor((local_pos + vec3(TIME * 0.12, 0.0, 0.0)) * 23.0));
|
||||
float threshold = clamp(reveal * 1.18 - 0.08, 0.0, 1.0);
|
||||
|
||||
if (bubble_noise > threshold) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float edge = 1.0 - smoothstep(0.0, 0.16, abs(bubble_noise - threshold));
|
||||
float shimmer = smoothstep(0.72, 1.0, fine_noise) * (1.0 - reveal * 0.45);
|
||||
vec3 black_bubble = vec3(0.012, 0.010, 0.018);
|
||||
vec3 final_tint = mix(team_color.rgb * 0.35, team_color.rgb, reveal);
|
||||
vec3 color = mix(black_bubble, final_tint, smoothstep(0.25, 1.0, reveal));
|
||||
color += team_color.rgb * (edge * 1.8 + shimmer * 0.9);
|
||||
|
||||
ALBEDO = color;
|
||||
EMISSION = team_color.rgb * (edge * 1.5 + shimmer);
|
||||
ROUGHNESS = 0.35;
|
||||
ALPHA = 1.0;
|
||||
}
|
||||
"""
|
||||
set_meta("_materialize_shader", shader)
|
||||
return shader
|
||||
|
||||
|
||||
func _ascend_color(team_color: Color) -> Color:
|
||||
return team_color.lerp(Color(1.0, 0.78, 0.22), 0.68).lightened(0.1)
|
||||
|
||||
|
||||
func _make_ascend_particles(team_color: Color, outgoing: bool) -> CPUParticles3D:
|
||||
var ascend_color: Color = _ascend_color(team_color)
|
||||
var particles: CPUParticles3D = CPUParticles3D.new()
|
||||
particles.name = "AscendRadianceOut" if outgoing else "AscendRadianceIn"
|
||||
particles.amount = 210 if outgoing else 260
|
||||
particles.lifetime = 1.45 if outgoing else 2.0
|
||||
particles.preprocess = 0.12
|
||||
particles.randomness = 0.86
|
||||
particles.lifetime_randomness = 0.38
|
||||
particles.local_coords = true
|
||||
particles.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
|
||||
particles.emission_sphere_radius = 0.5 if outgoing else 0.85
|
||||
particles.direction = Vector3.UP
|
||||
particles.spread = 130.0 if outgoing else 64.0
|
||||
particles.gravity = Vector3(0.0, 0.12, 0.0)
|
||||
particles.initial_velocity_min = 0.2 if outgoing else 0.04
|
||||
particles.initial_velocity_max = 1.15 if outgoing else 0.42
|
||||
particles.scale_amount_min = 0.018
|
||||
particles.scale_amount_max = 0.09 if outgoing else 0.12
|
||||
particles.color = Color(ascend_color.r, ascend_color.g, ascend_color.b, 0.92)
|
||||
|
||||
var mote_mesh: SphereMesh = SphereMesh.new()
|
||||
mote_mesh.radius = 0.045 if outgoing else 0.055
|
||||
mote_mesh.height = 0.09 if outgoing else 0.11
|
||||
mote_mesh.radial_segments = 12
|
||||
mote_mesh.rings = 6
|
||||
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(ascend_color.r, ascend_color.g, ascend_color.b, 0.78)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = Color(ascend_color.r, ascend_color.g, ascend_color.b)
|
||||
mat.emission_energy_multiplier = 4.0 if outgoing else 3.2
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mote_mesh.material = mat
|
||||
particles.mesh = mote_mesh
|
||||
return particles
|
||||
|
||||
|
||||
func _make_ascend_beams(color: Color) -> Node3D:
|
||||
var root: Node3D = Node3D.new()
|
||||
root.name = "AscendLightBeams"
|
||||
for i: int in 4:
|
||||
var beam: MeshInstance3D = MeshInstance3D.new()
|
||||
var mesh: CylinderMesh = CylinderMesh.new()
|
||||
mesh.top_radius = 0.018
|
||||
mesh.bottom_radius = 0.035
|
||||
mesh.height = 2.8
|
||||
mesh.radial_segments = 10
|
||||
beam.mesh = mesh
|
||||
var angle: float = (TAU / 4.0) * float(i)
|
||||
beam.position = Vector3(cos(angle) * 0.24, 0.0, sin(angle) * 0.24)
|
||||
beam.rotation.z = 0.08 * (-1.0 if i % 2 == 0 else 1.0)
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.2)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = Color(color.r, color.g, color.b)
|
||||
mat.emission_energy_multiplier = 2.4
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
beam.material_override = mat
|
||||
root.add_child(beam)
|
||||
|
||||
var light: OmniLight3D = OmniLight3D.new()
|
||||
light.light_color = Color(color.r, color.g, color.b)
|
||||
light.light_energy = 1.6
|
||||
light.omni_range = 3.0
|
||||
root.add_child(light)
|
||||
return root
|
||||
|
||||
|
||||
func _make_materialize_bubbles(team_color: Color, dark: bool) -> CPUParticles3D:
|
||||
var particles: CPUParticles3D = CPUParticles3D.new()
|
||||
particles.name = "MaterializeDarkBubbles" if dark else "MaterializeSparks"
|
||||
particles.amount = 130 if dark else 70
|
||||
particles.lifetime = 1.25 if dark else 0.9
|
||||
particles.preprocess = 0.08
|
||||
particles.randomness = 0.9
|
||||
particles.lifetime_randomness = 0.45
|
||||
particles.local_coords = true
|
||||
particles.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
|
||||
particles.emission_sphere_radius = 0.82 if dark else 0.62
|
||||
particles.direction = Vector3.UP
|
||||
particles.spread = 145.0 if dark else 80.0
|
||||
particles.gravity = Vector3(0.0, 0.05, 0.0)
|
||||
particles.initial_velocity_min = 0.03 if dark else 0.18
|
||||
particles.initial_velocity_max = 0.22 if dark else 0.42
|
||||
particles.scale_amount_min = 0.05 if dark else 0.015
|
||||
particles.scale_amount_max = 0.18 if dark else 0.055
|
||||
if dark:
|
||||
particles.color = Color(0.02, 0.018, 0.026, 0.78)
|
||||
else:
|
||||
particles.color = Color(team_color.r, team_color.g, team_color.b, 0.82)
|
||||
|
||||
var bubble_mesh: SphereMesh = SphereMesh.new()
|
||||
bubble_mesh.radius = 0.075 if dark else 0.035
|
||||
bubble_mesh.height = 0.15 if dark else 0.07
|
||||
bubble_mesh.radial_segments = 12
|
||||
bubble_mesh.rings = 6
|
||||
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
if dark:
|
||||
mat.albedo_color = Color(0.015, 0.012, 0.02, 0.62)
|
||||
mat.emission = Color(
|
||||
maxf(team_color.r * 0.18, 0.025),
|
||||
maxf(team_color.g * 0.18, 0.025),
|
||||
maxf(team_color.b * 0.18, 0.035))
|
||||
mat.emission_energy_multiplier = 0.75
|
||||
else:
|
||||
mat.albedo_color = Color(team_color.r, team_color.g, team_color.b, 0.7)
|
||||
mat.emission = Color(team_color.r, team_color.g, team_color.b)
|
||||
mat.emission_energy_multiplier = 2.6
|
||||
mat.emission_enabled = true
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
bubble_mesh.material = mat
|
||||
particles.mesh = bubble_mesh
|
||||
return particles
|
||||
|
||||
|
||||
func _make_dissolve_burst(team_color: Color, dark: bool) -> CPUParticles3D:
|
||||
var particles: CPUParticles3D = CPUParticles3D.new()
|
||||
particles.name = "DissolveBubbleBurst" if dark else "DissolveColorSparks"
|
||||
particles.amount = 150 if dark else 90
|
||||
particles.lifetime = 0.7 if dark else 0.52
|
||||
particles.preprocess = 0.0
|
||||
particles.one_shot = true
|
||||
particles.explosiveness = 0.95
|
||||
particles.randomness = 0.92
|
||||
particles.lifetime_randomness = 0.35
|
||||
particles.local_coords = true
|
||||
particles.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
|
||||
particles.emission_sphere_radius = 0.34 if dark else 0.22
|
||||
particles.direction = Vector3.UP
|
||||
particles.spread = 180.0
|
||||
particles.gravity = Vector3(0.0, 0.03, 0.0)
|
||||
particles.initial_velocity_min = 0.42 if dark else 0.58
|
||||
particles.initial_velocity_max = 1.25 if dark else 1.55
|
||||
particles.scale_amount_min = 0.035 if dark else 0.015
|
||||
particles.scale_amount_max = 0.16 if dark else 0.055
|
||||
if dark:
|
||||
particles.color = Color(0.015, 0.012, 0.02, 0.82)
|
||||
else:
|
||||
particles.color = Color(team_color.r, team_color.g, team_color.b, 0.9)
|
||||
|
||||
var bubble_mesh: SphereMesh = SphereMesh.new()
|
||||
bubble_mesh.radius = 0.07 if dark else 0.035
|
||||
bubble_mesh.height = 0.14 if dark else 0.07
|
||||
bubble_mesh.radial_segments = 12
|
||||
bubble_mesh.rings = 6
|
||||
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
if dark:
|
||||
mat.albedo_color = Color(0.012, 0.01, 0.018, 0.66)
|
||||
mat.emission = Color(
|
||||
maxf(team_color.r * 0.2, 0.03),
|
||||
maxf(team_color.g * 0.2, 0.03),
|
||||
maxf(team_color.b * 0.2, 0.04))
|
||||
mat.emission_energy_multiplier = 0.9
|
||||
else:
|
||||
mat.albedo_color = Color(team_color.r, team_color.g, team_color.b, 0.76)
|
||||
mat.emission = Color(team_color.r, team_color.g, team_color.b)
|
||||
mat.emission_energy_multiplier = 3.0
|
||||
mat.emission_enabled = true
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
bubble_mesh.material = mat
|
||||
particles.mesh = bubble_mesh
|
||||
return particles
|
||||
|
||||
|
||||
func _team_color_for_unit(iid: String) -> Color:
|
||||
var team_idx: int = int(unit_registry.unit_team_idx.get(iid, -1))
|
||||
var team_colors: Dictionary = Game.state.get("teamColors", {})
|
||||
var hex_str: String = str(team_colors.get(str(team_idx), ""))
|
||||
if not hex_str.is_empty():
|
||||
return Color.html("#" + hex_str)
|
||||
if unit_registry.is_enemy_unit(iid):
|
||||
return Color(1.0, 0.35, 0.35)
|
||||
return Color(0.3, 0.5, 1.0)
|
||||
|
||||
|
||||
## Schedule a retry to (re)download the real GLB model for a unit.
|
||||
## attempt is 1-based; retries stop after MAX_RETRIES.
|
||||
## Only schedules if no equal-or-later retry is already pending for this unit.
|
||||
@@ -302,8 +955,9 @@ func do_model_retry(iid: String, model_url: String, attempt: int, etag: String =
|
||||
model_node.queue_free()
|
||||
return
|
||||
# Remove placeholder mesh.
|
||||
var placeholder: Node3D = unit_meshes.get(iid) as Node3D
|
||||
for child in body.get_children():
|
||||
if child is MeshInstance3D:
|
||||
if child == placeholder:
|
||||
child.queue_free()
|
||||
# Re-read card config in case ContentCache was refreshed since placement.
|
||||
var def_id: String = unit_registry.unit_def_ids.get(iid, "")
|
||||
@@ -313,15 +967,16 @@ func do_model_retry(iid: String, model_url: String, attempt: int, etag: String =
|
||||
var model_tint: Color = Color.WHITE
|
||||
if not tint_str.is_empty() and tint_str != "null":
|
||||
model_tint = Color(tint_str)
|
||||
var target_scale: Vector3 = Vector3.ONE * model_scale
|
||||
if not is_equal_approx(model_scale, 1.0):
|
||||
model_node.scale = Vector3.ONE * model_scale
|
||||
model_node.scale = target_scale
|
||||
model_node.rotation.y = idle_rotation(iid)
|
||||
apply_model_tint(model_node, model_tint)
|
||||
var above_tile: float = body.get_meta("above_tile", 0.28)
|
||||
body.add_child(model_node)
|
||||
var m_aabb: AABB = model_local_aabb(model_node)
|
||||
if m_aabb.size != Vector3.ZERO:
|
||||
model_node.position.y = -above_tile - model_node.scale.y * m_aabb.position.y
|
||||
model_node.position.y = -above_tile - target_scale.y * m_aabb.position.y
|
||||
unit_meshes[iid] = model_node
|
||||
var ap: AnimationPlayer = find_animation_player(model_node)
|
||||
anim_players[iid] = ap
|
||||
|
||||
Reference in New Issue
Block a user