feat: log tree from Module 2 (logTree / log_tree); SpellGrid CLIs print Log:
Engine events carry the nesting depth they were recorded at; the harness prints the log as an indented tree. New tests test_02_log_tree_shows_nesting and test_03_log_tree_death_phase; both SpellGrid CLIs print the tree of the last command's Sequences under a Log: line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06a1b34c5d
commit
97c64ebee8
86 files changed
+1375
-55
No files matched your search
@@ -1,4 +1,5 @@
|
||||
//! What happened, in order. The engine records an event each time it changes the game.
|
||||
//! The world also keeps the nesting depth each event was recorded at (`World::log_depths`).
|
||||
|
||||
use super::card::TriggerOn;
|
||||
use super::world::{EntityId, PlayerId};
|
||||
|
||||
@@ -180,10 +180,13 @@ fn react(world: &mut World, events: &[Event]) {
|
||||
position,
|
||||
};
|
||||
let actions = (trigger.effect)(&ctx);
|
||||
// The trigger's consequences are one level deeper in the log tree.
|
||||
world.open_block();
|
||||
// Depth-first: each action, and every reaction it causes, finishes before the next.
|
||||
for action in actions {
|
||||
perform(world, action);
|
||||
}
|
||||
world.close_block();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,10 @@ pub struct World {
|
||||
sides: [Side; 2],
|
||||
next_order_of_play: u32,
|
||||
log: Vec<Event>,
|
||||
/// The nesting depth at which each event in `log` was recorded, index for index.
|
||||
depths: Vec<u32>,
|
||||
/// How many triggers are resolving right now, one inside another.
|
||||
depth: u32,
|
||||
}
|
||||
|
||||
impl World {
|
||||
@@ -83,6 +87,8 @@ impl World {
|
||||
sides: Default::default(),
|
||||
next_order_of_play: 0,
|
||||
log: Vec::new(),
|
||||
depths: Vec::new(),
|
||||
depth: 0,
|
||||
};
|
||||
for owner in 0..2 {
|
||||
let id = world.entities.len() as EntityId;
|
||||
@@ -243,14 +249,32 @@ impl World {
|
||||
&self.log
|
||||
}
|
||||
|
||||
/// The nesting depth of each event in `log()`, index for index: 0 for the outermost
|
||||
/// action's own events.
|
||||
pub fn log_depths(&self) -> &[u32] {
|
||||
&self.depths
|
||||
}
|
||||
|
||||
// ---- Changes: each one records its event ----------------------------
|
||||
|
||||
pub fn record(&mut self, event: Event) {
|
||||
self.log.push(event);
|
||||
self.depths.push(self.depth);
|
||||
}
|
||||
|
||||
/// A trigger starts resolving: the events it causes are recorded one level deeper.
|
||||
pub fn open_block(&mut self) {
|
||||
self.depth += 1;
|
||||
}
|
||||
|
||||
/// The trigger that last opened a block has finished resolving.
|
||||
pub fn close_block(&mut self) {
|
||||
self.depth -= 1;
|
||||
}
|
||||
|
||||
pub fn clear_log(&mut self) {
|
||||
self.log.clear();
|
||||
self.depths.clear();
|
||||
}
|
||||
|
||||
pub fn damage(&mut self, target: EntityId, amount: i32) {
|
||||
|
||||
Reference in new issue
Block a user