Action system with signal processing and event handling...

This commit is contained in:
Ognjen Milan Robovic 2023-10-10 23:46:07 -04:00
parent c8a3be2856
commit 1732e4669f

View File

@ -35,6 +35,15 @@ function xabina return integer is
maximum : natural := 0;
end record;
type signal_list is (
SIGNAL_A, SIGNAL_B, SIGNAL_C, SIGNAL_D, SIGNAL_E, SIGNAL_F, SIGNAL_G, SIGNAL_H,
SIGNAL_I, SIGNAL_J, SIGNAL_K, SIGNAL_L, SIGNAL_M, SIGNAL_N, SIGNAL_O, SIGNAL_P,
SIGNAL_Q, SIGNAL_R, SIGNAL_S, SIGNAL_T, SIGNAL_U, SIGNAL_V, SIGNAL_W, SIGNAL_X,
SIGNAL_Y, SIGNAL_Z, SIGNAL_0, SIGNAL_1, SIGNAL_2, SIGNAL_3, SIGNAL_4, SIGNAL_5,
SIGNAL_6, SIGNAL_7, SIGNAL_8, SIGNAL_9, SIGNAL_ESCAPE, SIGNAL_TABULATOR, SIGNAL_RETURN, SIGNAL_NEW_LINE,
SIGNAL_SLASH, SIGNAL_BACKSLASH, SIGNAL_QUOTE, SIGNAL_BACKQUOTE, SIGNAL_SPACE, SIGNAL_BACKSPACE, SIGNAL_DOT, SIGNAL_IDLE
);
type colours is (
COLOUR_GREY, COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW, COLOUR_BLUE, COLOUR_PINK, COLOUR_CYAN, COLOUR_WHITE
);
@ -43,35 +52,36 @@ function xabina return integer is
EFFECT_NORMAL, EFFECT_BOLD, EFFECT_ITALIC, EFFECT_UNDERLINE, EFFECT_BLINK, EFFECT_REVERSE
);
function render_character ( -- A joke function...
escape : constant character := character'val (27);
function format_symbol (
symbol : character := ' ';
colour : colours := COLOUR_WHITE;
effect : effects := EFFECT_NORMAL
) return natural is
) return string is
format : string (1 .. 12) := escape & "[E;3CmS" & escape & "[0m";
begin
put (character'val (27) & "[");
case effect is
when EFFECT_NORMAL => put ("0");
when EFFECT_BOLD => put ("1");
when EFFECT_ITALIC => put ("3");
when EFFECT_UNDERLINE => put ("4");
when EFFECT_BLINK => put ("5");
when EFFECT_REVERSE => put ("7");
when EFFECT_NORMAL => format (3) := '0';
when EFFECT_BOLD => format (3) := '1';
when EFFECT_ITALIC => format (3) := '3';
when EFFECT_UNDERLINE => format (3) := '4';
when EFFECT_BLINK => format (3) := '5';
when EFFECT_REVERSE => format (3) := '7';
end case;
put (";3");
case colour is
when COLOUR_GREY => put ("0");
when COLOUR_RED => put ("1");
when COLOUR_GREEN => put ("2");
when COLOUR_YELLOW => put ("3");
when COLOUR_BLUE => put ("4");
when COLOUR_PINK => put ("5");
when COLOUR_CYAN => put ("6");
when COLOUR_WHITE => put ("7");
when COLOUR_GREY => format (6) := '0';
when COLOUR_RED => format (6) := '1';
when COLOUR_GREEN => format (6) := '2';
when COLOUR_YELLOW => format (6) := '3';
when COLOUR_BLUE => format (6) := '4';
when COLOUR_PINK => format (6) := '5';
when COLOUR_CYAN => format (6) := '6';
when COLOUR_WHITE => format (6) := '7';
end case;
put ("m" & symbol & character'val (27) & "[0m");
return 1;
end render_character;
format (8) := symbol;
return format;
end format_symbol;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Entity
@ -494,52 +504,58 @@ function xabina return integer is
-- -- Currently constant, gonna use either my xurses library or <termios.h> C bindings.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
escape : character := character'val (27);
active : boolean := true;
button : character := character'val (0);
signal : signal_list := SIGNAL_IDLE;
width : natural := 120;
height : natural := 40;
buffer : unbounded_string := null_unbounded_string;
terminal_active : boolean := true;
terminal_signal : character := character'val (0);
terminal_width : natural := 120;
terminal_height : natural := 40;
terminal_buffer : unbounded_string := null_unbounded_string;
--~procedure synchronize is
--~begin
--~signal := character'val (0);
--~put (to_string (buffer));
--~get_immediate (signal);
--~if signal = escape then
--~active := false;
--~end if;
--~end synchronize;
function format_symbol (
symbol : character := ' ';
colour : colours := COLOUR_WHITE;
effect : effects := EFFECT_NORMAL
) return string is
format : string (1 .. 12) := escape & "[E;3CmS" & escape & "[0m";
procedure action_idle is
begin
case effect is
when EFFECT_NORMAL => format (3) := '0';
when EFFECT_BOLD => format (3) := '1';
when EFFECT_ITALIC => format (3) := '3';
when EFFECT_UNDERLINE => format (3) := '4';
when EFFECT_BLINK => format (3) := '5';
when EFFECT_REVERSE => format (3) := '7';
end case;
case colour is
when COLOUR_GREY => format (6) := '0';
when COLOUR_RED => format (6) := '1';
when COLOUR_GREEN => format (6) := '2';
when COLOUR_YELLOW => format (6) := '3';
when COLOUR_BLUE => format (6) := '4';
when COLOUR_PINK => format (6) := '5';
when COLOUR_CYAN => format (6) := '6';
when COLOUR_WHITE => format (6) := '7';
end case;
format (8) := symbol;
return format;
end format_symbol;
null;
end action_idle;
procedure terminal_synchronize is
procedure action_exit is
begin
terminal_signal := character'val (0);
put (to_string (terminal_buffer));
get_immediate (terminal_signal);
if terminal_signal = escape then
terminal_active := false;
end if;
end terminal_synchronize;
active := false;
end action_exit;
type procedure_pointer is access procedure;
type action_data is array (signal_list) of procedure_pointer;
action_list : action_data := (others => action_idle'access);
procedure bind (
key : signal_list := SIGNAL_IDLE;
act : procedure_pointer := action_idle'access
) is
begin
action_list (key) := act;
end bind;
procedure unbind (
key : signal_list := SIGNAL_IDLE
) is
begin
action_list (key) := action_idle'access;
end unbind;
procedure action_draw is
begin
buffer := buffer & format_symbol ('@', COLOUR_RED, EFFECT_BOLD);
end action_draw;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Main
@ -547,55 +563,112 @@ function xabina return integer is
begin
bind (SIGNAL_Q, action_exit'access);
bind (SIGNAL_D, action_draw'access);
loop
exit when terminal_active = false;
terminal_buffer := to_unbounded_string (escape & "[H");
for y in 1 .. terminal_height
exit when active = false;
buffer := to_unbounded_string (escape & "[H");
for y in 1 .. height
loop
for x in 1 .. terminal_width
for x in 1 .. width
loop
terminal_buffer := terminal_buffer & format_symbol ('X', COLOUR_GREY, EFFECT_BOLD);
buffer := buffer & format_symbol ('X', COLOUR_GREY, EFFECT_BOLD);
end loop;
terminal_buffer := terminal_buffer & character'val (13);
terminal_buffer := terminal_buffer & character'val (10);
buffer := buffer & character'val (13);
buffer := buffer & character'val (10);
end loop;
terminal_synchronize;
button := character'val (0);
put (to_string (buffer));
get_immediate (button);
case button is
--~SIGNAL_6, SIGNAL_7, SIGNAL_8, SIGNAL_9, SIGNAL_ESCAPE, SIGNAL_TABULATOR, SIGNAL_RETURN, SIGNAL_NEW_LINE,
--~SIGNAL_SLASH, SIGNAL_BACKSLASH, SIGNAL_QUOTE, SIGNAL_BACKQUOTE, SIGNAL_SPACE, SIGNAL_BACKSPACE, SIGNAL_DOT, SIGNAL_ESCAPE
when 'a' | 'A' => signal := SIGNAL_A;
when 'b' | 'B' => signal := SIGNAL_B;
when 'c' | 'C' => signal := SIGNAL_C;
when 'd' | 'D' => signal := SIGNAL_D;
when 'e' | 'E' => signal := SIGNAL_E;
when 'f' | 'F' => signal := SIGNAL_F;
when 'g' | 'G' => signal := SIGNAL_G;
when 'h' | 'H' => signal := SIGNAL_H;
when 'i' | 'I' => signal := SIGNAL_I;
when 'j' | 'J' => signal := SIGNAL_J;
when 'k' | 'K' => signal := SIGNAL_K;
when 'l' | 'L' => signal := SIGNAL_L;
when 'm' | 'M' => signal := SIGNAL_M;
when 'n' | 'N' => signal := SIGNAL_N;
when 'o' | 'O' => signal := SIGNAL_O;
when 'p' | 'P' => signal := SIGNAL_P;
when 'q' | 'Q' => signal := SIGNAL_Q;
when 'r' | 'R' => signal := SIGNAL_R;
when 's' | 'S' => signal := SIGNAL_S;
when 't' | 'T' => signal := SIGNAL_T;
when 'u' | 'U' => signal := SIGNAL_U;
when 'v' | 'V' => signal := SIGNAL_V;
when 'w' | 'W' => signal := SIGNAL_W;
when 'x' | 'X' => signal := SIGNAL_X;
when 'y' | 'Y' => signal := SIGNAL_Y;
when 'z' | 'Z' => signal := SIGNAL_Z;
when '0' => signal := SIGNAL_0;
when '1' => signal := SIGNAL_1;
when '2' => signal := SIGNAL_2;
when '3' => signal := SIGNAL_3;
when '4' => signal := SIGNAL_4;
when '5' => signal := SIGNAL_5;
when '6' => signal := SIGNAL_6;
when '7' => signal := SIGNAL_7;
when '8' => signal := SIGNAL_8;
when '9' => signal := SIGNAL_9;
when escape => signal := SIGNAL_ESCAPE;
when others => signal := SIGNAL_IDLE;
end case;
action_list (signal).all;
if button = escape then
active := false;
end if;
end loop;
--~for this in magic_list
--~loop
--~x := x + render_character (magic_constant_data (this).symbol, magic_constant_data (this).colour, magic_constant_data (this).effect);
--~put_line (" " & to_string (magic_constant_data (this).name));
--~put_line (format_symbol (magic_constant_data (this).symbol, magic_constant_data (this).colour, magic_constant_data (this).effect)
--~& " "
--~& to_string (magic_constant_data (this).name));
--~end loop;
--~for this in item_list
--~loop
--~x := x + render_character (item_constant_data (this).symbol, item_constant_data (this).colour, item_constant_data (this).effect);
--~put_line (" " & to_string (item_constant_data (this).name));
--~put_line (format_symbol (item_constant_data (this).symbol, item_constant_data (this).colour, item_constant_data (this).effect)
--~& " "
--~& to_string (item_constant_data (this).name));
--~end loop;
--~for this in ammunition_list
--~loop
--~x := x + render_character (ammunition_constant_data (this).symbol, ammunition_constant_data (this).colour, ammunition_constant_data (this).effect);
--~put_line (" " & to_string (ammunition_constant_data (this).name));
--~put_line (format_symbol (ammunition_constant_data (this).symbol, ammunition_constant_data (this).colour, ammunition_constant_data (this).effect)
--~& " "
--~& to_string (ammunition_constant_data (this).name));
--~end loop;
--~for this in weapon_list
--~loop
--~x := x + render_character (weapon_constant_data (this).symbol, weapon_constant_data (this).colour, weapon_constant_data (this).effect);
--~put_line (" " & to_string (weapon_constant_data (this).name));
--~put_line (format_symbol (weapon_constant_data (this).symbol, weapon_constant_data (this).colour, weapon_constant_data (this).effect)
--~& " "
--~& to_string (weapon_constant_data (this).name));
--~end loop;
--~for this in armour_list
--~loop
--~x := x + render_character (armour_constant_data (this).symbol, armour_constant_data (this).colour, armour_constant_data (this).effect);
--~put_line (" " & to_string (armour_constant_data (this).name));
--~put_line (format_symbol (armour_constant_data (this).symbol, armour_constant_data (this).colour, armour_constant_data (this).effect)
--~& " "
--~& to_string (armour_constant_data (this).name));
--~end loop;
--~for this in plant_list
--~loop
--~x := x + render_character (plant_constant_data (this).symbol, plant_constant_data (this).colour, plant_constant_data (this).effect);
--~put_line (" " & to_string (plant_constant_data (this).name));
--~put_line (format_symbol (plant_constant_data (this).symbol, plant_constant_data (this).colour, plant_constant_data (this).effect)
--~& " "
--~& to_string (plant_constant_data (this).name));
--~end loop;
return 0;