Name refactor
This commit is contained in:
parent
6f56fffb59
commit
e1cdf38dfb
21 changed files with 44 additions and 40 deletions
|
@ -1,9 +1,2 @@
|
|||
## Global class for runtime
|
||||
extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
get_tree().scene_changed.connect(cleanup_runtime_cache)
|
||||
|
||||
func cleanup_runtime_cache():
|
||||
build_zones.clear()
|
||||
|
||||
var build_zones : Array[BuildZone]
|
||||
|
|
|
@ -1 +1,12 @@
|
|||
## Global class for player in-game data
|
||||
|
||||
extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
get_tree().scene_changed.connect(cleanup_runtime_cache)
|
||||
|
||||
## Method to cleanup all data that will be nulled
|
||||
func cleanup_runtime_cache():
|
||||
build_zones.clear()
|
||||
|
||||
var build_zones : Array[PlacementZone]
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
extends Node2D
|
||||
|
||||
class_name EntityHolder
|
||||
class_name GridController
|
||||
|
||||
const GRID_SIZE : Vector2 = Vector2(16,16)
|
||||
|
||||
@export var building_zone : BuildZone
|
||||
var constructions : Array[Construction]
|
||||
@export var building_zone : PlacementZone
|
||||
var constructions : Array[Structure]
|
||||
|
||||
func _ready() -> void:
|
||||
constructions.resize(building_zone.get_capacity())
|
||||
|
||||
func add_construction(construction : Construction) -> bool:
|
||||
func add_construction(construction : Structure) -> bool:
|
||||
var construction_dp = construction.get_dimension_points()
|
||||
for point in construction_dp:
|
||||
if constructions[building_zone.indexify_global_point(construction.global_position + point)]:
|
||||
|
@ -21,7 +21,7 @@ func add_construction(construction : Construction) -> bool:
|
|||
constructions[building_zone.indexify_global_point(construction.global_position + point)] = construction
|
||||
return true
|
||||
|
||||
func get_at(point : Vector2) -> Construction:
|
||||
func get_at(point : Vector2) -> Structure:
|
||||
return constructions[building_zone.indexify_global_point(point)]
|
||||
|
||||
func is_point_occupied(point : Vector2) -> bool:
|
|
@ -1,6 +1,6 @@
|
|||
extends Button
|
||||
|
||||
@export var constructible : Constructible
|
||||
@export var constructible : Prototype
|
||||
|
||||
func _ready() -> void:
|
||||
icon = constructible.preview
|
||||
|
|
|
@ -2,5 +2,5 @@ extends Node
|
|||
|
||||
@warning_ignore_start("unused_signal")
|
||||
|
||||
signal construction_selected(constructible : Constructible)
|
||||
signal construction_placed(constructible : Constructible)
|
||||
signal construction_selected(constructible : Prototype)
|
||||
signal construction_placed(constructible : Prototype)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extends Node2D
|
||||
|
||||
var held_construction : Construction
|
||||
var held_construction : Structure
|
||||
|
||||
func _ready() -> void:
|
||||
GuiEventBus.construction_selected.connect(on_construction_selected)
|
||||
|
@ -19,7 +19,7 @@ func _input(event: InputEvent) -> void:
|
|||
if event.is_action_pressed("plc_cancel"):
|
||||
held_construction.queue_free()
|
||||
|
||||
func on_construction_selected(constructible : Constructible):
|
||||
func on_construction_selected(constructible : Prototype):
|
||||
if held_construction:
|
||||
held_construction.queue_free()
|
||||
held_construction = constructible.scene.instantiate()
|
||||
|
@ -36,8 +36,8 @@ func _process(_delta: float) -> void:
|
|||
else:
|
||||
global_position = mouse_pos
|
||||
|
||||
func try_get_zone(point : Vector2) -> BuildZone:
|
||||
for zone in Registry.build_zones:
|
||||
func try_get_zone(point : Vector2) -> PlacementZone:
|
||||
for zone in RuntimePlayerData.build_zones:
|
||||
if zone.is_global_point_in_zone(point):
|
||||
return zone
|
||||
return null
|
|
@ -4,7 +4,7 @@
|
|||
## Class that helps to manage construction sites
|
||||
extends Marker2D
|
||||
|
||||
class_name BuildZone
|
||||
class_name PlacementZone
|
||||
|
||||
## Rect that used for bounds check and conversions
|
||||
@export var building_rect : Rect2:
|
||||
|
@ -15,11 +15,11 @@ class_name BuildZone
|
|||
get:
|
||||
return building_rect
|
||||
|
||||
@export var entity_holder : EntityHolder
|
||||
@export var entity_holder : GridController
|
||||
|
||||
func _ready() -> void:
|
||||
if not Engine.is_editor_hint():
|
||||
Registry.build_zones.append(self)
|
||||
RuntimePlayerData.build_zones.append(self)
|
||||
|
||||
func _draw() -> void:
|
||||
if Engine.is_editor_hint() and EditorInterface.get_inspector().get_edited_object() == self:
|
|
@ -1,6 +1,6 @@
|
|||
extends Resource
|
||||
|
||||
class_name Constructible
|
||||
class_name Prototype
|
||||
|
||||
@export var scene : PackedScene
|
||||
@export var preview : Texture2D
|
|
@ -1,7 +1,7 @@
|
|||
@tool
|
||||
extends Node2D
|
||||
|
||||
class_name Construction
|
||||
class_name Structure
|
||||
|
||||
@export var dimensions : Rect2i = Rect2i(0,0,1,1):
|
||||
set(value):
|
||||
|
@ -17,10 +17,10 @@ func _draw() -> void:
|
|||
for y in range(dimensions.size.y):
|
||||
draw_circle((dimensions.position+Vector2i(x,y)) * Vector2i(Globals.GRID_SIZE),2,Color.AQUA)
|
||||
|
||||
func get_relative(dv : Vector2) -> Construction:
|
||||
func get_relative(dv : Vector2) -> Structure:
|
||||
return get_parent().get_at(global_position+dv)
|
||||
|
||||
func can_be_placed(zone : BuildZone) -> bool:
|
||||
func can_be_placed(zone : PlacementZone) -> bool:
|
||||
for dp in get_dimension_points():
|
||||
var point = global_position + dp
|
||||
if zone.is_global_point_in_zone(point) == false:
|
||||
|
@ -29,7 +29,7 @@ func can_be_placed(zone : BuildZone) -> bool:
|
|||
return false
|
||||
return true
|
||||
|
||||
func try_place(zone : BuildZone) -> bool:
|
||||
func try_place(zone : PlacementZone) -> bool:
|
||||
if can_be_placed(zone) == false:
|
||||
return false
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue