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

Cleanup IS_DEMO flags and introduce Restriction Manager

This commit is contained in:
tobspr
2020-10-07 09:48:31 +02:00
parent 81e7d96dd8
commit fa27d1681f
21 changed files with 971 additions and 884 deletions

View File

@@ -6,8 +6,7 @@ import { ReadWriteProxy } from "../core/read_write_proxy";
import { BoolSetting, EnumSetting, RangeSetting, BaseSetting } from "./setting_types";
import { createLogger } from "../core/logging";
import { ExplainedResult } from "../core/explained_result";
import { THEMES, THEME, applyGameTheme } from "../game/theme";
import { IS_DEMO } from "../core/config";
import { THEMES, applyGameTheme } from "../game/theme";
import { T } from "../translations";
import { LANGUAGES } from "../languages";
@@ -187,7 +186,9 @@ export const allApplicationSettings = [
app.platformWrapper.setFullscreen(value);
}
},
!IS_DEMO
/**
* @param {Application} app
*/ app => app.restrictionMgr.getHasExtendedSettings()
),
new BoolSetting(
@@ -215,7 +216,9 @@ export const allApplicationSettings = [
applyGameTheme(id);
document.documentElement.setAttribute("data-theme", id);
},
enabled: !IS_DEMO,
enabledCb: /**
* @param {Application} app
*/ app => app.restrictionMgr.getHasExtendedSettings(),
}),
new EnumSetting("autosaveInterval", {
@@ -271,7 +274,9 @@ export const allApplicationSettings = [
category: enumCategories.performance,
restartRequired: false,
changeCb: (app, id) => {},
enabled: !IS_DEMO,
enabledCb: /**
* @param {Application} app
*/ app => app.restrictionMgr.getHasExtendedSettings(),
}),
new BoolSetting("lowQualityMapResources", enumCategories.performance, (app, value) => {}),
@@ -355,7 +360,7 @@ export class ApplicationSettings extends ReadWriteProxy {
* @returns {SettingsStorage}
*/
getAllSettings() {
return this.getCurrentData().settings;
return this.currentData.settings;
}
/**

View File

@@ -13,13 +13,13 @@ export class BaseSetting {
* @param {string} id
* @param {string} categoryId
* @param {function(Application, any):void} changeCb
* @param {boolean} enabled
* @param {function(Application) : boolean=} enabledCb
*/
constructor(id, categoryId, changeCb, enabled) {
constructor(id, categoryId, changeCb, enabledCb = null) {
this.id = id;
this.categoryId = categoryId;
this.changeCb = changeCb;
this.enabled = enabled;
this.enabledCb = enabledCb;
/** @type {Application} */
this.app = null;
@@ -39,6 +39,7 @@ export class BaseSetting {
}
/**
* Binds all parameters
* @param {Application} app
* @param {HTMLElement} element
* @param {any} dialogs
@@ -49,19 +50,37 @@ export class BaseSetting {
this.dialogs = dialogs;
}
getHtml() {
/**
* Returns the HTML for this setting
* @param {Application} app
*/
getHtml(app) {
abstract;
return "";
}
/**
* Returns whether this setting is enabled and available
* @param {Application} app
*/
getIsAvailable(app) {
return this.enabledCb ? this.enabledCb(app) : true;
}
syncValueToElement() {
abstract;
}
/**
* Attempts to modify the setting
*/
modify() {
abstract;
}
/**
* Shows the dialog that a restart is required
*/
showRestartRequiredDialog() {
const { restart } = this.dialogs.showInfo(
T.dialogs.restartRequired.title,
@@ -74,6 +93,7 @@ export class BaseSetting {
}
/**
* Validates the set value
* @param {any} value
* @returns {boolean}
*/
@@ -96,10 +116,10 @@ export class EnumSetting extends BaseSetting {
iconPrefix = null,
changeCb = null,
magicValue = null,
enabled = true,
enabledCb = null,
}
) {
super(id, category, changeCb, enabled);
super(id, category, changeCb, enabledCb);
this.options = options;
this.valueGetter = valueGetter;
@@ -110,10 +130,14 @@ export class EnumSetting extends BaseSetting {
this.magicValue = magicValue;
}
getHtml() {
/**
* @param {Application} app
*/
getHtml(app) {
const available = this.getIsAvailable(app);
return `
<div class="setting cardbox ${this.enabled ? "enabled" : "disabled"}">
${this.enabled ? "" : `<span class="standaloneOnlyHint">${T.demo.settingNotAvailable}</span>`}
<div class="setting cardbox ${available ? "enabled" : "disabled"}">
${available ? "" : `<span class="standaloneOnlyHint">${T.demo.settingNotAvailable}</span>`}
<div class="row">
<label>${T.settings.labels[this.id].title}</label>
<div class="value enum" data-setting="${this.id}"></div>
@@ -180,14 +204,18 @@ export class EnumSetting extends BaseSetting {
}
export class BoolSetting extends BaseSetting {
constructor(id, category, changeCb = null, enabled = true) {
super(id, category, changeCb, enabled);
constructor(id, category, changeCb = null, enabledCb = null) {
super(id, category, changeCb, enabledCb);
}
getHtml() {
/**
* @param {Application} app
*/
getHtml(app) {
const available = this.getIsAvailable(app);
return `
<div class="setting cardbox ${this.enabled ? "enabled" : "disabled"}">
${this.enabled ? "" : `<span class="standaloneOnlyHint">${T.demo.settingNotAvailable}</span>`}
<div class="setting cardbox ${available ? "enabled" : "disabled"}">
${available ? "" : `<span class="standaloneOnlyHint">${T.demo.settingNotAvailable}</span>`}
<div class="row">
<label>${T.settings.labels[this.id].title}</label>
@@ -226,13 +254,13 @@ export class RangeSetting extends BaseSetting {
id,
category,
changeCb = null,
enabled = true,
defaultValue = 1.0,
minValue = 0,
maxValue = 1.0,
stepSize = 0.0001
stepSize = 0.0001,
enabledCb = null
) {
super(id, category, changeCb, enabled);
super(id, category, changeCb, enabledCb);
this.defaultValue = defaultValue;
this.minValue = minValue;
@@ -240,10 +268,14 @@ export class RangeSetting extends BaseSetting {
this.stepSize = stepSize;
}
getHtml() {
/**
* @param {Application} app
*/
getHtml(app) {
const available = this.getIsAvailable(app);
return `
<div class="setting cardbox ${this.enabled ? "enabled" : "disabled"}">
${this.enabled ? "" : `<span class="standaloneOnlyHint">${T.demo.settingNotAvailable}</span>`}
<div class="setting cardbox ${available ? "enabled" : "disabled"}">
${available ? "" : `<span class="standaloneOnlyHint">${T.demo.settingNotAvailable}</span>`}
<div class="row">
<label>${T.settings.labels[this.id].title}</label>