From faad7fac15d5de3e04d056b483b246709668f49c Mon Sep 17 00:00:00 2001 From: xolatile Date: Wed, 8 May 2024 16:45:08 -0400 Subject: [PATCH] Refactored some core and UI code... --- source/main.adb | 136 ++++++++++++++++++++++++++++---------------------------- source/ui.adb | 5 ++- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/source/main.adb b/source/main.adb index 64dc7cf..fc80b0c 100644 --- a/source/main.adb +++ b/source/main.adb @@ -7,6 +7,8 @@ pragma ada_2012; --~with core, ui, effect, attribute, skill, resource, faction, might, magic, item, unit, construction, chad, deity, world, ai; with core, ui, effect, attribute, skill, resource, faction, item, unit, construction, chad, world; +use core; + procedure main is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ @@ -24,17 +26,17 @@ procedure main is map_preview_panel, status_preview_panel, text_box_panel ); - view_icon : array (view) of core.sprite := (others => (others => 0)); - view_list : array (view) of boolean := (others => true); - view_text : array (view) of core.long_string := ( + view_icon : array (view) of sprite := (others => (others => 0)); + view_list : array (view) of boolean := (others => true); + view_text : array (view) of long_string := ( "Toggle map preview panel. ", "Toggle status preview panel. ", "Toggle text box panel. " ); - procedure swap_map_preview_panel is begin view_list (map_preview_panel) := (if view_list (map_preview_panel) then false else true); end swap_map_preview_panel; - procedure swap_status_preview_panel is begin view_list (status_preview_panel) := (if view_list (status_preview_panel) then false else true); end swap_status_preview_panel; - procedure swap_text_box_panel is begin view_list (text_box_panel) := (if view_list (text_box_panel) then false else true); end swap_text_box_panel; + procedure swap_map_preview_panel is begin view_list (map_preview_panel) := not view_list (map_preview_panel); end swap_map_preview_panel; + procedure swap_status_preview_panel is begin view_list (status_preview_panel) := not view_list (status_preview_panel); end swap_status_preview_panel; + procedure swap_text_box_panel is begin view_list (text_box_panel) := not view_list (text_box_panel); end swap_text_box_panel; view_show : array (view) of access procedure := ( swap_map_preview_panel'access, @@ -44,59 +46,59 @@ procedure main is ------------------------------------------------------------------------------------------ - procedure move_camera_up is + procedure check_move_camera_up is begin - core.move_camera_up; - core.camera.y := core.clip (core.camera.y, 0, world.map.height - 1); - if world.map.clips (core.camera.x, core.camera.y) then - core.increment (core.camera.y); + move_camera_up; + camera.y := clip (camera.y, 0, world.map.height - 1); + if world.map.clips (camera.x, camera.y) then + increment (camera.y); end if; - end move_camera_up; + end check_move_camera_up; - procedure move_camera_down is + procedure check_move_camera_down is begin - core.move_camera_down; - core.camera.y := core.clip (core.camera.y, 0, world.map.height - 1); - if world.map.clips (core.camera.x, core.camera.y) then - core.decrement (core.camera.y); + move_camera_down; + camera.y := clip (camera.y, 0, world.map.height - 1); + if world.map.clips (camera.x, camera.y) then + decrement (camera.y); end if; - end move_camera_down; + end check_move_camera_down; - procedure move_camera_left is + procedure check_move_camera_left is begin - core.move_camera_left; - core.camera.x := core.clip (core.camera.x, 0, world.map.width - 1); - if world.map.clips (core.camera.x, core.camera.y) then - core.increment (core.camera.x); + move_camera_left; + camera.x := clip (camera.x, 0, world.map.width - 1); + if world.map.clips (camera.x, camera.y) then + increment (camera.x); end if; - end move_camera_left; + end check_move_camera_left; - procedure move_camera_right is + procedure check_move_camera_right is begin - core.move_camera_right; - core.camera.x := core.clip (core.camera.x, 0, world.map.width - 1); - if world.map.clips (core.camera.x, core.camera.y) then - core.decrement (core.camera.x); + move_camera_right; + camera.x := clip (camera.x, 0, world.map.width - 1); + if world.map.clips (camera.x, camera.y) then + decrement (camera.x); end if; - end move_camera_right; + end check_move_camera_right; procedure ui_main_style is begin ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod (ui.style'pos (ui.style'last) + 1)); end ui_main_style; - procedure zoom_in is begin core.zoom := 2; end zoom_in; - procedure zoom_out is begin core.zoom := 1; end zoom_out; + procedure zoom_in is begin zoom := 2; end zoom_in; + procedure zoom_out is begin zoom := 1; end zoom_out; - signal_list : constant array (core.signal_code) of access procedure := ( - core.signal_up => move_camera_up'access, - core.signal_down => move_camera_down'access, - core.signal_left => move_camera_left'access, - core.signal_right => move_camera_right'access, - core.signal_v => ui_main_style'access, - core.signal_kp_add => zoom_in'access, - core.signal_kp_subtract => zoom_out'access, - others => core.idle'access + signal_list : constant array (signal_code) of access procedure := ( + signal_up => check_move_camera_up'access, + signal_down => check_move_camera_down'access, + signal_left => check_move_camera_left'access, + signal_right => check_move_camera_right'access, + signal_v => ui_main_style'access, + signal_kp_add => zoom_in'access, + signal_kp_subtract => zoom_out'access, + others => idle'access ); ------------------------------------------------------------------------------------------ @@ -113,11 +115,11 @@ procedure main is if not view_list (status_preview_panel) then side_panel := 0; else - side_panel := core.window_width / 4; + side_panel := window_width / 4; end if; -- - preview_width := core.window_width - side_panel; - preview_height := core.window_height - text_box_height; + preview_width := window_width - side_panel; + preview_height := window_height - text_box_height; text_box_height := 32; -- world.draw; @@ -132,17 +134,17 @@ procedure main is end if; -- if view_list (text_box_panel) then - ui.draw_help_box (0, core.window_height - text_box_height, core.window_width - core.icon * (view'pos (view'last) + 1), text_box_height); + ui.draw_help_box (0, window_height - text_box_height, window_width - icon * (view'pos (view'last) + 1), text_box_height); end if; -- for index in view loop ui.draw_icon (view_icon (index), view_text (index), - core.window_width - core.icon * (view'pos (view'last) + 1) + core.icon * view'pos (index), - core.window_height - text_box_height, + window_width - icon * (view'pos (view'last) + 1) + icon * view'pos (index), + window_height - text_box_height, view_show (index)); end loop; -- - signal_list (core.signal_mode).all; + signal_list (signal_mode).all; -- --~magic.menu (0, 0, true); --~might.menu (0, 0, true); @@ -156,18 +158,18 @@ procedure main is begin - core.dash; - core.echo (core.comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic"); - core.echo (core.comment, "Version -- 1.0.0"); - core.echo (core.comment, "License -- GNU/GPLv3+"); - core.echo (core.comment, "Xhads is free software, you can redistribute it and modify it under the terms of the GNU General Public License by Free Software Foundation."); - core.dash; + dash; + echo (comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic"); + echo (comment, "Version -- 1.0.0"); + echo (comment, "License -- GNU/GPLv3+"); + echo (comment, "Xhads is free software, you can redistribute it and modify it under the terms of the GNU General Public License by Free Software Foundation."); + dash; - core.initialize; + initialize; ui.configure; - core.play (core.import_song (core.c_string ("./song/main_menu.ogg")).index); + play (import_song (c_string ("./song/main_menu.ogg")).index); attribute.configure; skill.configure; @@ -183,40 +185,40 @@ begin world.make (world.swamp, 120, 60); - core.dash; - core.echo (core.success, "Successfully initialized game data, entering main gameplay loop."); - core.dash; + dash; + echo (success, "Successfully initialized game data, entering main gameplay loop."); + dash; for index in view loop - view_icon (index) := core.import_sprite ("./sprite/ui/icon/" & core.lowercase (view'image (index)) & ".png", 1, 1); + view_icon (index) := import_sprite ("./sprite/ui/icon/" & lowercase (view'image (index)) & ".png", 1, 1); end loop; ui.active := ui.imp; - core.camera := (1, 1); + camera := (1, 1); ------------------------------------------------------------------------------------------ introduction_loop: loop - core.synchronize; + synchronize; -- - exit when core.signal_code'pos (core.signal_mode) = core.signal_code'pos (core.signal_space); + exit when signal_mode = signal_space; -- introduction; end loop introduction_loop; gameplay_loop: loop - core.synchronize; + synchronize; -- - exit when core.engine_active = false; + exit when engine_active = false; -- gameplay; end loop gameplay_loop; ------------------------------------------------------------------------------------------ - core.deinitialize; + deinitialize; - core.dash; + dash; end main; diff --git a/source/ui.adb b/source/ui.adb index 3de09de..ab80cb6 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -227,10 +227,11 @@ package body ui is ------------------------------------------------------------------------------------------ procedure synchronize is + use core; begin for index in 0 .. structure_count - 1 loop - if core.signal_code'pos (core.signal_mode) = core.signal_code'pos (structure_array (index).toggle) then - structure_array (index).show := (if structure_array (index).show then false else true); + if signal_mode = structure_array (index).toggle then + structure_array (index).show := not structure_array (index).show; end if; -- if structure_array (index).show then