Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic undo #175

Merged
merged 21 commits into from
Mar 9, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
only lock undo when needed
zeitlinger committed Mar 9, 2025
commit ac8f8ab17c2e73d4d99af5ae4bf8b5e2191bb731
1 change: 0 additions & 1 deletion server/src/action.rs
Original file line number Diff line number Diff line change
@@ -283,7 +283,6 @@ pub(crate) fn execute_movement_action(
starting_position,
m.destination,
);
stop_current_move(game);
return;
}

5 changes: 2 additions & 3 deletions server/src/combat.rs
Original file line number Diff line number Diff line change
@@ -187,6 +187,8 @@ pub fn initiate_combat(

pub(crate) fn start_combat(game: &mut Game) {
game.lock_undo(); // combat should not be undoable
stop_current_move(game);

let combat = get_combat(game);
let attacker = combat.attacker;
let defender = combat.defender;
@@ -388,9 +390,6 @@ pub(crate) fn end_combat(game: &mut Game, combat: Combat, r: CombatResult) -> Op
}

take_combat(game);
if let Some(GameState::Movement(_)) = game.state_stack.last() {
stop_current_move(game);
}
None
}

2 changes: 1 addition & 1 deletion server/src/explore.rs
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ pub(crate) fn move_to_unexplored_tile(
destination: Position,
) -> bool {
game.lock_undo(); // tile is revealed, so we can't undo the move
stop_current_move(game);

for b in &game.map.unexplored_blocks.clone() {
for (position, _tile) in b.block.tiles(&b.position, b.position.rotation) {
@@ -301,7 +302,6 @@ pub(crate) fn explore_resolution() -> Builtin {
r.destination,
r.ship_can_teleport,
);
stop_current_move(game);
},
)
.build()
25 changes: 15 additions & 10 deletions server/tests/test_games/combat/ship_combat.outcome1.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,14 @@
"moved_units": [
7,
8
]
],
"current_move": {
"Fleet": {
"units": [
8
]
}
}
}
}
],
@@ -396,17 +403,15 @@
"unit_type": "Ship"
}
},
{
"op": "replace",
"path": "/state/1/Movement/current_move/Fleet/units/0",
"value": 7
},
{
"op": "add",
"path": "/state/1/Movement/current_move",
"value": {
"Fleet": {
"units": [
7,
8
]
}
}
"path": "/state/1/Movement/current_move/Fleet/units/1",
"value": 8
},
{
"op": "add",