Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
fix: Don't include savegame in release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Jul 17, 2021
1 parent 0cd45dd commit cb95352
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/userscript/bundle/kitten-scientists.user.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/userscript/source/fixtures/savegame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null;
8 changes: 6 additions & 2 deletions packages/userscript/source/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import lategame from "./fixtures/lategame";
import testConfig from "./fixtures/localstorage.json";
import savegame from "./fixtures/savegame";
import { Options } from "./options/Options";
import { SettingsStorage } from "./options/SettingsStorage";
import { cinfo } from "./tools/Log";
import { isNil } from "./tools/Maybe";
import { SavegameLoader } from "./tools/SavegameLoader";
import { UserScript } from "./UserScript";

(async () => {
const kittenGame = await UserScript.waitForGame();

// For development convenience, load a lategame save to give us more test options.
await new SavegameLoader(kittenGame).load(lategame);
if (!isNil(savegame)) {
await new SavegameLoader(kittenGame).load(savegame);
}

const userScript = await UserScript.getDefaultInstance();

Expand Down
10 changes: 8 additions & 2 deletions packages/userscript/source/tools/SavegameLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ export class SavegameLoader {

/**
* Conveniently wraps the savegame loading process in an async construct.
* @param data The savegame data to load.
* @param data The savegame data to load. We accept `null` here for convenience
* when dealing with `import`ed save game data.
* @returns Nothing
*/
load(data: string): Promise<void> {
load(data: string | null): Promise<void> {
return new Promise((resolve, reject) => {
if (data === null) {
resolve();
return;
}

this._gamePage.saveImportDropboxText(data, error => {
if (error) {
reject(error);
Expand Down
4 changes: 4 additions & 0 deletions packages/userscript/webpack.config.inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require("path");
const PnpWebpackPlugin = require("pnp-webpack-plugin");
const webpack = require("webpack");

module.exports = {
devtool: "inline-source-map",
Expand All @@ -20,6 +21,9 @@ module.exports = {
path: path.resolve(__dirname, "output"),
filename: "kitten-scientists.inject.js",
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/.\/fixtures\/savegame/, "./fixtures/lategame"),
],
resolve: {
extensions: [".ts", ".js"],
plugins: [PnpWebpackPlugin],
Expand Down

0 comments on commit cb95352

Please sign in to comment.