From 08dbe47434780fc290b123c0846224dd1cf22422 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 1 Apr 2025 13:13:00 +0200 Subject: [PATCH] state: cursor states are now also simply using a state machine --- src/buildings.s | 17 +++++++++++++++++ src/state.s | 10 ++++++++++ src/ui.s | 24 ++++++++++++++++-------- src/wram.s | 6 +++--- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/buildings.s b/src/buildings.s index 518a8e1..a8d365b 100644 --- a/src/buildings.s +++ b/src/buildings.s @@ -2,5 +2,22 @@ ; performs pre-checks and displays an error ; if pre-conditions for building fail ; e.g. not enough resources, not enough space + ; executes cursor_state state machine update building_build: ret + +build_warehouse: + ldnull bc + ret + +build_road: + ldnull bc + ret + +build_farm: + ldnull bc + ret + +build_lumber: + ldnull bc + ret diff --git a/src/state.s b/src/state.s index 749f1d2..5ead5ca 100644 --- a/src/state.s +++ b/src/state.s @@ -102,3 +102,13 @@ st_update_pause: st_update_game_over: st_def 0x00, update_game_over, st_update_game_over +; building states + +st_build_warehouse: + st_def 0x00, build_warehouse, st_null +st_build_road: + st_def 0x00, build_road, st_null +st_build_farm: + st_def 0x00, build_farm, st_null +st_build_lumber: + st_def 0x00, build_lumber, st_null diff --git a/src/ui.s b/src/ui.s index 90a72b0..4c1e15d 100644 --- a/src/ui.s +++ b/src/ui.s @@ -23,13 +23,12 @@ ui_cursor_label_table: dw STR_LUMBER ; converts from UI cursor position - ; to building type + ; to building state ui_to_building_selecction_table: - .db BT_WAREHOUSE - .db BT_ROAD - .db BT_FARM - .db BT_LUMBER - + dw st_build_warehouse + dw st_build_road + dw st_build_farm + dw st_build_lumber ; inits UI ui_init: @@ -160,14 +159,23 @@ ui_building_selector_inputs: input_just BTNA jr z, @not_a REL - ; load building to be built into building selector + ; load building to be built into building selector state ld a, [ui_cursor_pos] + sla a ; * 2 to get ptr offset ld d, 0 ld e, a + ld hl, ui_to_building_selecction_table add hl, de ; hl = correct value + ld a, [hl+] + ld e, a ld a, [hl] - ld [cursor_selected_building], a + ld d, a ; de = source of state ptr + + ld hl, cursor_state + ld bc, st_size + call memcpy + ld bc, st_ui_buildung_selector_exit ret @not_a: diff --git a/src/wram.s b/src/wram.s index cc254c2..e9f6fa9 100644 --- a/src/wram.s +++ b/src/wram.s @@ -16,6 +16,9 @@ ui_cursor_pos: .adv 1 game_mode: .adv st_size + ; cursor state +cursor_state: .adv st_size + ; actors ; actors are state machines ; they get updated once a frame @@ -37,9 +40,6 @@ cursor_x: .adv 1 cursor_move_y: .adv 1 cursor_move_x: .adv 1 - ; enum of type BT_ -cursor_selected_building: .adv 1 - ; +/-1 for each time the cursor moves ; allows us to move scroll when needed scroll_move_y: .adv 1 -- 2.30.2