-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
107 lines (93 loc) · 2.88 KB
/
plugin.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
let slot;
function save() {
if (!sc.model.isGame() || !sc.model.isRunning()) {
return;
}
if (sc.model.isCombatActive()) {
return;
}
for (const entity of ig.game.entities) {
if (entity && entity.onSave) {
entity.onSave();
}
}
const data = {};
ig.storage._saveState(data);
slot = new ig.SaveSlot(data);
const msg = new sc.ItemContent(0, 1);
if (sc.gui.itemHud.contentEntries.length >= 5) {
sc.gui.itemHud.delayedStack.push(msg);
} else {
sc.gui.itemHud.pushContent(msg, true);
}
msg.textGui.setText("Game saved");
msg.removeChildGui(msg.amountGui);
if (sc.gui.itemHud.hidden) {
sc.gui.itemHud.show();
}
}
function load() {
if (slot) {
ig.storage.loadSlot(slot, null, true);
ig.game.teleporting.timer = 0;
const msg = new sc.ItemContent(0, 1);
if (sc.gui.itemHud.contentEntries.length >= 5) {
sc.gui.itemHud.delayedStack.push(msg);
} else {
sc.gui.itemHud.pushContent(msg, true);
}
msg.textGui.setText("Game loaded");
msg.removeChildGui(msg.amountGui);
}
}
export default class QuickSave {
prestart() {
if (versions.hasOwnProperty('input-api')) {
sc.OPTIONS_DEFINITION['keys-quicksave'] = {
type: 'CONTROLS',
init: { key1: ig.KEY.U },
cat: sc.OPTION_CATEGORY.CONTROLS,
hasDivider: true,
header: 'quicksave',
};
sc.OPTIONS_DEFINITION['keys-quickload'] = {
type: 'CONTROLS',
init: { key1: ig.KEY.J },
cat: sc.OPTION_CATEGORY.CONTROLS,
hasDivider: false,
header: 'quicksave',
};
}
ig.Game.inject({
update(...args) {
if (ig.game.playerEntity) {
if (ig.input.pressed('quicksave')) {
save();
}
if (ig.input.pressed('quickload')) {
load();
}
}
return this.parent(...args);
}
});
ig.Storage.inject({
loadSlot(slot, teleport, bypassClear) {
if (!bypassClear) {
this.slot = null;
}
this.parent(slot, teleport);
}
});
}
poststart() {
if (versions.hasOwnProperty('input-api')) {
ig.lang.labels.sc.gui.options.controls.keys.quicksave = 'Quicksave';
ig.lang.labels.sc.gui.options.controls.keys.quickload = 'Quickload';
ig.lang.labels.sc.gui.options.headers.quicksave = 'quicksave';
} else {
ig.input.bind(ig.KEY.U, 'quicksave');
ig.input.bind(ig.KEY.J, 'quickload');
}
}
}