Add snapshots and Game.dryRun #464

Closed
opened 2026-01-28 17:21:38 +00:00 by LunarTides · 0 comments
LunarTides commented 2026-01-28 17:21:38 +00:00 (Migrated from github.com)

Add Game.dryRun, which undoes the code that's run. This should be a direct method of the game class since it affects the entire game.

Scripts can make use of this temporarily until #407 is done, or permanently if #407 is more intensive.

This makes #21 feasible.
This might allow for general undo in the future.

Example

assert.equal(game.player.health, 30); // OK
await game.dryRun(async () => {
    await game.player.damage(15);
    assert.equal(game.player.health, 15); // OK
});
assert.equal(game.player.health, 30); // OK

Implementation

Pseudo-code

dryRun(callback) {
    const snapshot = await createSnapshot();
    await callback();
    revertToSnapshot(snapshot);
}

createSnapshot() {
    const snapshot = await deepCloneGameWithExceptionOfBlueprints();
    return snapshot;
}

revertToSnapshot(snapshot) {
    // maybe?
    for key in gameVariables {
        game[key] = value;
    }
}
Add `Game.dryRun`, which undoes the code that's run. This should be a direct method of the game class since it affects the entire game. Scripts can make use of this temporarily until #407 is done, or permanently if #407 is more intensive. This makes #21 feasible. This might allow for general undo in the future. ## Example ```ts assert.equal(game.player.health, 30); // OK await game.dryRun(async () => { await game.player.damage(15); assert.equal(game.player.health, 15); // OK }); assert.equal(game.player.health, 30); // OK ``` ## Implementation Pseudo-code ```ts dryRun(callback) { const snapshot = await createSnapshot(); await callback(); revertToSnapshot(snapshot); } createSnapshot() { const snapshot = await deepCloneGameWithExceptionOfBlueprints(); return snapshot; } revertToSnapshot(snapshot) { // maybe? for key in gameVariables { game[key] = value; } } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
LunarTides/Hearthstone.js#464
No description provided.