Added job component and queue system
- Introduced a new JobComponent and JobQueue to manage jobs in the game. - Created two new jobs: DigJob and InfectJob with their respective scripts. - Updated CrystalGlowComponent, FreeCameraComponent, MushroomGlowComponent, WaterEffectComponent to improve logging messages. - Adjusted camera movement limits in FreeCameraGameCameraComponent for better control. - Added FiniteStateMachine class for managing states of entities. - Implemented GlowingIdle state as an example of using the state machine. - Included a utility function to fetch file paths by extension from a directory.
This commit is contained in:
parent
fc896925d6
commit
bb5724429a
23 changed files with 311 additions and 29 deletions
|
|
@ -16,13 +16,13 @@ func _ready() -> void:
|
|||
if !tile_map:
|
||||
Log.err("CrystalGlowComponent: TileMap not set")
|
||||
|
||||
Log.pr("CrystalGlowComponent ready")
|
||||
|
||||
tile_size = tile_map.get_tileset().tile_size
|
||||
tilemap_size = tile_map.get_used_rect().end - tile_map.get_used_rect().position
|
||||
|
||||
crystal_layer = tile_map.get_layer_id_by_name('Crystals')
|
||||
Log.pr(crystal_layer)
|
||||
|
||||
Log.pr("CrystalGlowComponent ready, working on layer: ", crystal_layer)
|
||||
|
||||
add_crystal_glow()
|
||||
|
||||
## Look for crystals in the scene and add the glow to the approprirate angle and colour
|
||||
|
|
@ -46,5 +46,3 @@ func add_crystal_glow() -> void:
|
|||
glow.orientation = orientation
|
||||
crystal_glow_container.add_child(glow)
|
||||
glowing_crystals.append(coords)
|
||||
|
||||
Log.pr("Glowing crystals: ", glowing_crystals)
|
||||
|
|
@ -9,20 +9,12 @@ func _ready() -> void:
|
|||
if !tile_map:
|
||||
Log.err("FreeCameraComponent: tile_map is not set")
|
||||
|
||||
## Set the limits for the camera based on the tilemap
|
||||
#camera.set_limits(0, tile_map.)
|
||||
|
||||
# Stop the camera scrolling out of bounds of the map
|
||||
var tile_size : Vector2i = tile_map.get_tileset().tile_size
|
||||
var tilemap_size : Vector2i = tile_map.get_used_rect().end - tile_map.get_used_rect().position
|
||||
var map_size_x : int = tile_size.x * tilemap_size.x
|
||||
var map_size_y : int = tile_size.y * tilemap_size.y
|
||||
|
||||
Log.pr("Size Y", map_size_y, get_viewport().size.y)
|
||||
Log.pr("Size X", map_size_x, get_viewport().size.x)
|
||||
|
||||
#Log.pr(map_size - get_viewport().size.x)
|
||||
|
||||
camera.set_limit(SIDE_LEFT, 0)
|
||||
camera.set_limit(SIDE_TOP, 0)
|
||||
camera.set_limit(SIDE_RIGHT, map_size_x)
|
||||
|
|
|
|||
|
|
@ -64,18 +64,18 @@ func _physics_process(delta : float) -> void:
|
|||
# If this movement would take us out of clamp we don't want to do it:
|
||||
var position_change : Vector2 = camera_movement * get_zoom()
|
||||
|
||||
if (position.x + position_change.x) <= limit_left or\
|
||||
(position.x + position_change.x) >= limit_right:
|
||||
if (position.x + position_change.x) < limit_left or\
|
||||
(position.x + position_change.x) > limit_right:
|
||||
camera_movement.x = 0
|
||||
|
||||
if (position.y + position_change.y) <= limit_top or\
|
||||
(position.y + position_change.y) >= limit_bottom:
|
||||
if (position.y + position_change.y) < limit_top or\
|
||||
(position.y + position_change.y) > limit_bottom:
|
||||
camera_movement.y = 0
|
||||
|
||||
if camera_movement.y != 0 or camera_movement.x != 0:
|
||||
# Update position of the camera.
|
||||
position += camera_movement * get_zoom()
|
||||
|
||||
|
||||
# Set camera movement to zero, update old mouse position.
|
||||
camera_movement = Vector2(0,0)
|
||||
_prev_mouse_pos = get_local_mouse_position()
|
||||
|
|
|
|||
57
components/scripts/job_component.gd
Normal file
57
components/scripts/job_component.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
extends Node
|
||||
class_name JobComponent
|
||||
|
||||
## Constants
|
||||
const JOB_FOLDER = "res://components/jobs/"
|
||||
|
||||
## Variables
|
||||
var job_types : Dictionary = {}
|
||||
|
||||
@onready var queue : JobQueue = $JobQueue
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
## Get the list of job types from the job folder
|
||||
load_jobs()
|
||||
add_jobs_to_queue()
|
||||
add_jobs_to_queue()
|
||||
add_jobs_to_queue()
|
||||
|
||||
Log.pr("I am the job component, and I am ready.")
|
||||
|
||||
|
||||
# Look in the JOB_FOLDER and preload all scenes into a dictionary
|
||||
func load_jobs() -> void:
|
||||
var job_files : Array = FileUtil.get_file_paths_by_extension(JOB_FOLDER, "tscn")
|
||||
|
||||
#Log.pr("Job files: ", job_files)
|
||||
|
||||
for file : String in job_files:
|
||||
#Log.pr("Loading job: ", file)
|
||||
var job_scene : PackedScene = load(file)
|
||||
var job_instance : Job = job_scene.instantiate()
|
||||
|
||||
#Log.pr("⚒️ Job Name:", job_instance.job_name, "-- Description:", job_instance.job_description)
|
||||
|
||||
var job_details : Dictionary = {
|
||||
'job_name': job_instance.job_name,
|
||||
'job_description': job_instance.job_description,
|
||||
'job_instance': job_scene
|
||||
}
|
||||
|
||||
job_types[job_instance.job_name] = job_details
|
||||
|
||||
#Log.pr(job_details)
|
||||
|
||||
Log.pr("Job types: ", job_types)
|
||||
|
||||
func add_jobs_to_queue() -> void:
|
||||
#Log.pr("This is a debug function!")
|
||||
|
||||
for job : String in job_types.keys():
|
||||
#Log.pr("Adding job to queue: ", job)
|
||||
if job_types[job].job_instance != null:
|
||||
var job_scene : PackedScene = job_types[job].job_instance
|
||||
var job_instance : Node = job_scene.instantiate()
|
||||
queue.add_child(job_instance)
|
||||
5
components/scripts/job_queue.gd
Normal file
5
components/scripts/job_queue.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends Node
|
||||
class_name JobQueue
|
||||
|
||||
func _ready() -> void:
|
||||
Log.pr("Job Queue ready...")
|
||||
|
|
@ -15,7 +15,7 @@ func _ready() -> void:
|
|||
if !tile_map:
|
||||
Log.err("MushroomGlowComponent: TileMap not set")
|
||||
|
||||
Log.pr("MushroomGlowComponent ready")
|
||||
|
||||
|
||||
tile_map.tilemap_updated.connect(add_mushroom_glow)
|
||||
|
||||
|
|
@ -23,7 +23,9 @@ func _ready() -> void:
|
|||
tilemap_size = tile_map.get_used_rect().end - tile_map.get_used_rect().position
|
||||
|
||||
mushroom_layer = tile_map.get_layer_id_by_name('Mushrooms')
|
||||
Log.pr(mushroom_layer)
|
||||
|
||||
Log.pr("MushroomGlowComponent ready, working on layer:", mushroom_layer)
|
||||
|
||||
add_mushroom_glow()
|
||||
|
||||
## Look for crystals in the scene and add the glow to the approprirate angle and colour
|
||||
|
|
|
|||
|
|
@ -18,13 +18,15 @@ func _ready() -> void:
|
|||
if !tile_map:
|
||||
Log.err("WaterEffectComponent: TileMap not set")
|
||||
|
||||
Log.pr("WaterEffectComponent ready")
|
||||
|
||||
|
||||
tile_size = tile_map.get_tileset().tile_size
|
||||
tilemap_size = tile_map.get_used_rect().end - tile_map.get_used_rect().position
|
||||
|
||||
water_layer = tile_map.get_layer_id_by_name('Water')
|
||||
Log.pr(water_layer)
|
||||
|
||||
Log.pr("WaterEffectComponent ready, working on layer:", water_layer)
|
||||
|
||||
add_water_effects()
|
||||
|
||||
## Look for crystals in the scene and add the glow to the approprirate angle and colour
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue