Skip to content

Commit

Permalink
Fixed offline mode and hopefully data.js issues
Browse files Browse the repository at this point in the history
  • Loading branch information
plasma4 committed Aug 4, 2024
1 parent fb0c31c commit 425b27b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion localDevelopment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// THIS VARIABLE IS FOR LOCALLY MODIFYING MAGIX AND SHOULD NOT BE CHANGED WHEN PLAYING NORMALLY.
// If you wish to force Magix to use your local files (magix.js and magixUtils.js), set the value below to true. This is not advised because normally, the game will automatically use the newest version when possible and use your browser's local storage to keep an offline copy of the scripts. You should only use this if you are trying to modify Magix!

var offlineMode = true
var offlineMode = false


// IMPORTANT: Settting this value to true will PREVENT FILES FROM WORKING WHEN YOU ARE OFFLINE (if you are getting a message about XML requests, they won't work offline anyway, so feel free to enable this).
Expand Down
1 change: 1 addition & 0 deletions magix.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ if (getObj("civ") != "1") {
author: 'pelletsstarPL',
desc: 'Fit more people, discover magic, and build strange wonders along the way. Unlock portals and more housing so you can fit more people, and explore the vast oceans! Note that this mod uses part of the base game, so credits to Orteil for the default dataset. (many, many new techs, features, and text fixes have been added by @1_e0)',
engineVersion: 1,
manifest: 0,
requires: ['MagixUtils'],
sheets: { 'magixmod': 'https://file.garden/Xbm-ilapeDSxWf1b/MaGiXmOdB4Ta.png', 'magix2': magix2Link, 'seasonal': 'https://file.garden/Xbm-ilapeDSxWf1b/seasonalMagix.png', 'terrain': 'https://file.garden/Xbm-ilapeDSxWf1b/terrainMagix.png' },//custom stylesheet (note : broken in IE and Edge for the time being)
func: function () {
Expand Down
43 changes: 31 additions & 12 deletions magixUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,47 @@ https://file.garden/ZmatEHzFI2_QBuAF/magix.js
/* Additionally, PLEASE BE AWARE: The creator of this mod has personally stated in Discord messages that the Magix mod may be modded by anyone who wishes. This mod provides a few important fixes that prevent the game from breaking, as well as a large amount of rewritings and small changes. To compare, visit https://file.garden/Xbm-ilapeDSxWf1b/MagixUtilsR55B.js to find the original source. */

// Custom storage tools that 1) don't break the save data and 2) are saved when exporting
var conflictingStorageObjects = ["civ"]
G.storageObject = {}
try {
G.storageObject = localStorage.getItem("legacySave-alpha")
if (G.storageObject) {
G.storageObject = unescape(b64DecodeUnicode(G.storageObject)).match(/\$\{.+?\}/)
if (!window.magixLoaded) {
window.magixLoaded = true
var conflictingStorageObjects = ["civ"]
G.storageObject = {}
try {
G.storageObject = localStorage.getItem("legacySave-alpha")
if (G.storageObject) {
G.storageObject = G.storageObject[G.storageObject.length - 1]
G.storageObject = unescape(b64DecodeUnicode(G.storageObject)).match(/\$\{.+?\}/)
if (G.storageObject) {
G.storageObject = JSON.parse(G.storageObject.slice(1).replaceAll('&QOT', '"'))
G.storageObject = G.storageObject[G.storageObject.length - 1]
if (G.storageObject) {
G.storageObject = JSON.parse(G.storageObject.slice(1).replaceAll('&QOT', '"'))
} else {
G.storageObject = {}
}
} else {
G.storageObject = {}
}
} else {
G.storageObject = {}
}
} else {
} catch (e) {
console.warn("Storage data could not be obtained.")
G.storageObject = {}
}
} catch (e) {
console.warn("Storage data could not be obtained.")
G.storageObject = {}

if (!window.skipModCheck) {
setTimeout(() => {
if (G.mods.length > 2) {
G.dialogue.popup(function (div) {
return '<div style="width:480px;height:240px;"><div class="fancyText title">Error!</div>' +
'<div class="bitBiggerText scrollBox underTitle"><div class="par">It appears that you have already installed mods with Magix before it loaded.</div><div class="divider"></div>' +
'<div class="par" style="color:#f30;">Wipe the save and remove the mods that you have installed (possibly the data.js one). (If you are a developer and for some reason you want to ignore this, set window.skipModCheck to true.)</div>' +
'</div>' +
'<div class="buttonBox">' +
G.button({ tooltip: 'Try to select different mods this time!', text: 'Clear data', classes: 'frameless', onclick: function () { G.Clear(); } }) +
'</div></div>';
}, 'noClose')
}
}, 4000)
}
}

// Cookies aren't really needed for this case, so they have been replaced with localStorage from now on; in addition, i've made it so that the game can detect the object data anyway without them by changing the releaseNumber value: this is just a backup method for those older versions
Expand Down

0 comments on commit 425b27b

Please sign in to comment.