forked from 1e1000000/universal-idle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveload.js
145 lines (135 loc) · 4.75 KB
/
saveload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
function save() {
localStorage.setItem("universal-idle", JSON.stringify(game))
}
function save2(){
save()
$.notify("Game Saved","success")
}
var autoSave = window.setInterval(function() {
save2();
}, 30000);
function load() {
const loadgame = JSON.parse(localStorage.getItem("universal-idle"));
if (loadgame !== null) {
loadGame(loadgame);
}
}
function loadGame(loadgame) {
reset()
for (const i in loadgame) {
game[i] = loadgame[i];
}
game.tPlayedWTimeSpeed = undefined
game.atoms = new Decimal(game.atoms)
game.size = new Decimal(game.size)
game.time = new Decimal(game.time)
game.totalAtoms = new Decimal(game.totalAtoms)
game.bestSize = new Decimal(game.bestSize)
game.bestGenBoost = new Decimal(game.bestGenBoost)
game.generatorBoost = new Decimal(game.generatorBoost)
game.universePoints = new Decimal(game.universePoints)
game.bestUniPtsInOneReset = new Decimal(game.bestUniPtsInOneReset)
for (let i = 1; i < 8.5; i++) {
game.generator[i] = new Decimal(game.generator[i])
game.generatorBought[i] = new Decimal(game.generatorBought[i])
}
for (let i = 1; i < 10.5; i++) { // failsave
if (game.universeUpgrade[i] == undefined) game.universeUpgrade[i] = false
}
for (let i = 1; i < 4.5; i++) { // failsave
if (game.repeatableUniverseUpgrade[i] == undefined) game.repeatableUniverseUpgrade[i] = new Decimal(0)
}
for (let i = 1; i < 4.5; i++) {
game.repeatableUniverseUpgrade[i] = new Decimal(game.repeatableUniverseUpgrade[i])
}
for (let i = 1; i < 10.5; i++) { // failsave
if (game.challengeCompletion[i] == undefined) game.challengeCompletion[i] = false
}
game.version = 20210219
}
function exporty() {
save();
copyStringToClipboard(btoa(JSON.stringify(game)));
}
function copyStringToClipboard(str) {
var el = document.createElement("textarea");
el.value = str;
el.setAttribute("readonly", "");
el.style = {
position: "absolute",
left: "-9999px"
};
document.body.appendChild(el);
copyToClipboard(el);
$.notify("Exported to Clipboard!","success")
document.body.removeChild(el);
}
function copyToClipboard(el) {
el = typeof el === "string" ? document.querySelector(el) : el;
if (navigator.userAgent.match(/ipad|ipod|iphone/i)) {
var editable = el.contentEditable;
var readOnly = el.readOnly;
el.contentEditable = true;
el.readOnly = true;
var range = document.createRange();
range.selectNodeContents(el);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
el.setSelectionRange(0, 999999);
el.contentEditable = editable;
el.readOnly = readOnly;
} else {
el.select();
}
document.execCommand("copy");
}
function importy() {
let loadgame = "";
loadgame = JSON.parse(atob(prompt("Paste in your save. WARNING: WILL OVERWRITE YOUR CURRENT SAVE")));
if (loadgame !== "") {
loadGame(loadgame);
save()
}
}
function reset(){
game = {
tLast: Date.now(),
tLastUniReset: Date.now(),
tStart: Date.now(),
atoms: new Decimal(10),
size: new Decimal(1),
time: new Decimal(0),
generator: [null, new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0)],
generatorBought: [null, new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0)],
generatorBoost: new Decimal(0),
universePoints: new Decimal(0),
bestUniPtsInOneReset: new Decimal(0),
universeUpgrade: [null, false, false, false, false, false, false, false, false, false, false],
repeatableUniverseUpgrade: [null, new Decimal(0), new Decimal(0), new Decimal(0), new Decimal(0)],
totalAtoms: new Decimal(0),
bestSize: new Decimal(0),
bestGenBoost: new Decimal(0),
challenge: 0,
challengeCompletion: [null, false, false, false, false, false, false, false, false, false, false],
tab: 1,
notation: 0,
timeDisplay: 0,
productionDisplay: 0,
version: 20210200,
achievement: [],
autoGen: false,
autoGenBoost: false,
alternateMain: false,
}
//save()
}
function resetConf() {
if (!confirm("Are you sure you want to delete all of your progress? You can't undo this process! Remaining confirmations: 4")) return
if (!confirm("Are you sure you want to delete all of your progress? You can't undo this process! Remaining confirmations: 3")) return
if (!confirm("Are you sure you want to delete all of your progress? You can't undo this process! Remaining confirmations: 2")) return
if (!confirm("Are you sure you want to delete all of your progress? You can't undo this process! Remaining confirmations: 1")) return
if (!confirm("Are you sure you want to delete all of your progress? You can't undo this process! Remaining confirmations: 0")) return
reset()
save()
}