1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Adjustments to support chinese versions

This commit is contained in:
Tobias Springer
2021-03-09 10:07:19 +01:00
parent e53ec8d6af
commit 1ee03d7398
24 changed files with 422 additions and 294 deletions

View File

@@ -13,7 +13,7 @@ import { cachebust } from "./cachebust";
const logger = createLogger("background_loader");
const essentialMainMenuSprites = [
"logo.png",
G_CHINA_VERSION ? "logo_cn.png" : "logo.png",
...G_ALL_UI_IMAGES.filter(src => src.startsWith("ui/") && src.indexOf(".gif") < 0),
];
const essentialMainMenuSounds = [

2
src/js/globals.d.ts vendored
View File

@@ -19,6 +19,8 @@ declare const G_BUILD_VERSION: string;
declare const G_ALL_UI_IMAGES: Array<string>;
declare const G_IS_RELEASE: boolean;
declare const G_CHINA_VERSION : boolean;
// Polyfills
declare interface String {
replaceAll(search: string, replacement: string): string;

View File

@@ -15,7 +15,9 @@ export class AboutState extends TextualGameState {
getMainContentHTML() {
return `
<div class="head">
<img src="${cachebust("res/logo.png")}" alt="shapez.io Logo">
<img src="${cachebust(
G_CHINA_VERSION ? "res/logo_cn.png" : "res/logo.png"
)}" alt="shapez.io Logo">
</div>
<div class="text">
${T.about.body

View File

@@ -42,7 +42,12 @@ export class MainMenuState extends GameState {
return `
<div class="topButtons">
<button class="languageChoose" data-languageicon="${this.app.settings.getLanguage()}"></button>
${
G_CHINA_VERSION
? ""
: `<button class="languageChoose" data-languageicon="${this.app.settings.getLanguage()}"></button>`
}
<button class="settingsButton"></button>
${
G_IS_STANDALONE || G_IS_DEV
@@ -58,7 +63,9 @@ export class MainMenuState extends GameState {
</video>
<div class="logo">
<img src="${cachebust("res/logo.png")}" alt="shapez.io Logo">
<img src="${cachebust(
G_CHINA_VERSION ? "res/logo_cn.png" : "res/logo.png"
)}" alt="shapez.io Logo">
<span class="updateLabel">v${G_BUILD_VERSION}</span>
</div>
@@ -77,11 +84,17 @@ export class MainMenuState extends GameState {
</div>
</div>
<div class="footer">
<div class="footer ${G_CHINA_VERSION ? "china" : ""}">
${
G_CHINA_VERSION
? ""
: `
<a class="githubLink boxLink" target="_blank">
${T.mainMenu.openSourceHint}
<span class="thirdpartyLogo githubLogo"></span>
</a>
</a>`
}
<a class="discordLink boxLink" target="_blank">
${T.mainMenu.discordLink}
@@ -89,11 +102,11 @@ export class MainMenuState extends GameState {
</a>
<div class="sidelinks">
<a class="redditLink">${T.mainMenu.subreddit}</a>
${G_CHINA_VERSION ? "" : `<a class="redditLink">${T.mainMenu.subreddit}</a>`}
<a class="changelog">${T.changelog.title}</a>
${G_CHINA_VERSION ? "" : `<a class="changelog">${T.changelog.title}</a>`}
<a class="helpTranslate">${T.mainMenu.helpTranslate}</a>
${G_CHINA_VERSION ? "" : `<a class="helpTranslate">${T.mainMenu.helpTranslate}</a>`}
</div>
<div class="author">${T.mainMenu.madeBy.replace(
@@ -208,10 +221,13 @@ export class MainMenuState extends GameState {
});
this.trackClicks(qs(".settingsButton"), this.onSettingsButtonClicked);
this.trackClicks(qs(".changelog"), this.onChangelogClicked);
this.trackClicks(qs(".redditLink"), this.onRedditClicked);
this.trackClicks(qs(".languageChoose"), this.onLanguageChooseClicked);
this.trackClicks(qs(".helpTranslate"), this.onTranslationHelpLinkClicked);
if (!G_CHINA_VERSION) {
this.trackClicks(qs(".languageChoose"), this.onLanguageChooseClicked);
this.trackClicks(qs(".redditLink"), this.onRedditClicked);
this.trackClicks(qs(".changelog"), this.onChangelogClicked);
this.trackClicks(qs(".helpTranslate"), this.onTranslationHelpLinkClicked);
}
if (G_IS_STANDALONE) {
this.trackClicks(qs(".exitAppButton"), this.onExitAppButtonClicked);
@@ -233,11 +249,13 @@ export class MainMenuState extends GameState {
);
const githubLink = this.htmlElement.querySelector(".githubLink");
this.trackClicks(
githubLink,
() => this.app.platformWrapper.openExternalLink(THIRDPARTY_URLS.github),
{ preventClick: true }
);
if (githubLink) {
this.trackClicks(
githubLink,
() => this.app.platformWrapper.openExternalLink(THIRDPARTY_URLS.github),
{ preventClick: true }
);
}
const producerLink = this.htmlElement.querySelector(".producerLink");
this.trackClicks(

View File

@@ -9,17 +9,19 @@ export class MobileWarningState extends GameState {
getInnerHTML() {
return `
<img class="logo" src="${cachebust("res/logo.png")}" alt="shapez.io Logo">
<img class="logo" src="${cachebust(
G_CHINA_VERSION ? "res/logo_cn.png" : "res/logo.png"
)}" alt="shapez.io Logo">
<p>
I'm sorry, but shapez.io is not available on mobile devices yet!
There is also no estimate when this will change, but feel to make a contribution! It's
&nbsp;<a href="https://github.com/tobspr/shapez.io" target="_blank">open source</a>!</p>
<p>If you want to play on your computer, you can also get the standalone on Steam:</p>
<a href="${
THIRDPARTY_URLS.standaloneStorePage + "?ref=mobile"
}" class="standaloneLink" target="_blank">Get the shapez.io standalone!</a>

View File

@@ -3,7 +3,6 @@ import { cachebust } from "../core/cachebust";
import { globalConfig } from "../core/config";
import { GameState } from "../core/game_state";
import { createLogger } from "../core/logging";
import { findNiceValue } from "../core/utils";
import { getRandomHint } from "../game/hints";
import { HUDModalDialogs } from "../game/hud/parts/modal_dialogs";
import { PlatformWrapperImplBrowser } from "../platform/browser/wrapper";
@@ -20,7 +19,7 @@ export class PreloadState extends GameState {
return `
<div class="loadingImage"></div>
<div class="loadingStatus">
<span class="desc">Booting</span>
<span class="desc">${G_CHINA_VERSION ? "加载中" : "Booting"}</span>
</div>
</div>
<span class="prefab_GameHint"></span>
@@ -115,6 +114,10 @@ export class PreloadState extends GameState {
.then(() => this.setStatus("Initializing language"))
.then(() => {
if (G_CHINA_VERSION) {
return this.app.settings.updateLanguage("zh-CN");
}
if (this.app.settings.getLanguage() === "auto-detect") {
const language = autoDetectLanguageId();
logger.log("Setting language to", language);
@@ -163,6 +166,10 @@ export class PreloadState extends GameState {
return;
}
if (G_CHINA_VERSION) {
return;
}
return this.app.storage
.readFileAsync("lastversion.bin")
.catch(err => {
@@ -220,6 +227,9 @@ export class PreloadState extends GameState {
}
update() {
if (G_CHINA_VERSION) {
return;
}
const now = performance.now();
if (now - this.lastHintShown > this.nextHintDuration) {
this.lastHintShown = now;
@@ -250,6 +260,9 @@ export class PreloadState extends GameState {
*/
setStatus(text) {
logger.log("✅ " + text);
if (G_CHINA_VERSION) {
return Promise.resolve();
}
this.currentStatus = text;
this.statusText.innerText = text;
return Promise.resolve();
@@ -265,7 +278,9 @@ export class PreloadState extends GameState {
subElement.innerHTML = `
<div class="logo">
<img src="${cachebust("res/logo.png")}" alt="Shapez.io Logo">
<img src="${cachebust(
G_CHINA_VERSION ? "res/logo_cn.png" : "res/logo.png"
)}" alt="Shapez.io Logo">
</div>
<div class="failureInner">
<div class="errorHeader">

View File

@@ -28,8 +28,14 @@ export class SettingsState extends TextualGameState {
}
<div class="other">
<button class="styledButton about">${T.about.title}</button>
${
G_CHINA_VERSION
? ""
: `
<button class="styledButton about">${T.about.title}</button>
`
}
<div class="versionbar">
<div class="buildVersion">${T.global.loading} ...</div>
</div>
@@ -68,6 +74,10 @@ export class SettingsState extends TextualGameState {
for (let i = 0; i < allApplicationSettings.length; ++i) {
const setting = allApplicationSettings[i];
if (G_CHINA_VERSION && setting.id === "language") {
continue;
}
categoriesHTML[setting.categoryId] += setting.getHtml(this.app);
}
@@ -94,9 +104,12 @@ export class SettingsState extends TextualGameState {
onEnter(payload) {
this.renderBuildText();
this.trackClicks(this.htmlElement.querySelector(".about"), this.onAboutClicked, {
preventDefault: false,
});
if (!G_CHINA_VERSION) {
this.trackClicks(this.htmlElement.querySelector(".about"), this.onAboutClicked, {
preventDefault: false,
});
}
const keybindingsButton = this.htmlElement.querySelector(".editKeybindings");
@@ -131,6 +144,10 @@ export class SettingsState extends TextualGameState {
initSettings() {
allApplicationSettings.forEach(setting => {
if (G_CHINA_VERSION && setting.id === "language") {
return;
}
/** @type {HTMLElement} */
const element = this.htmlElement.querySelector("[data-setting='" + setting.id + "']");
setting.bind(this.app, element, this.dialogs);