mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-04 12:22:54 +08:00
add save/load
This commit is contained in:
@@ -119,6 +119,14 @@ export default ({
|
||||
UI_Support_Programmer: 'Programmer',
|
||||
UI_Support_Designer: 'Designer',
|
||||
|
||||
UI_Save: 'Save',
|
||||
UI_Load: 'Load',
|
||||
UI_Read: 'Copy',
|
||||
UI_Write: 'Paste',
|
||||
|
||||
UI_LoadSuccess: 'Load Success!',
|
||||
UI_LoadFaild: 'Load Faild!',
|
||||
|
||||
M_NoRank: 'There is no rank',
|
||||
|
||||
F_RemakeTimes: 'Remake {0} Times',
|
||||
|
||||
@@ -119,6 +119,14 @@ export default ({
|
||||
UI_Support_Programmer: '打赏程序(顿顿饭)',
|
||||
UI_Support_Designer: '打赏策划(爱发电)',
|
||||
|
||||
UI_Save: '存档',
|
||||
UI_Load: '读档',
|
||||
UI_Read: '复制',
|
||||
UI_Write: '粘贴',
|
||||
|
||||
UI_LoadSuccess: '读档成功!',
|
||||
UI_LoadFaild: '读档失败!',
|
||||
|
||||
M_NoRank: '别卷了,没有排行榜',
|
||||
|
||||
F_RemakeTimes: '已重开{0}次',
|
||||
|
||||
30
src/index.js
30
src/index.js
@@ -34,6 +34,36 @@ globalThis.$$off = (tag, fn) => {
|
||||
if(listener) listener.delete(fn);
|
||||
}
|
||||
|
||||
globalThis.$$copy = async text => {
|
||||
const result = await navigator.permissions.query({ name: "clipboard-write" })
|
||||
if (result.state == "granted" || result.state == "prompt") {
|
||||
navigator.clipboard.writeText(data)
|
||||
return;
|
||||
}
|
||||
const input = document.createElement('input');
|
||||
input.setAttribute('style', 'opacity: 0;');
|
||||
document.body.appendChild(input);
|
||||
input.value = text;
|
||||
input.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(input);
|
||||
}
|
||||
|
||||
globalThis.$$read = async ()=>{
|
||||
const result = await navigator.permissions.query({ name: "clipboard-read" })
|
||||
if (result.state == "granted" || result.state == "prompt") {
|
||||
return await navigator.clipboard.readText();
|
||||
}
|
||||
const input = document.createElement('input');
|
||||
input.setAttribute('style', 'opacity: 0;');
|
||||
document.body.appendChild(input);
|
||||
input.focus();
|
||||
document.execCommand("paste");
|
||||
const text = input.value;
|
||||
document.body.removeChild(input);
|
||||
return text;
|
||||
};
|
||||
|
||||
const core = new Life();
|
||||
const game = new App();
|
||||
globalThis.core = core;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,6 +7,7 @@ export default class CyberMain extends ui.view.CyberTheme.CyberMainUI {
|
||||
this.btnGithub.on(Laya.Event.CLICK, this, goto, ['github']);
|
||||
this.btnDiscord.on(Laya.Event.CLICK, this, goto, ['discord']);
|
||||
this.btnThemes.on(Laya.Event.CLICK, this, ()=>$ui.showDialog(UI.pages.THEMES));
|
||||
this.btnSaveLoad.on(Laya.Event.CLICK, this, ()=>$ui.showDialog(UI.pages.SAVELOAD));
|
||||
this.on(Laya.Event.RESIZE, this, () => {
|
||||
const scale = Math.max(
|
||||
this.width / this.imgBg.width,
|
||||
|
||||
@@ -7,6 +7,7 @@ export default class Main extends ui.view.DefaultTheme.MainUI {
|
||||
this.btnGithub.on(Laya.Event.CLICK, this, goto, ['github']);
|
||||
this.btnDiscord.on(Laya.Event.CLICK, this, goto, ['discord']);
|
||||
this.btnThemes.on(Laya.Event.CLICK, this, ()=>$ui.showDialog(UI.pages.THEMES));
|
||||
this.btnSaveLoad.on(Laya.Event.CLICK, this, ()=>$ui.showDialog(UI.pages.SAVELOAD));
|
||||
}
|
||||
|
||||
static load() {
|
||||
|
||||
83
src/ui/themes/saveload.js
Normal file
83
src/ui/themes/saveload.js
Normal file
@@ -0,0 +1,83 @@
|
||||
export default class SaveLoad extends ui.view.SaveLoadUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnClose.on(Laya.Event.CLICK, this, async ()=>{
|
||||
await this.close();
|
||||
$ui.switchView(UI.pages.MAIN);
|
||||
});
|
||||
this.btnRead.on(Laya.Event.CLICK, this,()=>$$copy(this.input.text = this.data));
|
||||
this.btnWrite.on(Laya.Event.CLICK, this, async ()=>{
|
||||
const text = await $$read();
|
||||
if(text) {
|
||||
this.data = this.input.text = text;
|
||||
} else {
|
||||
this.data = this.input.text;
|
||||
}
|
||||
});
|
||||
|
||||
this.btnSave.on(Laya.Event.CLICK, this, ()=>{
|
||||
let blob = new Blob([this.data], { type: 'application/json' });
|
||||
const slice = blob.slice || blob.webkitSlice || blob.mozSlice;
|
||||
blob = slice.call(blob, 0, blob.size, 'application/octet-stream');
|
||||
const a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `Remake_save_${new Date().toISOString().replace(':','.')}.json`;
|
||||
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(a.href);
|
||||
});
|
||||
this.btnLoad.on(Laya.Event.CLICK, this, ()=>{
|
||||
const file = document.createElement('input');
|
||||
file.setAttribute('type', 'file');
|
||||
file.setAttribute('name', 'file');
|
||||
file.setAttribute('accept', 'application/json');
|
||||
file.setAttribute('style', 'display: none;');
|
||||
document.body.appendChild(file);
|
||||
file.click();
|
||||
file.onchange = (e)=>{
|
||||
const file = e.target.files[0];
|
||||
if(!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => this.data = reader.result;
|
||||
reader.readAsText(file);
|
||||
document.body.removeChild(file);
|
||||
};
|
||||
});
|
||||
this.input.on(Laya.Event.MOUSE_DOWN, this, ()=>{
|
||||
this.input.setSelection(0, this.input.text.length);
|
||||
})
|
||||
}
|
||||
|
||||
static load() {
|
||||
return ["images/atlas/images/radio.atlas"];
|
||||
}
|
||||
|
||||
init() {
|
||||
this.input.text = this.data;
|
||||
}
|
||||
|
||||
get data() {
|
||||
const data = {};
|
||||
Object
|
||||
.keys(localStorage)
|
||||
.filter(v=>v.substr(0,4)!='goog')
|
||||
.forEach(key=>data[key] = localStorage[key]);
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
set data(v) {
|
||||
try {
|
||||
const data = JSON.parse(v);
|
||||
for(const key in data)
|
||||
localStorage.setItem(key, data[key]);
|
||||
$$event('message', ['UI_LoadSuccess']);
|
||||
$ui.theme = $ui.theme;
|
||||
this.btnClose.event(Laya.Event.CLICK);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
$$event('message', ['UI_LoadFaild']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ const pages = {
|
||||
ACHIEVEMENT: 'ACHIEVEMENT',
|
||||
THANKS: 'THANKS',
|
||||
THEMES: 'THEMES',
|
||||
SAVELOAD: 'SAVELOAD',
|
||||
};
|
||||
|
||||
const popups = {
|
||||
@@ -26,6 +27,7 @@ const cyber = {
|
||||
[pages.ACHIEVEMENT]: "cyber/achievement",
|
||||
[pages.THANKS]: "default/thanks",
|
||||
[pages.THEMES]: 'themes',
|
||||
[pages.SAVELOAD]: 'saveload',
|
||||
},
|
||||
popups: {
|
||||
[popups.ACHIEVEMENT]: "cyber/popup/achievementPopup",
|
||||
@@ -61,6 +63,16 @@ const cyber = {
|
||||
defaultColor: '#cccccc',
|
||||
radius: 100,
|
||||
},
|
||||
btnSaveLoad: {
|
||||
defaultColor: '#5865f2',
|
||||
defaultStroke: '#eeeeee',
|
||||
defaultLabel: '#eeeeee',
|
||||
hoverColor: '#1160b0',
|
||||
hoverStroke: '#eeeeee',
|
||||
hoverLabel: '#eeeeee',
|
||||
lineWidth: 0,
|
||||
radius: 100,
|
||||
},
|
||||
}
|
||||
},
|
||||
[pages.THANKS]: {
|
||||
@@ -112,7 +124,38 @@ const cyber = {
|
||||
radius: 80,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
[pages.SAVELOAD]: {
|
||||
vars: {
|
||||
btnClose: {
|
||||
defaultColor: '#eb3941',
|
||||
hoverColor: '#ff0000',
|
||||
},
|
||||
btnSave: {
|
||||
defaultColor: '#007046',
|
||||
hoverColor: '#76f190',
|
||||
},
|
||||
btnRead: {
|
||||
defaultColor: '#007046',
|
||||
hoverColor: '#76f190',
|
||||
},
|
||||
btnLoad: {
|
||||
defaultColor: '#fc5531',
|
||||
hoverColor: '#f28b54',
|
||||
},
|
||||
btnWrite: {
|
||||
defaultColor: '#fc5531',
|
||||
hoverColor: '#f28b54',
|
||||
},
|
||||
},
|
||||
names: {
|
||||
btnSmall: {
|
||||
radius: 80,
|
||||
defaultLabel: '#ffffff',
|
||||
hoverLabel: '#ffffff',
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,6 +171,7 @@ const dark = {
|
||||
[pages.ACHIEVEMENT]: "default/achievement",
|
||||
[pages.THANKS]: "default/thanks",
|
||||
[pages.THEMES]: 'themes',
|
||||
[pages.SAVELOAD]: 'saveload',
|
||||
},
|
||||
popups: {
|
||||
[popups.ACHIEVEMENT]: "default/popup/achievementPopup",
|
||||
@@ -373,6 +417,16 @@ const dark = {
|
||||
defaultColor: '#cccccc',
|
||||
radius: 100,
|
||||
},
|
||||
btnSaveLoad: {
|
||||
defaultColor: '#5865f2',
|
||||
defaultStroke: '#eeeeee',
|
||||
defaultLabel: '#eeeeee',
|
||||
hoverColor: '#1160b0',
|
||||
hoverStroke: '#eeeeee',
|
||||
hoverLabel: '#eeeeee',
|
||||
lineWidth: 0,
|
||||
radius: 100,
|
||||
},
|
||||
},
|
||||
names: {
|
||||
title: 'title',
|
||||
@@ -498,7 +552,38 @@ const dark = {
|
||||
radius: 80,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
[pages.SAVELOAD]: {
|
||||
vars: {
|
||||
btnClose: {
|
||||
defaultColor: '#eb3941',
|
||||
hoverColor: '#ff0000',
|
||||
},
|
||||
btnSave: {
|
||||
defaultColor: '#007046',
|
||||
hoverColor: '#76f190',
|
||||
},
|
||||
btnRead: {
|
||||
defaultColor: '#007046',
|
||||
hoverColor: '#76f190',
|
||||
},
|
||||
btnLoad: {
|
||||
defaultColor: '#fc5531',
|
||||
hoverColor: '#f28b54',
|
||||
},
|
||||
btnWrite: {
|
||||
defaultColor: '#fc5531',
|
||||
hoverColor: '#f28b54',
|
||||
},
|
||||
},
|
||||
names: {
|
||||
btnSmall: {
|
||||
radius: 80,
|
||||
defaultLabel: '#ffffff',
|
||||
hoverLabel: '#ffffff',
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
popups: {
|
||||
[popups.ACHIEVEMENT]: {
|
||||
@@ -526,6 +611,7 @@ const light = {
|
||||
[pages.ACHIEVEMENT]: "default/achievement",
|
||||
[pages.THANKS]: "default/thanks",
|
||||
[pages.THEMES]: 'themes',
|
||||
[pages.SAVELOAD]: 'saveload',
|
||||
},
|
||||
popups: {
|
||||
[popups.ACHIEVEMENT]: "default/popup/achievementPopup",
|
||||
@@ -765,6 +851,16 @@ const light = {
|
||||
defaultColor: '#cccccc',
|
||||
radius: 100,
|
||||
},
|
||||
btnSaveLoad: {
|
||||
defaultColor: '#5865f2',
|
||||
defaultStroke: '#eeeeee',
|
||||
defaultLabel: '#eeeeee',
|
||||
hoverColor: '#1160b0',
|
||||
hoverStroke: '#eeeeee',
|
||||
hoverLabel: '#eeeeee',
|
||||
lineWidth: 0,
|
||||
radius: 100,
|
||||
},
|
||||
},
|
||||
names: {
|
||||
title: 'title',
|
||||
@@ -890,7 +986,38 @@ const light = {
|
||||
radius: 80,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
[pages.SAVELOAD]: {
|
||||
vars: {
|
||||
btnClose: {
|
||||
defaultColor: '#eb3941',
|
||||
hoverColor: '#ff0000',
|
||||
},
|
||||
btnSave: {
|
||||
defaultColor: '#007046',
|
||||
hoverColor: '#76f190',
|
||||
},
|
||||
btnRead: {
|
||||
defaultColor: '#007046',
|
||||
hoverColor: '#76f190',
|
||||
},
|
||||
btnLoad: {
|
||||
defaultColor: '#fc5531',
|
||||
hoverColor: '#f28b54',
|
||||
},
|
||||
btnWrite: {
|
||||
defaultColor: '#fc5531',
|
||||
hoverColor: '#f28b54',
|
||||
},
|
||||
},
|
||||
names: {
|
||||
btnSmall: {
|
||||
radius: 80,
|
||||
defaultLabel: '#ffffff',
|
||||
hoverLabel: '#ffffff',
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
popups: {
|
||||
[popups.ACHIEVEMENT]: {
|
||||
|
||||
Reference in New Issue
Block a user