Add campaign editor script runtime and debug overlays

This commit is contained in:
Richard Zink committed 2026-11-05 12:22:59 +01:00
1 parent cd35ca8e3d
commit b06c48172b
13 files changed
+2211 -66

No files matched your search

+28 -4
View File
@@ -159,7 +159,14 @@ impl Game {
Act::Guard { x, y } => (point(x as f32, y as f32), MARK_GUARD, 10.0),
Act::CancelOrders => (point(self.map.core.0 as f32, self.map.core.1 as f32), MARK_CANCEL, 4.0),
};
self.add_mark(x, y, kind, side, dur);
let fixed = matches!(act, Act::Guard { .. } | Act::Attack { .. } | Act::Flag { .. });
let dur = match act {
Act::Guard { .. } => 120.0,
Act::Attack { .. } => 20.0,
Act::Flag { .. } => 120.0,
_ => dur,
};
self.add_mark(x, y, kind, side, dur, fixed);
}
fn run_act(&mut self, act: Act) {
@@ -226,6 +233,7 @@ mod tests {
#[test]
fn a_queued_command_is_applied_at_the_next_step() {
let mut g = game(7);
g.debug_markers = true;
let (cx, cy) = g.map.core;
let (x, y) = (cx + 6, cy); // outside the treasury ring: rock that can be marked
g.queue(Act::Dig(Rect::new(x, y, x + 1, y + 1)));
@@ -239,14 +247,30 @@ mod tests {
#[test]
fn commands_leave_visible_markers() {
let mut g = game(12);
g.debug_markers = true;
let (cx, cy) = g.map.core;
g.queue(Act::Dig(Rect::new(cx + 6, cy, cx + 7, cy + 1)));
g.queue(Act::Guard { x: cx, y: cy });
g.queue(Act::Attack { ent: None, x: (cx + 20) as f32, y: (cy + 20) as f32 });
g.update(STEP);
assert!(g.marks.iter().any(|m| m.kind == MARK_DIG && m.side == 0), "dig marker");
assert!(g.marks.iter().any(|m| m.kind == MARK_GUARD && m.side == 0), "guard marker");
assert!(g.marks.iter().any(|m| m.kind == MARK_ATTACK && m.side == 0), "attack marker");
assert!(g.marks.iter().any(|m| m.kind == MARK_DIG && m.side == 0 && !m.fixed), "dig debug marker");
assert!(g.marks.iter().any(|m| m.kind == MARK_GUARD && m.side == 0 && m.fixed), "fixed guard flag");
assert!(g.marks.iter().any(|m| m.kind == MARK_ATTACK && m.side == 0 && m.fixed), "fixed attack flag");
}
#[test]
fn fixed_order_flags_do_not_need_the_debug_marker_setting() {
let mut g = game(13);
g.debug_markers = false;
let (cx, cy) = g.map.core;
g.queue(Act::Dig(Rect::new(cx + 6, cy, cx + 7, cy + 1)));
g.queue(Act::Guard { x: cx, y: cy });
g.queue(Act::Attack { ent: None, x: (cx + 20) as f32, y: (cy + 20) as f32 });
g.queue(Act::Flag { x: cx, y: cy });
assert!(!g.marks.iter().any(|m| m.kind == MARK_DIG), "dig stays hidden without debug markers");
assert!(g.marks.iter().any(|m| m.kind == MARK_GUARD && m.fixed), "guard is fixed");
assert!(g.marks.iter().any(|m| m.kind == MARK_ATTACK && m.fixed), "attack is fixed");
assert!(g.marks.iter().any(|m| m.kind == MARK_FLAG && m.fixed), "gather flag is fixed");
}
#[test]