Fix: Games and Game page save and navigation.

This commit is contained in:
2026-02-10 19:21:22 +00:00
parent 81fdfffbe5
commit 29ddd1ded0
7 changed files with 86 additions and 95 deletions

View File

@@ -1918,7 +1918,7 @@ class PageMtgGame extends TableBasePage {
damageDisplay.classList.remove('lethal');
}
const latestRoundId = PageMtgGame.getLatestRoundId();
const damageIndex = damageRecords.findIndex(damageRecord => damage[attrRoundId] == latestRoundId && damageRecord[attrPlayerId] == playerId && damageRecord[attrReceivedFromCommanderPlayerId] == sourceId);
const damageIndex = damageRecords.findIndex(damageRecord => damageRecord[attrRoundId] == latestRoundId && damageRecord[attrPlayerId] == playerId && damageRecord[attrReceivedFromCommanderPlayerId] == sourceId);
damageRecords[damageIndex][flagHealthChange] -= amount;
this.changeLife(playerId // playerId
, -amount // amount
@@ -2058,18 +2058,18 @@ class PageMtgGame extends TableBasePage {
}
}
async saveGame() {
const gameState = {
[flagPlayer]: players,
[flagRound]: rounds,
[flagDamage]: damageRecords
};
/*
const gameState = {
[flagPlayer]: players
, [flagRound]: rounds
, [flagDamage]: damageRecords
};
if (gameState[flagPlayer].length > 0) {
localStorage.setItem(`mtgGame_${gameId}`, JSON.stringify(gameState));
PageMtgGame.showSaveIndicator();
}
*/
const comment = 'Save players';
const comment = 'Save player damage';
const self = this;
API.saveGameRoundPlayerDamages(rounds, damageRecords, null, comment).then(data => {
if (data[flagStatus] == flagSuccess) {
@@ -2140,13 +2140,13 @@ class PageMtgGames extends TableBasePage {
this.hookupTcgGames();
}
hookupTcgGames() {
PageMtgGames.initGamesPage();
this.initGamesPage();
}
static initGamesPage() {
initGamesPage() {
// Initialize form submission
const newGameForm = document.getElementById('newGameForm');
if (newGameForm) {
newGameForm.addEventListener('submit', PageMtgGames.handleNewGameSubmit);
newGameForm.addEventListener('submit', this.handleNewGameSubmit.bind(this)); // () => { this.handleNewGameSubmit.bind(this); });
}
// Initialize filter form
@@ -2210,7 +2210,7 @@ class PageMtgGames extends TableBasePage {
}
}
}
static async handleNewGameSubmit(e) {
async handleNewGameSubmit(e) {
e.preventDefault();
const form = e.target;
const formData = new FormData(form);
@@ -2233,13 +2233,18 @@ class PageMtgGames extends TableBasePage {
const games = [gameData];
const comment = 'Create new game';
debugger;
// const self = this;
API.saveGame(games, form, comment).then(data => {
if (data[flagStatus] == flagSuccess) {
if (_verbose) {
utils_Utils.consoleLogIfNotProductionEnvironment('Records saved!');
utils_Utils.consoleLogIfNotProductionEnvironment('Data received:', data);
}
this.callFilterTableContent(gameData.game_id);
// this.callFilterTableContent(data[attrGameId]); // gameData.game_id
const gamePageHash = `${hashPageGame}/${data[attrGameId]}`;
let filtersJson = {};
this.leave();
API.goToHash(gamePageHash, filtersJson);
} else {
utils_Utils.consoleLogIfNotProductionEnvironment("error: " + data[flagMessage]);
// OverlayError.show(data[flagMessage]);
@@ -2253,13 +2258,6 @@ class PageMtgGames extends TableBasePage {
submitBtn.disabled = false;
});
}
callFilterTableContent(gameId) {
const gamePageHash = `${hashPageGame}/${gameId}`;
let filtersJson = {};
utils_Utils.consoleLogIfNotProductionEnvironment("callFilterTableContent");
this.leave();
API.goToHash(gamePageHash, filtersJson);
}
static handleFilterSubmit(e) {
// Let the form submit normally - it will reload with query params
// You can add client-side filtering here if needed

File diff suppressed because one or more lines are too long