2020-05-09 14:45:23 +00:00
|
|
|
import { GameState } from "../core/game_state";
|
|
|
|
import { cachebust } from "../core/cachebust";
|
|
|
|
import { globalConfig } from "../core/config";
|
2020-05-14 19:54:11 +00:00
|
|
|
import { makeDiv, formatSecondsToTimeAgo } from "../core/utils";
|
2020-05-09 14:45:23 +00:00
|
|
|
|
|
|
|
export class MainMenuState extends GameState {
|
|
|
|
constructor() {
|
|
|
|
super("MainMenuState");
|
|
|
|
}
|
|
|
|
|
|
|
|
getInnerHTML() {
|
|
|
|
return `
|
2020-05-12 07:56:11 +00:00
|
|
|
|
|
|
|
<video autoplay muted loop class="fullscreenBackgroundVideo">
|
|
|
|
<source src="${cachebust("res/bg_render.webm")}" type="video/webm">
|
|
|
|
</video>
|
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
<div class="logo">
|
|
|
|
<img src="${cachebust("res/logo.png")}" alt="shapez.io Logo">
|
|
|
|
</div>
|
2020-05-12 07:56:11 +00:00
|
|
|
|
|
|
|
<div class="betaWarning">
|
|
|
|
This game is still under development - Please report any issues!
|
|
|
|
</div>
|
2020-05-09 14:45:23 +00:00
|
|
|
|
|
|
|
<div class="mainContainer">
|
2020-05-11 11:22:05 +00:00
|
|
|
|
2020-05-09 14:45:23 +00:00
|
|
|
<button class="playButton styledButton">Play</button>
|
|
|
|
</div>
|
2020-05-10 17:20:32 +00:00
|
|
|
|
|
|
|
<div class="footer">
|
|
|
|
|
|
|
|
<a href="https://github.com/tobspr/shapez.io" target="_blank">
|
2020-05-11 11:11:07 +00:00
|
|
|
This game is open source!
|
2020-05-10 17:20:32 +00:00
|
|
|
<span class="thirdpartyLogo githubLogo"></span>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<a href="https://discord.gg/HN7EVzV" target="_blank">
|
2020-05-11 11:11:07 +00:00
|
|
|
Official discord server
|
|
|
|
<span class="thirdpartyLogo discordLogo"></span>
|
2020-05-10 17:20:32 +00:00
|
|
|
</a>
|
|
|
|
|
|
|
|
</div>
|
2020-05-09 14:45:23 +00:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
onBackButton() {
|
|
|
|
this.app.platformWrapper.exitApp();
|
|
|
|
}
|
|
|
|
|
|
|
|
onEnter(payload) {
|
|
|
|
if (payload.loadError) {
|
|
|
|
alert("Error while loading game: " + payload.loadError);
|
|
|
|
}
|
|
|
|
|
|
|
|
const qs = this.htmlElement.querySelector.bind(this.htmlElement);
|
|
|
|
this.trackClicks(qs(".mainContainer .playButton"), this.onPlayButtonClicked);
|
|
|
|
|
|
|
|
if (G_IS_DEV && globalConfig.debug.fastGameEnter) {
|
|
|
|
this.onPlayButtonClicked();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
this.renderSavegames();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSavegames() {
|
|
|
|
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-14 20:20:19 +00:00
|
|
|
makeDiv(elem, null, ["internalId"], games[i].internalId.substr(0, 6));
|
2020-05-14 19:54:11 +00:00
|
|
|
makeDiv(
|
|
|
|
elem,
|
|
|
|
null,
|
|
|
|
["updateTime"],
|
|
|
|
formatSecondsToTimeAgo((new Date().getTime() - games[i].lastUpdate) / 1000.0)
|
|
|
|
);
|
|
|
|
|
|
|
|
const resumeBtn = document.createElement("button");
|
|
|
|
resumeBtn.classList.add("styledButton", "resumeGame");
|
|
|
|
elem.appendChild(resumeBtn);
|
|
|
|
|
|
|
|
this.trackClicks(resumeBtn, () => this.resumeGame(games[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {object} game
|
|
|
|
*/
|
|
|
|
resumeGame(game) {
|
|
|
|
const savegame = this.app.savegameMgr.getSavegameById(game.internalId);
|
|
|
|
savegame.readAsync().then(() => {
|
|
|
|
this.moveToState("InGameState", {
|
|
|
|
savegame,
|
|
|
|
});
|
|
|
|
});
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onPlayButtonClicked() {
|
|
|
|
const savegame = this.app.savegameMgr.createNewSavegame();
|
|
|
|
|
|
|
|
this.app.analytics.trackUiClick("startgame");
|
|
|
|
this.moveToState("InGameState", {
|
|
|
|
savegame,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onLeave() {
|
|
|
|
// this.dialogs.cleanup();
|
|
|
|
}
|
|
|
|
}
|