Fix: Games and Game page save and navigation.
This commit is contained in:
36
static/dist/js/main.bundle.js
vendored
36
static/dist/js/main.bundle.js
vendored
@@ -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
|
||||
|
||||
2
static/dist/js/main.bundle.js.map
vendored
2
static/dist/js/main.bundle.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user