2019-10-30 12:45:59 +00:00
|
|
|
var SPLIT_LINE = '\\M\\W\\S|T|S|S/L/T/'
|
|
|
|
let serverKey = 'MiaoScript:server'
|
2020-01-13 07:28:25 +00:00
|
|
|
let codeStorageKey = "MiaoScript:code:"
|
2019-10-30 12:45:59 +00:00
|
|
|
var main = avalon.define({
|
|
|
|
$id: 'main',
|
|
|
|
server: window.localStorage.getItem(serverKey) || location.host,
|
|
|
|
type: 'unknow',
|
|
|
|
logs: '',
|
2020-01-16 09:27:24 +00:00
|
|
|
codes: ["default", "bukkit", "sponge", "bungee", "common", "test", "dev", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
|
2020-01-13 07:28:25 +00:00
|
|
|
code: 'default',
|
2019-10-30 12:45:59 +00:00
|
|
|
classes: {
|
2020-01-13 07:28:25 +00:00
|
|
|
total: 0,
|
2019-10-30 12:45:59 +00:00
|
|
|
loaded: 0,
|
|
|
|
},
|
|
|
|
precent: () => {
|
|
|
|
return classes.total
|
|
|
|
},
|
|
|
|
log: (info) => {
|
|
|
|
info.split("\n").forEach((line) => { term.writeln(mcColor2ANSI(line + '§r')) })
|
|
|
|
},
|
|
|
|
send: (type, content) => {
|
|
|
|
if (!ws || ws.readyState != 1) { term.writeln('Please Connect to Server first!'); return; }
|
|
|
|
ws.send(`${type}${SPLIT_LINE}${content}`);
|
|
|
|
},
|
|
|
|
connect: (event = { key: 'Enter' }) => {
|
|
|
|
if (event.key !== "Enter") {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-13 07:28:25 +00:00
|
|
|
connectWebSocket()
|
2019-10-30 12:45:59 +00:00
|
|
|
},
|
|
|
|
init: () => {
|
|
|
|
if (main.server) {
|
|
|
|
main.connect()
|
|
|
|
}
|
2020-01-13 07:28:25 +00:00
|
|
|
},
|
|
|
|
load: (editor) => {
|
|
|
|
editor.setValue(window.localStorage.getItem(codeStorageKey + main.code) || '')
|
|
|
|
},
|
|
|
|
save: (editor) => {
|
|
|
|
window.localStorage.setItem(codeStorageKey + main.code, editor.getValue())
|
|
|
|
showMessenger('代码页 ' + main.code + ' 保存成功!')
|
|
|
|
},
|
|
|
|
switch: (editor) => {
|
|
|
|
let index = main.codes.indexOf(main.code) + 1
|
|
|
|
main.code = main.codes[index == main.codes.length ? 0 : index]
|
2019-10-30 12:45:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-13 07:28:25 +00:00
|
|
|
main.$watch('code', (now, old, name) => {
|
|
|
|
window.localStorage.setItem(codeStorageKey + old, editor.getValue())
|
|
|
|
showMessenger('代码页 ' + old + ' 保存成功!')
|
|
|
|
editor.setValue(window.localStorage.getItem(codeStorageKey + now) || '// empty code page ' + now)
|
|
|
|
})
|
|
|
|
|
2019-10-30 12:45:59 +00:00
|
|
|
main.init()
|