2020-05-09 14:45:23 +00:00
|
|
|
import { GameState } from "../core/game_state";
|
|
|
|
import { cachebust } from "../core/cachebust";
|
2020-05-19 13:03:13 +00:00
|
|
|
import { globalConfig, IS_DEBUG, IS_DEMO, THIRDPARTY_URLS } from "../core/config";
|
2020-05-16 15:57:25 +00:00
|
|
|
import {
|
|
|
|
makeDiv,
|
|
|
|
formatSecondsToTimeAgo,
|
|
|
|
generateFileDownload,
|
|
|
|
waitNextFrame,
|
2020-05-16 20:45:40 +00:00
|
|
|
isSupportedBrowser,
|
2020-05-16 15:57:25 +00:00
|
|
|
} from "../core/utils";
|
2020-05-16 08:05:19 +00:00
|
|
|
import { ReadWriteProxy } from "../core/read_write_proxy";
|
2020-05-16 15:57:25 +00:00
|
|
|
import { HUDModalDialogs } from "../game/hud/parts/modal_dialogs";
|
2020-05-17 10:12:13 +00:00
|
|
|
import { T } from "../translations";
|
2020-05-22 11:12:07 +00:00
|
|
|
import { PlatformWrapperImplBrowser } from "../platform/browser/wrapper";
|
2020-06-10 10:29:21 +00:00
|
|
|
import { getApplicationSettingById } from "../profile/application_settings";
|
|
|
|
import { EnumSetting } from "../profile/setting_types";
|
2020-05-09 14:45:23 +00:00
|
|
|
|
|
|
|
export class MainMenuState extends GameState {
|
|
|
|
constructor() {
|
|
|
|
super("MainMenuState");
|
|
|
|
}
|
|
|
|
|
|
|
|
getInnerHTML() {
|
2020-05-16 15:57:25 +00:00
|
|
|
const bannerHtml = `
|
2020-05-17 10:12:13 +00:00
|
|
|
<h3>${T.demoBanners.title}</h3>
|
2020-05-16 15:57:25 +00:00
|
|
|
|
2020-05-17 10:12:13 +00:00
|
|
|
<p>${T.demoBanners.intro}</p>
|
2020-05-16 15:57:25 +00:00
|
|
|
|
2020-05-21 20:49:00 +00:00
|
|
|
<a href="#" class="steamLink" target="_blank">Get the shapez.io standalone!</a>
|
2020-05-16 15:57:25 +00:00
|
|
|
`;
|
|
|
|
|
2020-06-07 10:56:02 +00:00
|
|
|
return (
|
|
|
|
`
|
2020-05-12 07:56:11 +00:00
|
|
|
|
2020-06-10 10:29:21 +00:00
|
|
|
<div class="topButtons">
|
|
|
|
<button class="languageChoose" data-languageicon="${this.app.settings.getLanguage()}"></button>
|
|
|
|
<button class="settingsButton"></button>
|
|
|
|
|
|
|
|
${
|
|
|
|
G_IS_STANDALONE || G_IS_DEV
|
|
|
|
? `
|
|
|
|
<button class="exitAppButton"></button>
|
|
|
|
`
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
</div>
|
2020-05-17 11:24:47 +00:00
|
|
|
|
2020-05-21 11:05:21 +00:00
|
|
|
${
|
|
|
|
G_IS_STANDALONE
|
|
|
|
? ""
|
|
|
|
: `<video autoplay muted loop class="fullscreenBackgroundVideo">
|
2020-05-12 07:56:11 +00:00
|
|
|
<source src="${cachebust("res/bg_render.webm")}" type="video/webm">
|
2020-05-21 11:05:21 +00:00
|
|
|
</video>`
|
|
|
|
}
|
2020-05-12 07:56:11 +00:00
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
<div class="logo">
|
|
|
|
<img src="${cachebust("res/logo.png")}" alt="shapez.io Logo">
|
|
|
|
</div>
|
|
|
|
|
2020-05-11 11:22:05 +00:00
|
|
|
|
2020-05-19 13:03:13 +00:00
|
|
|
<div class="mainWrapper ${IS_DEMO ? "demo" : "noDemo"}">
|
|
|
|
|
2020-06-03 08:06:13 +00:00
|
|
|
<div class="sideContainer">
|
|
|
|
${IS_DEMO ? `<div class="standaloneBanner">${bannerHtml}</div>` : ""}
|
2020-06-07 10:56:02 +00:00
|
|
|
|
2020-06-03 08:06:13 +00:00
|
|
|
<div class="contest">
|
|
|
|
<h3>${T.mainMenu.contests.contest_01_03062020.title}</h3>
|
2020-06-07 10:56:02 +00:00
|
|
|
` +
|
|
|
|
/*<p>${T.mainMenu.contests.contest_01_03062020.desc}</p>
|
2020-06-03 08:06:13 +00:00
|
|
|
<button class="styledButton participateContest">${
|
|
|
|
T.mainMenu.contests.showInfo
|
2020-06-07 10:56:02 +00:00
|
|
|
}</button>*/
|
|
|
|
|
|
|
|
`
|
|
|
|
<p>${T.mainMenu.contests.contestOver}</p>
|
|
|
|
|
2020-06-03 08:06:13 +00:00
|
|
|
</div>
|
2020-06-07 10:56:02 +00:00
|
|
|
|
2020-06-03 08:06:13 +00:00
|
|
|
</div>
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
<div class="mainContainer">
|
2020-05-19 13:03:13 +00:00
|
|
|
${
|
|
|
|
isSupportedBrowser()
|
|
|
|
? ""
|
|
|
|
: `<div class="browserWarning">${T.mainMenu.browserWarning}</div>`
|
|
|
|
}
|
2020-05-17 10:12:13 +00:00
|
|
|
<button class="playButton styledButton">${T.mainMenu.play}</button>
|
|
|
|
<button class="importButton styledButton">${T.mainMenu.importSavegame}</button>
|
2020-05-16 15:57:25 +00:00
|
|
|
</div>
|
2020-05-19 13:03:13 +00:00
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
</div>
|
2020-05-10 17:20:32 +00:00
|
|
|
|
|
|
|
<div class="footer">
|
|
|
|
|
2020-05-23 13:04:55 +00:00
|
|
|
<a class="githubLink boxLink" target="_blank">
|
2020-05-17 10:12:13 +00:00
|
|
|
${T.mainMenu.openSourceHint}
|
2020-05-10 17:20:32 +00:00
|
|
|
<span class="thirdpartyLogo githubLogo"></span>
|
2020-05-22 11:12:07 +00:00
|
|
|
</a>
|
2020-05-17 10:12:13 +00:00
|
|
|
|
2020-05-23 13:04:55 +00:00
|
|
|
<a class="discordLink boxLink" target="_blank">
|
2020-05-17 10:12:13 +00:00
|
|
|
${T.mainMenu.discordLink}
|
|
|
|
<span class="thirdpartyLogo discordLogo"></span>
|
2020-05-22 11:12:07 +00:00
|
|
|
</a>
|
2020-05-10 17:20:32 +00:00
|
|
|
|
2020-05-23 13:04:55 +00:00
|
|
|
<a class="changelog">${T.changelog.title}</a>
|
2020-06-10 10:29:21 +00:00
|
|
|
|
|
|
|
<a class="helpTranslate">${T.mainMenu.helpTranslate}</a>
|
2020-05-21 15:34:39 +00:00
|
|
|
|
2020-05-22 11:12:07 +00:00
|
|
|
<div class="author">Made by <a class="producerLink" target="_blank">Tobias Springer</a></div>
|
2020-05-21 14:56:53 +00:00
|
|
|
|
2020-05-10 17:20:32 +00:00
|
|
|
</div>
|
2020-06-07 10:56:02 +00:00
|
|
|
`
|
|
|
|
);
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
requestImportSavegame() {
|
2020-05-24 15:49:12 +00:00
|
|
|
if (
|
|
|
|
IS_DEMO &&
|
|
|
|
this.app.savegameMgr.getSavegamesMetaData().length > 0 &&
|
|
|
|
!this.app.platformWrapper.getHasUnlimitedSavegames()
|
|
|
|
) {
|
2020-05-22 11:12:07 +00:00
|
|
|
this.app.analytics.trackUiClick("importgame_slot_limit_show");
|
2020-05-21 18:16:33 +00:00
|
|
|
this.dialogs.showWarning(T.dialogs.oneSavegameLimit.title, T.dialogs.oneSavegameLimit.desc);
|
2020-05-19 13:03:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
var input = document.createElement("input");
|
|
|
|
input.type = "file";
|
|
|
|
input.accept = ".bin";
|
|
|
|
|
|
|
|
input.onchange = e => {
|
|
|
|
const file = input.files[0];
|
|
|
|
if (file) {
|
|
|
|
waitNextFrame().then(() => {
|
2020-05-19 10:07:55 +00:00
|
|
|
this.app.analytics.trackUiClick("import_savegame");
|
2020-05-16 15:57:25 +00:00
|
|
|
const closeLoader = this.dialogs.showLoadingDialog();
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.addEventListener("load", event => {
|
2020-05-24 14:54:18 +00:00
|
|
|
// @ts-ignore
|
2020-05-16 15:57:25 +00:00
|
|
|
const contents = event.target.result;
|
|
|
|
let realContent;
|
|
|
|
|
|
|
|
try {
|
|
|
|
realContent = ReadWriteProxy.deserializeObject(contents);
|
|
|
|
} catch (err) {
|
|
|
|
closeLoader();
|
|
|
|
this.dialogs.showWarning(
|
2020-05-17 10:12:13 +00:00
|
|
|
T.dialogs.importSavegameError.title,
|
|
|
|
T.dialogs.importSavegameError.text + "<br><br>" + err
|
2020-05-16 15:57:25 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.app.savegameMgr.importSavegame(realContent).then(
|
|
|
|
() => {
|
|
|
|
closeLoader();
|
2020-05-17 10:12:13 +00:00
|
|
|
this.dialogs.showWarning(
|
|
|
|
T.dialogs.importSavegameSuccess.title,
|
|
|
|
T.dialogs.importSavegameSuccess.text
|
|
|
|
);
|
2020-05-16 15:57:25 +00:00
|
|
|
|
|
|
|
this.renderSavegames();
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
closeLoader();
|
|
|
|
this.dialogs.showWarning(
|
2020-05-17 10:12:13 +00:00
|
|
|
T.dialogs.importSavegameError.title,
|
|
|
|
T.dialogs.importSavegameError.text + ":<br><br>" + err
|
2020-05-16 15:57:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
reader.addEventListener("error", error => {
|
2020-05-17 10:12:13 +00:00
|
|
|
this.dialogs.showWarning(
|
|
|
|
T.dialogs.importSavegameError.title,
|
|
|
|
T.dialogs.importSavegameError.text + ":<br><br>" + error
|
|
|
|
);
|
2020-05-16 15:57:25 +00:00
|
|
|
});
|
|
|
|
reader.readAsText(file, "utf-8");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
input.click();
|
|
|
|
}
|
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
onBackButton() {
|
|
|
|
this.app.platformWrapper.exitApp();
|
|
|
|
}
|
|
|
|
|
|
|
|
onEnter(payload) {
|
2020-05-21 21:57:38 +00:00
|
|
|
this.dialogs = new HUDModalDialogs(null, this.app);
|
|
|
|
const dialogsElement = document.body.querySelector(".modalDialogParent");
|
|
|
|
this.dialogs.initializeToElement(dialogsElement);
|
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
if (payload.loadError) {
|
2020-05-17 10:12:13 +00:00
|
|
|
this.dialogs.showWarning(
|
|
|
|
T.dialogs.gameLoadFailure.title,
|
|
|
|
T.dialogs.gameLoadFailure.text + "<br><br>" + payload.loadError
|
|
|
|
);
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const qs = this.htmlElement.querySelector.bind(this.htmlElement);
|
|
|
|
this.trackClicks(qs(".mainContainer .playButton"), this.onPlayButtonClicked);
|
2020-05-16 15:57:25 +00:00
|
|
|
this.trackClicks(qs(".mainContainer .importButton"), this.requestImportSavegame);
|
2020-05-09 14:45:23 +00:00
|
|
|
|
|
|
|
if (G_IS_DEV && globalConfig.debug.fastGameEnter) {
|
2020-05-27 12:30:59 +00:00
|
|
|
const games = this.app.savegameMgr.getSavegamesMetaData();
|
2020-06-01 18:18:50 +00:00
|
|
|
if (games.length > 0 && globalConfig.debug.resumeGameOnFastEnter) {
|
2020-05-27 12:30:59 +00:00
|
|
|
this.resumeGame(games[0]);
|
|
|
|
} else {
|
|
|
|
this.onPlayButtonClicked();
|
|
|
|
}
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
2020-05-12 07:56:11 +00:00
|
|
|
|
|
|
|
// Initialize video
|
|
|
|
this.videoElement = this.htmlElement.querySelector("video");
|
|
|
|
if (this.videoElement) {
|
|
|
|
this.videoElement.playbackRate = 0.9;
|
|
|
|
this.videoElement.addEventListener("canplay", () => {
|
|
|
|
if (this.videoElement) {
|
|
|
|
this.videoElement.classList.add("loaded");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 19:54:11 +00:00
|
|
|
|
2020-05-17 11:24:47 +00:00
|
|
|
this.trackClicks(qs(".settingsButton"), this.onSettingsButtonClicked);
|
2020-05-23 13:04:55 +00:00
|
|
|
this.trackClicks(qs(".changelog"), this.onChangelogClicked);
|
2020-06-10 10:29:21 +00:00
|
|
|
this.trackClicks(qs(".languageChoose"), this.onLanguageChooseClicked);
|
2020-05-21 11:05:21 +00:00
|
|
|
|
2020-06-07 10:56:02 +00:00
|
|
|
const contestButton = qs(".participateContest");
|
|
|
|
if (contestButton) {
|
|
|
|
this.trackClicks(contestButton, this.onContestClicked);
|
|
|
|
}
|
2020-06-03 08:06:13 +00:00
|
|
|
|
2020-05-21 11:05:21 +00:00
|
|
|
if (G_IS_STANDALONE) {
|
|
|
|
this.trackClicks(qs(".exitAppButton"), this.onExitAppButtonClicked);
|
|
|
|
}
|
|
|
|
|
2020-05-14 19:54:11 +00:00
|
|
|
this.renderSavegames();
|
2020-05-19 10:07:55 +00:00
|
|
|
|
2020-05-22 11:12:07 +00:00
|
|
|
const steamLink = this.htmlElement.querySelector(".steamLink");
|
|
|
|
if (steamLink) {
|
|
|
|
this.trackClicks(steamLink, () => this.onSteamLinkClicked(), { preventClick: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
const discordLink = this.htmlElement.querySelector(".discordLink");
|
|
|
|
this.trackClicks(
|
|
|
|
discordLink,
|
|
|
|
() => this.app.platformWrapper.openExternalLink(THIRDPARTY_URLS.discord),
|
|
|
|
{ preventClick: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
const githubLink = this.htmlElement.querySelector(".githubLink");
|
|
|
|
this.trackClicks(
|
|
|
|
githubLink,
|
|
|
|
() => this.app.platformWrapper.openExternalLink(THIRDPARTY_URLS.github),
|
|
|
|
{ preventClick: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
const producerLink = this.htmlElement.querySelector(".producerLink");
|
|
|
|
this.trackClicks(
|
|
|
|
producerLink,
|
|
|
|
() => this.app.platformWrapper.openExternalLink("https://tobspr.com"),
|
|
|
|
{ preventClick: true }
|
|
|
|
);
|
2020-05-19 10:07:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 11:12:07 +00:00
|
|
|
onSteamLinkClicked() {
|
2020-06-07 10:56:02 +00:00
|
|
|
this.app.analytics.trackUiClick("main_menu_steam_link_2");
|
2020-05-22 11:12:07 +00:00
|
|
|
this.app.platformWrapper.openExternalLink(THIRDPARTY_URLS.standaloneStorePage);
|
2020-05-19 10:07:55 +00:00
|
|
|
return false;
|
2020-05-14 19:54:11 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 11:05:21 +00:00
|
|
|
onExitAppButtonClicked() {
|
|
|
|
this.app.platformWrapper.exitApp();
|
|
|
|
}
|
|
|
|
|
2020-05-23 13:04:55 +00:00
|
|
|
onChangelogClicked() {
|
|
|
|
this.moveToState("ChangelogState");
|
|
|
|
}
|
|
|
|
|
2020-06-03 08:06:13 +00:00
|
|
|
onContestClicked() {
|
|
|
|
this.app.analytics.trackUiClick("contest_click");
|
|
|
|
|
|
|
|
this.dialogs.showInfo(
|
|
|
|
T.mainMenu.contests.contest_01_03062020.title,
|
|
|
|
T.mainMenu.contests.contest_01_03062020.longDesc
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:29:21 +00:00
|
|
|
onLanguageChooseClicked() {
|
|
|
|
const setting = /** @type {EnumSetting} */ (getApplicationSettingById("language"));
|
|
|
|
|
|
|
|
const { optionSelected } = this.dialogs.showOptionChooser(T.settings.labels.language.title, {
|
|
|
|
active: this.app.settings.getLanguage(),
|
|
|
|
options: setting.options.map(option => ({
|
|
|
|
value: setting.valueGetter(option),
|
|
|
|
text: setting.textGetter(option),
|
|
|
|
desc: setting.descGetter(option),
|
|
|
|
iconPrefix: setting.iconPrefix,
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
|
|
|
optionSelected.add(value => {
|
|
|
|
this.app.settings.updateLanguage(value);
|
|
|
|
if (setting.restartRequired) {
|
|
|
|
if (this.app.platformWrapper.getSupportsRestart()) {
|
|
|
|
this.app.platformWrapper.performRestart();
|
|
|
|
} else {
|
|
|
|
this.dialogs.showInfo(T.dialogs.restartRequired.title, T.dialogs.restartRequired.text, [
|
|
|
|
"ok:good",
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.changeCb) {
|
|
|
|
setting.changeCb(this.app, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update current icon
|
|
|
|
this.htmlElement.querySelector("button.languageChoose").setAttribute("data-languageIcon", value);
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
2020-05-14 19:54:11 +00:00
|
|
|
renderSavegames() {
|
2020-05-16 15:57:25 +00:00
|
|
|
const oldContainer = this.htmlElement.querySelector(".mainContainer .savegames");
|
|
|
|
if (oldContainer) {
|
|
|
|
oldContainer.remove();
|
|
|
|
}
|
2020-05-14 19:54:11 +00:00
|
|
|
const games = this.app.savegameMgr.getSavegamesMetaData();
|
|
|
|
if (games.length > 0) {
|
|
|
|
const parent = makeDiv(this.htmlElement.querySelector(".mainContainer"), null, ["savegames"]);
|
|
|
|
|
|
|
|
for (let i = 0; i < games.length; ++i) {
|
|
|
|
const elem = makeDiv(parent, null, ["savegame"]);
|
|
|
|
|
2020-05-30 15:50:29 +00:00
|
|
|
makeDiv(
|
|
|
|
elem,
|
|
|
|
null,
|
|
|
|
["playtime"],
|
|
|
|
formatSecondsToTimeAgo((new Date().getTime() - games[i].lastUpdate) / 1000.0)
|
|
|
|
);
|
|
|
|
|
2020-05-14 19:54:11 +00:00
|
|
|
makeDiv(
|
|
|
|
elem,
|
|
|
|
null,
|
2020-05-28 12:53:11 +00:00
|
|
|
["level"],
|
|
|
|
games[i].level
|
|
|
|
? T.mainMenu.savegameLevel.replace("<x>", "" + games[i].level)
|
|
|
|
: T.mainMenu.savegameLevelUnknown
|
2020-05-14 19:54:11 +00:00
|
|
|
);
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
const deleteButton = document.createElement("button");
|
|
|
|
deleteButton.classList.add("styledButton", "deleteGame");
|
|
|
|
elem.appendChild(deleteButton);
|
|
|
|
|
2020-05-16 08:05:19 +00:00
|
|
|
const downloadButton = document.createElement("button");
|
|
|
|
downloadButton.classList.add("styledButton", "downloadGame");
|
|
|
|
elem.appendChild(downloadButton);
|
|
|
|
|
2020-05-14 19:54:11 +00:00
|
|
|
const resumeBtn = document.createElement("button");
|
|
|
|
resumeBtn.classList.add("styledButton", "resumeGame");
|
|
|
|
elem.appendChild(resumeBtn);
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
this.trackClicks(deleteButton, () => this.deleteGame(games[i]));
|
2020-05-16 08:05:19 +00:00
|
|
|
this.trackClicks(downloadButton, () => this.downloadGame(games[i]));
|
2020-05-14 19:54:11 +00:00
|
|
|
this.trackClicks(resumeBtn, () => this.resumeGame(games[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {object} game
|
|
|
|
*/
|
|
|
|
resumeGame(game) {
|
2020-05-19 10:07:55 +00:00
|
|
|
this.app.analytics.trackUiClick("resume_game");
|
2020-05-19 13:03:13 +00:00
|
|
|
|
2020-05-22 11:12:07 +00:00
|
|
|
this.app.adProvider.showVideoAd().then(() => {
|
|
|
|
this.app.analytics.trackUiClick("resume_game_adcomplete");
|
|
|
|
const savegame = this.app.savegameMgr.getSavegameById(game.internalId);
|
|
|
|
savegame.readAsync().then(() => {
|
|
|
|
this.moveToState("InGameState", {
|
|
|
|
savegame,
|
|
|
|
});
|
2020-05-14 19:54:11 +00:00
|
|
|
});
|
|
|
|
});
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
/**
|
|
|
|
* @param {object} game
|
|
|
|
*/
|
|
|
|
deleteGame(game) {
|
2020-05-22 11:12:07 +00:00
|
|
|
this.app.analytics.trackUiClick("delete_game");
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
const signals = this.dialogs.showWarning(
|
2020-05-17 10:12:13 +00:00
|
|
|
T.dialogs.confirmSavegameDelete.title,
|
|
|
|
T.dialogs.confirmSavegameDelete.text,
|
2020-05-16 15:57:25 +00:00
|
|
|
["delete:bad", "cancel:good"]
|
|
|
|
);
|
|
|
|
|
|
|
|
signals.delete.add(() => {
|
|
|
|
this.app.savegameMgr.deleteSavegame(game).then(
|
|
|
|
() => {
|
|
|
|
this.renderSavegames();
|
|
|
|
},
|
|
|
|
err => {
|
2020-05-17 10:12:13 +00:00
|
|
|
this.dialogs.showWarning(
|
|
|
|
T.dialogs.savegameDeletionError.title,
|
|
|
|
T.dialogs.savegameDeletionError.text + "<br><br>" + err
|
|
|
|
);
|
2020-05-16 15:57:25 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-16 08:05:19 +00:00
|
|
|
/**
|
|
|
|
* @param {object} game
|
|
|
|
*/
|
|
|
|
downloadGame(game) {
|
2020-05-19 10:07:55 +00:00
|
|
|
this.app.analytics.trackUiClick("download_game");
|
|
|
|
|
2020-05-16 08:05:19 +00:00
|
|
|
const savegame = this.app.savegameMgr.getSavegameById(game.internalId);
|
|
|
|
savegame.readAsync().then(() => {
|
|
|
|
const data = ReadWriteProxy.serializeObject(savegame.currentData);
|
|
|
|
generateFileDownload(savegame.filename, data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-17 11:24:47 +00:00
|
|
|
onSettingsButtonClicked() {
|
|
|
|
this.moveToState("SettingsState");
|
|
|
|
}
|
|
|
|
|
2020-05-21 14:56:53 +00:00
|
|
|
onPlayButtonClicked() {
|
2020-05-24 15:49:12 +00:00
|
|
|
if (
|
|
|
|
IS_DEMO &&
|
|
|
|
this.app.savegameMgr.getSavegamesMetaData().length > 0 &&
|
|
|
|
!this.app.platformWrapper.getHasUnlimitedSavegames()
|
|
|
|
) {
|
2020-05-22 11:12:07 +00:00
|
|
|
this.app.analytics.trackUiClick("startgame_slot_limit_show");
|
2020-05-21 18:16:33 +00:00
|
|
|
this.dialogs.showWarning(T.dialogs.oneSavegameLimit.title, T.dialogs.oneSavegameLimit.desc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:58:36 +00:00
|
|
|
this.app.analytics.trackUiClick("startgame");
|
|
|
|
this.app.adProvider.showVideoAd().then(() => {
|
|
|
|
const savegame = this.app.savegameMgr.createNewSavegame();
|
2020-05-21 14:56:53 +00:00
|
|
|
|
2020-06-01 17:58:36 +00:00
|
|
|
this.moveToState("InGameState", {
|
|
|
|
savegame,
|
|
|
|
});
|
|
|
|
this.app.analytics.trackUiClick("startgame_adcomplete");
|
|
|
|
});
|
2020-05-21 14:56:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
onLeave() {
|
2020-05-16 15:57:25 +00:00
|
|
|
this.dialogs.cleanup();
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
|
|
|
}
|