forked from Savateria/local-settings
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (53 loc) · 1.32 KB
/
index.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
module.exports = function LocalSettings(mod) {
mod.settings.$init({
version: 2,
defaults: {
ui: null,
chatOption: null
},
migrate(version) {
switch(version) {
case 1:
this.ui = this.ui.map(ui => ({
name: ui.name,
locked: Boolean(ui.unk),
x: ui.x,
y: ui.y
}))
}
}
})
// UI
mod.hook('C_REQUEST_CLIENT_UI_SETTING', 1, event => {
if(mod.settings.ui) {
mod.send('S_REPLY_CLIENT_UI_SETTING', 2, {
accountId: event.accountId,
uis: mod.settings.ui
})
return false
}
})
mod.hook('S_REPLY_CLIENT_UI_SETTING', 2, event => {
if(mod.settings.ui) return false
for(let ui of event.uis) ui.locked = Boolean(ui.locked)
mod.settings.ui = event.uis
})
mod.hook('C_SAVE_CLIENT_UI_SETTING', 2, event => {
mod.settings.ui = event.uis
})
// Chat options
mod.hook('C_REQUEST_CLIENT_CHAT_OPTION_SETTING', 1, event => {
if(mod.settings.chatOption) {
mod.send('S_REPLY_CLIENT_CHAT_OPTION_SETTING', 1, Object.assign({ accountId: event.accountId }, mod.settings.chatOption))
return false
}
})
mod.hook('S_REPLY_CLIENT_CHAT_OPTION_SETTING', 1, event => {
if(mod.settings.chatOption) return false
mod.settings.chatOption = event
})
mod.hook('C_SAVE_CLIENT_CHAT_OPTION_SETTING', 1, event => {
delete event.accountId
mod.settings.chatOption = event
})
}