Skip to content

Commit

Permalink
Add in-game log
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeSaward1 committed Nov 11, 2024
1 parent d3a9452 commit bbda746
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ copy tool\minimap.re build\practice-windows
copy tool\mapeditor.re build\practice-windows
copy tool\world_options.re build\practice-windows
copy tool\player.re build\practice-windows
copy tool\log.re build\practice-windows
echo Converting lf to crlf
call :convert main.re
call :convert prelude.re
Expand All @@ -53,6 +54,7 @@ call :convert minimap.re
call :convert mapeditor.re
call :convert world_options.re
call :convert player.re
call :convert log.re

echo Don't forget to create a zip
exit /b 0
Expand Down
52 changes: 52 additions & 0 deletions tool/log.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
static mut LOG = Log {
messages: List::new(),
message_expire_delay: 5000,
};

struct Log {
messages: List<LogMessage>,
message_expire_delay: int,
}

struct LogMessage {
content: string,
added_timestamp: int,
}

fn log(content: string) {
let message = LogMessage {
content: content,
added_timestamp: current_time_millis(),
};
LOG.messages.push(message);
}
fn clean_expired_messages() {
let mut i = 0;
while i < LOG.messages.len() {
if (current_time_millis() - LOG.messages.get(i).unwrap().added_timestamp) > LOG.message_expire_delay {
LOG.messages.remove(i);
} else {
i += 1;
}
}
}

fn draw_log_messages() {
let mut i = 0;
while i < LOG.messages.len() {
let viewport = Tas::get_viewport_size();
let message = LOG.messages.get(i).unwrap();
Tas::draw_text(DrawText {
text: message.content,
color: Color { red: 1., green: 0., blue: 0., alpha: 1.},
x: 10.,
// 51 denotes the amount of vertical space from the bottom of the screen.
// 48 denotes the amount of vertical space between each log message.
y: viewport.height.to_float() - ((51. * SETTINGS.ui_scale) + ((48. * SETTINGS.ui_scale) * i.to_float())),
scale: SETTINGS.ui_scale,
scale_position: false,
});
i += 1;
}
clean_expired_messages();
}
2 changes: 2 additions & 0 deletions tool/main.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include "log.re";
include "settings.re";
include "keys.re";
include "component.re"
Expand Down Expand Up @@ -61,6 +62,7 @@ Platforms: {GAME_STATS.current_platforms} (Total: {GAME_STATS.total_platforms})
Resets: {GAME_STATS.total_resets} | Any%: {GAME_STATS.total_runs_completed} | 100%: {GAME_STATS.total_100_runs_completed} | All Platforms: {GAME_STATS.total_all_platforms_runs_completed} | All Cubes: {GAME_STATS.total_all_cubes_runs_completed} | Lowest #Platforms: {GAME_STATS.fewest_platform_run}";
}
start_menu_text.text = text;
draw_log_messages();
}),
selected: 0,
}
Expand Down

0 comments on commit bbda746

Please sign in to comment.