-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add save/load, add Options and Info menu
- Loading branch information
1 parent
9ee4bb3
commit 28fc0df
Showing
13 changed files
with
116 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** This includes all headers of the Cookie Monster Framework and their relevant data */ | ||
const headers = { infoMenu: 1, optionsMenu: 1 }; | ||
export default headers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** This includes all options of the Cookie Monster Framework and their relevant data */ | ||
const settings = {}; | ||
export default settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import loadMod from '../saveDataFunctions/loadMod'; | ||
import headers from './data/headers'; | ||
import settings from './data/settings'; | ||
import logicLoop from './logic/logicLoop'; | ||
|
||
/** | ||
* This creates a load function to the CM object. Per Game code/comments: | ||
* "do stuff with the string data you saved previously" | ||
* @param {string} JSON string of save-data | ||
*/ | ||
export default function load(str) { | ||
window.cookieMonsterFrameworkData.framework = JSON.parse(str); | ||
loadMod('cookieMonsterFramework', str, settings, headers, logicLoop); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Main logic loop | ||
*/ | ||
export default function logicLoop() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Creates the save data object to be stored | ||
* @param {object} saveData The loaded save data | ||
* @param {object} settingsData The data containing default values of settings | ||
* @param {object} headersData The data containing default values of headers | ||
*/ | ||
export default function createSaveDataObject(saveData, settingsData, headersData) { | ||
const modSaveData = {}; | ||
|
||
const settingsObject = {}; | ||
Object.keys(settingsData).forEach((i) => { | ||
if (typeof saveData.settings === 'undefined' || typeof saveData.settings[i] === 'undefined') { | ||
settingsObject[i] = settingsData[i].defaultValue; // eslint-disable-line prefer-destructuring | ||
} else { | ||
settingsObject[i] = saveData.settings[i]; | ||
} | ||
}); | ||
modSaveData.settings = settingsObject; | ||
|
||
const headersObject = {}; | ||
Object.keys(headersData).forEach((i) => { | ||
if (typeof saveData.headers === 'undefined' || typeof saveData.headers[i] === 'undefined') { | ||
headersObject[i] = headersData[i]; | ||
} else { | ||
headersObject[i] = saveData.headers[i]; | ||
} | ||
}); | ||
modSaveData.headers = headersObject; | ||
|
||
Object.keys(saveData).forEach((key) => { | ||
if (key !== 'settings' && key !== 'headers') { | ||
modSaveData[key] = saveData[key]; | ||
} | ||
}); | ||
return modSaveData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import createSaveDataObject from './createSaveDataObject'; | ||
import saveFramework from './saveFramework'; | ||
|
||
/** | ||
* Load the data from a save-file into a mod | ||
* @param {string} modName The name of the mode to be saved | ||
* @param {string} saveData JSON-string of the save data | ||
* @param {object} settingsData The data containing default values of settings | ||
* @param {object} headersData The data containing default values of headers | ||
* @param {Function} logicLoop The logic-loop of the mod | ||
*/ | ||
export default function loadMod(modName, saveData, settingsData, headersData, logicLoop) { | ||
const saveDataObject = JSON.parse(saveData); | ||
Game.mods.cookieMonsterFramework.saveData[modName] = createSaveDataObject( | ||
saveDataObject, | ||
settingsData, | ||
headersData, | ||
); | ||
saveFramework(); | ||
logicLoop(); | ||
Object.keys(Game.mods.cookieMonsterFramework.saveData[modName].settings).forEach((i) => { | ||
if (typeof settingsData[i].func !== 'undefined') { | ||
settingsData[i].func(); | ||
} | ||
}); | ||
Game.UpdateMenu(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* This function saves the settings and headers within the Framework without saving any of the other save-data | ||
* This allows saving in between the autosave intervals | ||
*/ | ||
export default function saveFramework() { | ||
Object.keys(Game.mods.cookieMonsterFramework.saveData).forEach((modName) => { | ||
const modSaveString = JSON.stringify(Game.mods.cookieMonsterFramework.saveData[modName]); | ||
|
||
const cookieClickerSaveString = b64_to_utf8( | ||
unescape(localStorage.getItem('CookieClickerGame')).split('!END!')[0], | ||
); | ||
const pattern = new RegExp(`${modName}.*(;|$)`); | ||
const modSave = cookieClickerSaveString.match(pattern); | ||
if (modSave !== null) { | ||
const newSaveString = cookieClickerSaveString.replace( | ||
modSave[0], | ||
`${modName}:${modSaveString}`, | ||
); | ||
localStorage.setItem('CookieClickerGame', escape(`${utf8_to_b64(newSaveString)}!END!`)); | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.