2020-10-07 07:48:31 +00:00
|
|
|
import { globalConfig, IS_MOBILE } from "../../core/config";
|
|
|
|
|
import { createLogger } from "../../core/logging";
|
|
|
|
|
import { clamp } from "../../core/utils";
|
Achievements (#1087)
* [WIP] Add boilerplate for achievement implementation
* Add config.local.template.js and rm cached copy of config.local.js
* [WIP] Implement painting, cutting, rotating achievements (to log only)
* [WIP] Refactor achievements, jsdoc fixes, add npm script
- Refactor achievements to make use of Signals
- Move implemented achievement interfaces to appropriate
platform folders (SteamAchievements in currently in use
in browser wrapper for testing)
- Fix invalid jsdocs
- Add dev-standalone script to package.json scripts
* Add steam/greenworks IPC calls and optional private-artifact dependency
* Include private artifacts in standalone builds
* Uncomment appid include
* [WIP] Add steam overlay fix, add hash to artifact dependency
* Update electron, greenworks. Add task to add local config if not present
* Add more achievements, refactor achievement code
* Add receiver flexibility and more achievements
- Add check to see if necessary to create achievement and add receiver
- Add remove receiver functionality when achievement is unlocked
* Add achievements and accommodations for switching states
- Fix startup code to avoid clobbering achievements on state switch
- Add a few more achievements
* Add achievements, ids. Update names, keys for consistency
* Add play time achievements
* [WIP] Add more achievements
* Add more achievements. Add bulk achievement check signal
* [WIP] Add achievements. Start savefile migration
* Add achievements. Add savefile migration
* Remove superfluous achievement stat
* Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
|
|
|
import { SteamAchievementProvider } from "../electron/steam_achievement_provider";
|
2020-10-07 07:48:31 +00:00
|
|
|
import { PlatformWrapperInterface } from "../wrapper";
|
Achievements (#1087)
* [WIP] Add boilerplate for achievement implementation
* Add config.local.template.js and rm cached copy of config.local.js
* [WIP] Implement painting, cutting, rotating achievements (to log only)
* [WIP] Refactor achievements, jsdoc fixes, add npm script
- Refactor achievements to make use of Signals
- Move implemented achievement interfaces to appropriate
platform folders (SteamAchievements in currently in use
in browser wrapper for testing)
- Fix invalid jsdocs
- Add dev-standalone script to package.json scripts
* Add steam/greenworks IPC calls and optional private-artifact dependency
* Include private artifacts in standalone builds
* Uncomment appid include
* [WIP] Add steam overlay fix, add hash to artifact dependency
* Update electron, greenworks. Add task to add local config if not present
* Add more achievements, refactor achievement code
* Add receiver flexibility and more achievements
- Add check to see if necessary to create achievement and add receiver
- Add remove receiver functionality when achievement is unlocked
* Add achievements and accommodations for switching states
- Fix startup code to avoid clobbering achievements on state switch
- Add a few more achievements
* Add achievements, ids. Update names, keys for consistency
* Add play time achievements
* [WIP] Add more achievements
* Add more achievements. Add bulk achievement check signal
* [WIP] Add achievements. Start savefile migration
* Add achievements. Add savefile migration
* Remove superfluous achievement stat
* Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
|
|
|
import { NoAchievementProvider } from "./no_achievement_provider";
|
2020-10-07 07:48:31 +00:00
|
|
|
import { StorageImplBrowser } from "./storage";
|
|
|
|
|
import { StorageImplBrowserIndexedDB } from "./storage_indexed_db";
|
|
|
|
|
|
|
|
|
|
const logger = createLogger("platform/browser");
|
|
|
|
|
|
|
|
|
|
export class PlatformWrapperImplBrowser extends PlatformWrapperInterface {
|
|
|
|
|
initialize() {
|
|
|
|
|
return this.detectStorageImplementation()
|
Achievements (#1087)
* [WIP] Add boilerplate for achievement implementation
* Add config.local.template.js and rm cached copy of config.local.js
* [WIP] Implement painting, cutting, rotating achievements (to log only)
* [WIP] Refactor achievements, jsdoc fixes, add npm script
- Refactor achievements to make use of Signals
- Move implemented achievement interfaces to appropriate
platform folders (SteamAchievements in currently in use
in browser wrapper for testing)
- Fix invalid jsdocs
- Add dev-standalone script to package.json scripts
* Add steam/greenworks IPC calls and optional private-artifact dependency
* Include private artifacts in standalone builds
* Uncomment appid include
* [WIP] Add steam overlay fix, add hash to artifact dependency
* Update electron, greenworks. Add task to add local config if not present
* Add more achievements, refactor achievement code
* Add receiver flexibility and more achievements
- Add check to see if necessary to create achievement and add receiver
- Add remove receiver functionality when achievement is unlocked
* Add achievements and accommodations for switching states
- Fix startup code to avoid clobbering achievements on state switch
- Add a few more achievements
* Add achievements, ids. Update names, keys for consistency
* Add play time achievements
* [WIP] Add more achievements
* Add more achievements. Add bulk achievement check signal
* [WIP] Add achievements. Start savefile migration
* Add achievements. Add savefile migration
* Remove superfluous achievement stat
* Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
|
|
|
.then(() => this.initializeAchievementProvider())
|
2020-10-07 07:48:31 +00:00
|
|
|
.then(() => super.initialize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
detectStorageImplementation() {
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
logger.log("Detecting storage");
|
|
|
|
|
|
|
|
|
|
if (!window.indexedDB) {
|
|
|
|
|
logger.log("Indexed DB not supported");
|
|
|
|
|
this.app.storage = new StorageImplBrowser(this.app);
|
|
|
|
|
resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try accessing the indexedb
|
|
|
|
|
let request;
|
|
|
|
|
try {
|
|
|
|
|
request = window.indexedDB.open("indexeddb_feature_detection", 1);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
logger.warn("Error while opening indexed db:", ex);
|
|
|
|
|
this.app.storage = new StorageImplBrowser(this.app);
|
|
|
|
|
resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
request.onerror = err => {
|
|
|
|
|
logger.log("Indexed DB can *not* be accessed: ", err);
|
|
|
|
|
logger.log("Using fallback to local storage");
|
|
|
|
|
this.app.storage = new StorageImplBrowser(this.app);
|
|
|
|
|
resolve();
|
|
|
|
|
};
|
|
|
|
|
request.onsuccess = () => {
|
|
|
|
|
logger.log("Indexed DB *can* be accessed");
|
|
|
|
|
this.app.storage = new StorageImplBrowserIndexedDB(this.app);
|
|
|
|
|
resolve();
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getId() {
|
2024-04-16 07:25:16 +00:00
|
|
|
return "browser";
|
2020-10-07 07:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getUiScale() {
|
|
|
|
|
if (IS_MOBILE) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const avgDims = Math.min(this.app.screenWidth, this.app.screenHeight);
|
|
|
|
|
return clamp((avgDims / 1000.0) * 1.9, 0.1, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSupportsRestart() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTouchPanStrength() {
|
|
|
|
|
return IS_MOBILE ? 1 : 0.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openExternalLink(url, force = false) {
|
|
|
|
|
logger.log("Opening external:", url);
|
2021-08-17 19:13:32 +00:00
|
|
|
window.open(url);
|
2020-10-07 07:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
performRestart() {
|
|
|
|
|
logger.log("Performing restart");
|
2023-11-17 22:02:08 +00:00
|
|
|
window.location.reload();
|
2020-10-07 07:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
Achievements (#1087)
* [WIP] Add boilerplate for achievement implementation
* Add config.local.template.js and rm cached copy of config.local.js
* [WIP] Implement painting, cutting, rotating achievements (to log only)
* [WIP] Refactor achievements, jsdoc fixes, add npm script
- Refactor achievements to make use of Signals
- Move implemented achievement interfaces to appropriate
platform folders (SteamAchievements in currently in use
in browser wrapper for testing)
- Fix invalid jsdocs
- Add dev-standalone script to package.json scripts
* Add steam/greenworks IPC calls and optional private-artifact dependency
* Include private artifacts in standalone builds
* Uncomment appid include
* [WIP] Add steam overlay fix, add hash to artifact dependency
* Update electron, greenworks. Add task to add local config if not present
* Add more achievements, refactor achievement code
* Add receiver flexibility and more achievements
- Add check to see if necessary to create achievement and add receiver
- Add remove receiver functionality when achievement is unlocked
* Add achievements and accommodations for switching states
- Fix startup code to avoid clobbering achievements on state switch
- Add a few more achievements
* Add achievements, ids. Update names, keys for consistency
* Add play time achievements
* [WIP] Add more achievements
* Add more achievements. Add bulk achievement check signal
* [WIP] Add achievements. Start savefile migration
* Add achievements. Add savefile migration
* Remove superfluous achievement stat
* Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
|
|
|
initializeAchievementProvider() {
|
|
|
|
|
if (G_IS_DEV && globalConfig.debug.testAchievements) {
|
|
|
|
|
this.app.achievementProvider = new SteamAchievementProvider(this.app);
|
|
|
|
|
|
2021-03-10 08:29:20 +00:00
|
|
|
return this.app.achievementProvider.initialize().catch(err => {
|
|
|
|
|
logger.error("Failed to initialize achievement provider, disabling:", err);
|
Achievements (#1087)
* [WIP] Add boilerplate for achievement implementation
* Add config.local.template.js and rm cached copy of config.local.js
* [WIP] Implement painting, cutting, rotating achievements (to log only)
* [WIP] Refactor achievements, jsdoc fixes, add npm script
- Refactor achievements to make use of Signals
- Move implemented achievement interfaces to appropriate
platform folders (SteamAchievements in currently in use
in browser wrapper for testing)
- Fix invalid jsdocs
- Add dev-standalone script to package.json scripts
* Add steam/greenworks IPC calls and optional private-artifact dependency
* Include private artifacts in standalone builds
* Uncomment appid include
* [WIP] Add steam overlay fix, add hash to artifact dependency
* Update electron, greenworks. Add task to add local config if not present
* Add more achievements, refactor achievement code
* Add receiver flexibility and more achievements
- Add check to see if necessary to create achievement and add receiver
- Add remove receiver functionality when achievement is unlocked
* Add achievements and accommodations for switching states
- Fix startup code to avoid clobbering achievements on state switch
- Add a few more achievements
* Add achievements, ids. Update names, keys for consistency
* Add play time achievements
* [WIP] Add more achievements
* Add more achievements. Add bulk achievement check signal
* [WIP] Add achievements. Start savefile migration
* Add achievements. Add savefile migration
* Remove superfluous achievement stat
* Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
|
|
|
|
2021-03-10 08:29:20 +00:00
|
|
|
this.app.achievementProvider = new NoAchievementProvider(this.app);
|
|
|
|
|
});
|
Achievements (#1087)
* [WIP] Add boilerplate for achievement implementation
* Add config.local.template.js and rm cached copy of config.local.js
* [WIP] Implement painting, cutting, rotating achievements (to log only)
* [WIP] Refactor achievements, jsdoc fixes, add npm script
- Refactor achievements to make use of Signals
- Move implemented achievement interfaces to appropriate
platform folders (SteamAchievements in currently in use
in browser wrapper for testing)
- Fix invalid jsdocs
- Add dev-standalone script to package.json scripts
* Add steam/greenworks IPC calls and optional private-artifact dependency
* Include private artifacts in standalone builds
* Uncomment appid include
* [WIP] Add steam overlay fix, add hash to artifact dependency
* Update electron, greenworks. Add task to add local config if not present
* Add more achievements, refactor achievement code
* Add receiver flexibility and more achievements
- Add check to see if necessary to create achievement and add receiver
- Add remove receiver functionality when achievement is unlocked
* Add achievements and accommodations for switching states
- Fix startup code to avoid clobbering achievements on state switch
- Add a few more achievements
* Add achievements, ids. Update names, keys for consistency
* Add play time achievements
* [WIP] Add more achievements
* Add more achievements. Add bulk achievement check signal
* [WIP] Add achievements. Start savefile migration
* Add achievements. Add savefile migration
* Remove superfluous achievement stat
* Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.app.achievementProvider.initialize();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-07 07:48:31 +00:00
|
|
|
exitApp() {
|
|
|
|
|
// Can not exit app
|
|
|
|
|
}
|
|
|
|
|
}
|