Files
windroost/p2_godot_sample/scripts/p2_sample.gd
T

79 lines
3.7 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends Node2D
const HERO_SLOTS := ["H01", "H02", "H04"]
const ENEMY_SLOTS := ["E-R1-F1-V1", "E-R1-F3-V1"]
const BOSS_ID := "B-R1-01"
const VFX_IDS := ["vfx.common.hit_light", "vfx.common.shield_break", "vfx.common.ultimate_burst"]
var palette := {
"ink": Color("#16233c"),
"panel": Color("#f7e9c9"),
"panel_dark": Color("#c49b63"),
"accent": Color("#ed8f4d"),
"green": Color("#5aa66f"),
"red": Color("#c95d5d"),
}
func _ready() -> void:
var fixtures := FrozenFixture.load_all()
var check := FrozenFixture.validate(fixtures)
if not check["pass"]:
push_error("P2 sample fixture check failed: %s" % JSON.stringify(check["errors"]))
_build_sample(check)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, Vector2(390, 844)), Color("#b8d6d5"))
draw_rect(Rect2(0, 0, 390, 90), palette["ink"])
draw_rect(Rect2(16, 108, 358, 148), Color("#d8eff0"))
draw_rect(Rect2(16, 286, 358, 216), Color("#f0d8aa"))
draw_rect(Rect2(16, 526, 358, 192), palette["panel"])
draw_rect(Rect2(0, 760, 390, 84), palette["ink"])
for x in [32, 146, 260]:
draw_line(Vector2(x, 640), Vector2(x + 92, 640), palette["panel_dark"], 2.0)
func _build_sample(check: Dictionary) -> void:
queue_redraw()
_add_label("风栖旅团 · P2 技术小样", Vector2(20, 14), 24, Color.WHITE)
_add_label("FROZEN FIXTURE / HEADLESS-READY", Vector2(20, 51), 12, Color("#b6d7dc"))
_add_label("N01 · 自动战斗", Vector2(28, 120), 18, palette["ink"])
_add_label("目标:E-R1-F1-V1", Vector2(28, 150), 14, palette["ink"])
_add_label("HP 480 · tick 0.1s", Vector2(28, 181), 14, palette["ink"])
_add_label("点击 / 风暴号令 / 终极覆盖", Vector2(28, 219), 13, palette["ink"])
_add_label("3 个可视英雄位", Vector2(28, 300), 16, palette["ink"])
_add_label("2 个敌方样本位 + 1 Boss fixture", Vector2(28, 332), 13, palette["ink"])
_add_label("P2 VFX", Vector2(28, 484), 12, palette["ink"])
_add_label("命中闪白 · 破盾 · 终极环", Vector2(84, 484), 12, palette["ink"])
_add_label("390×844 · nearest · safe-area sample", Vector2(28, 733), 12, palette["ink"])
_add_label("天空港", Vector2(44, 792), 14, Color.WHITE)
_add_label("战斗", Vector2(168, 792), 14, palette["accent"])
_add_label("设置", Vector2(294, 792), 14, Color.WHITE)
_add_sprite("res://assets/H01_idle_source.png", Vector2(78, 602), 0.09, Color.WHITE, "H01")
_add_sprite("res://assets/H01_idle_source.png", Vector2(195, 602), 0.09, Color("#d4e6ff"), "H02")
_add_sprite("res://assets/H01_attack_source.png", Vector2(312, 602), 0.075, Color("#ffe2bd"), "H04")
_add_sprite("res://assets/EG01_idle_source.png", Vector2(100, 420), 0.09, Color.WHITE, "E-R1-F1-V1")
_add_sprite("res://assets/EG01_hit_source.png", Vector2(290, 420), 0.09, Color("#ffd2d2"), "E-R1-F3-V1")
_add_sprite("res://assets/B01_idle_source_safe_margin.png", Vector2(195, 390), 0.09, Color("#f3d7ff"), BOSS_ID)
if not check["pass"]:
_add_label("FIXTURE ERROR", Vector2(28, 250), 14, palette["red"])
func _add_label(text_value: String, at: Vector2, font_size: int, color: Color) -> void:
var label := Label.new()
label.text = text_value
label.position = at
label.add_theme_font_size_override("font_size", font_size)
label.add_theme_color_override("font_color", color)
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(label)
func _add_sprite(path: String, at: Vector2, scale_value: float, tint: Color, caption: String) -> void:
var texture := load(path) as Texture2D
if texture != null:
var sprite := Sprite2D.new()
sprite.texture = texture
sprite.position = at
sprite.scale = Vector2(scale_value, scale_value)
sprite.modulate = tint
sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
add_child(sprite)
_add_label(caption, at + Vector2(-46, 76), 10, palette["ink"])