1
0

copy game rules on game creation

This commit is contained in:
Adrian Wannenmacher 2026-03-10 00:11:38 +01:00
parent 6f643f7070
commit 04a84785f6
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5
2 changed files with 12 additions and 1 deletions

View File

@ -130,7 +130,7 @@ export default class Session extends EventTarget {
/** Add another round if there is no current one. */ /** Add another round if there is no current one. */
anotherGame() { anotherGame() {
if (this.#currentGame === null) { if (this.#currentGame === null) {
this.#currentGame = new Game(this.rules); this.#currentGame = new Game(new GameRules(this.#rules));
this.#currentGame.addEventListener( this.#currentGame.addEventListener(
Game.EVENT_CHANGE, this.#boundHandleGameChange); Game.EVENT_CHANGE, this.#boundHandleGameChange);
this.#changed(); this.#changed();

View File

@ -60,6 +60,17 @@ export default function() {
assert.notStrictEqual(session.currentGame, null, "game in progress"); assert.notStrictEqual(session.currentGame, null, "game in progress");
}); });
QUnit.test("session rule change doesn't affect games", function(assert) {
let session = new Session();
session.anotherGame();
session.rules.goal = 7;
assert.notStrictEqual(
session.currentGame.rules.goal,
session.rules.goal,
"game rules have been copied",
);
});
QUnit.test("single game finished", function(assert) { QUnit.test("single game finished", function(assert) {
let session = new Session(); let session = new Session();
session.anotherGame(); session.anotherGame();