2020-10-07 16:35:03 +00:00
|
|
|
/* typehints:start */
|
2020-10-07 07:48:31 +00:00
|
|
|
import { Application } from "../application";
|
2020-10-07 16:35:03 +00:00
|
|
|
/* typehints:end */
|
2020-10-07 13:02:27 +00:00
|
|
|
import { IS_MAC } from "./config";
|
2020-10-07 07:48:31 +00:00
|
|
|
import { ExplainedResult } from "./explained_result";
|
|
|
|
import { queryParamOptions } from "./query_parameters";
|
|
|
|
import { ReadWriteProxy } from "./read_write_proxy";
|
|
|
|
|
|
|
|
export class RestrictionManager extends ReadWriteProxy {
|
|
|
|
/**
|
|
|
|
* @param {Application} app
|
|
|
|
*/
|
|
|
|
constructor(app) {
|
|
|
|
super(app, "restriction-flags.bin");
|
2020-10-07 13:02:27 +00:00
|
|
|
|
|
|
|
this.currentData = this.getDefaultData();
|
2020-10-07 07:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -- RW Proxy Impl
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {any} data
|
|
|
|
*/
|
|
|
|
verify(data) {
|
|
|
|
return ExplainedResult.good();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
getDefaultData() {
|
|
|
|
return {
|
2020-10-07 13:02:27 +00:00
|
|
|
version: this.getCurrentVersion(),
|
2020-10-07 07:48:31 +00:00
|
|
|
savegameV1119Imported: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
getCurrentVersion() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {any} data
|
|
|
|
*/
|
|
|
|
migrate(data) {
|
|
|
|
return ExplainedResult.good();
|
|
|
|
}
|
|
|
|
|
2020-10-07 13:02:27 +00:00
|
|
|
initialize() {
|
|
|
|
return this.readAsync().then(() => {
|
|
|
|
if (this.currentData.savegameV1119Imported) {
|
|
|
|
console.warn("Levelunlock is granted to current user due to past savegame");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-07 07:48:31 +00:00
|
|
|
// -- End RW Proxy Impl
|
|
|
|
|
2020-10-07 13:02:27 +00:00
|
|
|
/**
|
|
|
|
* Checks if there are any savegames from the 1.1.19 version
|
|
|
|
*/
|
|
|
|
onHasLegacySavegamesChanged(has119Savegames = false) {
|
|
|
|
if (has119Savegames && !this.currentData.savegameV1119Imported) {
|
|
|
|
this.currentData.savegameV1119Imported = true;
|
|
|
|
console.warn("Current user now has access to all levels due to 1119 savegame");
|
|
|
|
return this.writeAsync();
|
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2020-10-07 07:48:31 +00:00
|
|
|
/**
|
|
|
|
* Returns if the app is currently running as the limited version
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isLimitedVersion() {
|
2020-10-07 13:02:27 +00:00
|
|
|
if (IS_MAC) {
|
|
|
|
// On mac, the full version is always active
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_IS_STANDALONE) {
|
|
|
|
// Standalone is never limited
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-17 19:13:32 +00:00
|
|
|
if (queryParamOptions.embedProvider === "gamedistribution") {
|
|
|
|
// also full version on gamedistribution
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-07 13:02:27 +00:00
|
|
|
if (G_IS_DEV) {
|
|
|
|
return typeof window !== "undefined" && window.location.search.indexOf("demo") >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-10-07 07:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the app markets the standalone version on steam
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
getIsStandaloneMarketingActive() {
|
|
|
|
return this.isLimitedVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if exporting the base as a screenshot is possible
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
getIsExportingScreenshotsPossible() {
|
|
|
|
return !this.isLimitedVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the maximum number of supported waypoints
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
getMaximumWaypoints() {
|
|
|
|
return this.isLimitedVersion() ? 2 : 1e20;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the user has unlimited savegames
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
getHasUnlimitedSavegames() {
|
|
|
|
return !this.isLimitedVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the app has all settings available
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
getHasExtendedSettings() {
|
|
|
|
return !this.isLimitedVersion();
|
|
|
|
}
|
2020-10-07 13:02:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if all upgrades are available
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
getHasExtendedUpgrades() {
|
|
|
|
return !this.isLimitedVersion() || this.currentData.savegameV1119Imported;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if all levels & freeplay is available
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
getHasExtendedLevelsAndFreeplay() {
|
|
|
|
return !this.isLimitedVersion() || this.currentData.savegameV1119Imported;
|
|
|
|
}
|
2020-10-07 07:48:31 +00:00
|
|
|
}
|