class_name EnemyDefinitions extends RefCounted const DEFAULT_ID: String = "chaser" const ORDER: PackedStringArray = ["chaser", "sniper", "artillery", "turret_spawner", "enemy_mothership"] const DEFINITIONS: Dictionary = { "chaser": preload("res://enemies/ChaserEnemyDefinition.tres"), "sniper": preload("res://enemies/SniperEnemyDefinition.tres"), "artillery": preload("res://enemies/ArtilleryEnemyDefinition.tres"), "turret_spawner": preload("res://enemies/TurretSpawnerEnemyDefinition.tres"), "enemy_mothership": preload("res://enemies/MothershipEnemyDefinition.tres"), } # The single place that knows what an enemy LOOKS like. Three things draw # enemies - the enemy itself, the map editor's markers, and the editor's # palette buttons - and each used to reimplement it from hull_points alone. # Adding interior detail to the definitions therefore showed up in the game # and nowhere else, so an editor marker no longer matched the ship it placed. # # `at` and `scale` exist because the palette draws into a small button # centred on itself, while the other two draw around their own origin at # full size. static func draw_definition(item: CanvasItem, definition: Resource, glow: Color, scale: float = 1.0, at: Vector2 = Vector2.ZERO) -> void: if definition == null: return var core: Color = definition.core_color item.draw_set_transform(at, 0.0, Vector2(scale, scale)) NeonDraw.draw_glowing_polygon(item, definition.hull_points, glow, 1.0, core) var lines: PackedVector2Array = definition.detail_lines for i in range(0, lines.size() - 1, 2): NeonDraw.draw_glowing_line(item, lines[i], lines[i + 1], glow, 0.85, 0.55, core) var rings: PackedVector2Array = definition.detail_rings for i in range(0, rings.size() - 1, 2): NeonDraw.draw_glowing_circle(item, rings[i], rings[i + 1].x, glow, 0.85, core) item.draw_set_transform(Vector2.ZERO, 0.0, Vector2.ONE) static func get_definition(enemy_id: String) -> Resource: return DEFINITIONS.get(enemy_id, DEFINITIONS[DEFAULT_ID]) static func all() -> Array: var result: Array = [] for enemy_id in ORDER: result.append(DEFINITIONS[enemy_id]) return result