Add spirit and affinity transition effects

This commit is contained in:
dingo
2026-05-07 13:31:57 -04:00
parent f6210caef4
commit 3be1099d93
3 changed files with 1085 additions and 14 deletions
@@ -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