mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-18 18:58:06 +08:00
Squashed commit of the following:
commitb421082374Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Dec 31 20:26:20 2021 +0800 update specialthanks commit765a69294bAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 19:10:03 2021 +0800 fix ios goto commit8eb8c3ca72Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 19:03:37 2021 +0800 add event grade commitab705dd46cAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:48:42 2021 +0800 build version commita1e4232369Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:47:05 2021 +0800 change talent replace before property allocate commitf4d7b3ae3cAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:06:18 2021 +0800 add event grade commit0567e40ddcAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 21:28:10 2021 +0800 add particle commitf17003925eAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 20:14:26 2021 +0800 change ui commitf8beda1d8fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 19:08:30 2021 +0800 change popup message ui commit915a2aa17dAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 18:34:29 2021 +0800 new build commitb5edabc104Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 18:18:46 2021 +0800 add hint message commita143feadafAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 17:57:31 2021 +0800 fix copy bug commiteab1975791Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 17:56:28 2021 +0800 add save/load commitacf9b92134Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 14:35:33 2021 +0800 add theme switch commit488a6054abAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Dec 1 18:30:36 2021 +0800 fix uiManager bug commitf0317eaf14Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Dec 1 16:07:03 2021 +0800 add message popup commiteb02d1ee6fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 21:22:54 2021 +0800 change relocation commit60503eae47Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:27:16 2021 +0800 change ScaleButton -> Laya.runtime.ScaleButton commit52ef5909c1Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:26:31 2021 +0800 change ScaleButton -> Laya.runtime.ScaleButton commit0284f6aa71Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:05:24 2021 +0800 config webpack commit0e272ffd99Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 13:17:41 2021 +0800 add thanks commite1e2ab4701Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 11:40:21 2021 +0800 add light theme commit4f55c00f86Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 27 22:27:39 2021 +0800 fix bug commit1d07bdfc46Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 27 21:48:47 2021 +0800 daily update commit52d6a0ca8fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Nov 24 23:10:04 2021 +0800 daily update commitf8dd720d4dAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Nov 24 19:08:13 2021 +0800 daily update commitd088c1a862Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 21 21:41:46 2021 +0800 remove useless commita711fcf3edAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Nov 16 00:53:05 2021 +0800 add achievement popup add page adaptive add talent extends commit05e02de3dbAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 13 01:24:04 2021 +0800 add github and discord commitbff0109cc5Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 13 00:30:01 2021 +0800 add trajectory auto mode commit54c04f65c2Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Nov 12 19:54:31 2021 +0800 fix property judge negative number bug commit660739530bAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Nov 12 19:48:58 2021 +0800 update achievement commitc94e9e7433Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Nov 11 21:37:45 2021 +0800 update daily commitc06cd9ea62Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Nov 9 00:08:05 2021 +0800 update daily commit2666983f89Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 7 23:00:22 2021 +0800 add uiManager auto scan and load skin resource commit22fa5d755aAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 7 22:17:04 2021 +0800 update framework commitf40698d63eAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Oct 31 00:13:22 2021 +0800 add laya
This commit is contained in:
31609
src/@types/LayaAir.d.ts
vendored
Normal file
31609
src/@types/LayaAir.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1262
src/@types/layaAir.minigame.d.ts
vendored
Normal file
1262
src/@types/layaAir.minigame.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6118
src/@types/union.d.ts
vendored
Normal file
6118
src/@types/union.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
954
src/app.js
954
src/app.js
@@ -1,830 +1,182 @@
|
||||
import { summary } from './functions/summary.js';
|
||||
import { getRate, getGrade } from './functions/addition.js';
|
||||
import Life from './life.js';
|
||||
import './ui/runtime.js';
|
||||
import './ui/pluginFunction.js'
|
||||
import './ui/promisesLaya.js'
|
||||
import './ui/layaUI.max.all.js';
|
||||
import UIManager from './ui/uiManager.js';
|
||||
import * as utils from './functions/util.js';
|
||||
|
||||
globalThis.UIManager =
|
||||
globalThis.UI =
|
||||
UIManager;
|
||||
|
||||
globalThis.$_ = utils;
|
||||
|
||||
globalThis.goto = async tag => {
|
||||
let url;
|
||||
switch(tag) {
|
||||
case 'github': url = 'https://github.com/VickScarlet/lifeRestart'; break;
|
||||
case 'discord': url = 'https://discord.gg/U3qrf49NMQ'; break;
|
||||
case 'sponsor_afd': url = 'https://afdian.net/@LifeRestart'; break;
|
||||
case 'sponsor_ddf': url = 'https://dun.mianbaoduo.com/@vickscarlet'; break;
|
||||
}
|
||||
try {
|
||||
if(Laya.Browser.onIOS) {
|
||||
window.location.href = url;
|
||||
} else {
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
class App{
|
||||
constructor(){
|
||||
this.#life = new Life();
|
||||
this.name = 'lifeRestart';
|
||||
this.version = '2.0.0';
|
||||
console.log(`${this.name} ${this.version}`);
|
||||
}
|
||||
|
||||
#life;
|
||||
#pages;
|
||||
#currentPage;
|
||||
#talentSelected = new Set();
|
||||
#totalMax=20;
|
||||
#isEnd = false;
|
||||
#selectedExtendTalent = null;
|
||||
#hintTimeout;
|
||||
#specialthanks;
|
||||
#autoTrajectory;
|
||||
#language;
|
||||
static languages = {
|
||||
'zh-cn': 'zh-cn',
|
||||
'en-us': 'en-us',
|
||||
};
|
||||
|
||||
async initial() {
|
||||
this.initPages();
|
||||
this.switch('loading');
|
||||
const [,specialthanks] = await Promise.all([
|
||||
this.#life.initial(),
|
||||
json('specialthanks')
|
||||
]);
|
||||
this.#specialthanks = specialthanks;
|
||||
this.switch('index');
|
||||
globalThis.onerror = (event, source, lineno, colno, error) => {
|
||||
this.hint(`[ERROR] at (${source}:${lineno}:${colno})\n\n${error?.stack||error||'unknow Error'}`, 'error');
|
||||
}
|
||||
const keyDownCallback = ({which: w, keyCode: k}) => {
|
||||
if ( w === 13 || k === 13 || w === 32 || k === 32 ) {
|
||||
const pressEnterFunc = this.#pages[this.#currentPage]?.pressEnter;
|
||||
pressEnterFunc && typeof pressEnterFunc === 'function' && pressEnterFunc();
|
||||
#initLaya() {
|
||||
/**
|
||||
*...特殊的字符,如泰文,必须重新实现这个类
|
||||
*/
|
||||
//class laya.webgl.text.CharSegment
|
||||
class CharSegment {
|
||||
constructor() {
|
||||
this._sourceStr=null;
|
||||
}
|
||||
textToSpit(str) {
|
||||
this._sourceStr=str;
|
||||
var texLen = str.length;
|
||||
var idx = -1;
|
||||
this._words = [];
|
||||
while (++idx < texLen) {
|
||||
var character = str.charAt(idx);
|
||||
var code = str.charCodeAt(idx);
|
||||
if (code >= 0xD800 && code <= 0xDBFF) {
|
||||
this._words.push(character + str.charAt(++idx));
|
||||
} else {
|
||||
this._words.push(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
getChar(i){
|
||||
return this._words;
|
||||
}
|
||||
getCharCode(i){
|
||||
return this._words[i].codePointAt(0);
|
||||
}
|
||||
length(){
|
||||
return this._words.length;
|
||||
}
|
||||
}
|
||||
globalThis.removeEventListener('keydown', keyDownCallback);
|
||||
globalThis.addEventListener('keydown', keyDownCallback);
|
||||
Laya.class(CharSegment,'laya.webgl.text.CharSegment');
|
||||
Laya.imps(CharSegment.prototype,{"laya.webgl.text.ICharSegment":true})
|
||||
|
||||
|
||||
// Laya.init(1125, 2436, Laya.WebGL);
|
||||
Laya.Config.isAntialias = true;
|
||||
Laya.init(...this.#fitScreen, Laya.WebGL);
|
||||
|
||||
Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
|
||||
Laya.stage.alignH = Laya.Stage.ALIGN_CENTER;
|
||||
|
||||
Laya.stage.scaleMode = "showall";
|
||||
Laya.stage.bgColor = "#000000";
|
||||
window.onresize = () => Laya.stage.size(...this.#fitScreen);
|
||||
}
|
||||
|
||||
initPages() {
|
||||
get #fitScreen() {
|
||||
const designWidth = 1125;
|
||||
const designHeight = 2436;
|
||||
const maxWidth = designHeight * 3 / 4;
|
||||
const maxHeight = designWidth * 24 / 9;
|
||||
const designRatio = designWidth / designHeight;
|
||||
|
||||
// Loading
|
||||
const loadingPage = $(`
|
||||
<div id="main">
|
||||
<div id="title">
|
||||
人生重开模拟器<br>
|
||||
<div style="font-size:1.5rem; font-weight:normal;">加载中...</div>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
|
||||
// Index
|
||||
const indexPage = $(`
|
||||
<div id="main">
|
||||
<button id="achievement">成就</button>
|
||||
<button id="specialthanks">特别感谢</button>
|
||||
<button id="themeToggleBtn">黑</button>
|
||||
<button id="save">Save</button>
|
||||
<button id="load">Load</button>
|
||||
<div id="title">
|
||||
人生重开模拟器<br>
|
||||
<div style="font-size:1.5rem; font-weight:normal;">这垃圾人生一秒也不想呆了</div>
|
||||
</div>
|
||||
<button id="restart" class="mainbtn"><span class="iconfont"></span>立即重开</button>
|
||||
<a id="discord" href="https://discord.gg/U3qrf49NMQ" style="z-index: 9999;" aria-label="Chat on Discord"><button class="discord-btn"><svg width="50%" height="55" viewBox="0 0 71 55" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0)"><path d="M60.1045 4.8978C55.5792 2.8214 50.7265 1.2916 45.6527 0.41542C45.5603 0.39851 45.468 0.440769 45.4204 0.525289C44.7963 1.6353 44.105 3.0834 43.6209 4.2216C38.1637 3.4046 32.7345 3.4046 27.3892 4.2216C26.905 3.0581 26.1886 1.6353 25.5617 0.525289C25.5141 0.443589 25.4218 0.40133 25.3294 0.41542C20.2584 1.2888 15.4057 2.8186 10.8776 4.8978C10.8384 4.9147 10.8048 4.9429 10.7825 4.9795C1.57795 18.7309 -0.943561 32.1443 0.293408 45.3914C0.299005 45.4562 0.335386 45.5182 0.385761 45.5576C6.45866 50.0174 12.3413 52.7249 18.1147 54.5195C18.2071 54.5477 18.305 54.5139 18.3638 54.4378C19.7295 52.5728 20.9469 50.6063 21.9907 48.5383C22.0523 48.4172 21.9935 48.2735 21.8676 48.2256C19.9366 47.4931 18.0979 46.6 16.3292 45.5858C16.1893 45.5041 16.1781 45.304 16.3068 45.2082C16.679 44.9293 17.0513 44.6391 17.4067 44.3461C17.471 44.2926 17.5606 44.2813 17.6362 44.3151C29.2558 49.6202 41.8354 49.6202 53.3179 44.3151C53.3935 44.2785 53.4831 44.2898 53.5502 44.3433C53.9057 44.6363 54.2779 44.9293 54.6529 45.2082C54.7816 45.304 54.7732 45.5041 54.6333 45.5858C52.8646 46.6197 51.0259 47.4931 49.0921 48.2228C48.9662 48.2707 48.9102 48.4172 48.9718 48.5383C50.038 50.6034 51.2554 52.5699 52.5959 54.435C52.6519 54.5139 52.7526 54.5477 52.845 54.5195C58.6464 52.7249 64.529 50.0174 70.6019 45.5576C70.6551 45.5182 70.6887 45.459 70.6943 45.3942C72.1747 30.0791 68.2147 16.7757 60.1968 4.9823C60.1772 4.9429 60.1437 4.9147 60.1045 4.8978ZM23.7259 37.3253C20.2276 37.3253 17.3451 34.1136 17.3451 30.1693C17.3451 26.225 20.1717 23.0133 23.7259 23.0133C27.308 23.0133 30.1626 26.2532 30.1066 30.1693C30.1066 34.1136 27.28 37.3253 23.7259 37.3253ZM47.3178 37.3253C43.8196 37.3253 40.9371 34.1136 40.9371 30.1693C40.9371 26.225 43.7636 23.0133 47.3178 23.0133C50.9 23.0133 53.7545 26.2532 53.6986 30.1693C53.6986 34.1136 50.9 37.3253 47.3178 37.3253Z" fill="#ffffff"/></g><defs><clipPath id="clip0"><rect width="71" height="55" fill="white"/></clipPath></defs></svg>CHAT</button><style>.discord-btn {position: fixed;bottom: 0.5rem;left: 0.5rem;background-color: #5865F2;padding: 0.7rem;height: auto;color: white;text-align: right;vertical-align: middle;border: none;width: 6.5rem;font-size: 1rem;border-radius: 4px;}.discord-btn svg {height: 1.5rem;position: absolute;top: 50%;left: 0;transform: translateY(-50%);}.discord-btn:hover svg{animation:discord-wave 560ms ease-in-out;}@keyframes discord-wave{0%,100%{transform:translateY(-50%) rotate(0)}20%,60%{transform:translateY(-50%) rotate(-25deg)}40%,80%{transform:translateY(-50%) rotate(10deg)}}@media (max-width:500px){.discord-btn:hover svg{animation:none}.discord-btn svg{animation:discord-wave 560ms ease-in-out}}</style></a>
|
||||
</div>
|
||||
`);
|
||||
|
||||
// Init theme
|
||||
let date = new Date();
|
||||
if( date.getMonth() == 9 && date.getDate() == 31
|
||||
|| date.getMonth() == 10 && date.getDate() == 1
|
||||
){
|
||||
this.setTheme('halloween');
|
||||
const screenWidth = window.innerWidth;
|
||||
const screenHeight = window.innerHeight;
|
||||
const screenRatio = screenWidth / screenHeight;
|
||||
if(screenRatio > designRatio) {
|
||||
return [
|
||||
Math.min(screenWidth*designHeight/screenHeight, maxWidth),
|
||||
designHeight
|
||||
]
|
||||
} else {
|
||||
this.setTheme(localStorage.getItem('theme'))
|
||||
return [
|
||||
designWidth,
|
||||
Math.min(screenHeight*designWidth/screenWidth, maxHeight)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
indexPage
|
||||
.find('#restart')
|
||||
.click(()=>this.switch('talent'));
|
||||
async setLanguage(language) {
|
||||
return this.#setLanguage(language);
|
||||
}
|
||||
|
||||
indexPage
|
||||
.find('#achievement')
|
||||
.click(()=>this.switch('achievement'));
|
||||
|
||||
|
||||
indexPage
|
||||
.find('#save')
|
||||
.click(()=>{
|
||||
const data = {};
|
||||
Object
|
||||
.keys(localStorage)
|
||||
.filter(v=>v.substr(0,4)!='goog')
|
||||
.forEach(key=>data[key] = localStorage[key]);
|
||||
|
||||
let blob = new Blob([JSON.stringify(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);
|
||||
});
|
||||
|
||||
indexPage
|
||||
.find('#load')
|
||||
.click(()=>{
|
||||
const file = $(`<input type="file" name="file" accept="application/json" style="display: none;" />`)
|
||||
file.appendTo('body');
|
||||
file.click();
|
||||
file.on('change', (e)=>{
|
||||
this.switch('loading');
|
||||
const file = e.target.files[0];
|
||||
if(!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const data = JSON.parse(reader.result);
|
||||
for(const key in data) {
|
||||
localStorage[key] = data[key];
|
||||
}
|
||||
this.switch('index');
|
||||
this.setTheme(localStorage.getItem('theme'))
|
||||
if(localStorage.getItem('theme') == 'light') {
|
||||
indexPage.find('#themeToggleBtn').text('黑')
|
||||
} else{
|
||||
indexPage.find('#themeToggleBtn').text('白')
|
||||
}
|
||||
this.hint('加载存档成功', 'success');
|
||||
}
|
||||
reader.readAsText(file);
|
||||
});
|
||||
});
|
||||
|
||||
if(localStorage.getItem('theme') == 'light') {
|
||||
indexPage.find('#themeToggleBtn').text('黑')
|
||||
} else{
|
||||
indexPage.find('#themeToggleBtn').text('白')
|
||||
async #setLanguage(language) {
|
||||
switch(language) {
|
||||
case App.languages['en-us']:
|
||||
case App.languages['zh-cn']:
|
||||
this.#language = language;
|
||||
break;
|
||||
default:
|
||||
this.#language = App.languages['zh-cn'];
|
||||
break;
|
||||
}
|
||||
globalThis.$lang =
|
||||
Laya.Text.langPacks =
|
||||
(await import(`./i18n/${this.#language}.js`)).default;
|
||||
}
|
||||
|
||||
indexPage
|
||||
.find("#themeToggleBtn")
|
||||
.click(() => {
|
||||
if(localStorage.getItem('theme') == 'light') {
|
||||
localStorage.setItem('theme', 'dark');
|
||||
indexPage.find('#themeToggleBtn').text('白')
|
||||
} else {
|
||||
localStorage.setItem('theme', 'light');
|
||||
indexPage.find('#themeToggleBtn').text('黑')
|
||||
}
|
||||
|
||||
this.setTheme(localStorage.getItem('theme'))
|
||||
});
|
||||
|
||||
indexPage
|
||||
.find('#specialthanks')
|
||||
.click(()=>this.switch('specialthanks'));
|
||||
|
||||
const specialThanksPage = $(`
|
||||
<div id="main">
|
||||
<button id="specialthanks">返回</button>
|
||||
<div id="spthx">
|
||||
<ul class="g1"></ul>
|
||||
<ul class="g2"></ul>
|
||||
</div>
|
||||
<button class="sponsor" onclick="globalThis.open('https://afdian.net/@LifeRestart')" style="background: linear-gradient(90deg,#946ce6,#7e5fd9); left:auto; right:50%; transform: translate(-2rem,-50%);">打赏策划(爱发电)</button>
|
||||
<button class="sponsor" onclick="globalThis.open('https://dun.mianbaoduo.com/@vickscarlet')" style="background-color:#c69; left:50%; right:auto; transform: translate(2rem,-50%);">打赏程序(顿顿饭)</button>
|
||||
</div>
|
||||
`);
|
||||
|
||||
specialThanksPage
|
||||
.find('#specialthanks')
|
||||
.click(()=>this.switch('index'));
|
||||
|
||||
const achievementPage = $(`
|
||||
<div id="main">
|
||||
<button id="specialthanks">返回</button>
|
||||
<span class="title">统计</span>
|
||||
<ul id="total"></ul>
|
||||
<span style="padding:0.25rem; margin: 0.5rem 0; border: none; background: #ccc;"></span>
|
||||
<span class="title">成就<button id="rank">排行榜</button></span>
|
||||
<ul id="achievements"></ul>
|
||||
`)
|
||||
|
||||
achievementPage
|
||||
.find('#specialthanks')
|
||||
.click(()=>this.switch('index'));
|
||||
|
||||
achievementPage
|
||||
.find('#rank')
|
||||
.click(()=>this.hint('别卷了,没有排行榜'));
|
||||
// Talent
|
||||
const talentPage = $(`
|
||||
<div id="main">
|
||||
<div class="head" style="font-size: 1.6rem">天赋抽卡</div>
|
||||
<button id="random" class="mainbtn" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);"">10连抽!</button>
|
||||
<ul id="talents" class="selectlist"></ul>
|
||||
<button id="next" class="mainbtn">请选择3个</button>
|
||||
</div>
|
||||
`);
|
||||
|
||||
const createTalent = ({ grade, name, description }) => {
|
||||
return $(`<li class="grade${grade}b">${name}(${description})</li>`)
|
||||
};
|
||||
|
||||
talentPage
|
||||
.find('#random')
|
||||
.click(()=>{
|
||||
talentPage.find('#random').hide();
|
||||
const ul = talentPage.find('#talents');
|
||||
this.#life.talentRandom()
|
||||
.forEach(talent=>{
|
||||
const li = createTalent(talent);
|
||||
ul.append(li);
|
||||
li.click(()=>{
|
||||
if(li.hasClass('selected')) {
|
||||
li.removeClass('selected')
|
||||
this.#talentSelected.delete(talent);
|
||||
if(this.#talentSelected.size<3) {
|
||||
talentPage.find('#next').text('请选择3个')
|
||||
}
|
||||
} else {
|
||||
if(this.#talentSelected.size==3) {
|
||||
this.hint('只能选3个天赋');
|
||||
return;
|
||||
}
|
||||
|
||||
const exclusive = this.#life.exclusive(
|
||||
Array.from(this.#talentSelected).map(({id})=>id),
|
||||
talent.id
|
||||
);
|
||||
if(exclusive != null) {
|
||||
for(const { name, id } of this.#talentSelected) {
|
||||
if(id == exclusive) {
|
||||
this.hint(`与已选择的天赋【${name}】冲突`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
li.addClass('selected');
|
||||
this.#talentSelected.add(talent);
|
||||
if(this.#talentSelected.size==3) {
|
||||
talentPage.find('#next').text('开始新人生')
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
talentPage.find('#next').show()
|
||||
});
|
||||
|
||||
talentPage
|
||||
.find('#next')
|
||||
.click(()=>{
|
||||
if(this.#talentSelected.size!=3) {
|
||||
this.hint('请选择3个天赋');
|
||||
return;
|
||||
}
|
||||
talentPage.find('#next').hide()
|
||||
this.#totalMax = 20 + this.#life.getTalentAllocationAddition(Array.from(this.#talentSelected).map(({id})=>id));
|
||||
this.switch('property');
|
||||
})
|
||||
|
||||
// Property
|
||||
// hint of extension tobermory.es6-string-html
|
||||
const propertyPage = $(/*html*/`
|
||||
<div id="main">
|
||||
<div class="head" style="font-size: 1.6rem">
|
||||
<div>调整初始属性</div>
|
||||
<div id="total" style="font-size:1rem; font-weight:normal;">可用属性点:0</div>
|
||||
</div>
|
||||
<ul id="propertyAllocation" class="propinitial"></ul>
|
||||
<ul class="selectlist" id="talentSelectedView"></ul>
|
||||
<div class="btn-area">
|
||||
<button id="random" class="mainbtn">随机分配</button>
|
||||
<button id="start" class="mainbtn">开始新人生</button>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
propertyPage.mounted = ()=>{
|
||||
propertyPage
|
||||
.find('#talentSelectedView').append(
|
||||
`<li>已选天赋</li>` +
|
||||
Array.from(this.#talentSelected)
|
||||
.map(({name,description})=>`<li class="grade0b">${name}(${description})</li>`)
|
||||
.join('')
|
||||
)
|
||||
}
|
||||
const groups = {};
|
||||
const total = ()=>{
|
||||
let t = 0;
|
||||
for(const type in groups)
|
||||
t += groups[type].get();
|
||||
return t;
|
||||
}
|
||||
const freshTotal = ()=>{
|
||||
propertyPage.find('#total').text(`可用属性点:${this.#totalMax - total()}`);
|
||||
}
|
||||
const getBtnGroups = (name, min, max)=>{
|
||||
const group = $(`<li>${name} </li>`);
|
||||
const btnSub = $(`<span class="iconfont propbtn"></span>`);
|
||||
const inputBox = $(`<input value="0" type="number" />`);
|
||||
const btnAdd = $(`<span class="iconfont propbtn"></span>`);
|
||||
group.append(btnSub);
|
||||
group.append(inputBox);
|
||||
group.append(btnAdd);
|
||||
|
||||
const limit = v=>{
|
||||
v = Number(v)||0;
|
||||
v = Math.round(v);
|
||||
return v < min ? min : (
|
||||
v > max ? max : v
|
||||
)
|
||||
}
|
||||
const get = ()=>Number(inputBox.val());
|
||||
const set = v=>{
|
||||
inputBox.val(limit(v));
|
||||
freshTotal();
|
||||
}
|
||||
btnAdd.click(()=>{
|
||||
if(total() >= this.#totalMax) {
|
||||
this.hint('没有可分配的点数了');
|
||||
return;
|
||||
}
|
||||
set(get()+1);
|
||||
});
|
||||
btnSub.click(()=>set(get()-1));
|
||||
inputBox.on('input', ()=>{
|
||||
const t = total();
|
||||
let val = get();
|
||||
if(t > this.#totalMax) {
|
||||
val -= t - this.#totalMax;
|
||||
}
|
||||
val = limit(val);
|
||||
if(val != inputBox.val()) {
|
||||
set(val);
|
||||
}
|
||||
freshTotal();
|
||||
});
|
||||
return {group, get, set};
|
||||
}
|
||||
|
||||
groups.CHR = getBtnGroups("颜值", 0, 10); // 颜值 charm CHR
|
||||
groups.INT = getBtnGroups("智力", 0, 10); // 智力 intelligence INT
|
||||
groups.STR = getBtnGroups("体质", 0, 10); // 体质 strength STR
|
||||
groups.MNY = getBtnGroups("家境", 0, 10); // 家境 money MNY
|
||||
|
||||
const ul = propertyPage.find('#propertyAllocation');
|
||||
|
||||
for(const type in groups) {
|
||||
ul.append(groups[type].group);
|
||||
}
|
||||
|
||||
propertyPage
|
||||
.find('#random')
|
||||
.click(()=>{
|
||||
let t = this.#totalMax;
|
||||
const arr = [10, 10, 10, 10];
|
||||
while(t>0) {
|
||||
const sub = Math.round(Math.random() * (Math.min(t, 10) - 1)) + 1;
|
||||
while(true) {
|
||||
const select = Math.floor(Math.random() * 4) % 4;
|
||||
if(arr[select] - sub <0) continue;
|
||||
arr[select] -= sub;
|
||||
t -= sub;
|
||||
break;
|
||||
}
|
||||
}
|
||||
groups.CHR.set(10 - arr[0]);
|
||||
groups.INT.set(10 - arr[1]);
|
||||
groups.STR.set(10 - arr[2]);
|
||||
groups.MNY.set(10 - arr[3]);
|
||||
});
|
||||
|
||||
propertyPage
|
||||
.find('#start')
|
||||
.click(()=>{
|
||||
if(total() < this.#totalMax) {
|
||||
this.hint(`你还有${this.#totalMax-total()}属性点没有分配完`);
|
||||
return;
|
||||
} else if (total() > this.#totalMax) {
|
||||
this.hint(`你多使用了${total() - this.#totalMax}属性点`);
|
||||
return;
|
||||
}
|
||||
const contents = this.#life.restart({
|
||||
CHR: groups.CHR.get(),
|
||||
INT: groups.INT.get(),
|
||||
STR: groups.STR.get(),
|
||||
MNY: groups.MNY.get(),
|
||||
SPR: 5,
|
||||
TLT: Array.from(this.#talentSelected).map(({id})=>id),
|
||||
});
|
||||
this.switch('trajectory');
|
||||
this.#pages.trajectory.born(contents);
|
||||
// $(document).keydown(function(event){
|
||||
// if(event.which == 32 || event.which == 13){
|
||||
// $('#lifeTrajectory').click();
|
||||
// }
|
||||
// })
|
||||
});
|
||||
|
||||
// Trajectory
|
||||
const trajectoryPage = $(`
|
||||
<div id="main">
|
||||
<ul id="lifeProperty" class="lifeProperty"></ul>
|
||||
<ul id="lifeTrajectory" class="lifeTrajectory"></ul>
|
||||
<div class="btn-area">
|
||||
<button id="auto" class="mainbtn">自动播放</button>
|
||||
<button id="auto2x" class="mainbtn">自动播放2x</button>
|
||||
<button id="summary" class="mainbtn">人生总结</button>
|
||||
<button id="domToImage" class="mainbtn">人生回放</button>
|
||||
</div>
|
||||
<div class="domToImage2wx">
|
||||
<img src="" id="endImage" />
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
|
||||
trajectoryPage
|
||||
.find('#lifeTrajectory')
|
||||
.click(()=>{
|
||||
if(this.#isEnd) return;
|
||||
const trajectory = this.#life.next();
|
||||
const { age, content, isEnd } = trajectory;
|
||||
const li = $(`<li><span>${age}岁:</span><span>${
|
||||
content.map(
|
||||
({type, description, grade, name, postEvent}) => {
|
||||
switch(type) {
|
||||
case 'TLT':
|
||||
return `天赋【${name}】发动:${description}`;
|
||||
case 'EVT':
|
||||
return description + (postEvent?`<br>${postEvent}`:'');
|
||||
}
|
||||
}
|
||||
).join('<br>')
|
||||
}</span></li>`);
|
||||
li.appendTo('#lifeTrajectory');
|
||||
$("#lifeTrajectory").scrollTop($("#lifeTrajectory")[0].scrollHeight);
|
||||
if(isEnd) {
|
||||
$(document).unbind("keydown");
|
||||
this.#isEnd = true;
|
||||
trajectoryPage.find('#summary').show();
|
||||
trajectoryPage.find('#auto').hide();
|
||||
trajectoryPage.find('#auto2x').hide();
|
||||
// trajectoryPage.find('#domToImage').show();
|
||||
}
|
||||
const property = this.#life.getLastRecord();
|
||||
$("#lifeProperty").html(`
|
||||
<li><span>颜值</span><span>${property.CHR}</span></li>
|
||||
<li><span>智力</span><span>${property.INT}</span></li>
|
||||
<li><span>体质</span><span>${property.STR}</span></li>
|
||||
<li><span>家境</span><span>${property.MNY}</span></li>
|
||||
<li><span>快乐</span><span>${property.SPR}</span></li>
|
||||
`);
|
||||
});
|
||||
// html2canvas
|
||||
trajectoryPage
|
||||
.find('#domToImage')
|
||||
.click(()=>{
|
||||
$("#lifeTrajectory").addClass("deleteFixed");
|
||||
const ua = navigator.userAgent.toLowerCase();
|
||||
domtoimage.toJpeg(document.getElementById('lifeTrajectory'))
|
||||
.then(function (dataUrl) {
|
||||
let link = document.createElement('a');
|
||||
link.download = '我的人生回放.jpeg';
|
||||
link.href = dataUrl;
|
||||
link.click();
|
||||
$("#lifeTrajectory").removeClass("deleteFixed");
|
||||
// 微信内置浏览器,显示图片,需要用户单独保存
|
||||
if(ua.match(/MicroMessenger/i)=="micromessenger") {
|
||||
$('#endImage').attr('src', dataUrl);
|
||||
}
|
||||
|
||||
});
|
||||
})
|
||||
.hide();
|
||||
|
||||
trajectoryPage
|
||||
.find('#summary')
|
||||
.click(()=>{
|
||||
clearInterval(this.#autoTrajectory);
|
||||
this.#autoTrajectory = null;
|
||||
this.switch('summary');
|
||||
});
|
||||
|
||||
const auto = tick=>{
|
||||
if(this.#autoTrajectory) {
|
||||
clearInterval(this.#autoTrajectory);
|
||||
this.#autoTrajectory = null;
|
||||
resigterEvent() {
|
||||
$$on('achievement', achievement => {
|
||||
$ui.popup(UI.popups.ACHIEVEMENT, {achievement});
|
||||
})
|
||||
$$on('message', ([message, ...args]) => {
|
||||
if(Array.isArray(message)) {
|
||||
message = message.map(([m, ...a]) => $_.format($lang[m], ...a)) .join('\n');
|
||||
} else {
|
||||
if(!this.isEnd)
|
||||
trajectoryPage
|
||||
.find('#lifeTrajectory')
|
||||
.click();
|
||||
this.#autoTrajectory = setInterval(()=>{
|
||||
if(this.isEnd) {
|
||||
clearInterval(this.#autoTrajectory);
|
||||
this.#autoTrajectory = null;
|
||||
} else {
|
||||
trajectoryPage
|
||||
.find('#lifeTrajectory')
|
||||
.click();
|
||||
}
|
||||
}, tick);
|
||||
message = $_.format(
|
||||
$lang[message], ...args
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
trajectoryPage
|
||||
.find('#auto')
|
||||
.click(()=>auto(1000));
|
||||
trajectoryPage
|
||||
.find('#auto2x')
|
||||
.click(()=>auto(500));
|
||||
|
||||
// Summary
|
||||
const summaryPage = $(`
|
||||
<div id="main">
|
||||
<div class="head">人生总结</div>
|
||||
<ul id="judge" class="judge">
|
||||
<li class="grade2"><span>颜值:</span><span>9级 美若天仙</span></li>
|
||||
<li class="grade0"><span>智力:</span><span>4级 智力一般</span></li>
|
||||
<li class="grade0"><span>体质:</span><span>1级 极度虚弱</span></li>
|
||||
<li class="grade0"><span>家境:</span><span>6级 小康之家</span></li>
|
||||
<li class="grade0"><span>享年:</span><span>3岁 早夭</span></li>
|
||||
<li class="grade0"><span>快乐:</span><span></span>3级 不太幸福的人生</li>
|
||||
</ul>
|
||||
<div class="head" style="height:auto;">天赋,你可以选一个,下辈子还能抽到</div>
|
||||
<ul id="talents" class="selectlist" style="flex: 0 1 auto;">
|
||||
<li class="grade2b">黑幕(面试一定成功)</li>
|
||||
</ul>
|
||||
<button id="again" class="mainbtn"><span class="iconfont"></span>再次重开</button>
|
||||
</div>
|
||||
`);
|
||||
|
||||
summaryPage
|
||||
.find('#again')
|
||||
.click(()=>{
|
||||
this.times ++;
|
||||
this.#life.talentExtend(this.#selectedExtendTalent);
|
||||
this.#selectedExtendTalent = null;
|
||||
this.#talentSelected.clear();
|
||||
this.#totalMax = 20;
|
||||
this.#isEnd = false;
|
||||
this.switch('index');
|
||||
});
|
||||
|
||||
this.#pages = {
|
||||
loading: {
|
||||
page: loadingPage,
|
||||
clear: ()=>{
|
||||
this.#currentPage = 'loading';
|
||||
},
|
||||
},
|
||||
index: {
|
||||
page: indexPage,
|
||||
btnAchievement: indexPage.find('#achievement'),
|
||||
btnRestart: indexPage.find('#restart'),
|
||||
hint: indexPage.find('.hint'),
|
||||
pressEnter: ()=>{
|
||||
this.#pages.index.btnRestart.click();
|
||||
},
|
||||
clear: ()=>{
|
||||
this.#currentPage = 'index';
|
||||
indexPage.find('.hint').hide();
|
||||
|
||||
const times = this.times;
|
||||
const achievement = indexPage.find('#achievement');
|
||||
const discord = indexPage.find('#discord');
|
||||
const specialthanks = indexPage.find('#specialthanks');
|
||||
|
||||
if(times > 0) {
|
||||
achievement.show();
|
||||
discord.show();
|
||||
specialthanks.show();
|
||||
return;
|
||||
}
|
||||
|
||||
achievement.hide();
|
||||
discord.hide();
|
||||
specialthanks.hide();
|
||||
},
|
||||
},
|
||||
specialthanks: {
|
||||
page: specialThanksPage,
|
||||
clear: () => {
|
||||
const groups = [
|
||||
specialThanksPage.find('#spthx > ul.g1'),
|
||||
specialThanksPage.find('#spthx > ul.g2'),
|
||||
];
|
||||
groups.forEach(g=>g.empty());
|
||||
this.#specialthanks
|
||||
.sort(()=>0.5-Math.random())
|
||||
.forEach(({group, name, comment, color})=>groups[--group].append(`
|
||||
<li>
|
||||
<span class="name" ${color?('style="color:'+color+'"'):''}>${name}</span>
|
||||
<span class="comment">${comment||''}</span>
|
||||
</li>
|
||||
`))
|
||||
}
|
||||
},
|
||||
achievement: {
|
||||
page: achievementPage,
|
||||
clear: () => {
|
||||
const total = achievementPage.find("ul#total");
|
||||
const achievements = achievementPage.find("ul#achievements");
|
||||
total.empty();
|
||||
achievements.empty();
|
||||
|
||||
const formatRate = (type, value) => {
|
||||
const rate = getRate(type, value);
|
||||
let color = Object.keys(rate)[0];
|
||||
switch(parseInt(color)) {
|
||||
case 0: color = '白色'; break;
|
||||
case 1: color = '蓝色'; break;
|
||||
case 2: color = '紫色'; break;
|
||||
case 3: color = '橙色'; break;
|
||||
default: break;
|
||||
}
|
||||
let r = Object.values(rate)[0];
|
||||
switch(parseInt(r)) {
|
||||
case 1: r = '不变'; break;
|
||||
case 2: r = '翻倍'; break;
|
||||
case 3: r = '三倍'; break;
|
||||
case 4: r = '四倍'; break;
|
||||
case 5: r = '五倍'; break;
|
||||
case 6: r = '六倍'; break;
|
||||
default: break;
|
||||
}
|
||||
return `抽到${color}概率${r}`;
|
||||
}
|
||||
|
||||
const { times, achievement, talentRate, eventRate } = this.#life.getTotal();
|
||||
total.append(`
|
||||
<li class="achvg${getGrade('times', times)}"><span class="achievementtitle">已重开${times}次</span>${formatRate('times', times)}</li>
|
||||
<li class="achvg${getGrade('achievement', achievement)}"><span class="achievementtitle">成就达成${achievement}个</span>${formatRate('achievement', achievement)}</li>
|
||||
<li class="achvg${getGrade('eventRate', eventRate)}"><span class="achievementtitle">事件收集率</span>${Math.floor(eventRate * 100)}%</li>
|
||||
<li class="achvg${getGrade('talentRate', talentRate)}"><span class="achievementtitle">天赋收集率</span>${Math.floor(talentRate * 100)}%</li>
|
||||
`);
|
||||
|
||||
const achievementsData = this.#life.getAchievements();
|
||||
achievementsData.forEach(({
|
||||
name, description, hide,
|
||||
grade, isAchieved
|
||||
})=>{
|
||||
if(hide && !isAchieved) name = description = '???';
|
||||
achievements.append(
|
||||
`<li class="achvg${grade} ${isAchieved?'':'mask'}"><span class="achievementtitle">${name}</span>${description}</li>`
|
||||
);
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
talent: {
|
||||
page: talentPage,
|
||||
talentList: talentPage.find('#talents'),
|
||||
btnRandom: talentPage.find('#random'),
|
||||
btnNext: talentPage.find('#next'),
|
||||
pressEnter: ()=>{
|
||||
const talentList = this.#pages.talent.talentList;
|
||||
const btnRandom = this.#pages.talent.btnRandom;
|
||||
const btnNext = this.#pages.talent.btnNext;
|
||||
if (talentList.children().length) {
|
||||
btnNext.click();
|
||||
} else {
|
||||
btnRandom.click();
|
||||
}
|
||||
},
|
||||
clear: ()=>{
|
||||
this.#currentPage = 'talent';
|
||||
talentPage.find('ul.selectlist').empty();
|
||||
talentPage.find('#random').show();
|
||||
this.#totalMax = 20;
|
||||
},
|
||||
},
|
||||
property: {
|
||||
page: propertyPage,
|
||||
btnStart: propertyPage.find('#start'),
|
||||
pressEnter: ()=>{
|
||||
this.#pages.property.btnStart.click();
|
||||
},
|
||||
clear: ()=>{
|
||||
this.#currentPage = 'property';
|
||||
freshTotal();
|
||||
propertyPage
|
||||
.find('#talentSelectedView')
|
||||
.empty();
|
||||
},
|
||||
},
|
||||
trajectory: {
|
||||
page: trajectoryPage,
|
||||
lifeTrajectory: trajectoryPage.find('#lifeTrajectory'),
|
||||
pressEnter: ()=>{
|
||||
this.#pages.trajectory.lifeTrajectory.click();
|
||||
},
|
||||
clear: ()=>{
|
||||
this.#currentPage = 'trajectory';
|
||||
trajectoryPage.find('#lifeTrajectory').empty();
|
||||
trajectoryPage.find('#summary').hide();
|
||||
trajectoryPage.find('#auto').show();
|
||||
trajectoryPage.find('#auto2x').show();
|
||||
this.#isEnd = false;
|
||||
},
|
||||
born: contents => {
|
||||
if(contents.length > 0)
|
||||
$('#lifeTrajectory')
|
||||
.append(`<li><span>初始:</span><span>${
|
||||
contents.map(
|
||||
({source, target}) => `天赋【${source.name}】发动:替换为天赋【${target.name}】`
|
||||
).join('<br>')
|
||||
}</span></li>`);
|
||||
|
||||
trajectoryPage.find('#lifeTrajectory').trigger("click");
|
||||
}
|
||||
},
|
||||
summary: {
|
||||
page: summaryPage,
|
||||
clear: ()=>{
|
||||
this.#currentPage = 'summary';
|
||||
const judge = summaryPage.find('#judge');
|
||||
const talents = summaryPage.find('#talents');
|
||||
judge.empty();
|
||||
talents.empty();
|
||||
const lastExtendTalent = this.#life.getLastExtendTalent();
|
||||
Array
|
||||
.from(this.#talentSelected)
|
||||
.sort((
|
||||
{id:a, grade:ag},
|
||||
{id:b, grade:bg},
|
||||
)=>{
|
||||
if(a == lastExtendTalent) return -1;
|
||||
if(b == lastExtendTalent) return 1;
|
||||
return bg - ag;
|
||||
})
|
||||
.forEach((talent, i)=>{
|
||||
const li = createTalent(talent);
|
||||
talents.append(li);
|
||||
li.click(()=>{
|
||||
if(li.hasClass('selected')) {
|
||||
this.#selectedExtendTalent = null;
|
||||
li.removeClass('selected');
|
||||
} else if(this.#selectedExtendTalent != null) {
|
||||
this.hint('只能继承一个天赋');
|
||||
return;
|
||||
} else {
|
||||
this.#selectedExtendTalent = talent.id;
|
||||
li.addClass('selected');
|
||||
}
|
||||
});
|
||||
if(!i) li.click();
|
||||
});
|
||||
|
||||
const summaryData = this.#life.getSummary();
|
||||
const format = (discription, type)=>{
|
||||
const value = summaryData[type];
|
||||
const { judge, grade } = summary(type, value);
|
||||
return `<li class="grade${grade}"><span>${discription}:</span><span>${value} ${judge}</span></li>`;
|
||||
};
|
||||
|
||||
judge.append(`
|
||||
${format('颜值', 'CHR')}
|
||||
${format('智力', 'INT')}
|
||||
${format('体质', 'STR')}
|
||||
${format('家境', 'MNY')}
|
||||
${format('快乐', 'SPR')}
|
||||
${format('享年', 'AGE')}
|
||||
${format('总评', 'SUM')}
|
||||
`);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
$$on('achievement', ({name})=>{
|
||||
this.hint(`解锁成就【${name}】`, 'success');
|
||||
$ui.popup(UI.popups.MESSAGE, {message});
|
||||
})
|
||||
}
|
||||
|
||||
switch(page) {
|
||||
const p = this.#pages[page];
|
||||
if(!p) return;
|
||||
$('#main').detach();
|
||||
p.clear();
|
||||
p.page.appendTo('body');
|
||||
if(typeof p.page.mounted === 'function'){
|
||||
p.page.mounted()
|
||||
}
|
||||
}
|
||||
async start({
|
||||
language = App.languages['zh-cn'],
|
||||
theme = 'default',
|
||||
}) {
|
||||
this.resigterEvent();
|
||||
this.#initLaya();
|
||||
globalThis.$ui = UIManager.getInstance();
|
||||
|
||||
hint(message, type='info') {
|
||||
if(this.#hintTimeout) {
|
||||
clearTimeout(this.#hintTimeout);
|
||||
this.#hintTimeout = null;
|
||||
}
|
||||
hideBanners();
|
||||
requestAnimationFrame(() => {
|
||||
const banner = $(`.banner.${type}`);
|
||||
banner.addClass('visible');
|
||||
banner.find('.banner-message').text(message);
|
||||
if(type != 'error') {
|
||||
this.#hintTimeout = setTimeout(hideBanners, 3000);
|
||||
if(theme=='default') {
|
||||
if(!localStorage.getItem('__')) {
|
||||
localStorage.setItem('__', 1);
|
||||
localStorage.setItem('theme', 'cyber');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setTheme(theme) {
|
||||
const themeLink = $(document).find('#themeLink');
|
||||
|
||||
switch(theme){
|
||||
case 'dark':
|
||||
case 'light':
|
||||
case 'halloween':
|
||||
themeLink.attr('href', `${theme}.css`);
|
||||
break;
|
||||
default:
|
||||
themeLink.attr('href', 'dark.css');
|
||||
theme = localStorage.getItem('theme');
|
||||
}
|
||||
|
||||
$ui.theme = theme;
|
||||
await this.#setLanguage(language);
|
||||
await $ui.setLoading(UI.pages.LOADING);
|
||||
await $ui.switchView(UI.pages.LOADING);
|
||||
await core.initial(
|
||||
dataSet=>Laya.promises.loader.load(`data/${this.#language}/${dataSet}.json`, null, Laya.Loader.JSON),
|
||||
dataSet=>Laya.promises.loader.load(`data/${dataSet}.json`, null, Laya.Loader.JSON),
|
||||
);
|
||||
await $ui.switchView(UI.pages.MAIN);
|
||||
|
||||
}
|
||||
|
||||
get times() {return this.#life?.times || 0;}
|
||||
set times(v) { if(this.#life) this.#life.times = v };
|
||||
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
export function getRate(type, value) {
|
||||
switch(type) {
|
||||
case 'times':
|
||||
if(value >= 100) return {2:6};
|
||||
if(value >= 70) return {2:5};
|
||||
if(value >= 50) return {2:4};
|
||||
if(value >= 30) return {2:3};
|
||||
if(value >= 10) return {2:2};
|
||||
return {2: 1};
|
||||
case 'achievement':
|
||||
if(value >= 100) return {3:6};
|
||||
if(value >= 70) return {3:5};
|
||||
if(value >= 50) return {3:4};
|
||||
if(value >= 30) return {3:3};
|
||||
if(value >= 10) return {3:2};
|
||||
return {3:1};
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function getGrade(type, value) {
|
||||
switch(type) {
|
||||
case 'times':
|
||||
case 'achievement':
|
||||
if(value >= 100) return 3;
|
||||
if(value >= 50) return 2;
|
||||
if(value >= 10) return 1;
|
||||
return 0;
|
||||
case 'talentRate':
|
||||
if(value >= 0.9) return 3;
|
||||
if(value >= 0.6) return 2;
|
||||
if(value >= 0.3) return 1;
|
||||
return 0;
|
||||
case 'eventRate':
|
||||
if(value >= 0.6) return 3;
|
||||
if(value >= 0.4) return 2;
|
||||
if(value >= 0.2) return 1;
|
||||
return 0;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ function extractMaxTriggers(condition) {
|
||||
// Not age related, single trigger.
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const age_list = match_object[1].split(",");
|
||||
return age_list.length;
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
const data = {
|
||||
"CHR": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
],
|
||||
"MNY": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
],
|
||||
"SPR": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不幸", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "幸福", "grade": 1},
|
||||
{"min":9, "judge": "极乐", "grade": 2},
|
||||
{"min":11, "judge": "天命", "grade": 3},
|
||||
],
|
||||
"INT": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
{"min":21, "judge": "识海", "grade": 3},
|
||||
{"min":131, "judge": "元神", "grade": 3},
|
||||
{"min":501, "judge": "仙魂", "grade": 3},
|
||||
],
|
||||
"STR": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":1, "judge": "折磨", "grade": 0},
|
||||
{"min":2, "judge": "不佳", "grade": 0},
|
||||
{"min":4, "judge": "普通", "grade": 0},
|
||||
{"min":7, "judge": "优秀", "grade": 1},
|
||||
{"min":9, "judge": "罕见", "grade": 2},
|
||||
{"min":11, "judge": "逆天", "grade": 3},
|
||||
{"min":21, "judge": "凝气", "grade": 3},
|
||||
{"min":101, "judge": "筑基", "grade": 3},
|
||||
{"min":401, "judge": "金丹", "grade": 3},
|
||||
{"min":1001, "judge": "元婴", "grade": 3},
|
||||
{"min":2001, "judge": "仙体", "grade": 3},
|
||||
],
|
||||
"AGE": [
|
||||
{"judge": "胎死腹中", "grade": 0},
|
||||
{"min":1, "judge": "早夭", "grade": 0},
|
||||
{"min":10, "judge": "少年", "grade": 0},
|
||||
{"min":18, "judge": "盛年", "grade": 0},
|
||||
{"min":40, "judge": "中年", "grade": 0},
|
||||
{"min":60, "judge": "花甲", "grade": 1},
|
||||
{"min":70, "judge": "古稀", "grade": 1},
|
||||
{"min":80, "judge": "杖朝", "grade": 2},
|
||||
{"min":90, "judge": "南山", "grade": 2},
|
||||
{"min":95, "judge": "不老", "grade": 3},
|
||||
{"min":100, "judge": "修仙", "grade": 3},
|
||||
{"min":500, "judge": "仙寿", "grade": 3},
|
||||
],
|
||||
"SUM": [
|
||||
{"judge": "地狱", "grade": 0},
|
||||
{"min":41, "judge": "折磨", "grade": 0},
|
||||
{"min":50, "judge": "不佳", "grade": 0},
|
||||
{"min":60, "judge": "普通", "grade": 0},
|
||||
{"min":80, "judge": "优秀", "grade": 1},
|
||||
{"min":100, "judge": "罕见", "grade": 2},
|
||||
{"min":110, "judge": "逆天", "grade": 3},
|
||||
{"min":120, "judge": "传说", "grade": 3},
|
||||
]
|
||||
}
|
||||
|
||||
function summary(type, value) {
|
||||
let length = data[type].length;
|
||||
while(length--) {
|
||||
const {min, judge, grade} = data[type][length];
|
||||
if(min==void 0 || value >= min) return {judge, grade};
|
||||
}
|
||||
}
|
||||
|
||||
export { summary };
|
||||
@@ -44,4 +44,72 @@ function listRandom(list) {
|
||||
return list[Math.floor(Math.random() * list.length)];
|
||||
}
|
||||
|
||||
export { clone, max, min, sum, average, weightRandom, listRandom };
|
||||
function getListValuesMap(list, fn) {
|
||||
const map = {};
|
||||
list.forEach(key=>map[key] = fn(key));
|
||||
return map;
|
||||
}
|
||||
|
||||
function mapConvert(map, fn) {
|
||||
for(const key in map)
|
||||
map[key] = fn(key, map[key]);
|
||||
}
|
||||
|
||||
function getConvertedMap(map, fn) {
|
||||
const newMap = {};
|
||||
for(const key in map)
|
||||
newMap[key] = fn(key, map[key]);
|
||||
return newMap;
|
||||
}
|
||||
|
||||
function mapSet(target, source) {
|
||||
for(const key in source)
|
||||
target[key] = source[key];
|
||||
}
|
||||
|
||||
function deepMapSet(target, source) {
|
||||
for(const key in source) {
|
||||
let value = source[key];
|
||||
switch(typeof value) {
|
||||
case 'function': value = value();
|
||||
case 'object':
|
||||
if(!Array.isArray(value)) {
|
||||
deepMapSet(target[key], value);
|
||||
break;
|
||||
}
|
||||
default: target[key] = value;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function deepGet(obj, path) {
|
||||
for(const key of path.split('.')) {
|
||||
if(!(key in obj)) return undefined;
|
||||
obj = obj[key];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function format(str, ...args) {
|
||||
const replace = set => (match, key) => {
|
||||
const value = deepGet(set, key);
|
||||
switch(typeof value) {
|
||||
case 'object': return JSON.stringify(value);
|
||||
case 'boolean':
|
||||
case 'number':
|
||||
case 'string': return value;
|
||||
default: return value?.toString?.() || match;
|
||||
}
|
||||
};
|
||||
|
||||
switch(args.length) {
|
||||
case 0: return str;
|
||||
case 1:
|
||||
if (typeof(args[0]) != "object") break;
|
||||
return str.replace(/{(.+?)}/g, replace(args[0]));
|
||||
}
|
||||
return str.replace(/{(\d+)}/g, replace(args));
|
||||
}
|
||||
|
||||
export { clone, max, min, sum, average, weightRandom, listRandom, getListValuesMap, mapConvert, getConvertedMap, mapSet, deepMapSet, format };
|
||||
148
src/i18n/en-us.js
Normal file
148
src/i18n/en-us.js
Normal file
@@ -0,0 +1,148 @@
|
||||
export default ({
|
||||
UI_Next: 'Next',
|
||||
UI_Back: 'Back',
|
||||
UI_Skip: 'Skip',
|
||||
UI_Done: 'Done',
|
||||
UI_Cancel: 'Cancel',
|
||||
UI_Confirm: 'Confirm',
|
||||
UI_Retry: 'Retry',
|
||||
UI_Yes: 'Yes',
|
||||
UI_No: 'No',
|
||||
UI_OK: 'OK',
|
||||
UI_Close: 'Close',
|
||||
UI_Open: 'Open',
|
||||
UI_Search: 'Search',
|
||||
UI_Loading: 'Now Loading',
|
||||
UI_Error: 'Error',
|
||||
|
||||
UI_Colon: ':',
|
||||
UI_Times: 'Times',
|
||||
UI_Count: '',
|
||||
|
||||
UI_Property_Charm: 'CHR',
|
||||
UI_Property_Intelligence: 'INT',
|
||||
UI_Property_Strength: 'STR',
|
||||
UI_Property_Money: 'MNY',
|
||||
UI_Property_Spirit: 'SPR',
|
||||
|
||||
UI_Title_Remake: 'Remake Simulate',
|
||||
UI_Title_Subsequent: 'The rubbish life doesn\'t want to stay for a second',
|
||||
UI_Remake: 'Remake Now',
|
||||
UI_Thanks: 'Thx',
|
||||
UI_Achievement: 'Achv',
|
||||
UI_Cyber_Theme_Art_Design: 'UI Design by 晰晰',
|
||||
|
||||
UI_Title_Talent: 'Talent Draw',
|
||||
UI_Talent_Draw: '!10 Pulls!',
|
||||
UI_Talent_Select_Uncomplete: 'Choose 3 Talents, Please.',
|
||||
|
||||
UI_Title_Property: 'Property Allocate',
|
||||
UI_Left_Property_Point: 'Left Property Point',
|
||||
UI_Selected_Talent: 'Selected Talent',
|
||||
UI_Random_Allocate: 'Random Allocate',
|
||||
UI_Make_New_Life: 'Make New Life',
|
||||
|
||||
UI_Manual: 'Manual',
|
||||
UI_Auto: 'Auto',
|
||||
|
||||
UI_Goto_Summary: 'Goto Summary',
|
||||
UI_Title_Summary: 'Life Summary',
|
||||
UI_Talent_Extend: 'Talent, You can choose one to extend',
|
||||
UI_Remake_Again: 'Remake Again',
|
||||
|
||||
UI_Final_Age: 'Age',
|
||||
UI_Total_Judge: 'Judge',
|
||||
|
||||
UI_Achievement_Count: 'Achievement',
|
||||
UI_Remake_Times: 'Remake Times',
|
||||
UI_Event_Collection_Rate: 'Event Collection',
|
||||
UI_Talent_Collection_Rate: 'Talent Collection',
|
||||
UI_Statistics: 'Statistics',
|
||||
UI_Rank: 'Rank',
|
||||
|
||||
UI_Achievement_Achieve: 'Achievement',
|
||||
|
||||
UI_Judge_Level_0: 'Hell', // 地狱
|
||||
UI_Judge_Level_1: 'Worse', // 折磨
|
||||
UI_Judge_Level_2: 'Bad', // 不佳
|
||||
UI_Judge_Level_3: 'Normal', // 普通
|
||||
UI_Judge_Level_4: 'Good', // 优秀
|
||||
UI_Judge_Level_5: 'Great', // 罕见
|
||||
UI_Judge_Level_6: 'Excellent', // 逆天
|
||||
UI_Judge_Level_7: 'Perfect', // 传说
|
||||
|
||||
UI_Spirit_Judge_Level_0: 'Hell', // 地狱
|
||||
UI_Spirit_Judge_Level_1: 'Tortured', // 折磨
|
||||
UI_Spirit_Judge_Level_2: 'Unlucky', // 不幸
|
||||
UI_Spirit_Judge_Level_3: 'Normal', // 普通
|
||||
UI_Spirit_Judge_Level_4: 'Happy', // 幸福
|
||||
UI_Spirit_Judge_Level_5: 'Blissful ', // 极乐
|
||||
UI_Spirit_Judge_Level_6: 'Paradise', // 天命
|
||||
|
||||
UI_AGE_Judge_Level_0: 'Stillborn', // 胎死腹中
|
||||
UI_AGE_Judge_Level_1: 'Early', // 早夭
|
||||
UI_AGE_Judge_Level_2: 'Young', // 少年
|
||||
UI_AGE_Judge_Level_3: 'Heyday', // 盛年
|
||||
UI_AGE_Judge_Level_4: 'Middle', // 中年
|
||||
UI_AGE_Judge_Level_5: 'Sexagenarian', // 花甲
|
||||
UI_AGE_Judge_Level_6: 'Septuagenarian', // 古稀
|
||||
UI_AGE_Judge_Level_7: 'Octogenarian', // 杖朝
|
||||
UI_AGE_Judge_Level_8: 'Nonagenarian', // 南山
|
||||
UI_AGE_Judge_Level_9: '不老', // 不老
|
||||
UI_AGE_Judge_Level_10: '修仙', // 修仙
|
||||
UI_AGE_Judge_Level_11: '仙寿', // 仙寿
|
||||
|
||||
UI_Intelligence_Judge_Level_7: '识海',
|
||||
UI_Intelligence_Judge_Level_8: '元神',
|
||||
UI_Intelligence_Judge_Level_9: '仙魂',
|
||||
|
||||
UI_Strength_Judge_Level_7: '凝气',
|
||||
UI_Strength_Judge_Level_8: '筑基',
|
||||
UI_Strength_Judge_Level_9: '金丹',
|
||||
UI_Strength_Judge_Level_10: '元婴',
|
||||
UI_Strength_Judge_Level_11: '仙体',
|
||||
|
||||
UI_Remake_Times_Judge_Level_0: 'Purple rate constant',
|
||||
UI_Remake_Times_Judge_Level_1: 'Purple rate double',
|
||||
UI_Remake_Times_Judge_Level_2: 'Purple rate triple',
|
||||
UI_Remake_Times_Judge_Level_3: 'Purple rate Quadruple',
|
||||
UI_Remake_Times_Judge_Level_4: 'Purple rate Quintuple',
|
||||
UI_Remake_Times_Judge_Level_5: 'Purple rate Sextuple',
|
||||
|
||||
UI_Achievement_Count_Judge_Level_0: 'Orange rate constant',
|
||||
UI_Achievement_Count_Judge_Level_1: 'Orange rate double',
|
||||
UI_Achievement_Count_Judge_Level_2: 'Orange rate triple',
|
||||
UI_Achievement_Count_Judge_Level_3: 'Orange rate Quadruple',
|
||||
UI_Achievement_Count_Judge_Level_4: 'Orange rate Quintuple',
|
||||
UI_Achievement_Count_Judge_Level_5: 'Orange rate Sextuple',
|
||||
|
||||
UI_Support_Programmer: 'Programmer',
|
||||
UI_Support_Designer: 'Designer',
|
||||
|
||||
UI_Save: 'Save',
|
||||
UI_Load: 'Load',
|
||||
UI_Read: 'Copy',
|
||||
UI_Write: 'Paste',
|
||||
|
||||
UI_CopySuccess: 'Copy to clipboard success',
|
||||
UI_CopyFaild: 'Copy to clipboard faild',
|
||||
|
||||
UI_PasteSuccessDecodeSuccess: 'Load Success!',
|
||||
UI_PasteSuccessDecodeFaild: 'Paste success, but load faild!',
|
||||
UI_PasteFaildDecodeSuccess: 'Paste faild, use input load success!',
|
||||
UI_PasteFaildDecodeFaild: 'Paste faild, use input load faild!',
|
||||
|
||||
UI_LoadSuccess: 'Load Success!',
|
||||
UI_LoadFaild: 'Load Faild!',
|
||||
|
||||
M_NoRank: 'There is no rank',
|
||||
|
||||
F_RemakeTimes: 'Remake {0} Times',
|
||||
F_AchievementCount: 'Achievement {0}',
|
||||
F_TalentSelection: '{name} ({description})',
|
||||
F_TalentConflict: 'Conflict with talent ({0})',
|
||||
F_TalentSelectLimit: 'Talent select limit {0}',
|
||||
F_TalentSelectNotComplect: 'Please select {0} talent',
|
||||
F_PropertyPointLeft: 'You have left {0} property point',
|
||||
F_TalentReplace: 'Talent replace [{source.name}] -> [{target.name}]',
|
||||
});
|
||||
148
src/i18n/zh-cn.js
Normal file
148
src/i18n/zh-cn.js
Normal file
@@ -0,0 +1,148 @@
|
||||
export default ({
|
||||
UI_Next: '下一步',
|
||||
UI_Back: '返回',
|
||||
UI_Skip: '跳过',
|
||||
UI_Done: '完成',
|
||||
UI_Cancel: '取消',
|
||||
UI_Confirm: '确认',
|
||||
UI_Retry: '重试',
|
||||
UI_Yes: '是',
|
||||
UI_No: '否',
|
||||
UI_OK: '确定',
|
||||
UI_Close: '关闭',
|
||||
UI_Open: '打开',
|
||||
UI_Search: '搜索',
|
||||
UI_Loading: '加载中...',
|
||||
UI_Error: '错误',
|
||||
|
||||
UI_Colon: ':',
|
||||
UI_Times: '次',
|
||||
UI_Count: '个',
|
||||
|
||||
UI_Property_Charm: '颜值',
|
||||
UI_Property_Intelligence: '智力',
|
||||
UI_Property_Strength: '体质',
|
||||
UI_Property_Money: '家境',
|
||||
UI_Property_Spirit: '快乐',
|
||||
|
||||
UI_Title_Remake: '人生重开模拟器',
|
||||
UI_Title_Subsequent: '这垃圾人生一秒也不想待了',
|
||||
UI_Remake: '立即重开',
|
||||
UI_Thanks: '感谢',
|
||||
UI_Achievement: '成就',
|
||||
UI_Cyber_Theme_Art_Design: 'UI 设计 by 晰晰',
|
||||
|
||||
UI_Title_Talent: '天赋抽卡',
|
||||
UI_Talent_Draw: '10连抽!',
|
||||
UI_Talent_Select_Uncomplete: '请选取 3 个天赋',
|
||||
|
||||
UI_Title_Property: '调整初始属性',
|
||||
UI_Left_Property_Point: '剩余属性点',
|
||||
UI_Selected_Talent: '已选天赋',
|
||||
UI_Random_Allocate: '随机分配',
|
||||
UI_Make_New_Life: '开始新人生',
|
||||
|
||||
UI_Manual: '手动',
|
||||
UI_Auto: '自动',
|
||||
|
||||
UI_Goto_Summary: '人生总结',
|
||||
UI_Title_Summary: '人生总结',
|
||||
UI_Talent_Extend: '天赋:你可以选择一个,下辈子还能抽到',
|
||||
UI_Remake_Again: '再次重开',
|
||||
|
||||
UI_Final_Age: '享年',
|
||||
UI_Total_Judge: '总评',
|
||||
|
||||
UI_Achievement_Count: '获得成就',
|
||||
UI_Remake_Times: '重开次数',
|
||||
UI_Event_Collection_Rate: '事件收集率',
|
||||
UI_Talent_Collection_Rate: '天赋收集率',
|
||||
UI_Statistics: '统计',
|
||||
UI_Rank: '排行榜',
|
||||
|
||||
UI_Achievement_Achieve: '获得成就',
|
||||
|
||||
UI_Judge_Level_0: '地狱',
|
||||
UI_Judge_Level_1: '折磨',
|
||||
UI_Judge_Level_2: '不佳',
|
||||
UI_Judge_Level_3: '普通',
|
||||
UI_Judge_Level_4: '优秀',
|
||||
UI_Judge_Level_5: '罕见',
|
||||
UI_Judge_Level_6: '逆天',
|
||||
UI_Judge_Level_7: '传说',
|
||||
|
||||
UI_Spirit_Judge_Level_0: '地狱',
|
||||
UI_Spirit_Judge_Level_1: '折磨',
|
||||
UI_Spirit_Judge_Level_2: '不幸',
|
||||
UI_Spirit_Judge_Level_3: '普通',
|
||||
UI_Spirit_Judge_Level_4: '幸福',
|
||||
UI_Spirit_Judge_Level_5: '极乐',
|
||||
UI_Spirit_Judge_Level_6: '天命',
|
||||
|
||||
UI_AGE_Judge_Level_0: '胎死腹中',
|
||||
UI_AGE_Judge_Level_1: '早夭',
|
||||
UI_AGE_Judge_Level_2: '少年',
|
||||
UI_AGE_Judge_Level_3: '盛年',
|
||||
UI_AGE_Judge_Level_4: '中年',
|
||||
UI_AGE_Judge_Level_5: '花甲',
|
||||
UI_AGE_Judge_Level_6: '古稀',
|
||||
UI_AGE_Judge_Level_7: '杖朝',
|
||||
UI_AGE_Judge_Level_8: '南山',
|
||||
UI_AGE_Judge_Level_9: '不老',
|
||||
UI_AGE_Judge_Level_10: '修仙',
|
||||
UI_AGE_Judge_Level_11: '仙寿',
|
||||
|
||||
UI_Intelligence_Judge_Level_7: '识海',
|
||||
UI_Intelligence_Judge_Level_8: '元神',
|
||||
UI_Intelligence_Judge_Level_9: '仙魂',
|
||||
|
||||
UI_Strength_Judge_Level_7: '凝气',
|
||||
UI_Strength_Judge_Level_8: '筑基',
|
||||
UI_Strength_Judge_Level_9: '金丹',
|
||||
UI_Strength_Judge_Level_10: '元婴',
|
||||
UI_Strength_Judge_Level_11: '仙体',
|
||||
|
||||
UI_Remake_Times_Judge_Level_0: '抽到紫色概率不变',
|
||||
UI_Remake_Times_Judge_Level_1: '抽到紫色概率翻倍',
|
||||
UI_Remake_Times_Judge_Level_2: '抽到紫色概率三倍',
|
||||
UI_Remake_Times_Judge_Level_3: '抽到紫色概率四倍',
|
||||
UI_Remake_Times_Judge_Level_4: '抽到紫色概率五倍',
|
||||
UI_Remake_Times_Judge_Level_5: '抽到紫色概率六倍',
|
||||
|
||||
UI_Achievement_Count_Judge_Level_0: '抽到橙色概率不变',
|
||||
UI_Achievement_Count_Judge_Level_1: '抽到橙色概率翻倍',
|
||||
UI_Achievement_Count_Judge_Level_2: '抽到橙色概率三倍',
|
||||
UI_Achievement_Count_Judge_Level_3: '抽到橙色概率四倍',
|
||||
UI_Achievement_Count_Judge_Level_4: '抽到橙色概率五倍',
|
||||
UI_Achievement_Count_Judge_Level_5: '抽到橙色概率六倍',
|
||||
|
||||
UI_Support_Programmer: '打赏程序(顿顿饭)',
|
||||
UI_Support_Designer: '打赏策划(爱发电)',
|
||||
|
||||
UI_Save: '存档',
|
||||
UI_Load: '读档',
|
||||
UI_Read: '复制',
|
||||
UI_Write: '粘贴',
|
||||
|
||||
UI_LoadSuccess: '读档成功!',
|
||||
UI_LoadFaild: '读档失败!',
|
||||
|
||||
UI_CopySuccess: '成功复制存档到剪贴板',
|
||||
UI_CopyFaild: '复制存档到剪贴板失败,请手动复制存档内容',
|
||||
|
||||
UI_PasteSuccessDecodeSuccess: '读档成功!',
|
||||
UI_PasteSuccessDecodeFaild: '粘贴剪贴板存档内容成功,但剪贴板内容读档失败',
|
||||
UI_PasteFaildDecodeSuccess: '粘贴剪贴板存档内容失败,使用输入的内容读档成功',
|
||||
UI_PasteFaildDecodeFaild: '粘贴剪贴板存档内容失败,使用输入的内容读档失败',
|
||||
|
||||
M_NoRank: '别卷了,没有排行榜',
|
||||
|
||||
F_RemakeTimes: '已重开{0}次',
|
||||
F_AchievementCount: '成就达成{0}个',
|
||||
F_TalentSelection: '{name}({description})',
|
||||
F_TalentConflict: '与已选的「{0}」天赋冲突',
|
||||
F_TalentSelectLimit: '只能选 {0} 个天赋',
|
||||
F_TalentSelectNotComplect: '要选满{0}个天赋',
|
||||
F_PropertyPointLeft: '你还有 {0} 属性点没有分配完',
|
||||
F_TalentReplace: '天赋替换【{source.name}】->【{target.name}】',
|
||||
});
|
||||
187
src/index.js
187
src/index.js
@@ -1,4 +1,5 @@
|
||||
import App from '../src/app.js';
|
||||
import App from './app.js';
|
||||
import Life from './modules/life.js';
|
||||
|
||||
globalThis.$$eventMap = new Map();
|
||||
globalThis.$$event = (tag, data) => {
|
||||
@@ -18,14 +19,182 @@ globalThis.$$off = (tag, fn) => {
|
||||
if(listener) listener.delete(fn);
|
||||
}
|
||||
|
||||
globalThis.json = async fileName => await (await fetch(`../data/${fileName}.json`)).json();
|
||||
globalThis.$$copy = async text => {
|
||||
const result = await navigator.permissions.query({ name: "clipboard-write" })
|
||||
if (result.state == "granted" || result.state == "prompt") {
|
||||
navigator.clipboard.writeText(text)
|
||||
return true;
|
||||
}
|
||||
const input = document.createElement('input');
|
||||
input.setAttribute('style', 'opacity: 0;');
|
||||
document.body.appendChild(input);
|
||||
input.value = text;
|
||||
input.select();
|
||||
const r = document.execCommand("copy");
|
||||
document.body.removeChild(input);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Pssst, I've created a github package - https://github.com/brookesb91/dismissible
|
||||
globalThis.hideBanners = (e) => {
|
||||
document
|
||||
.querySelectorAll(".banner.visible")
|
||||
.forEach((b) => b.classList.remove("visible"));
|
||||
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();
|
||||
const r = document.execCommand("paste");
|
||||
const text = input.value;
|
||||
document.body.removeChild(input);
|
||||
return r?text:r;
|
||||
};
|
||||
|
||||
const app = new App();
|
||||
app.initial();
|
||||
const core = new Life();
|
||||
const game = new App();
|
||||
globalThis.core = core;
|
||||
globalThis.game = game;
|
||||
|
||||
const query = {};
|
||||
location.search.substr(1).split('&').forEach(item => {
|
||||
const parts = item.split('=');
|
||||
query[parts[0]] = parts[1];
|
||||
});
|
||||
|
||||
core.config({
|
||||
defaultPropertyPoints: 20, // default number of points for a property
|
||||
talentSelectLimit: 3, // max number of talents that can be selected
|
||||
propertyAllocateLimit: [0, 10], // scoop of properties that can be allocated,
|
||||
defaultPropertys: { SPR: 5 }, // default properties
|
||||
talentConfig: { // config for talent
|
||||
talentPullCount: 10, // number of talents to pull from the talent pool
|
||||
talentRate: { 1:100, 2:10, 3:1, total: 1000 }, // rate of talent pull
|
||||
additions: {
|
||||
TMS: [
|
||||
[ 10, { 2: 1 }],
|
||||
[ 30, { 2: 2 }],
|
||||
[ 50, { 2: 3 }],
|
||||
[ 70, { 2: 4 }],
|
||||
[100, { 2: 5 }],
|
||||
],
|
||||
CACHV: [
|
||||
[ 10, { 2: 1 }],
|
||||
[ 30, { 2: 2 }],
|
||||
[ 50, { 2: 3 }],
|
||||
[ 70, { 2: 4 }],
|
||||
[100, { 2: 5 }],
|
||||
]
|
||||
},
|
||||
},
|
||||
propertyConfig: { // config for property
|
||||
judge: {
|
||||
// type: [min, grade, judge]
|
||||
RTLT: [
|
||||
[ 0, 0],
|
||||
[ 0.3, 1],
|
||||
[ 0.6, 2],
|
||||
[ 0.9, 3],
|
||||
],
|
||||
REVT: [
|
||||
[ 0, 0],
|
||||
[ 0.2, 1],
|
||||
[ 0.4, 2],
|
||||
[ 0.6, 3],
|
||||
],
|
||||
TMS: [
|
||||
[ 0, 0, 'UI_Remake_Times_Judge_Level_0'],
|
||||
[ 10, 1, 'UI_Remake_Times_Judge_Level_1'],
|
||||
[ 30, 1, 'UI_Remake_Times_Judge_Level_2'],
|
||||
[ 50, 2, 'UI_Remake_Times_Judge_Level_3'],
|
||||
[ 70, 2, 'UI_Remake_Times_Judge_Level_4'],
|
||||
[ 100, 3, 'UI_Remake_Times_Judge_Level_5'],
|
||||
],
|
||||
CACHV: [
|
||||
[ 0, 0, 'UI_Achievement_Count_Judge_Level_0'],
|
||||
[ 10, 1, 'UI_Achievement_Count_Judge_Level_1'],
|
||||
[ 30, 1, 'UI_Achievement_Count_Judge_Level_2'],
|
||||
[ 50, 2, 'UI_Achievement_Count_Judge_Level_3'],
|
||||
[ 70, 2, 'UI_Achievement_Count_Judge_Level_4'],
|
||||
[ 100, 3, 'UI_Achievement_Count_Judge_Level_5'],
|
||||
],
|
||||
HCHR: [
|
||||
[ 0, 0, 'UI_Judge_Level_0'],
|
||||
[ 1, 0, 'UI_Judge_Level_1'],
|
||||
[ 2, 0, 'UI_Judge_Level_2'],
|
||||
[ 4, 0, 'UI_Judge_Level_3'],
|
||||
[ 7, 1, 'UI_Judge_Level_4'],
|
||||
[ 9, 2, 'UI_Judge_Level_5'],
|
||||
[ 11, 3, 'UI_Judge_Level_6'],
|
||||
],
|
||||
HMNY: [
|
||||
[ 0, 0, 'UI_Judge_Level_0'],
|
||||
[ 1, 0, 'UI_Judge_Level_1'],
|
||||
[ 2, 0, 'UI_Judge_Level_2'],
|
||||
[ 4, 0, 'UI_Judge_Level_3'],
|
||||
[ 7, 1, 'UI_Judge_Level_4'],
|
||||
[ 9, 2, 'UI_Judge_Level_5'],
|
||||
[ 11, 3, 'UI_Judge_Level_6'],
|
||||
],
|
||||
HSPR: [
|
||||
[ 0, 0, 'UI_Spirit_Judge_Level_0'],
|
||||
[ 1, 0, 'UI_Spirit_Judge_Level_1'],
|
||||
[ 2, 0, 'UI_Spirit_Judge_Level_2'],
|
||||
[ 4, 0, 'UI_Spirit_Judge_Level_3'],
|
||||
[ 7, 1, 'UI_Spirit_Judge_Level_4'],
|
||||
[ 9, 2, 'UI_Spirit_Judge_Level_5'],
|
||||
[ 11, 3, 'UI_Spirit_Judge_Level_6'],
|
||||
],
|
||||
HINT: [
|
||||
[ 0, 0, 'UI_Judge_Level_0'],
|
||||
[ 1, 0, 'UI_Judge_Level_1'],
|
||||
[ 2, 0, 'UI_Judge_Level_2'],
|
||||
[ 4, 0, 'UI_Judge_Level_3'],
|
||||
[ 7, 1, 'UI_Judge_Level_4'],
|
||||
[ 9, 2, 'UI_Judge_Level_5'],
|
||||
[ 11, 3, 'UI_Judge_Level_6'],
|
||||
[ 21, 3, 'UI_Intelligence_Judge_Level_7'],
|
||||
[ 131, 3, 'UI_Intelligence_Judge_Level_8'],
|
||||
[ 501, 3, 'UI_Intelligence_Judge_Level_9'],
|
||||
],
|
||||
HSTR: [
|
||||
[ 0, 0, 'UI_Judge_Level_0'],
|
||||
[ 1, 0, 'UI_Judge_Level_1'],
|
||||
[ 2, 0, 'UI_Judge_Level_2'],
|
||||
[ 4, 0, 'UI_Judge_Level_3'],
|
||||
[ 7, 1, 'UI_Judge_Level_4'],
|
||||
[ 9, 2, 'UI_Judge_Level_5'],
|
||||
[ 11, 3, 'UI_Judge_Level_6'],
|
||||
[ 21, 3, 'UI_Strength_Judge_Level_7'],
|
||||
[ 101, 3, 'UI_Strength_Judge_Level_8'],
|
||||
[ 401, 3, 'UI_Strength_Judge_Level_9'],
|
||||
[1001, 3, 'UI_Strength_Judge_Level_10'],
|
||||
[2001, 3, 'UI_Strength_Judge_Level_11'],
|
||||
],
|
||||
HAGE: [
|
||||
[ 0, 0, 'UI_AGE_Judge_Level_0'],
|
||||
[ 1, 0, 'UI_AGE_Judge_Level_1'],
|
||||
[ 10, 0, 'UI_AGE_Judge_Level_2'],
|
||||
[ 18, 0, 'UI_AGE_Judge_Level_3'],
|
||||
[ 40, 0, 'UI_AGE_Judge_Level_4'],
|
||||
[ 60, 1, 'UI_AGE_Judge_Level_5'],
|
||||
[ 70, 1, 'UI_AGE_Judge_Level_6'],
|
||||
[ 80, 2, 'UI_AGE_Judge_Level_7'],
|
||||
[ 90, 2, 'UI_AGE_Judge_Level_8'],
|
||||
[ 95, 3, 'UI_AGE_Judge_Level_9'],
|
||||
[ 100, 3, 'UI_AGE_Judge_Level_10'],
|
||||
[ 500, 3, 'UI_AGE_Judge_Level_11'],
|
||||
],
|
||||
SUM: [
|
||||
[ 0, 0, 'UI_Judge_Level_0'],
|
||||
[ 41, 0, 'UI_Judge_Level_1'],
|
||||
[ 50, 0, 'UI_Judge_Level_2'],
|
||||
[ 60, 0, 'UI_Judge_Level_3'],
|
||||
[ 80, 1, 'UI_Judge_Level_4'],
|
||||
[ 100, 2, 'UI_Judge_Level_5'],
|
||||
[ 110, 3, 'UI_Judge_Level_6'],
|
||||
[ 120, 3, 'UI_Judge_Level_7'],
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
game.start(query);
|
||||
|
||||
222
src/life.js
222
src/life.js
@@ -1,222 +0,0 @@
|
||||
import { weightRandom } from './functions/util.js'
|
||||
import Property from './property.js';
|
||||
import Event from './event.js';
|
||||
import Talent from './talent.js';
|
||||
import Achievement from './achievement.js';
|
||||
|
||||
class Life {
|
||||
constructor() {
|
||||
this.#property = new Property();
|
||||
this.#event = new Event();
|
||||
this.#talent = new Talent();
|
||||
this.#achievement = new Achievement();
|
||||
}
|
||||
|
||||
#property;
|
||||
#event;
|
||||
#talent;
|
||||
#achievement;
|
||||
#triggerTalents;
|
||||
|
||||
async initial() {
|
||||
const [age, talents, events, achievements] = await Promise.all([
|
||||
json('age'),
|
||||
json('talents'),
|
||||
json('events'),
|
||||
json('achievement'),
|
||||
])
|
||||
this.#property.initial({age});
|
||||
this.#talent.initial({talents});
|
||||
this.#event.initial({events});
|
||||
this.#achievement.initial({achievements});
|
||||
}
|
||||
|
||||
restart(allocation) {
|
||||
this.#triggerTalents = {};
|
||||
const contents = this.talentReplace(allocation.TLT);
|
||||
this.#property.restart(allocation);
|
||||
this.doTalent()
|
||||
this.#property.restartLastStep();
|
||||
this.#achievement.achieve(
|
||||
this.#achievement.Opportunity.START,
|
||||
this.#property
|
||||
)
|
||||
return contents;
|
||||
}
|
||||
|
||||
getTalentAllocationAddition(talents) {
|
||||
return this.#talent.allocationAddition(talents);
|
||||
}
|
||||
|
||||
getTalentCurrentTriggerCount(talentId) {
|
||||
return this.#triggerTalents[talentId] || 0;
|
||||
}
|
||||
|
||||
next() {
|
||||
const {age, event, talent} = this.#property.ageNext();
|
||||
|
||||
const talentContent = this.doTalent(talent);
|
||||
const eventContent = this.doEvent(this.random(event));
|
||||
|
||||
const isEnd = this.#property.isEnd();
|
||||
|
||||
const content = [talentContent, eventContent].flat();
|
||||
this.#achievement.achieve(
|
||||
this.#achievement.Opportunity.TRAJECTORY,
|
||||
this.#property
|
||||
)
|
||||
return { age, content, isEnd };
|
||||
}
|
||||
|
||||
talentReplace(talents) {
|
||||
const result = this.#talent.replace(talents);
|
||||
const contents = [];
|
||||
for(const id in result) {
|
||||
talents.push(result[id]);
|
||||
const source = this.#talent.get(id);
|
||||
const target = this.#talent.get(result[id]);
|
||||
contents.push({
|
||||
type: 'talentReplace',
|
||||
source, target
|
||||
});
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
doTalent(talents) {
|
||||
if(talents) this.#property.change(this.#property.TYPES.TLT, talents);
|
||||
talents = this.#property.get(this.#property.TYPES.TLT)
|
||||
.filter(talentId => this.getTalentCurrentTriggerCount(talentId) < this.#talent.get(talentId).max_triggers);
|
||||
|
||||
const contents = [];
|
||||
for(const talentId of talents) {
|
||||
const result = this.#talent.do(talentId, this.#property);
|
||||
if(!result) continue;
|
||||
this.#triggerTalents[talentId] = this.getTalentCurrentTriggerCount(talentId) + 1;
|
||||
const { effect, name, description, grade } = result;
|
||||
contents.push({
|
||||
type: this.#property.TYPES.TLT,
|
||||
name,
|
||||
grade,
|
||||
description,
|
||||
})
|
||||
if(!effect) continue;
|
||||
this.#property.effect(effect);
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
doEvent(eventId) {
|
||||
const { effect, next, description, postEvent } = this.#event.do(eventId, this.#property);
|
||||
this.#property.change(this.#property.TYPES.EVT, eventId);
|
||||
this.#property.effect(effect);
|
||||
const content = {
|
||||
type: this.#property.TYPES.EVT,
|
||||
description,
|
||||
postEvent,
|
||||
}
|
||||
if(next) return [content, this.doEvent(next)].flat();
|
||||
return [content];
|
||||
}
|
||||
|
||||
random(events) {
|
||||
return weightRandom(
|
||||
events.filter(
|
||||
([eventId])=>this.#event.check(eventId, this.#property)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
talentRandom() {
|
||||
const times = this.#property.get(this.#property.TYPES.TMS);
|
||||
const achievement = this.#property.get(this.#property.TYPES.CACHV);
|
||||
return this.#talent.talentRandom(this.getLastExtendTalent(), { times, achievement });
|
||||
}
|
||||
|
||||
talentExtend(talentId) {
|
||||
this.#property.set(this.#property.TYPES.EXT, talentId);
|
||||
}
|
||||
|
||||
getLastExtendTalent() {
|
||||
return this.#property.get(this.#property.TYPES.EXT);
|
||||
}
|
||||
|
||||
getSummary() {
|
||||
this.#achievement.achieve(
|
||||
this.#achievement.Opportunity.SUMMARY,
|
||||
this.#property
|
||||
)
|
||||
return {
|
||||
AGE: this.#property.get(this.#property.TYPES.HAGE),
|
||||
CHR: this.#property.get(this.#property.TYPES.HCHR),
|
||||
INT: this.#property.get(this.#property.TYPES.HINT),
|
||||
STR: this.#property.get(this.#property.TYPES.HSTR),
|
||||
MNY: this.#property.get(this.#property.TYPES.HMNY),
|
||||
SPR: this.#property.get(this.#property.TYPES.HSPR),
|
||||
SUM: this.#property.get(this.#property.TYPES.SUM),
|
||||
};
|
||||
}
|
||||
|
||||
getLastRecord() {
|
||||
return this.#property.getLastRecord();
|
||||
}
|
||||
|
||||
exclusive(talents, exclusive) {
|
||||
return this.#talent.exclusive(talents, exclusive);
|
||||
}
|
||||
|
||||
getAchievements() {
|
||||
const ticks = {};
|
||||
this.#property
|
||||
.get(this.#property.TYPES.ACHV)
|
||||
.forEach(([id, tick]) => ticks[id] = tick);
|
||||
return this
|
||||
.#achievement
|
||||
.list(this.#property)
|
||||
.sort((
|
||||
{id: a, grade: ag, hide: ah},
|
||||
{id: b, grade: bg, hide: bh}
|
||||
)=>{
|
||||
a = ticks[a];
|
||||
b = ticks[b];
|
||||
if(a&&b) return b - a;
|
||||
if(!a&&!b) {
|
||||
if(ah&&bh) return bg - ag;
|
||||
if(ah) return 1;
|
||||
if(bh) return -1;
|
||||
return bg - ag;
|
||||
}
|
||||
if(!a) return 1;
|
||||
if(!b) return -1;
|
||||
});
|
||||
}
|
||||
|
||||
getTotal() {
|
||||
const TMS = this.#property.get(this.#property.TYPES.TMS);
|
||||
const CACHV = this.#property.get(this.#property.TYPES.CACHV);
|
||||
const CTLT = this.#property.get(this.#property.TYPES.CTLT);
|
||||
const CEVT = this.#property.get(this.#property.TYPES.CEVT);
|
||||
|
||||
const totalTalent = this.#talent.count();
|
||||
const totalEvent = this.#event.count();
|
||||
|
||||
return {
|
||||
times: TMS,
|
||||
achievement: CACHV,
|
||||
talentRate: CTLT / totalTalent,
|
||||
eventRate: CEVT / totalEvent,
|
||||
}
|
||||
}
|
||||
|
||||
get times() { return this.#property?.get(this.#property.TYPES.TMS) || 0; }
|
||||
set times(v) {
|
||||
this.#property?.set(this.#property.TYPES.TMS, v) || 0;
|
||||
this.#achievement.achieve(
|
||||
this.#achievement.Opportunity.END,
|
||||
this.#property
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Life;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { clone } from './functions/util.js';
|
||||
import { checkCondition } from './functions/condition.js';
|
||||
import { clone } from '../functions/util.js';
|
||||
import { checkCondition } from '../functions/condition.js';
|
||||
|
||||
class Achievement {
|
||||
constructor() {}
|
||||
@@ -16,9 +16,10 @@ class Achievement {
|
||||
|
||||
initial({achievements}) {
|
||||
this.#achievements = achievements;
|
||||
return this.count;
|
||||
}
|
||||
|
||||
count() {
|
||||
get count() {
|
||||
return Object.keys(this.#achievements).length;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { clone } from './functions/util.js';
|
||||
import { checkCondition } from './functions/condition.js';
|
||||
import { clone } from '../functions/util.js';
|
||||
import { checkCondition } from '../functions/condition.js';
|
||||
|
||||
class Event {
|
||||
constructor() {}
|
||||
@@ -17,9 +17,10 @@ class Event {
|
||||
return b;
|
||||
});
|
||||
}
|
||||
return this.count;
|
||||
}
|
||||
|
||||
count() {
|
||||
get count() {
|
||||
return Object.keys(this.#events).length;
|
||||
}
|
||||
|
||||
@@ -43,12 +44,12 @@ class Event {
|
||||
}
|
||||
|
||||
do(eventId, property) {
|
||||
const { effect, branch, event: description, postEvent } = this.get(eventId);
|
||||
const { effect, branch, event: description, postEvent, grade } = this.get(eventId);
|
||||
if(branch)
|
||||
for(const [cond, next] of branch)
|
||||
if(checkCondition(property, cond))
|
||||
return { effect, next, description };
|
||||
return { effect, postEvent, description };
|
||||
return { effect, next, description, grade };
|
||||
return { effect, postEvent, description, grade };
|
||||
}
|
||||
|
||||
}
|
||||
260
src/modules/life.js
Normal file
260
src/modules/life.js
Normal file
@@ -0,0 +1,260 @@
|
||||
import { clone, weightRandom, getListValuesMap, getConvertedMap } from '../functions/util.js'
|
||||
import Property from './property.js';
|
||||
import Event from './event.js';
|
||||
import Talent from './talent.js';
|
||||
import Achievement from './achievement.js';
|
||||
|
||||
class Life {
|
||||
constructor() {
|
||||
this.#property = new Property();
|
||||
this.#event = new Event();
|
||||
this.#talent = new Talent();
|
||||
this.#achievement = new Achievement();
|
||||
}
|
||||
|
||||
#property;
|
||||
#event;
|
||||
#talent;
|
||||
#achievement;
|
||||
#triggerTalents;
|
||||
#defaultPropertyPoints;
|
||||
#talentSelectLimit;
|
||||
#propertyAllocateLimit;
|
||||
#defaultPropertys;
|
||||
#specialThanks;
|
||||
#initialData;
|
||||
|
||||
async initial(i18nLoad, commonLoad) {
|
||||
const [age, talents, events, achievements, specialThanks] = await Promise.all([
|
||||
i18nLoad('age'),
|
||||
i18nLoad('talents'),
|
||||
i18nLoad('events'),
|
||||
i18nLoad('achievement'),
|
||||
commonLoad('specialthanks'),
|
||||
]);
|
||||
this.#specialThanks = specialThanks;
|
||||
|
||||
const total = {
|
||||
[this.PropertyTypes.TACEV]: this.#achievement.initial({achievements}),
|
||||
[this.PropertyTypes.TEVT]: this.#event.initial({events}),
|
||||
[this.PropertyTypes.TTLT]: this.#talent.initial({talents}),
|
||||
};
|
||||
|
||||
this.#property.initial({age, total});
|
||||
}
|
||||
|
||||
config({
|
||||
defaultPropertyPoints = 20, // default number of points for a property
|
||||
talentSelectLimit = 3, // max number of talents that can be selected
|
||||
propertyAllocateLimit = [0, 10], // scoop of properties that can be allocated
|
||||
defaultPropertys = {}, // default propertys
|
||||
talentConfig, // config for talent
|
||||
propertyConfig, // config for property
|
||||
} = {}) {
|
||||
this.#defaultPropertyPoints = defaultPropertyPoints;
|
||||
this.#talentSelectLimit = talentSelectLimit;
|
||||
this.#propertyAllocateLimit = propertyAllocateLimit;
|
||||
this.#defaultPropertys = defaultPropertys;
|
||||
this.#talent.config(talentConfig);
|
||||
this.#property.config(propertyConfig);
|
||||
}
|
||||
|
||||
remake(talents) {
|
||||
this.#initialData = clone(this.#defaultPropertys);
|
||||
this.#initialData.TLT = clone(talents);
|
||||
this.#triggerTalents = {};
|
||||
return this.talentReplace(this.#initialData.TLT);
|
||||
}
|
||||
|
||||
start(allocation) {
|
||||
for(const key in allocation) {
|
||||
this.#initialData[key] = clone(allocation[key]);
|
||||
}
|
||||
this.#property.restart(this.#initialData);
|
||||
this.doTalent()
|
||||
this.#property.restartLastStep();
|
||||
this.#achievement.achieve(
|
||||
this.AchievementOpportunity.START,
|
||||
this.#property
|
||||
);
|
||||
}
|
||||
|
||||
getPropertyPoints() {
|
||||
return this.#defaultPropertyPoints + this.#talent.allocationAddition(this.#initialData.TLT);
|
||||
}
|
||||
|
||||
getTalentCurrentTriggerCount(talentId) {
|
||||
return this.#triggerTalents[talentId] || 0;
|
||||
}
|
||||
|
||||
next() {
|
||||
const {age, event, talent} = this.#property.ageNext();
|
||||
|
||||
const talentContent = this.doTalent(talent);
|
||||
const eventContent = this.doEvent(this.random(event));
|
||||
|
||||
const isEnd = this.#property.isEnd();
|
||||
|
||||
const content = [talentContent, eventContent].flat();
|
||||
this.#achievement.achieve(
|
||||
this.AchievementOpportunity.TRAJECTORY,
|
||||
this.#property
|
||||
)
|
||||
return { age, content, isEnd };
|
||||
}
|
||||
|
||||
talentReplace(talents) {
|
||||
const result = this.#talent.replace(talents);
|
||||
const contents = [];
|
||||
for(const id in result) {
|
||||
talents.push(result[id]);
|
||||
const source = this.#talent.get(id);
|
||||
const target = this.#talent.get(result[id]);
|
||||
contents.push({
|
||||
type: 'talentReplace',
|
||||
source, target
|
||||
});
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
doTalent(talents) {
|
||||
if(talents) this.#property.change(this.PropertyTypes.TLT, talents);
|
||||
talents = this.#property.get(this.PropertyTypes.TLT)
|
||||
.filter(talentId => this.getTalentCurrentTriggerCount(talentId) < this.#talent.get(talentId).max_triggers);
|
||||
|
||||
const contents = [];
|
||||
for(const talentId of talents) {
|
||||
const result = this.#talent.do(talentId, this.#property);
|
||||
if(!result) continue;
|
||||
this.#triggerTalents[talentId] = this.getTalentCurrentTriggerCount(talentId) + 1;
|
||||
const { effect, name, description, grade } = result;
|
||||
contents.push({
|
||||
type: this.PropertyTypes.TLT,
|
||||
name,
|
||||
grade,
|
||||
description,
|
||||
})
|
||||
if(!effect) continue;
|
||||
this.#property.effect(effect);
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
doEvent(eventId) {
|
||||
const { effect, next, description, postEvent, grade } = this.#event.do(eventId, this.#property);
|
||||
this.#property.change(this.PropertyTypes.EVT, eventId);
|
||||
this.#property.effect(effect);
|
||||
const content = {
|
||||
type: this.PropertyTypes.EVT,
|
||||
description,
|
||||
postEvent,
|
||||
grade,
|
||||
}
|
||||
if(next) return [content, this.doEvent(next)].flat();
|
||||
return [content];
|
||||
}
|
||||
|
||||
random(events) {
|
||||
return weightRandom(
|
||||
events.filter(
|
||||
([eventId])=>this.#event.check(eventId, this.#property)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
talentRandom() {
|
||||
return this.#talent.talentRandom(
|
||||
this.lastExtendTalent,
|
||||
this.#getPropertys(
|
||||
this.PropertyTypes.TMS,
|
||||
this.PropertyTypes.CACHV,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
talentExtend(talentId) {
|
||||
this.#property.set(this.PropertyTypes.EXT, talentId);
|
||||
}
|
||||
|
||||
exclusive(talents, exclusive) {
|
||||
return this.#talent.exclusive(talents, exclusive);
|
||||
}
|
||||
|
||||
#getJudges(...types) {
|
||||
return getListValuesMap(types.flat(), key => this.#property.judge(key));
|
||||
}
|
||||
|
||||
#getPropertys(...types) {
|
||||
return getListValuesMap(types.flat(), key => this.#property.get(key));
|
||||
}
|
||||
|
||||
get lastExtendTalent() {
|
||||
return this.#property.get(this.PropertyTypes.EXT);
|
||||
}
|
||||
|
||||
get summary() {
|
||||
this.#achievement.achieve(
|
||||
this.AchievementOpportunity.SUMMARY,
|
||||
this.#property
|
||||
)
|
||||
|
||||
const pt = this.PropertyTypes;
|
||||
|
||||
return this.#getJudges(pt.SUM,
|
||||
pt.HAGE, pt.HCHR, pt.HINT,
|
||||
pt.HSTR, pt.HMNY, pt.HSPR,
|
||||
);
|
||||
}
|
||||
|
||||
get statistics() {
|
||||
const pt = this.PropertyTypes;
|
||||
|
||||
return this.#getJudges( pt.TMS,
|
||||
pt.CACHV, pt.RTLT, pt.REVT,
|
||||
);
|
||||
}
|
||||
get achievements() {
|
||||
const ticks = {};
|
||||
this.#property
|
||||
.get(this.PropertyTypes.ACHV)
|
||||
.forEach(([id, tick]) => ticks[id] = tick);
|
||||
return this
|
||||
.#achievement
|
||||
.list(this.#property)
|
||||
.sort((
|
||||
{id: a, grade: ag, hide: ah},
|
||||
{id: b, grade: bg, hide: bh}
|
||||
)=>{
|
||||
a = ticks[a];
|
||||
b = ticks[b];
|
||||
if(a&&b) return b - a;
|
||||
if(!a&&!b) {
|
||||
if(ah&&bh) return bg - ag;
|
||||
if(ah) return 1;
|
||||
if(bh) return -1;
|
||||
return bg - ag;
|
||||
}
|
||||
if(!a) return 1;
|
||||
if(!b) return -1;
|
||||
});
|
||||
}
|
||||
|
||||
get PropertyTypes() { return this.#property.TYPES; }
|
||||
get AchievementOpportunity() { return this.#achievement.Opportunity; }
|
||||
get talentSelectLimit() { return this.#talentSelectLimit; }
|
||||
get propertyAllocateLimit() { return clone(this.#propertyAllocateLimit); }
|
||||
|
||||
get propertys() { return this.#property.getPropertys(); }
|
||||
get times() { return this.#property.get(this.PropertyTypes.TMS) || 0; }
|
||||
set times(v) {
|
||||
this.#property.set(this.PropertyTypes.TMS, v);
|
||||
this.#achievement.achieve(
|
||||
this.AchievementOpportunity.END,
|
||||
this.#property
|
||||
)
|
||||
}
|
||||
get specialThanks() { return this.#specialThanks; }
|
||||
}
|
||||
|
||||
export default Life;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { max, min, sum, clone, listRandom } from './functions/util.js';
|
||||
import { max, min, sum, clone, listRandom } from '../functions/util.js';
|
||||
|
||||
class Property {
|
||||
constructor() {}
|
||||
@@ -40,10 +40,20 @@ class Property {
|
||||
AEVT: "AEVT", // 触发过的事件 Achieve Event
|
||||
ACHV: "ACHV", // 达成的成就 Achievement
|
||||
|
||||
CTLT: "RTLT", // 天赋选择数 Count Talent
|
||||
CEVT: "REVT", // 事件收集数 Count Event
|
||||
CTLT: "CTLT", // 天赋选择数 Count Talent
|
||||
CEVT: "CEVT", // 事件收集数 Count Event
|
||||
CACHV: "CACHV", // 成就达成数 Count Achievement
|
||||
|
||||
// 总数
|
||||
TTLT: "TTLT", // 总天赋数 Total Talent
|
||||
TEVT: "TEVT", // 总事件数 Total Event
|
||||
TACHV: "TACHV", // 总成就数 Total Achievement
|
||||
|
||||
// 比率
|
||||
REVT: "REVT", // 事件收集率 Rate Event
|
||||
RTLT: "RTLT", // 天赋选择率 Rate Talent
|
||||
RACHV: "RACHV", // 成就达成率 Rate Achievement
|
||||
|
||||
// SPECIAL
|
||||
RDM: 'RDM', // 随机属性 random RDM
|
||||
|
||||
@@ -62,9 +72,10 @@ class Property {
|
||||
|
||||
#ageData;
|
||||
#data = {};
|
||||
#total;
|
||||
#judge;
|
||||
|
||||
initial({age}) {
|
||||
|
||||
initial({age, total}) {
|
||||
this.#ageData = age;
|
||||
for(const a in age) {
|
||||
let { event, talent } = age[a];
|
||||
@@ -84,6 +95,11 @@ class Property {
|
||||
|
||||
age[a] = { event, talent };
|
||||
}
|
||||
this.#total = total;
|
||||
}
|
||||
|
||||
config({judge = {}}) {
|
||||
this.#judge = judge;
|
||||
}
|
||||
|
||||
restart(data) {
|
||||
@@ -188,6 +204,15 @@ class Property {
|
||||
return this.get(
|
||||
this.fallback(prop)
|
||||
).length;
|
||||
case this.TYPES.TTLT:
|
||||
case this.TYPES.TEVT:
|
||||
case this.TYPES.TACHV:
|
||||
return this.#total[prop];
|
||||
case this.TYPES.RTLT:
|
||||
case this.TYPES.REVT:
|
||||
case this.TYPES.RACHV:
|
||||
const fb = this.fallback(prop);
|
||||
return this.get(fb[0]) / this.get(fb[1]);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@@ -209,6 +234,10 @@ class Property {
|
||||
case this.TYPES.CTLT: return this.TYPES.ATLT;
|
||||
case this.TYPES.CEVT: return this.TYPES.AEVT;
|
||||
case this.TYPES.CACHV: return this.TYPES.ACHV;
|
||||
case this.TYPES.LIF: return this.TYPES.LIF;
|
||||
case this.TYPES.RTLT: return [this.TYPES.CTLT, this.TYPES.TTLT];
|
||||
case this.TYPES.REVT: return [this.TYPES.CEVT, this.TYPES.TEVT];
|
||||
case this.TYPES.RACHV: return [this.TYPES.CACHV, this.TYPES.TACHV];
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
@@ -237,7 +266,7 @@ class Property {
|
||||
}
|
||||
}
|
||||
|
||||
getLastRecord() {
|
||||
getPropertys() {
|
||||
return clone({
|
||||
[this.TYPES.AGE]: this.get(this.TYPES.AGE),
|
||||
[this.TYPES.CHR]: this.get(this.TYPES.CHR),
|
||||
@@ -299,6 +328,29 @@ class Property {
|
||||
);
|
||||
}
|
||||
|
||||
judge(prop) {
|
||||
const value = this.get(prop);
|
||||
|
||||
const d = this.#judge[prop];
|
||||
let length = d.length;
|
||||
|
||||
// progress judge
|
||||
// const p = 1/length;
|
||||
// const progress = () => {
|
||||
// const min = d[length][0] || 0;
|
||||
// const max = d[length+1]?.[0] || value;
|
||||
// if(max == min) return 1;
|
||||
// return p * (length + (value - min) / (max - min));
|
||||
// }
|
||||
|
||||
const progress = () => Math.max(Math.min(value, 10), 0) / 10;
|
||||
|
||||
while(length--) {
|
||||
const [min, grade, judge] = d[length];
|
||||
if(!length || min==void 0 || value >= min) return {prop, value, judge, grade, progress: progress()};
|
||||
}
|
||||
}
|
||||
|
||||
isEnd() {
|
||||
return this.get(this.TYPES.LIF) < 1;
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import { clone, weightRandom } from './functions/util.js';
|
||||
import { checkCondition, extractMaxTriggers } from './functions/condition.js';
|
||||
import { getRate } from './functions/addition.js';
|
||||
import { clone, weightRandom } from '../functions/util.js';
|
||||
import { checkCondition, extractMaxTriggers } from '../functions/condition.js';
|
||||
|
||||
class Talent {
|
||||
constructor() {}
|
||||
|
||||
#talents;
|
||||
#talentPullCount;
|
||||
#talentRate;
|
||||
#additions;
|
||||
|
||||
initial({talents}) {
|
||||
this.#talents = talents;
|
||||
@@ -25,12 +27,24 @@ class Talent {
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.count;
|
||||
}
|
||||
|
||||
count() {
|
||||
get count() {
|
||||
return Object.keys(this.#talents).length;
|
||||
}
|
||||
|
||||
config({
|
||||
talentPullCount = 10, // number of talents to pull from the talent pool
|
||||
talentRate = { 1:100, 2:10, 3:1, total: 1000 }, // rate of talent pull
|
||||
additions = {}, // additional additions
|
||||
} = {}) {
|
||||
this.#talentPullCount = talentPullCount;
|
||||
this.#talentRate = talentRate;
|
||||
this.#additions = additions;
|
||||
}
|
||||
|
||||
|
||||
check(talentId, property) {
|
||||
const { condition } = this.get(talentId);
|
||||
return checkCondition(property, condition);
|
||||
@@ -58,30 +72,41 @@ class Talent {
|
||||
return null;
|
||||
}
|
||||
|
||||
talentRandom(include, {times = 0, achievement = 0} = {}) {
|
||||
const rate = { 1:100, 2:10, 3:1, };
|
||||
const rateAddition = { 1:1, 2:1, 3:1, };
|
||||
const timesRate = getRate('times', times);
|
||||
const achievementRate = getRate('achievement', achievement);
|
||||
getAddition(type, value) {
|
||||
if(!this.#additions[type]) return {};
|
||||
for(const [min, addition] of this.#additions[type]) {
|
||||
if(value >= min) return addition;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
for(const grade in timesRate)
|
||||
rateAddition[grade] += timesRate[grade] - 1;
|
||||
getRate(additionValues = {}) {
|
||||
const rate = clone(this.#talentRate);
|
||||
const addition = { 1:1, 2:1, 3:1, };
|
||||
|
||||
for(const grade in achievementRate)
|
||||
rateAddition[grade] += achievementRate[grade] - 1;
|
||||
Object.keys(additionValues).forEach(key => {
|
||||
const addi = this.getAddition(key, additionValues[key])
|
||||
for(const grade in addi)
|
||||
addition[grade] += addi[grade];
|
||||
});
|
||||
|
||||
for(const grade in rateAddition)
|
||||
rate[grade] *= rateAddition[grade];
|
||||
for(const grade in addition)
|
||||
rate[grade] *= addition[grade];
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
talentRandom(include, additionValues) {
|
||||
const rate = this.getRate(additionValues);
|
||||
|
||||
const randomGrade = () => {
|
||||
let randomNumber = Math.floor(Math.random() * 1000);
|
||||
let randomNumber = Math.floor(Math.random() * rate.total);
|
||||
if((randomNumber -= rate[3]) < 0) return 3;
|
||||
if((randomNumber -= rate[2]) < 0) return 2;
|
||||
if((randomNumber -= rate[1]) < 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 1000, 100, 10, 1
|
||||
const talentList = {};
|
||||
for(const talentId in this.#talents) {
|
||||
const { id, grade, name, description } = this.#talents[talentId];
|
||||
@@ -93,7 +118,7 @@ class Talent {
|
||||
else talentList[grade].push({ grade, name, description, id });
|
||||
}
|
||||
|
||||
return new Array(10)
|
||||
return new Array(this.#talentPullCount)
|
||||
.fill(1).map((v, i)=>{
|
||||
if(!i && include) return include;
|
||||
let grade = randomGrade();
|
||||
597
src/ui/layaUI.max.all.js
Normal file
597
src/ui/layaUI.max.all.js
Normal file
File diff suppressed because one or more lines are too long
25
src/ui/pluginFunction.js
Normal file
25
src/ui/pluginFunction.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const plugin =
|
||||
Laya.plugin = {};
|
||||
|
||||
plugin.extractComponents = function(uiView, componentNames) {
|
||||
const components = {};
|
||||
const deepSearch = (uiView, componentNames) => {
|
||||
if(!uiView.child) return;
|
||||
for(let i = uiView.child.length - 1; i >= 0; i--) {
|
||||
const child = uiView.child[i];
|
||||
if(componentNames.includes(child?.props.name)) {
|
||||
components[child.props.name] = child;
|
||||
uiView.child.splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
deepSearch(child, componentNames, components);
|
||||
}
|
||||
};
|
||||
deepSearch(uiView, componentNames);
|
||||
return componentName => {
|
||||
if(components[componentName]) {
|
||||
return Laya.View.createComp(components[componentName]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
34
src/ui/promisesLaya.js
Normal file
34
src/ui/promisesLaya.js
Normal file
@@ -0,0 +1,34 @@
|
||||
Laya.promises = {
|
||||
Tween: {
|
||||
from: async function (target, props, duration, ease, delay, coverBefore) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
Laya.Tween.from(target, props, duration, ease, Laya.Handler.create(null, ()=>resolve(), null, true), delay, coverBefore);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
to: async function (target, props, duration, ease, delay, coverBefore) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
Laya.Tween.to(target, props, duration, ease, Laya.Handler.create(null, ()=>resolve(), null, true), delay, coverBefore);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
loader: {
|
||||
load: async function (url, progress, type) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
Laya.loader.load(url, Laya.Handler.create(null, ret=>resolve(ret), null, true), progress, type);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
537
src/ui/runtime.js
Normal file
537
src/ui/runtime.js
Normal file
@@ -0,0 +1,537 @@
|
||||
const runtime =
|
||||
Laya.runtime = {};
|
||||
|
||||
runtime.ColorFilterItem =
|
||||
class ColorFilterItem extends Laya.Image {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
#hexToRgba = (hex) => {
|
||||
const rgba = [];
|
||||
hex = hex.replace('#', '');
|
||||
hex = hex.match(new RegExp('(.{2})(.{2})(.{2})(.{2})', 'i'));
|
||||
hex.forEach((item, index) => {
|
||||
rgba[index] = parseInt(item, 16);
|
||||
});
|
||||
rgba.shift();
|
||||
return rgba;
|
||||
}
|
||||
|
||||
#rgbaToMatrix = (rgba) => {
|
||||
let matrix = [
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
];
|
||||
matrix[0] = rgba[0] / 255;
|
||||
matrix[6] = rgba[1] / 255;
|
||||
matrix[12] = rgba[2] / 255;
|
||||
matrix[18] = rgba[3] / 255;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
get colorFilter() {
|
||||
return this._colorFilter;
|
||||
}
|
||||
set colorFilter(value) {
|
||||
this._colorFilter = value;
|
||||
if(value) {
|
||||
const rgba = this.#hexToRgba(this.colorFilter);
|
||||
const matrix = this.#rgbaToMatrix(rgba);
|
||||
const colorFilter = new Laya.ColorFilter(matrix);
|
||||
this.filters = [colorFilter];
|
||||
} else {
|
||||
this.filters = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
runtime.UIBase =
|
||||
class UIBase extends Laya.View {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
runtime.ViewBase =
|
||||
class ViewBase extends runtime.UIBase {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
runtime.DialogBase =
|
||||
class DialogBase extends runtime.UIBase {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
runtime.ScaleButton =
|
||||
class ScaleButton extends Laya.Button {
|
||||
constructor() {
|
||||
super();
|
||||
this.on(Laya.Event.MOUSE_DOWN, this, this.onMouse, [Laya.Event.MOUSE_DOWN]);
|
||||
this.on(Laya.Event.MOUSE_OUT, this, this.onMouse, [Laya.Event.MOUSE_OUT]);
|
||||
this.on(Laya.Event.MOUSE_UP, this, this.onMouse, [Laya.Event.MOUSE_UP]);
|
||||
}
|
||||
|
||||
onMouse(type) {
|
||||
Laya.Tween.clearAll(this);
|
||||
switch (type) {
|
||||
case Laya.Event.MOUSE_DOWN:
|
||||
Laya.Tween.to(this, { scaleX: 0.9, scaleY: 0.9 }, 100);
|
||||
break;
|
||||
case Laya.Event.MOUSE_OUT:
|
||||
case Laya.Event.MOUSE_UP:
|
||||
Laya.Tween.to(this, { scaleX: 1, scaleY: 1 }, 100);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runtime.RGBAItem =
|
||||
class RGBAItem {
|
||||
constructor(config={}) {
|
||||
for(const key in config)
|
||||
switch(key) {
|
||||
case 'r':
|
||||
case 'g':
|
||||
case 'b':
|
||||
case 'a':
|
||||
case 'hex':
|
||||
case 'hexa':
|
||||
case 'rgb':
|
||||
case 'rgba':
|
||||
this[key] = config[key];
|
||||
break;
|
||||
case 'on':
|
||||
this.on(config[key]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#r;
|
||||
#g;
|
||||
#b;
|
||||
#a;
|
||||
#on = new Set();
|
||||
|
||||
on(fn) {
|
||||
this.#on.add(fn);
|
||||
}
|
||||
|
||||
off(fn) {
|
||||
this.#on.delete(fn);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.#on.clear();
|
||||
}
|
||||
|
||||
#event() {
|
||||
this.#on.forEach(fn => fn(this));
|
||||
}
|
||||
|
||||
#rgb(v) {
|
||||
return [
|
||||
this.#dec(v.slice(1, 3)),
|
||||
this.#dec(v.slice(3, 5)),
|
||||
this.#dec(v.slice(5, 7)),
|
||||
];
|
||||
}
|
||||
|
||||
#rgba(v) {
|
||||
return [
|
||||
this.#dec(v.slice(1, 3)),
|
||||
this.#dec(v.slice(3, 5)),
|
||||
this.#dec(v.slice(5, 7)),
|
||||
this.#dec(v.slice(7, 9)),
|
||||
];
|
||||
}
|
||||
|
||||
#hex(v) {
|
||||
v = parseInt(v).toString(16);
|
||||
return v.length == 1 ? '0' + v : v;
|
||||
}
|
||||
|
||||
#dec(v) {
|
||||
return parseInt(v, 16);
|
||||
}
|
||||
|
||||
get hex() {
|
||||
return `#${
|
||||
this.#hex(this.r)
|
||||
}${
|
||||
this.#hex(this.g)
|
||||
}${
|
||||
this.#hex(this.b)
|
||||
}`;
|
||||
}
|
||||
set hex(v) {
|
||||
[this.#r, this.#g, this.#b] = this.#rgb(v);
|
||||
this.#event();
|
||||
}
|
||||
|
||||
get hexa() {
|
||||
return `#${
|
||||
this.#hex(this.r)
|
||||
}${
|
||||
this.#hex(this.g)
|
||||
}${
|
||||
this.#hex(this.b)
|
||||
}${
|
||||
this.#hex(this.a)
|
||||
}`;
|
||||
}
|
||||
set hexa(v) {
|
||||
[this.#r, this.#g, this.#b] = this.#rgba(v);
|
||||
this.#event();
|
||||
}
|
||||
|
||||
get rgb() {
|
||||
return [this.r, this.g, this.b];
|
||||
}
|
||||
set rgb(v) {
|
||||
[this.#r, this.#g, this.#b] = v;
|
||||
this.#event();
|
||||
}
|
||||
|
||||
get rgba() {
|
||||
return [this.r, this.g, this.b, this.a];
|
||||
}
|
||||
set rgba(v) {
|
||||
[this.#r, this.#g, this.#b, this.#a] = v;
|
||||
this.#event();
|
||||
}
|
||||
|
||||
|
||||
get r() {
|
||||
return this.#r||0;
|
||||
}
|
||||
set r(value) {
|
||||
this.#r = value;
|
||||
this.#event();
|
||||
}
|
||||
get g() {
|
||||
return this.#g||0;
|
||||
}
|
||||
set g(value) {
|
||||
this.#g = value;
|
||||
this.#event();
|
||||
}
|
||||
get b() {
|
||||
return this.#b||0;
|
||||
}
|
||||
set b(value) {
|
||||
this.#b = value;
|
||||
this.#event();
|
||||
}
|
||||
get a() {
|
||||
return this.#a||0;
|
||||
}
|
||||
set a(value) {
|
||||
this.#a = value;
|
||||
this.#event();
|
||||
}
|
||||
|
||||
cRgb(hex) {
|
||||
const [r, g, b] = this.#rgb(hex);
|
||||
return {r, g, b};
|
||||
}
|
||||
|
||||
cRgba(hexa) {
|
||||
const [r, g, b, a] = this.#rgba(hexa);
|
||||
return {r, g, b, a};
|
||||
}
|
||||
|
||||
distance(left, right) {
|
||||
const [lr, lg, lb] = this.#rgb(left);
|
||||
const [rr, rg, rb] = this.#rgb(right);
|
||||
const {r, g, b} = this;
|
||||
|
||||
const ddr = Math.abs(r - lr);
|
||||
const ddg = Math.abs(g - lg);
|
||||
const ddb = Math.abs(b - lb);
|
||||
|
||||
const result = (d, a, b) => ((d / Math.abs(b - a)) || 0);
|
||||
|
||||
switch(Math.max(ddr, ddg, ddb)) {
|
||||
case ddr: return result(ddr, lr, rr);
|
||||
case ddg: return result(ddg, lg, rg);
|
||||
case ddb: return result(ddb, lb, rb);
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
runtime.ColorfulBox =
|
||||
class ColorfulBox extends Laya.Box {
|
||||
constructor() {
|
||||
super();
|
||||
this.on(Laya.Event.MOUSE_OVER, this, this.onMouse, [Laya.Event.MOUSE_DOWN]);
|
||||
// this.on(Laya.Event.MOUSE_DOWN, this, this.onMouse, [Laya.Event.MOUSE_DOWN]);
|
||||
this.on(Laya.Event.MOUSE_OUT, this, this.onMouse, [Laya.Event.MOUSE_OUT]);
|
||||
// this.on(Laya.Event.MOUSE_UP, this, this.onMouse, [Laya.Event.MOUSE_UP]);
|
||||
this.#draw();
|
||||
}
|
||||
|
||||
#defaultColor = '#ffffff';
|
||||
#hoverColor = '#ffffff';
|
||||
#defaultStroke = '#ffffff';
|
||||
#hoverStroke = '#ffffff';
|
||||
#defaultLabel = '#000000';
|
||||
#hoverLabel = '#000000';
|
||||
#color = new runtime.RGBAItem({hex: this.#defaultColor, on: ()=>this.#draw()});
|
||||
#stroke = new runtime.RGBAItem({hex: this.#defaultStroke, on: ()=>this.#draw()});
|
||||
#label = new runtime.RGBAItem({hex: this.#defaultLabel, on: ({hex})=>{
|
||||
const label = this.getChildByName('label');
|
||||
if (!label) return;
|
||||
label.color = hex;
|
||||
}});
|
||||
#lineWidth = 0;
|
||||
#radius = 0;
|
||||
#animationTime = 200;
|
||||
#state = 1;
|
||||
|
||||
onMouse(type) {
|
||||
const label = this.getChildByName('label');
|
||||
const tween = (colorItem, target, last) => {
|
||||
Laya.Tween.clearAll(colorItem);
|
||||
const distance = colorItem.distance(target, last);
|
||||
if(!isFinite(distance)) {
|
||||
colorItem.hex = target;
|
||||
return;
|
||||
}
|
||||
Laya.Tween.to(colorItem, colorItem.cRgb(target), colorItem.distance(target, last) * this.#animationTime);
|
||||
}
|
||||
switch (type) {
|
||||
case Laya.Event.MOUSE_OVER:
|
||||
case Laya.Event.MOUSE_DOWN:
|
||||
if(this.#state == 2) return;
|
||||
this.#state = 2;
|
||||
tween(this.#color, this.#hoverColor, this.#defaultColor);
|
||||
tween(this.#stroke, this.#hoverStroke, this.#defaultStroke);
|
||||
if(label) tween(this.#label, this.#hoverLabel, this.#defaultLabel);
|
||||
break;
|
||||
case Laya.Event.MOUSE_OUT:
|
||||
case Laya.Event.MOUSE_UP:
|
||||
if(this.#state == 1) return;
|
||||
this.#state = 1;
|
||||
tween(this.#color, this.#defaultColor, this.#hoverColor);
|
||||
tween(this.#stroke, this.#defaultStroke, this.#hoverStroke);
|
||||
if(label) tween(this.#label, this.#defaultLabel, this.#hoverLabel);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#draw() {
|
||||
this.graphics.clear();
|
||||
const w = this.width;
|
||||
const h = this.height;
|
||||
const r = Math.min(this.#radius, w / 2, h / 2);
|
||||
const fillStyle = this.#color.hex;
|
||||
const strokeStyle = this.#stroke.hex;
|
||||
const lineWidth = this.lineWidth;
|
||||
|
||||
if(r <= 0) {
|
||||
this.graphics.drawRect(0, 0, w, h, fillStyle, strokeStyle, lineWidth);
|
||||
return;
|
||||
}
|
||||
|
||||
const a = w + lineWidth;
|
||||
const b = h + lineWidth;
|
||||
const c = r + lineWidth;
|
||||
const d = a - r;
|
||||
const e = b - r;
|
||||
const f = -lineWidth;
|
||||
|
||||
this.graphics.drawPath(0, 0, [
|
||||
["moveTo", c, f],
|
||||
["arcTo", a, f, a, c, c],
|
||||
["arcTo", a, b, d, b, c],
|
||||
["arcTo", f, b, f, e, c],
|
||||
["arcTo", f, f, c, f, c],
|
||||
["closePath"],
|
||||
], { fillStyle: strokeStyle });
|
||||
|
||||
const x = w - r;
|
||||
const y = h - r;
|
||||
this.graphics.drawPath(0, 0, [
|
||||
["moveTo", r, 0],
|
||||
["arcTo", w, 0, w, r, r],
|
||||
["arcTo", w, h, x, h, r],
|
||||
["arcTo", 0, h, 0, y, r],
|
||||
["arcTo", 0, 0, r, 0, r],
|
||||
["closePath"],
|
||||
], { fillStyle });
|
||||
}
|
||||
|
||||
get width() {
|
||||
return super.width;
|
||||
}
|
||||
set width(value) {
|
||||
super.width = value;
|
||||
this.#draw();
|
||||
}
|
||||
get height() {
|
||||
return super.height;
|
||||
}
|
||||
set height(value) {
|
||||
super.height = value;
|
||||
this.#draw();
|
||||
}
|
||||
|
||||
get defaultColor() {
|
||||
return this.#defaultColor;
|
||||
}
|
||||
set defaultColor(value) {
|
||||
this.#defaultColor = value;
|
||||
Laya.Tween.clearAll(this.#color);
|
||||
Laya.Tween.clearAll(this.#stroke);
|
||||
Laya.Tween.clearAll(this.#label);
|
||||
this.#color.hex = value;
|
||||
}
|
||||
|
||||
get hoverColor() {
|
||||
return this.#hoverColor;
|
||||
}
|
||||
set hoverColor(value) {
|
||||
this.#hoverColor = value;
|
||||
}
|
||||
|
||||
get defaultStroke() {
|
||||
return this.#defaultStroke;
|
||||
}
|
||||
set defaultStroke(value) {
|
||||
this.#defaultStroke = value;
|
||||
Laya.Tween.clearAll(this.#color);
|
||||
Laya.Tween.clearAll(this.#stroke);
|
||||
Laya.Tween.clearAll(this.#label);
|
||||
this.#stroke.hex = value;
|
||||
}
|
||||
|
||||
get hoverStroke() {
|
||||
return this.#hoverStroke;
|
||||
}
|
||||
set hoverStroke(value) {
|
||||
this.#hoverStroke = value;
|
||||
}
|
||||
|
||||
get defaultLabel() {
|
||||
return this.#defaultLabel;
|
||||
}
|
||||
set defaultLabel(value) {
|
||||
this.#defaultLabel = value;
|
||||
const label = this.getChildByName('label');
|
||||
if (!label) return;
|
||||
Laya.Tween.clearAll(this.#color);
|
||||
Laya.Tween.clearAll(this.#stroke);
|
||||
Laya.Tween.clearAll(this.#label);
|
||||
label.color = value;
|
||||
}
|
||||
|
||||
get hoverLabel() {
|
||||
return this.#hoverLabel;
|
||||
}
|
||||
set hoverLabel(value) {
|
||||
this.#hoverLabel = value;
|
||||
}
|
||||
|
||||
get animationTime() {
|
||||
return this.#animationTime;
|
||||
}
|
||||
set animationTime(value) {
|
||||
this.#animationTime = value;
|
||||
}
|
||||
|
||||
get radius() {
|
||||
return this.#radius||0;
|
||||
}
|
||||
set radius(value) {
|
||||
this.#radius = value;
|
||||
this.#draw();
|
||||
}
|
||||
|
||||
get lineWidth() {
|
||||
return this.#lineWidth||0;
|
||||
}
|
||||
set lineWidth(value) {
|
||||
this.#lineWidth = value;
|
||||
this.#draw();
|
||||
}
|
||||
get label() {
|
||||
return this.getChildByName('label')?.text;
|
||||
}
|
||||
set label(value) {
|
||||
const label = this.getChildByName('label');
|
||||
if (!label) return;
|
||||
label.text = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
runtime.BlankBox =
|
||||
class BlankBox extends Laya.Box {
|
||||
constructor() {
|
||||
super();
|
||||
this.mask = new Laya.Sprite();
|
||||
this.#blank = new Laya.Sprite();
|
||||
this.addChild(this.#blank);
|
||||
}
|
||||
|
||||
#blank;
|
||||
#timeLine;
|
||||
#pause = true;
|
||||
|
||||
#draw() {
|
||||
this.mask.graphics.clear();
|
||||
this.#blank.graphics.clear();
|
||||
this.mask.graphics.drawRect(0, 0, this.width, this.height, '#000000');
|
||||
this.#blank.graphics.drawRect(0, 0, this.width, this.height, '#000000');
|
||||
if(this.#timeLine) this.#timeLine.destroy();
|
||||
this.#timeLine = new Laya.TimeLine()
|
||||
.to(this.#blank, { x: this.width }, 2000)
|
||||
.to(this.#blank, { x: -this.width }, 0);
|
||||
this.#timeLine.play(0, true);
|
||||
if(this.#pause) this.#timeLine.pause();
|
||||
}
|
||||
get pause() {
|
||||
return this.#pause;
|
||||
}
|
||||
set pause(value) {
|
||||
if(this.#pause == value) return;
|
||||
this.#pause = value;
|
||||
this.#blank.visible = !value;
|
||||
if(value) this.#timeLine.pause();
|
||||
else this.#timeLine.resume();
|
||||
}
|
||||
|
||||
destroy(destroyChild) {
|
||||
this.#timeLine.destroy(true);
|
||||
super.destroy(destroyChild);
|
||||
}
|
||||
|
||||
get width() {
|
||||
return super.width;
|
||||
}
|
||||
set width(value) {
|
||||
super.width = value;
|
||||
this.#blank.x = -this.width;
|
||||
this.#draw();
|
||||
}
|
||||
|
||||
get height() {
|
||||
return super.height;
|
||||
}
|
||||
set height(value) {
|
||||
super.height = value;
|
||||
this.#draw();
|
||||
}
|
||||
}
|
||||
102
src/ui/themes/cyber/achievement.js
Normal file
102
src/ui/themes/cyber/achievement.js
Normal file
@@ -0,0 +1,102 @@
|
||||
export default class CyberAchievement extends ui.view.CyberTheme.CyberAchievementUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnBack.on(Laya.Event.CLICK, this, () => $ui.switchView(UI.pages.MAIN));
|
||||
const min = Math.min(this.btnAchievement.fontSize, this.btnStatistics.fontSize);
|
||||
const max = Math.max(this.btnAchievement.fontSize, this.btnStatistics.fontSize);
|
||||
this.#state = {min, max};
|
||||
this.btnStatistics.on(Laya.Event.CLICK, this, ()=>this.switch('statistics'));
|
||||
this.btnAchievement.on(Laya.Event.CLICK, this, ()=>this.switch('achievement'));
|
||||
this.btnRank.on(Laya.Event.CLICK, this, $$event, ['message', ['M_NoRank']]);
|
||||
|
||||
this.listAchievements.renderHandler = new Laya.Handler(this, this.onRenderAchievement);
|
||||
this.listAchievements.scrollBar.elasticDistance = 150;
|
||||
this.on(Laya.Event.RESIZE, this, () => {
|
||||
this.boxPage.width = 2 * this.width;
|
||||
this.boxA.width = this.boxB.width = this.width;
|
||||
if(this.boxPage.x < 0) {
|
||||
this.boxPage.x = - this.width;
|
||||
}
|
||||
|
||||
const renderWidth = this.listAchievements?._itemRender?.props?.width;
|
||||
if(renderWidth) {
|
||||
const col = Math.max(Math.floor((this.width - 65) / renderWidth), 1);
|
||||
this.listAchievements.width = col * renderWidth + (col - 1) * (this.listAchievements.spaceY || 0) + 30;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#state;
|
||||
#tweens;
|
||||
|
||||
init() {
|
||||
this.switch('statistics', 0);
|
||||
|
||||
const {statistics, achievements, PropertyTypes: pt} = core;
|
||||
|
||||
this.listAchievements.array = achievements;
|
||||
|
||||
this.labRemakeTimes.text = statistics[pt.TMS].value;
|
||||
this.labRemakeTimesJudge.text = statistics[pt.TMS].judge;
|
||||
this.labAchievementCountJudge.color = $ui.common.grade[statistics[pt.TMS].grade];
|
||||
|
||||
this.labAchievementCount.text = statistics[pt.CACHV].value;
|
||||
this.labAchievementCountJudge.text = statistics[pt.CACHV].judge;
|
||||
this.labAchievementCountJudge.color = $ui.common.grade[statistics[pt.CACHV].grade];
|
||||
|
||||
this.labEventRate.text = parseInt(statistics[pt.REVT].value*100)+'%';
|
||||
this.prgEventRate.value = statistics[pt.REVT].value;
|
||||
|
||||
this.labTalentRate.text = parseInt(statistics[pt.RTLT].value*100)+'%';
|
||||
this.prgTalentRate.value = statistics[pt.RTLT].value;
|
||||
}
|
||||
|
||||
switch(page, time=300) {
|
||||
if(this.#tweens) {
|
||||
this.#tweens.forEach(tween => Laya.Tween.clear(tween));
|
||||
}
|
||||
this.#tweens = [];
|
||||
|
||||
switch (page) {
|
||||
case 'statistics':
|
||||
time = - this.boxPage.x / this.width * time;
|
||||
this.#tweens.push(
|
||||
Laya.Tween.to(this.boxPage, {x: 0}, time, Laya.Ease.backOut, Laya.Handler.create(this, () => this.#tweens = null)),
|
||||
Laya.Tween.to(this.btnStatistics, {fontSize: this.#state.max, anchorX: 0.5, anchorY: 1}, time, Laya.Ease.backOut),
|
||||
Laya.Tween.to(this.btnAchievement, {fontSize: this.#state.min, anchorX: 0.5, anchorY: 1}, time, Laya.Ease.backOut),
|
||||
);
|
||||
break;
|
||||
case 'achievement':
|
||||
time = (this.width + this.boxPage.x) / this.width * time;
|
||||
this.#tweens.push(
|
||||
Laya.Tween.to(this.boxPage, {x: - this.width}, time, Laya.Ease.backOut, Laya.Handler.create(this, () => this.#tweens = null)),
|
||||
Laya.Tween.to(this.btnStatistics, {fontSize: this.#state.min, anchorX: 0.5, anchorY: 1}, time, Laya.Ease.backOut),
|
||||
Laya.Tween.to(this.btnAchievement, {fontSize: this.#state.max, anchorX: 0.5, anchorY: 1}, time, Laya.Ease.backOut),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onRenderAchievement(box, index) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
const name = box.getChildByName('name');
|
||||
const description = box.getChildByName('description');
|
||||
const completed = box.getChildByName('completed');
|
||||
const uncomplete = box.getChildByName('uncomplete');
|
||||
|
||||
if(dataSource.isAchieved) {
|
||||
name.text = dataSource.name;
|
||||
description.text = dataSource.description;
|
||||
completed.visible = true;
|
||||
uncomplete.visible = false;
|
||||
} else {
|
||||
name.text = dataSource.hide? '???': dataSource.name;
|
||||
description.text = dataSource.hide? '???': dataSource.description;
|
||||
completed.visible = false;
|
||||
uncomplete.visible = true;
|
||||
}
|
||||
|
||||
box.colorFilter = $ui.gradeFilter(dataSource.grade);
|
||||
}
|
||||
}
|
||||
37
src/ui/themes/cyber/main.js
Normal file
37
src/ui/themes/cyber/main.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export default class CyberMain extends ui.view.CyberTheme.CyberMainUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnRemake.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.TALENT));
|
||||
this.btnAchievement.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.ACHIEVEMENT));
|
||||
this.btnThanks.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.THANKS));
|
||||
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,
|
||||
this.height / this.imgBg.height
|
||||
);
|
||||
this.imgBg.scale(scale, scale);
|
||||
});
|
||||
}
|
||||
|
||||
static load() {
|
||||
return [
|
||||
"fonts/方正像素12.ttf",
|
||||
"images/atlas/images/accessories.atlas",
|
||||
"images/atlas/images/border.atlas",
|
||||
"images/atlas/images/button.atlas",
|
||||
"images/atlas/images/icons.atlas",
|
||||
"images/atlas/images/progress.atlas",
|
||||
"images/atlas/images/slider.atlas",
|
||||
]
|
||||
}
|
||||
|
||||
init() {
|
||||
this.btnDiscord.visible =
|
||||
this.btnAchievement.visible =
|
||||
this.btnThanks.visible = !!core.times;
|
||||
}
|
||||
}
|
||||
20
src/ui/themes/cyber/popup/achievementPopup.js
Normal file
20
src/ui/themes/cyber/popup/achievementPopup.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export default class CyberAchievementPopup extends ui.view.CyberTheme.CyberAchievementPopupUI {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
async popup({achievement}, parent) {
|
||||
Laya.Tween.clearAll(this);
|
||||
Laya.Tween.clearAll(this.boxBg);
|
||||
this.alpha = 0.8;
|
||||
this.labName.text = achievement.name;
|
||||
this.labName.color = $ui.common.grade[achievement.grade];
|
||||
this.x = - this.width;
|
||||
this.boxBg.x = this.boxBg.width;
|
||||
await Promise.all([
|
||||
Laya.promises.Tween.to(this, {x: 0}, 300, Laya.Ease.strongOut),
|
||||
Laya.promises.Tween.to(this.boxBg, {x: 0}, 300, Laya.Ease.strongOut, 50),
|
||||
])
|
||||
await Laya.promises.Tween.to(this, {alpha: 0}, 3000, Laya.Ease.strongIn);
|
||||
}
|
||||
}
|
||||
245
src/ui/themes/cyber/property.js
Normal file
245
src/ui/themes/cyber/property.js
Normal file
@@ -0,0 +1,245 @@
|
||||
export default class CyberProperty extends ui.view.CyberTheme.CyberPropertyUI {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
const types =
|
||||
this.#types = core.PropertyTypes;
|
||||
|
||||
this.btnCharmIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.CHR, 1]);
|
||||
this.btnCharmReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.CHR, -1]);
|
||||
|
||||
this.btnIntelligenceIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.INT, 1]);
|
||||
this.btnIntelligenceReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.INT, -1]);
|
||||
|
||||
this.btnStrengthIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.STR, 1]);
|
||||
this.btnStrengthReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.STR, -1]);
|
||||
|
||||
this.btnMoneyIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.MNY, 1]);
|
||||
this.btnMoneyReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.MNY, -1]);
|
||||
|
||||
this.inputCharm.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.CHR]);
|
||||
this.inputIntelligence.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.INT]);
|
||||
this.inputStrength.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.STR]);
|
||||
this.inputMoney.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.MNY]);
|
||||
|
||||
const selectAll = ({currentTarget: item}) => { item.text=''; };
|
||||
this.inputCharm.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
this.inputIntelligence.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
this.inputStrength.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
this.inputMoney.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
|
||||
this.btnRandomAllocate.on(Laya.Event.CLICK, this, this.random);
|
||||
this.btnNext.on(Laya.Event.CLICK, this, this.next);
|
||||
|
||||
this.listSelectedTalents.renderHandler = Laya.Handler.create(this, this.renderTalent, null, false);
|
||||
}
|
||||
|
||||
#types;
|
||||
#propertyPoints;
|
||||
#propertyAllocate;
|
||||
#propertyAllocateLimit;
|
||||
|
||||
init({talents}) {
|
||||
this.listSelectedTalents.array = talents;
|
||||
const replace = core.remake(talents.map(talent => talent.id));
|
||||
if(replace.length > 0) {
|
||||
$$event('message', [replace.map(v => ['F_TalentReplace', v])]);
|
||||
}
|
||||
this.#propertyPoints = core.getPropertyPoints();
|
||||
this.#propertyAllocateLimit = core.propertyAllocateLimit;
|
||||
this.labLeftPropertyPoint.text = this.#propertyPoints;
|
||||
this.#propertyAllocate = {
|
||||
[this.#types.CHR]: 0,
|
||||
[this.#types.INT]: 0,
|
||||
[this.#types.STR]: 0,
|
||||
[this.#types.MNY]: 0,
|
||||
}
|
||||
this.updateAllocate();
|
||||
}
|
||||
|
||||
next() {
|
||||
const left = this.#propertyPoints - this.total;
|
||||
if (left > 0) {
|
||||
return $$event('message', ['F_PropertyPointLeft', left]);
|
||||
}
|
||||
$ui.switchView(
|
||||
UI.pages.TRAJECTORY,
|
||||
{
|
||||
propertyAllocate: this.#propertyAllocate,
|
||||
talents: this.listSelectedTalents.array,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
get total() {
|
||||
return this.#propertyAllocate[this.#types.CHR]
|
||||
+ this.#propertyAllocate[this.#types.INT]
|
||||
+ this.#propertyAllocate[this.#types.STR]
|
||||
+ this.#propertyAllocate[this.#types.MNY];
|
||||
}
|
||||
|
||||
updateAllocate() {
|
||||
const charm = this.#propertyAllocate[this.#types.CHR];
|
||||
const intelligence = this.#propertyAllocate[this.#types.INT];
|
||||
const strength = this.#propertyAllocate[this.#types.STR];
|
||||
const money = this.#propertyAllocate[this.#types.MNY];
|
||||
|
||||
this.inputCharm.text = ''+charm;
|
||||
this.inputIntelligence.text = ''+intelligence;
|
||||
this.inputStrength.text = ''+strength;
|
||||
this.inputMoney.text = ''+money;
|
||||
|
||||
this.labLeftPropertyPoint.text = this.#propertyPoints - this.total;
|
||||
|
||||
this.btnCharmIncrease.disabled = this.btnCharmIncrease.gray = false;
|
||||
this.btnCharmReduce.disabled = this.btnCharmReduce.gray = false;
|
||||
this.btnIntelligenceIncrease.disabled = this.btnIntelligenceIncrease.gray = false;
|
||||
this.btnIntelligenceReduce.disabled = this.btnIntelligenceReduce.gray = false;
|
||||
this.btnStrengthIncrease.disabled = this.btnStrengthIncrease.gray = false;
|
||||
this.btnStrengthReduce.disabled = this.btnStrengthReduce.gray = false;
|
||||
this.btnMoneyIncrease.disabled = this.btnMoneyIncrease.gray = false;
|
||||
this.btnMoneyReduce.disabled = this.btnMoneyReduce.gray = false;
|
||||
|
||||
if (this.total >= this.#propertyPoints) {
|
||||
this.btnCharmIncrease.disabled = this.btnCharmIncrease.gray = true;
|
||||
this.btnIntelligenceIncrease.disabled = this.btnIntelligenceIncrease.gray = true;
|
||||
this.btnStrengthIncrease.disabled = this.btnStrengthIncrease.gray = true;
|
||||
this.btnMoneyIncrease.disabled = this.btnMoneyIncrease.gray = true;
|
||||
} else if (this.total <= 0) {
|
||||
this.btnCharmReduce.disabled = this.btnCharmReduce.gray = true;
|
||||
this.btnIntelligenceReduce.disabled = this.btnIntelligenceReduce.gray = true;
|
||||
this.btnStrengthReduce.disabled = this.btnStrengthReduce.gray = true;
|
||||
this.btnMoneyReduce.disabled = this.btnMoneyReduce.gray = true;
|
||||
}
|
||||
|
||||
if (charm <= this.#propertyAllocateLimit[0]) {
|
||||
this.btnCharmReduce.disabled = this.btnCharmReduce.gray = true;
|
||||
} else if (charm >= this.#propertyAllocateLimit[1]) {
|
||||
this.btnCharmIncrease.disabled = this.btnCharmIncrease.gray = true;
|
||||
}
|
||||
|
||||
if (intelligence <= this.#propertyAllocateLimit[0]) {
|
||||
this.btnIntelligenceReduce.disabled = this.btnIntelligenceReduce.gray = true;
|
||||
} else if (intelligence >= this.#propertyAllocateLimit[1]) {
|
||||
this.btnIntelligenceIncrease.disabled = this.btnIntelligenceIncrease.gray = true;
|
||||
}
|
||||
|
||||
if (strength <= this.#propertyAllocateLimit[0]) {
|
||||
this.btnStrengthReduce.disabled = this.btnStrengthReduce.gray = true;
|
||||
} else if (strength >= this.#propertyAllocateLimit[1]) {
|
||||
this.btnStrengthIncrease.disabled = this.btnStrengthIncrease.gray = true;
|
||||
}
|
||||
|
||||
if (money <= this.#propertyAllocateLimit[0]) {
|
||||
this.btnMoneyReduce.disabled = this.btnMoneyReduce.gray = true;
|
||||
} else if (money >= this.#propertyAllocateLimit[1]) {
|
||||
this.btnMoneyIncrease.disabled = this.btnMoneyIncrease.gray = true;
|
||||
}
|
||||
}
|
||||
|
||||
check(left, right, value) {
|
||||
if (value < left) return false;
|
||||
if (value > right) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
random() {
|
||||
let t = this.#propertyPoints;
|
||||
const arr = new Array(4).fill(this.#propertyAllocateLimit[1]);
|
||||
|
||||
while (t > 0) {
|
||||
const sub = Math.round(Math.random() * (Math.min(t, this.#propertyAllocateLimit[1]) - 1)) + 1;
|
||||
while(true) {
|
||||
const select = Math.floor(Math.random() * 4) % 4;
|
||||
if(arr[select] - sub <0) continue;
|
||||
arr[select] -= sub;
|
||||
t -= sub;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.#propertyAllocate[this.#types.CHR] = this.#propertyAllocateLimit[1] - arr[0];
|
||||
this.#propertyAllocate[this.#types.INT] = this.#propertyAllocateLimit[1] - arr[1];
|
||||
this.#propertyAllocate[this.#types.STR] = this.#propertyAllocateLimit[1] - arr[2];
|
||||
this.#propertyAllocate[this.#types.MNY] = this.#propertyAllocateLimit[1] - arr[3];
|
||||
|
||||
this.updateAllocate();
|
||||
}
|
||||
|
||||
onPropertyAllocate(type, value) {
|
||||
if (!this.check(
|
||||
this.#propertyAllocateLimit[0],
|
||||
this.#propertyAllocateLimit[1],
|
||||
this.#propertyAllocate[type] + value
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
if (!this.check(
|
||||
0,
|
||||
this.#propertyPoints,
|
||||
this.total + value
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
this.#propertyAllocate[type] += value;
|
||||
this.updateAllocate();
|
||||
}
|
||||
|
||||
onPropertyAllocateInput(type, inputItem) {
|
||||
let value = parseInt(inputItem.text) || 0;
|
||||
const total = this.total;
|
||||
if (total + value < 0) {
|
||||
value = this.#propertyAllocateLimit[0] * 4 - total;
|
||||
} else if (total + value > this.#propertyPoints) {
|
||||
value = this.#propertyPoints - total;
|
||||
}
|
||||
|
||||
if (value < this.#propertyAllocateLimit[0]) {
|
||||
value = this.#propertyAllocateLimit[0];
|
||||
} else if (value > this.#propertyAllocateLimit[1]) {
|
||||
value = this.#propertyAllocateLimit[1];
|
||||
}
|
||||
|
||||
|
||||
const alter = value - this.#propertyAllocate[type];
|
||||
if (alter) {
|
||||
this.onPropertyAllocate(type, alter);
|
||||
} else {
|
||||
this.updateAllocate();
|
||||
}
|
||||
}
|
||||
|
||||
renderTalent(box) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
const labTitle = box.getChildByName("labTitle");
|
||||
const grade1 = box.getChildByName("grade1");
|
||||
const grade2 = box.getChildByName("grade2");
|
||||
const grade3 = box.getChildByName("grade3");
|
||||
const labDescription = box.getChildByName("labDescription");
|
||||
|
||||
labTitle.text = dataSource.name;
|
||||
labDescription.text = dataSource.description;
|
||||
switch (dataSource.grade) {
|
||||
case 1:
|
||||
grade1.visible = true;
|
||||
grade2.visible = false;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
case 2:
|
||||
grade1.visible = false;
|
||||
grade2.visible = true;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
case 3:
|
||||
grade1.visible = false;
|
||||
grade2.visible = false;
|
||||
grade3.visible = true;
|
||||
break;
|
||||
default:
|
||||
grade1.visible = false;
|
||||
grade2.visible = false;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
126
src/ui/themes/cyber/summary.js
Normal file
126
src/ui/themes/cyber/summary.js
Normal file
@@ -0,0 +1,126 @@
|
||||
export default class CyberSummary extends ui.view.CyberTheme.CyberSummaryUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.listSelectedTalents.renderHandler = Laya.Handler.create(this, this.renderTalent, null, false);
|
||||
this.btnAgain.on(Laya.Event.CLICK, this, this.onAgain);
|
||||
}
|
||||
|
||||
#selectedTalent;
|
||||
|
||||
onAgain() {
|
||||
core.talentExtend(this.#selectedTalent);
|
||||
core.times ++;
|
||||
$ui.switchView(UI.pages.MAIN);
|
||||
}
|
||||
|
||||
init({talents}) {
|
||||
const {summary, lastExtendTalent} = core;
|
||||
const gradeFilters = $ui.common.filter;
|
||||
const gradeColors = $ui.common.grade;
|
||||
|
||||
const age = summary[core.PropertyTypes.HAGE];
|
||||
this.labAge.text = ''+age.value;
|
||||
this.labAgeJudge.text = age.judge;
|
||||
this.labAgeJudge.color = gradeColors[age.grade];
|
||||
|
||||
const sum = summary[core.PropertyTypes.SUM];
|
||||
this.labTotal.text = ''+sum.value;
|
||||
this.labTotalJudge.text = sum.judge;
|
||||
this.labTotalJudge.color = gradeColors[sum.grade];
|
||||
|
||||
const chr = summary[core.PropertyTypes.HCHR];
|
||||
this.labCharm.text = ''+chr.value;
|
||||
this.prgCharm.value = chr.progress;
|
||||
this.labCharmJudge.text = chr.judge;
|
||||
this.labCharmJudge.color = gradeColors[chr.grade];
|
||||
this.boxCharmGrade.colorFilter = gradeFilters[chr.grade];
|
||||
|
||||
const int = summary[core.PropertyTypes.HINT];
|
||||
this.labIntelligence.text = ''+int.value;
|
||||
this.prgIntelligence.value = int.progress;
|
||||
this.labIntelligenceJudge.text = int.judge;
|
||||
this.labIntelligenceJudge.color = gradeColors[int.grade];
|
||||
this.boxIntelligenceGrade.colorFilter = gradeFilters[int.grade];
|
||||
|
||||
const str = summary[core.PropertyTypes.HSTR];
|
||||
this.labStrength.text = ''+str.value;
|
||||
this.prgStrength.value = str.progress;
|
||||
this.labStrengthJudge.text = str.judge;
|
||||
this.labStrengthJudge.color = gradeColors[str.grade];
|
||||
this.boxStrengthGrade.colorFilter = gradeFilters[str.grade];
|
||||
|
||||
const mny = summary[core.PropertyTypes.HMNY];
|
||||
this.labMoney.text = ''+mny.value;
|
||||
this.prgMoney.value = mny.progress;
|
||||
this.labMoneyJudge.text = mny.judge;
|
||||
this.labMoneyJudge.color = gradeColors[mny.grade];
|
||||
this.boxMoneyGrade.colorFilter = gradeFilters[mny.grade];
|
||||
|
||||
const spr = summary[core.PropertyTypes.HSPR];
|
||||
this.labSpirit.text = ''+spr.value;
|
||||
this.prgSpirit.value = spr.progress;
|
||||
this.labSpiritJudge.text = spr.judge;
|
||||
this.labSpiritJudge.color = gradeColors[spr.grade];
|
||||
this.boxSpiritGrade.colorFilter = gradeFilters[spr.grade];
|
||||
|
||||
talents.sort(({id:a, grade:ag}, {id:b, grade:bg},)=>{
|
||||
if(a == lastExtendTalent) return -1;
|
||||
if(b == lastExtendTalent) return 1;
|
||||
return bg - ag;
|
||||
});
|
||||
this.#selectedTalent = talents[0].id;
|
||||
this.listSelectedTalents.array = talents;
|
||||
}
|
||||
|
||||
renderTalent(box) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
const labTitle = box.getChildByName("labTitle");
|
||||
const grade1 = box.getChildByName("grade1");
|
||||
const grade2 = box.getChildByName("grade2");
|
||||
const grade3 = box.getChildByName("grade3");
|
||||
const labDescription = box.getChildByName("labDescription");
|
||||
const selected = box.getChildByName("selected");
|
||||
const unselected = box.getChildByName("unselected");
|
||||
|
||||
labTitle.text = dataSource.name;
|
||||
labDescription.text = dataSource.description;
|
||||
switch (dataSource.grade) {
|
||||
case 1:
|
||||
grade1.visible = true;
|
||||
grade2.visible = false;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
case 2:
|
||||
grade1.visible = false;
|
||||
grade2.visible = true;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
case 3:
|
||||
grade1.visible = false;
|
||||
grade2.visible = false;
|
||||
grade3.visible = true;
|
||||
break;
|
||||
default:
|
||||
grade1.visible = false;
|
||||
grade2.visible = false;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
}
|
||||
|
||||
selected.visible = dataSource.id == this.#selectedTalent;
|
||||
unselected.visible = !selected.visible;
|
||||
box.off(Laya.Event.CLICK, this, this.onSelectTalent);
|
||||
box.on(Laya.Event.CLICK, this, this.onSelectTalent, [dataSource.id]);
|
||||
}
|
||||
|
||||
onSelectTalent(talentId) {
|
||||
if(talentId == this.#selectedTalent) {
|
||||
this.#selectedTalent = null;
|
||||
} else {
|
||||
this.#selectedTalent = talentId;
|
||||
}
|
||||
|
||||
this.listSelectedTalents.refresh();
|
||||
}
|
||||
}
|
||||
121
src/ui/themes/cyber/talent.js
Normal file
121
src/ui/themes/cyber/talent.js
Normal file
@@ -0,0 +1,121 @@
|
||||
export default class CyberTalent extends ui.view.CyberTheme.CyberTalentUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnDrawCard.on(Laya.Event.CLICK, this, this.onClickDrawCard);
|
||||
this.btnNext.on(Laya.Event.CLICK, this, this.onClickNext);
|
||||
this.listTalents.renderHandler = Laya.Handler.create(this, this.renderTalent, null, false);
|
||||
this.listTalents.scrollBar.elasticDistance = 150;
|
||||
this.on(Laya.Event.RESIZE, this, () => {
|
||||
const renderWidth = this.listTalents?._itemRender?.props?.width;
|
||||
if(renderWidth) {
|
||||
const col = Math.max(Math.floor((this.width - 40) / renderWidth), 1);
|
||||
this.listTalents.width = col * renderWidth + (col - 1) * (this.listTalents.spaceY || 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#selected = new Set();
|
||||
static load() {
|
||||
return ['images/background/background_2@3x.png'];
|
||||
}
|
||||
|
||||
init() {
|
||||
this.pageDrawCard.visible = true;
|
||||
this.pageResult.visible = false;
|
||||
this.btnNext.label = 'UI_Talent_Select_Uncomplete';
|
||||
this.#selected.clear();
|
||||
}
|
||||
|
||||
close() {}
|
||||
|
||||
onClickDrawCard() {
|
||||
this.pageDrawCard.visible = false;
|
||||
this.pageResult.visible = true;
|
||||
this.listTalents.array = core.talentRandom();
|
||||
}
|
||||
|
||||
onClickNext() {
|
||||
if(this.#selected.size < core.talentSelectLimit) {
|
||||
return $$event('message', ['F_TalentSelectNotComplect', core.talentSelectLimit]);
|
||||
}
|
||||
|
||||
const talents = [...this.#selected].map(index => this.listTalents.array[index]);
|
||||
$ui.switchView(UI.pages.PROPERTY, { talents });
|
||||
}
|
||||
|
||||
renderTalent(box, index) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
const hboxTitle = box.getChildByName("hboxTitle");
|
||||
const labTitle = hboxTitle.getChildByName("labTitle");
|
||||
const grades = hboxTitle.getChildByName("grades");
|
||||
const grade1 = grades.getChildByName("grade1");
|
||||
const grade2 = grades.getChildByName("grade2");
|
||||
const grade3 = grades.getChildByName("grade3");
|
||||
const labDescription = box.getChildByName("labDescription");
|
||||
const unselected = box.getChildByName("unselected");
|
||||
const selected = box.getChildByName("selected");
|
||||
|
||||
|
||||
switch (dataSource.grade) {
|
||||
case 1:
|
||||
grades.x = 0;
|
||||
labTitle.x = 1;
|
||||
grade1.visible = true;
|
||||
grade2.visible = false;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
case 2:
|
||||
grades.x = 0;
|
||||
labTitle.x = 1;
|
||||
grade1.visible = false;
|
||||
grade2.visible = true;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
case 3:
|
||||
grades.x = 0;
|
||||
labTitle.x = 1;
|
||||
grade1.visible = false;
|
||||
grade2.visible = false;
|
||||
grade3.visible = true;
|
||||
break;
|
||||
default:
|
||||
grades.x = 1;
|
||||
labTitle.x = 0;
|
||||
grade1.visible = false;
|
||||
grade2.visible = false;
|
||||
grade3.visible = false;
|
||||
break;
|
||||
}
|
||||
labTitle.text = dataSource.name;
|
||||
labTitle.event(Laya.Event.RESIZE);
|
||||
labDescription.text = dataSource.description;
|
||||
unselected.visible = !( selected.visible = this.#selected.has(index) );
|
||||
box.offAll(Laya.Event.CLICK);
|
||||
box.on(Laya.Event.CLICK, this, () => {
|
||||
if(this.#selected.has(index)) {
|
||||
this.#selected.delete(index);
|
||||
} else {
|
||||
if(this.#selected.size >= core.talentSelectLimit) {
|
||||
return $$event('message', ['F_TalentSelectLimit', core.talentSelectLimit]);
|
||||
}
|
||||
const exclusive = core.exclusive(
|
||||
[...this.#selected].map(index => this.listTalents.array[index].id),
|
||||
this.listTalents.array[index].id
|
||||
);
|
||||
if(exclusive != null) {
|
||||
for(const {name, id} of this.listTalents.array)
|
||||
if(exclusive == id)
|
||||
return $$event('message', ['F_TalentConflict', name]);
|
||||
return;
|
||||
}
|
||||
this.#selected.add(index);
|
||||
}
|
||||
|
||||
this.btnNext.label = this.#selected.size === core.talentSelectLimit
|
||||
? 'UI_Next'
|
||||
: 'UI_Talent_Select_Uncomplete';
|
||||
unselected.visible = !( selected.visible = this.#selected.has(index) );
|
||||
});
|
||||
}
|
||||
}
|
||||
167
src/ui/themes/cyber/trajectory.js
Normal file
167
src/ui/themes/cyber/trajectory.js
Normal file
@@ -0,0 +1,167 @@
|
||||
export default class CyberTrajectory extends ui.view.CyberTheme.CyberTrajectoryUI {
|
||||
constructor() {
|
||||
super();
|
||||
let pos1 = [0, 0];
|
||||
this.panelTrajectory.on(Laya.Event.MOUSE_DOWN, this, e => pos1 = [e.stageX, e.stageY]);
|
||||
this.panelTrajectory.on(Laya.Event.MOUSE_UP, this, e => {
|
||||
const distanceX = e.stageX - pos1[0];
|
||||
const distanceY = e.stageY - pos1[1];
|
||||
if(Math.sqrt(Math.abs(distanceX) + Math.abs(distanceY)) > 10) {
|
||||
return;
|
||||
}
|
||||
this.onNext();
|
||||
});
|
||||
this.btnSummary.on(Laya.Event.CLICK, this, this.onSummary);
|
||||
|
||||
this.panelTrajectory.vScrollBar.elasticDistance = 150;
|
||||
|
||||
let interval = null;
|
||||
let timeout = null;
|
||||
|
||||
const scroll = alter => {
|
||||
let value = this.panelTrajectory.vScrollBar.value + alter;
|
||||
if(value < 0) value = 0;
|
||||
if(value > this.panelTrajectory.vScrollBar.max) value = this.panelTrajectory.vScrollBar.max;
|
||||
this.panelTrajectory.scrollTo(0, value);
|
||||
}
|
||||
const on = (btn, alter) => {
|
||||
btn.off(Laya.Event.CLICK, this, scroll);
|
||||
btn.on(Laya.Event.CLICK, this, scroll, [100*alter]);
|
||||
timeout = setTimeout(() => {
|
||||
btn.off(Laya.Event.CLICK, this, scroll);
|
||||
interval = setInterval(() => scroll(10*alter), 10);
|
||||
}, 100);
|
||||
}
|
||||
const clear = () => {
|
||||
if(interval) {
|
||||
clearInterval(interval);
|
||||
interval = null;
|
||||
}
|
||||
if(timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
};
|
||||
this.btnUp.on(Laya.Event.MOUSE_DOWN, this, on, [this.btnUp, -1]);
|
||||
this.btnDown.on(Laya.Event.MOUSE_DOWN, this, on, [this.btnDown, 1]);
|
||||
this.btnUp.on(Laya.Event.MOUSE_UP, this, clear);
|
||||
this.btnUp.on(Laya.Event.MOUSE_OUT, this, clear);
|
||||
this.btnDown.on(Laya.Event.MOUSE_UP, this, clear);
|
||||
this.btnDown.on(Laya.Event.MOUSE_OUT, this, clear);
|
||||
this.scbSpeed.on(Laya.Event.CHANGE, this, () => this.speed = this.scbSpeed.value);
|
||||
this.scbSpeed.on(Laya.Event.MOUSE_UP, this, () => this.onNext());
|
||||
}
|
||||
|
||||
#speed;
|
||||
#auto;
|
||||
|
||||
static #createComponent = Laya.plugin.extractComponents(CyberTrajectory.uiView, ['boxTrajectoryItem']);
|
||||
#createTrajectoryItem() {
|
||||
const item = CyberTrajectory.#createComponent('boxTrajectoryItem');
|
||||
item.labContent = item.getChildByName('labContent');
|
||||
item.labAge = item.getChildByName('hboxAge').getChildByName('labAge');
|
||||
item.boxGrade = item.getChildByName('boxGrade');
|
||||
return item;
|
||||
}
|
||||
#isEnd;
|
||||
#trajectoryItems;
|
||||
#talents;
|
||||
|
||||
init({propertyAllocate, talents}) {
|
||||
this.boxParticle.visible = false;
|
||||
this.boxSpeed.visible = true;
|
||||
this.btnSummary.visible = false;
|
||||
this.#trajectoryItems = [];
|
||||
this.#isEnd = false;
|
||||
this.#talents = talents;
|
||||
core.start(propertyAllocate);
|
||||
this.updateProperty();
|
||||
this.onNext();
|
||||
}
|
||||
|
||||
close() {
|
||||
this.scbSpeed.value = 0;
|
||||
this.speed = 0;
|
||||
this.#trajectoryItems.forEach(item => {
|
||||
item.removeSelf();
|
||||
item.destroy();
|
||||
});
|
||||
this.#trajectoryItems = null;
|
||||
}
|
||||
|
||||
updateProperty() {
|
||||
const types = core.PropertyTypes;
|
||||
const propertys = core.propertys;
|
||||
|
||||
this.labCharm.text = propertys[types.CHR];
|
||||
this.labIntelligence.text = propertys[types.INT];
|
||||
this.labStrength.text = propertys[types.STR];
|
||||
this.labMoney.text = propertys[types.MNY];
|
||||
this.labSpirit.text = propertys[types.SPR];
|
||||
}
|
||||
|
||||
onNext() {
|
||||
if(this.#isEnd) return;
|
||||
|
||||
const { age, content, isEnd } = core.next();
|
||||
this.#isEnd = isEnd;
|
||||
|
||||
if(isEnd) {
|
||||
this.boxSpeed.visible = false;
|
||||
this.btnSummary.visible = true;
|
||||
}
|
||||
|
||||
this.renderTrajectory(age, content);
|
||||
|
||||
if(age >= 100) {
|
||||
this.boxParticle.visible = true;
|
||||
}
|
||||
Laya.timer.frameOnce(1, this, () => {
|
||||
this.panelTrajectory.scrollTo(0, this.panelTrajectory.contentHeight);
|
||||
});
|
||||
this.updateProperty();
|
||||
}
|
||||
|
||||
renderTrajectory(age, content) {
|
||||
const item = this.#createTrajectoryItem();
|
||||
item.labAge.text = ''+age;
|
||||
item.labContent.text = content.map(
|
||||
({type, description, grade, name, postEvent}) => {
|
||||
switch(type) {
|
||||
case 'TLT':
|
||||
return `天赋【${name}】发动:${description}`;
|
||||
case 'EVT':
|
||||
return description + (postEvent?`\n${postEvent}`:'');
|
||||
}
|
||||
}
|
||||
).join('\n');
|
||||
$_.deepMapSet(
|
||||
item.boxGrade,
|
||||
$ui.common.gradeBlk[content[content.length - 1].grade || 0]
|
||||
);
|
||||
this.vboxTrajectory.addChild(item);
|
||||
this.#trajectoryItems.push(item);
|
||||
this.#trajectoryItems.forEach((item, index) => item.y = index);
|
||||
}
|
||||
|
||||
onSummary() {
|
||||
const talents = this.#talents;
|
||||
$ui.switchView(UI.pages.SUMMARY, {talents});
|
||||
}
|
||||
|
||||
get speed() {
|
||||
return this.#speed;
|
||||
}
|
||||
|
||||
set speed(speed) {
|
||||
this.#speed = speed;
|
||||
this.prgSpeed.value = speed / this.scbSpeed.max;
|
||||
clearInterval(this.#auto);
|
||||
this.#auto = null;
|
||||
if(!speed) return;
|
||||
this.#auto = setInterval(
|
||||
() => this.onNext(),
|
||||
3000 * (1 - this.prgSpeed.value) + 300
|
||||
);
|
||||
}
|
||||
}
|
||||
53
src/ui/themes/default/achievement.js
Normal file
53
src/ui/themes/default/achievement.js
Normal file
@@ -0,0 +1,53 @@
|
||||
export default class Achievement extends ui.view.DefaultTheme.AchievementUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnBack.on(Laya.Event.CLICK, this, () => $ui.switchView(UI.pages.MAIN));
|
||||
this.btnRank.on(Laya.Event.CLICK, this, $$event, ['message', ['M_NoRank']]);
|
||||
this.listAchievements.renderHandler = new Laya.Handler(this, this.onRenderAchievement);
|
||||
this.listAchievements.scrollBar.elasticDistance = 150;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const {statistics, achievements, PropertyTypes: pt} = core;
|
||||
|
||||
this.listAchievements.array = achievements;
|
||||
|
||||
this.labRemakeTimes.text = $_.format($lang.F_RemakeTimes, statistics[pt.TMS].value);
|
||||
this.labRemakeTimesJudge.text = statistics[pt.TMS].judge;
|
||||
$_.deepMapSet(this.boxRemakeTimes, $ui.common.achievement[statistics[pt.TMS].grade]);
|
||||
|
||||
this.labAchievementCount.text = $_.format($lang.F_AchievementCount, statistics[pt.CACHV].value);
|
||||
this.labAchievementCountJudge.text = statistics[pt.CACHV].judge;
|
||||
$_.deepMapSet(this.boxAchievementCount, $ui.common.achievement[statistics[pt.CACHV].grade]);
|
||||
|
||||
this.labEventRate.text = parseInt(statistics[pt.REVT].value*100)+'%';
|
||||
this.prgEventRate.scaleX = statistics[pt.REVT].value;
|
||||
$_.deepMapSet(this.boxEventRate, $ui.common.achievement[statistics[pt.REVT].grade]);
|
||||
|
||||
this.labTalentRate.text = parseInt(statistics[pt.RTLT].value*100)+'%';
|
||||
this.prgTalentRate.scaleX = statistics[pt.RTLT].value;
|
||||
$_.deepMapSet(this.boxTalentRate, $ui.common.achievement[statistics[pt.RTLT].grade]);
|
||||
}
|
||||
|
||||
onRenderAchievement(box) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
const name = box.getChildByName('name');
|
||||
const description = box.getChildByName('description');
|
||||
const boxMask = box.getChildByName('boxMask');
|
||||
|
||||
$_.deepMapSet(box, $ui.common.achievement[dataSource.grade]);
|
||||
name.color = description.color = $ui.common.defaultFontColor;
|
||||
|
||||
if(dataSource.isAchieved) {
|
||||
name.text = dataSource.name;
|
||||
description.text = dataSource.description;
|
||||
boxMask.visible = false;
|
||||
} else {
|
||||
name.text = dataSource.hide? '???': dataSource.name;
|
||||
description.text = dataSource.hide? '???': dataSource.description;
|
||||
boxMask.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/ui/themes/default/main.js
Normal file
27
src/ui/themes/default/main.js
Normal file
@@ -0,0 +1,27 @@
|
||||
export default class Main extends ui.view.DefaultTheme.MainUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnRemake.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.TALENT));
|
||||
this.btnAchievement.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.ACHIEVEMENT));
|
||||
this.btnThanks.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.THANKS));
|
||||
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() {
|
||||
return [
|
||||
"images/atlas/images/icons.atlas",
|
||||
]
|
||||
}
|
||||
|
||||
init() {
|
||||
this.btnDiscord.visible =
|
||||
this.btnAchievement.visible =
|
||||
this.btnThanks.visible = !!core.times;
|
||||
const text = this.labSubTitle.text;
|
||||
this.labSubTitle.text = ' ';
|
||||
this.labSubTitle.text = text;
|
||||
}
|
||||
}
|
||||
20
src/ui/themes/default/popup/achievementPopup.js
Normal file
20
src/ui/themes/default/popup/achievementPopup.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export default class achievementPopup extends ui.view.DefaultTheme.AchievementPopupUI {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
async popup({achievement}, parent) {
|
||||
Laya.Tween.clearAll(this);
|
||||
Laya.Tween.clearAll(this.boxBg);
|
||||
this.alpha = 0.8;
|
||||
this.labName.text = achievement.name;
|
||||
this.labName.color = $ui.common.grade[achievement.grade];
|
||||
this.x = - this.width;
|
||||
this.boxBg.x = this.boxBg.width;
|
||||
await Promise.all([
|
||||
Laya.promises.Tween.to(this, {x: 0}, 300, Laya.Ease.strongOut),
|
||||
Laya.promises.Tween.to(this.boxBg, {x: 0}, 300, Laya.Ease.strongOut, 50),
|
||||
])
|
||||
await Laya.promises.Tween.to(this, {alpha: 0}, 3000, Laya.Ease.strongIn);
|
||||
}
|
||||
}
|
||||
183
src/ui/themes/default/property.js
Normal file
183
src/ui/themes/default/property.js
Normal file
@@ -0,0 +1,183 @@
|
||||
export default class Property extends ui.view.DefaultTheme.PropertyUI {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
const types =
|
||||
this.#types = core.PropertyTypes;
|
||||
|
||||
this.btnCharmIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.CHR, 1]);
|
||||
this.btnCharmReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.CHR, -1]);
|
||||
|
||||
this.btnIntelligenceIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.INT, 1]);
|
||||
this.btnIntelligenceReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.INT, -1]);
|
||||
|
||||
this.btnStrengthIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.STR, 1]);
|
||||
this.btnStrengthReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.STR, -1]);
|
||||
|
||||
this.btnMoneyIncrease.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.MNY, 1]);
|
||||
this.btnMoneyReduce.on(Laya.Event.CLICK, this, this.onPropertyAllocate, [types.MNY, -1]);
|
||||
|
||||
this.inputCharm.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.CHR]);
|
||||
this.inputIntelligence.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.INT]);
|
||||
this.inputStrength.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.STR]);
|
||||
this.inputMoney.on(Laya.Event.INPUT, this, this.onPropertyAllocateInput, [types.MNY]);
|
||||
|
||||
const selectAll = ({currentTarget: item}) => { item.text=''; };
|
||||
this.inputCharm.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
this.inputIntelligence.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
this.inputStrength.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
this.inputMoney.on(Laya.Event.MOUSE_DOWN, this, selectAll);
|
||||
|
||||
this.btnRandomAllocate.on(Laya.Event.CLICK, this, this.random);
|
||||
this.btnNext.on(Laya.Event.CLICK, this, this.next);
|
||||
|
||||
this.listSelectedTalents.renderHandler = Laya.Handler.create(this, this.renderTalent, null, false);
|
||||
}
|
||||
|
||||
#types;
|
||||
#propertyPoints;
|
||||
#propertyAllocate;
|
||||
#propertyAllocateLimit;
|
||||
|
||||
init({talents}) {
|
||||
this.listSelectedTalents.array = talents;
|
||||
const replace = core.remake(talents.map(talent => talent.id));
|
||||
if(replace.length > 0) {
|
||||
$$event('message', [replace.map(v => ['F_TalentReplace', v])]);
|
||||
}
|
||||
this.#propertyPoints = core.getPropertyPoints();
|
||||
this.#propertyAllocateLimit = core.propertyAllocateLimit;
|
||||
this.labLeftPropertyPoint.text = this.#propertyPoints;
|
||||
this.#propertyAllocate = {
|
||||
[this.#types.CHR]: 0,
|
||||
[this.#types.INT]: 0,
|
||||
[this.#types.STR]: 0,
|
||||
[this.#types.MNY]: 0,
|
||||
}
|
||||
this.updateAllocate();
|
||||
}
|
||||
|
||||
next() {
|
||||
const left = this.#propertyPoints - this.total;
|
||||
if (left > 0) {
|
||||
return $$event('message', ['F_PropertyPointLeft', left]);
|
||||
}
|
||||
$ui.switchView(
|
||||
UI.pages.TRAJECTORY,
|
||||
{
|
||||
propertyAllocate: this.#propertyAllocate,
|
||||
talents: this.listSelectedTalents.array,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
get total() {
|
||||
return this.#propertyAllocate[this.#types.CHR]
|
||||
+ this.#propertyAllocate[this.#types.INT]
|
||||
+ this.#propertyAllocate[this.#types.STR]
|
||||
+ this.#propertyAllocate[this.#types.MNY];
|
||||
}
|
||||
|
||||
updateAllocate() {
|
||||
const charm = this.#propertyAllocate[this.#types.CHR];
|
||||
const intelligence = this.#propertyAllocate[this.#types.INT];
|
||||
const strength = this.#propertyAllocate[this.#types.STR];
|
||||
const money = this.#propertyAllocate[this.#types.MNY];
|
||||
|
||||
this.inputCharm.text = ''+charm;
|
||||
this.inputIntelligence.text = ''+intelligence;
|
||||
this.inputStrength.text = ''+strength;
|
||||
this.inputMoney.text = ''+money;
|
||||
|
||||
this.labLeftPropertyPoint.text = this.#propertyPoints - this.total;
|
||||
|
||||
this.btnCharmIncrease.disabled = this.btnCharmIncrease.gray = false;
|
||||
this.btnCharmReduce.disabled = this.btnCharmReduce.gray = false;
|
||||
this.btnIntelligenceIncrease.disabled = this.btnIntelligenceIncrease.gray = false;
|
||||
this.btnIntelligenceReduce.disabled = this.btnIntelligenceReduce.gray = false;
|
||||
this.btnStrengthIncrease.disabled = this.btnStrengthIncrease.gray = false;
|
||||
this.btnStrengthReduce.disabled = this.btnStrengthReduce.gray = false;
|
||||
this.btnMoneyIncrease.disabled = this.btnMoneyIncrease.gray = false;
|
||||
this.btnMoneyReduce.disabled = this.btnMoneyReduce.gray = false;
|
||||
}
|
||||
|
||||
check(left, right, value) {
|
||||
if (value < left) return false;
|
||||
if (value > right) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
random() {
|
||||
let t = this.#propertyPoints;
|
||||
const arr = new Array(4).fill(this.#propertyAllocateLimit[1]);
|
||||
|
||||
while (t > 0) {
|
||||
const sub = Math.round(Math.random() * (Math.min(t, this.#propertyAllocateLimit[1]) - 1)) + 1;
|
||||
while(true) {
|
||||
const select = Math.floor(Math.random() * 4) % 4;
|
||||
if(arr[select] - sub <0) continue;
|
||||
arr[select] -= sub;
|
||||
t -= sub;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.#propertyAllocate[this.#types.CHR] = this.#propertyAllocateLimit[1] - arr[0];
|
||||
this.#propertyAllocate[this.#types.INT] = this.#propertyAllocateLimit[1] - arr[1];
|
||||
this.#propertyAllocate[this.#types.STR] = this.#propertyAllocateLimit[1] - arr[2];
|
||||
this.#propertyAllocate[this.#types.MNY] = this.#propertyAllocateLimit[1] - arr[3];
|
||||
|
||||
this.updateAllocate();
|
||||
}
|
||||
|
||||
onPropertyAllocate(type, value) {
|
||||
if (!this.check(
|
||||
this.#propertyAllocateLimit[0],
|
||||
this.#propertyAllocateLimit[1],
|
||||
this.#propertyAllocate[type] + value
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
if (!this.check(
|
||||
0,
|
||||
this.#propertyPoints,
|
||||
this.total + value
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
this.#propertyAllocate[type] += value;
|
||||
this.updateAllocate();
|
||||
}
|
||||
|
||||
onPropertyAllocateInput(type, inputItem) {
|
||||
let value = parseInt(inputItem.text) || 0;
|
||||
const total = this.total;
|
||||
if (total + value < 0) {
|
||||
value = this.#propertyAllocateLimit[0] * 4 - total;
|
||||
} else if (total + value > this.#propertyPoints) {
|
||||
value = this.#propertyPoints - total;
|
||||
}
|
||||
|
||||
if (value < this.#propertyAllocateLimit[0]) {
|
||||
value = this.#propertyAllocateLimit[0];
|
||||
} else if (value > this.#propertyAllocateLimit[1]) {
|
||||
value = this.#propertyAllocateLimit[1];
|
||||
}
|
||||
|
||||
|
||||
const alter = value - this.#propertyAllocate[type];
|
||||
if (alter) {
|
||||
this.onPropertyAllocate(type, alter);
|
||||
} else {
|
||||
this.updateAllocate();
|
||||
}
|
||||
}
|
||||
|
||||
renderTalent(box) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
box.label = $_.format($lang.F_TalentSelection, dataSource);
|
||||
const style = $ui.common.card[dataSource.grade].normal;
|
||||
|
||||
$_.deepMapSet(box, style);
|
||||
}
|
||||
}
|
||||
68
src/ui/themes/default/summary.js
Normal file
68
src/ui/themes/default/summary.js
Normal file
@@ -0,0 +1,68 @@
|
||||
export default class Summary extends ui.view.DefaultTheme.SummaryUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.listSummary.renderHandler = Laya.Handler.create(this, this.renderSummary, null, false);
|
||||
this.listSelectedTalents.renderHandler = Laya.Handler.create(this, this.renderTalent, null, false);
|
||||
this.btnAgain.on(Laya.Event.CLICK, this, this.onAgain);
|
||||
}
|
||||
|
||||
#selectedTalent;
|
||||
|
||||
onAgain() {
|
||||
core.talentExtend(this.#selectedTalent);
|
||||
core.times ++;
|
||||
$ui.switchView(UI.pages.MAIN);
|
||||
}
|
||||
|
||||
init({talents}) {
|
||||
const {summary, lastExtendTalent} = core;
|
||||
|
||||
this.listSummary.array = [
|
||||
[core.PropertyTypes.HCHR, $lang.UI_Property_Charm],
|
||||
[core.PropertyTypes.HINT, $lang.UI_Property_Intelligence],
|
||||
[core.PropertyTypes.HSTR, $lang.UI_Property_Strength],
|
||||
[core.PropertyTypes.HMNY, $lang.UI_Property_Money],
|
||||
[core.PropertyTypes.HSPR, $lang.UI_Property_Spirit],
|
||||
[core.PropertyTypes.HAGE, $lang.UI_Final_Age],
|
||||
[core.PropertyTypes.SUM, $lang.UI_Total_Judge],
|
||||
].map(([type, key]) => {
|
||||
const data = summary[type];
|
||||
return {
|
||||
label: `${key}${$lang.UI_Colon} ${data.value} ${$lang[data.judge]}`,
|
||||
grade: data.grade,
|
||||
}
|
||||
});
|
||||
|
||||
talents.sort(({id:a, grade:ag}, {id:b, grade:bg},)=>{
|
||||
if(a == lastExtendTalent) return -1;
|
||||
if(b == lastExtendTalent) return 1;
|
||||
return bg - ag;
|
||||
});
|
||||
this.#selectedTalent = talents[0].id;
|
||||
this.listSelectedTalents.array = talents;
|
||||
}
|
||||
renderSummary(box) {
|
||||
const {label, grade} = box.dataSource;
|
||||
box.label = label;
|
||||
$_.deepMapSet(box, $ui.common.summary[grade]);
|
||||
}
|
||||
renderTalent(box) {
|
||||
const dataSource = box.dataSource;
|
||||
box.label = $_.format($lang.F_TalentSelection, dataSource);
|
||||
const style = $ui.common.card[dataSource.grade];
|
||||
$_.deepMapSet(box, dataSource.id == this.#selectedTalent? style.selected: style.normal);
|
||||
box.getChildByName('blank').pause = dataSource.id != this.#selectedTalent;
|
||||
box.off(Laya.Event.CLICK, this, this.onSelectTalent);
|
||||
box.on(Laya.Event.CLICK, this, this.onSelectTalent, [dataSource.id]);
|
||||
}
|
||||
|
||||
onSelectTalent(talentId) {
|
||||
if(talentId == this.#selectedTalent) {
|
||||
this.#selectedTalent = null;
|
||||
} else {
|
||||
this.#selectedTalent = talentId;
|
||||
}
|
||||
|
||||
this.listSelectedTalents.refresh();
|
||||
}
|
||||
}
|
||||
78
src/ui/themes/default/talent.js
Normal file
78
src/ui/themes/default/talent.js
Normal file
@@ -0,0 +1,78 @@
|
||||
export default class Talent extends ui.view.DefaultTheme.TalentUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnDrawCard.on(Laya.Event.CLICK, this, this.onClickDrawCard);
|
||||
this.btnNext.on(Laya.Event.CLICK, this, this.onClickNext);
|
||||
this.listTalents.renderHandler = Laya.Handler.create(this, this.renderTalent, null, false);
|
||||
this.listTalents.scrollBar.elasticDistance = 150;
|
||||
}
|
||||
|
||||
#selected = new Set();
|
||||
|
||||
init() {
|
||||
this.pageDrawCard.visible = true;
|
||||
this.pageResult.visible = false;
|
||||
this.btnNext.label = 'UI_Talent_Select_Uncomplete';
|
||||
this.#selected.clear();
|
||||
}
|
||||
|
||||
close() {}
|
||||
|
||||
onClickDrawCard() {
|
||||
this.pageDrawCard.visible = false;
|
||||
this.pageResult.visible = true;
|
||||
this.listTalents.array = core.talentRandom();
|
||||
}
|
||||
|
||||
onClickNext() {
|
||||
if(this.#selected.size < core.talentSelectLimit) {
|
||||
return $$event('message', ['F_TalentSelectNotComplect', core.talentSelectLimit]);
|
||||
}
|
||||
|
||||
const talents = [...this.#selected].map(index => this.listTalents.array[index]);
|
||||
$ui.switchView(UI.pages.PROPERTY, { talents });
|
||||
}
|
||||
|
||||
renderTalent(box, index) {
|
||||
const dataSource = box.dataSource;
|
||||
|
||||
const blank = box.getChildByName('blank');
|
||||
box.label = $_.format($lang.F_TalentSelection, dataSource);
|
||||
|
||||
const style = $ui.common.card[dataSource.grade];
|
||||
const changeStyle = () => {
|
||||
const selected = this.#selected.has(index);
|
||||
blank.pause = !selected;
|
||||
$_.deepMapSet(box, selected? style.selected: style.normal);
|
||||
}
|
||||
changeStyle();
|
||||
|
||||
box.offAll(Laya.Event.CLICK);
|
||||
box.on(Laya.Event.CLICK, this, () => {
|
||||
if(this.#selected.has(index)) {
|
||||
this.#selected.delete(index);
|
||||
} else {
|
||||
if(this.#selected.size >= core.talentSelectLimit) {
|
||||
return $$event('message', ['F_TalentSelectLimit', core.talentSelectLimit]);
|
||||
}
|
||||
const exclusive = core.exclusive(
|
||||
[...this.#selected].map(index => this.listTalents.array[index].id),
|
||||
this.listTalents.array[index].id
|
||||
);
|
||||
if(exclusive != null) {
|
||||
for(const {name, id} of this.listTalents.array)
|
||||
if(exclusive == id)
|
||||
return $$event('message', ['F_TalentConflict', name]);
|
||||
return;
|
||||
}
|
||||
this.#selected.add(index);
|
||||
}
|
||||
|
||||
this.btnNext.label = this.#selected.size === core.talentSelectLimit
|
||||
? 'UI_Next'
|
||||
: 'UI_Talent_Select_Uncomplete';
|
||||
|
||||
changeStyle();
|
||||
});
|
||||
}
|
||||
}
|
||||
59
src/ui/themes/default/thanks.js
Normal file
59
src/ui/themes/default/thanks.js
Normal file
@@ -0,0 +1,59 @@
|
||||
export default class Thanks extends ui.view.DefaultTheme.ThanksUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnBack.on(Laya.Event.CLICK, this, ()=>$ui.switchView(UI.pages.MAIN));
|
||||
this.listSupports.renderHandler = Laya.Handler.create(this, this.renderSupport, null, false);
|
||||
this.panelTopSupports.vScrollBar.elasticDistance = 150;
|
||||
this.listSupports.scrollBar.elasticDistance = 150;
|
||||
this.btnAFD.on(Laya.Event.CLICK, this, goto, ['sponsor_afd']);
|
||||
this.btnDDF.on(Laya.Event.CLICK, this, goto, ['sponsor_ddf']);
|
||||
}
|
||||
|
||||
static #createComponent = Laya.plugin.extractComponents(Thanks.uiView, ['boxTopSupport']);
|
||||
#createTopSupportItem() {
|
||||
const item = Thanks.#createComponent('boxTopSupport');
|
||||
item.name = item.getChildByName('name');
|
||||
item.comment = item.getChildByName('comment');
|
||||
$_.deepMapSet(item, $ui.common.topSupportItem);
|
||||
return item;
|
||||
}
|
||||
|
||||
#topSupports;
|
||||
|
||||
init() {
|
||||
const supports = [];
|
||||
this.#topSupports = [];
|
||||
core.specialThanks
|
||||
.sort(()=>0.5-Math.random())
|
||||
.forEach(({group, name, comment, color})=>
|
||||
group == 2
|
||||
? supports.push({name, color})
|
||||
: this.renderTopSupport(name, comment, color)
|
||||
);
|
||||
this.listSupports.array = supports;
|
||||
}
|
||||
|
||||
renderTopSupport(name, comment, color) {
|
||||
const item = this.#createTopSupportItem();
|
||||
item.name.text = name;
|
||||
item.comment.text = comment;
|
||||
item.name.color = color || '#000000';
|
||||
this.vboxTopSupports.addChild(item);
|
||||
this.#topSupports.push(item);
|
||||
this.#topSupports.forEach((item, index) => item.y = index);
|
||||
}
|
||||
|
||||
renderSupport(label) {
|
||||
const {name, color} = label.dataSource;
|
||||
label.text = name;
|
||||
label.color = color || $ui.common.defaultFontColor;
|
||||
}
|
||||
|
||||
close() {
|
||||
this.#topSupports.forEach(item => {
|
||||
item.removeSelf();
|
||||
item.destroy();
|
||||
});
|
||||
this.#topSupports = null;
|
||||
}
|
||||
}
|
||||
143
src/ui/themes/default/trajectory.js
Normal file
143
src/ui/themes/default/trajectory.js
Normal file
@@ -0,0 +1,143 @@
|
||||
export default class Trajectory extends ui.view.DefaultTheme.TrajectoryUI {
|
||||
constructor() {
|
||||
super();
|
||||
let pos1 = [0, 0];
|
||||
this.panelTrajectory.on(Laya.Event.MOUSE_DOWN, this, e => pos1 = [e.stageX, e.stageY]);
|
||||
this.panelTrajectory.on(Laya.Event.MOUSE_UP, this, e => {
|
||||
const distanceX = e.stageX - pos1[0];
|
||||
const distanceY = e.stageY - pos1[1];
|
||||
if(Math.sqrt(Math.abs(distanceX) + Math.abs(distanceY)) > 10) {
|
||||
return;
|
||||
}
|
||||
this.onNext();
|
||||
});
|
||||
this.btnSummary.on(Laya.Event.CLICK, this, this.onSummary);
|
||||
|
||||
this.panelTrajectory.vScrollBar.elasticDistance = 150;
|
||||
this.scbSpeed.on(Laya.Event.CHANGE, this, () => this.speed = this.scbSpeed.value);
|
||||
this.scbSpeed.on(Laya.Event.MOUSE_UP, this, () => this.onNext());
|
||||
}
|
||||
|
||||
#speed;
|
||||
#auto;
|
||||
|
||||
static load() {
|
||||
return [
|
||||
"images/atlas/images/progress.atlas",
|
||||
'images/atlas/images/slider.atlas',
|
||||
];
|
||||
}
|
||||
|
||||
static #createComponent = Laya.plugin.extractComponents(Trajectory.uiView, ['boxTrajectoryItem']);
|
||||
#createTrajectoryItem() {
|
||||
const item = Trajectory.#createComponent('boxTrajectoryItem');
|
||||
item.labContent = item.getChildByName('labContent');
|
||||
item.labAge = item.getChildByName('hboxAge').getChildByName('labAge');
|
||||
const config = $ui.common.trajectoryItem;
|
||||
$_.deepMapSet(item, config.box);
|
||||
item.grade = grade => {
|
||||
$_.deepMapSet(item, config.grade[grade || 0]);
|
||||
}
|
||||
item.getChildByName('hboxAge')._childs.forEach(child => child.color = config.ageColor);
|
||||
item.labContent.color = config.contentColor;
|
||||
return item;
|
||||
}
|
||||
#isEnd;
|
||||
#trajectoryItems;
|
||||
#talents;
|
||||
|
||||
init({propertyAllocate, talents}) {
|
||||
this.boxParticle.visible = false;
|
||||
this.boxSpeed.visible = true;
|
||||
this.btnSummary.visible = false;
|
||||
this.#trajectoryItems = [];
|
||||
this.#isEnd = false;
|
||||
this.#talents = talents;
|
||||
core.start(propertyAllocate);
|
||||
this.updateProperty();
|
||||
this.onNext();
|
||||
}
|
||||
|
||||
close() {
|
||||
this.scbSpeed.value = 0;
|
||||
this.speed = 0;
|
||||
this.#trajectoryItems.forEach(item => {
|
||||
item.removeSelf();
|
||||
item.destroy();
|
||||
});
|
||||
this.#trajectoryItems = null;
|
||||
}
|
||||
|
||||
updateProperty() {
|
||||
const types = core.PropertyTypes;
|
||||
const propertys = core.propertys;
|
||||
|
||||
this.labCharm.text = propertys[types.CHR];
|
||||
this.labIntelligence.text = propertys[types.INT];
|
||||
this.labStrength.text = propertys[types.STR];
|
||||
this.labMoney.text = propertys[types.MNY];
|
||||
this.labSpirit.text = propertys[types.SPR];
|
||||
}
|
||||
|
||||
onNext() {
|
||||
if(this.#isEnd) return;
|
||||
|
||||
const { age, content, isEnd } = core.next();
|
||||
this.#isEnd = isEnd;
|
||||
|
||||
if(isEnd) {
|
||||
this.boxSpeed.visible = false;
|
||||
this.btnSummary.visible = true;
|
||||
}
|
||||
|
||||
this.renderTrajectory(age, content);
|
||||
|
||||
if(age >= 100) {
|
||||
this.boxParticle.visible = true;
|
||||
}
|
||||
Laya.timer.frameOnce(1, this, () => {
|
||||
this.panelTrajectory.scrollTo(0, this.panelTrajectory.contentHeight);
|
||||
});
|
||||
this.updateProperty();
|
||||
}
|
||||
|
||||
renderTrajectory(age, content) {
|
||||
const item = this.#createTrajectoryItem();
|
||||
item.labAge.text = ''+age;
|
||||
item.labContent.text = content.map(
|
||||
({type, description, grade, name, postEvent}) => {
|
||||
switch(type) {
|
||||
case 'TLT':
|
||||
return `天赋【${name}】发动:${description}`;
|
||||
case 'EVT':
|
||||
return description + (postEvent?`\n${postEvent}`:'');
|
||||
}
|
||||
}
|
||||
).join('\n');
|
||||
item.grade(content[content.length - 1].grade);
|
||||
this.vboxTrajectory.addChild(item);
|
||||
this.#trajectoryItems.push(item);
|
||||
this.#trajectoryItems.forEach((item, index) => item.y = index);
|
||||
}
|
||||
|
||||
onSummary() {
|
||||
const talents = this.#talents;
|
||||
$ui.switchView(UI.pages.SUMMARY, {talents});
|
||||
}
|
||||
|
||||
get speed() {
|
||||
return this.#speed;
|
||||
}
|
||||
|
||||
set speed(speed) {
|
||||
this.#speed = speed;
|
||||
this.prgSpeed.value = speed / this.scbSpeed.max;
|
||||
clearInterval(this.#auto);
|
||||
this.#auto = null;
|
||||
if(!speed) return;
|
||||
this.#auto = setInterval(
|
||||
() => this.onNext(),
|
||||
3000 * (1 - this.prgSpeed.value) + 300
|
||||
);
|
||||
}
|
||||
}
|
||||
15
src/ui/themes/loading.js
Normal file
15
src/ui/themes/loading.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default class Loading extends ui.view.LoadingUI {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
static load() {
|
||||
return [
|
||||
"images/atlas/images/resource.atlas"
|
||||
]
|
||||
}
|
||||
|
||||
show() {}
|
||||
|
||||
onProgress(progress) {}
|
||||
}
|
||||
20
src/ui/themes/message.js
Normal file
20
src/ui/themes/message.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export default class MessagePopup extends ui.view.MessagePopupUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.left = this.right = 0;
|
||||
this.boxBg.defaultColor = "#000000";
|
||||
this.boxBg.hoverColor = "#000000";
|
||||
this.boxBg.radius = 20;
|
||||
}
|
||||
|
||||
async popup({message}, parent) {
|
||||
this.message.text = message;
|
||||
this.message.commitMeasure();
|
||||
this.height = this.message.height + this.boxBg.radius * 2 + this.message.fontSize;
|
||||
Laya.Tween.clearAll(this);
|
||||
this.alpha = 0;
|
||||
this.y = - 2 * this.height;
|
||||
await Laya.promises.Tween.to(this, { y: 0, alpha: 1 }, 300, Laya.Ease.backOut),
|
||||
await Laya.promises.Tween.to(this, { alpha: 0}, 300, Laya.Ease.strongIn, 3000);
|
||||
}
|
||||
}
|
||||
95
src/ui/themes/saveload.js
Normal file
95
src/ui/themes/saveload.js
Normal file
@@ -0,0 +1,95 @@
|
||||
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, async ()=>{
|
||||
const result = await $$copy(this.input.text = this.data);
|
||||
$$event('message', [result? 'UI_CopySuccess': 'UI_CopyFaild']);
|
||||
});
|
||||
this.btnWrite.on(Laya.Event.CLICK, this, async ()=>{
|
||||
const text = await $$read();
|
||||
if(text == false) {
|
||||
this.data = [
|
||||
this.input.text,
|
||||
'UI_PasteFaildDecodeSuccess',
|
||||
'UI_PasteFaildDecodeFaild'
|
||||
];
|
||||
} else {
|
||||
this.input.text = text;
|
||||
this.data = [
|
||||
text,
|
||||
'UI_PasteSuccessDecodeSuccess',
|
||||
'UI_PasteSuccessDecodeFaild'
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
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, success = 'UI_LoadSuccess', faild = 'UI_LoadFaild']) {
|
||||
try {
|
||||
const data = JSON.parse(v);
|
||||
for(const key in data)
|
||||
localStorage.setItem(key, data[key]);
|
||||
$$event('message', [success]);
|
||||
$ui.theme = $ui.theme;
|
||||
this.btnClose.event(Laya.Event.CLICK);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
$$event('message', [faild]);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/ui/themes/themes.js
Normal file
40
src/ui/themes/themes.js
Normal file
@@ -0,0 +1,40 @@
|
||||
export default class Themes extends ui.view.ThemesUI {
|
||||
constructor() {
|
||||
super();
|
||||
this.btnClose.on(Laya.Event.CLICK, this, ()=>this.close());
|
||||
this.btnOK.on(Laya.Event.CLICK, this, async ()=>{
|
||||
const selected = this.selected;
|
||||
if(!selected == $ui.theme) return this.close();
|
||||
$ui.theme = selected;
|
||||
await this.close();
|
||||
$ui.switchView(UI.pages.MAIN);
|
||||
});
|
||||
}
|
||||
|
||||
static load() {
|
||||
return ["images/atlas/images/radio.atlas"];
|
||||
}
|
||||
|
||||
init() {
|
||||
this.selected = localStorage.getItem('theme');
|
||||
}
|
||||
|
||||
get selected() {
|
||||
switch(this.radioTheme.selectedIndex) {
|
||||
case 0: return 'cyber';
|
||||
case 1: return 'dark';
|
||||
case 2: return 'light';
|
||||
default: return 'default';
|
||||
}
|
||||
}
|
||||
set selected(v) {
|
||||
let index;
|
||||
switch(v) {
|
||||
case 'cyber': index = 0; break;
|
||||
case 'dark': index = 1; break;
|
||||
case 'light': index = 2; break;
|
||||
default: index = -1; break;
|
||||
}
|
||||
this.radioTheme.selectedIndex = index;
|
||||
}
|
||||
}
|
||||
1088
src/ui/themes/views.js
Normal file
1088
src/ui/themes/views.js
Normal file
File diff suppressed because it is too large
Load Diff
360
src/ui/uiManager.js
Normal file
360
src/ui/uiManager.js
Normal file
@@ -0,0 +1,360 @@
|
||||
import Views from './themes/views.js';
|
||||
export default class UIManager {
|
||||
constructor(stage) {
|
||||
UIManager.#views = Views;
|
||||
|
||||
if(!stage) {
|
||||
stage = Laya.stage;
|
||||
}
|
||||
this.#stage = stage;
|
||||
|
||||
stage.addChild(this.#viewLayer);
|
||||
this.#viewLayer.zOrder = 1;
|
||||
stage.addChild(this.#dialogLayer);
|
||||
this.#dialogLayer.zOrder = 2;
|
||||
stage.addChild(this.#popupLayer);
|
||||
this.#popupLayer.zOrder = 3;
|
||||
this.#viewLayer.top =
|
||||
this.#viewLayer.bottom =
|
||||
this.#viewLayer.left =
|
||||
this.#viewLayer.right =
|
||||
this.#dialogLayer.top =
|
||||
this.#dialogLayer.bottom =
|
||||
this.#dialogLayer.left =
|
||||
this.#dialogLayer.right =
|
||||
this.#popupLayer.top =
|
||||
this.#popupLayer.bottom =
|
||||
this.#popupLayer.left =
|
||||
this.#popupLayer.right =
|
||||
this.#dialogMask.top =
|
||||
this.#dialogMask.bottom =
|
||||
this.#dialogMask.left =
|
||||
this.#dialogMask.right = 0;
|
||||
this.#dialogMask.graphics.drawRect(0, 0, 5000, 5000, '#000000');
|
||||
this.#dialogMask.alpha = 0.4;
|
||||
this.#dialogMask.on(Laya.Event.CLICK, this, ()=>{
|
||||
this.#dialogStack[this.#dialogStack.length - 1]?.close?.();
|
||||
})
|
||||
}
|
||||
|
||||
static #instance = {};
|
||||
static #views;
|
||||
#stage;
|
||||
#loading;
|
||||
#currentView;
|
||||
#viewLayer = new Laya.Panel();
|
||||
#dialogLayer = new Laya.Panel();
|
||||
#popupLayer = new Laya.Panel();
|
||||
#dialogMask = new Laya.Sprite();
|
||||
#viewMap = new Map();
|
||||
#class = new Map();
|
||||
#dialogStack = [];
|
||||
|
||||
static get inst() {
|
||||
return this.getInstance();
|
||||
}
|
||||
static getInstance(name="default") {
|
||||
return this.#instance[name] || (this.#instance[name] = new UIManager());
|
||||
}
|
||||
|
||||
static get pages() {
|
||||
return this.#views.pages;
|
||||
}
|
||||
|
||||
static get popups() {
|
||||
return this.#views.popups;
|
||||
}
|
||||
|
||||
static theme(theme, prop) {
|
||||
return this.#views.themes[theme][prop];
|
||||
}
|
||||
|
||||
async setLoading(loading) {
|
||||
const className = this.#pages[loading];
|
||||
const view = await this.getView(className, null, null, loading);
|
||||
view.top = view.bottom = view.left = view.right = 0;
|
||||
view.zOrder = 4;
|
||||
this.#loading = view;
|
||||
}
|
||||
|
||||
async switchView(viewName, args, actions) {
|
||||
const className = this.#pages[viewName];
|
||||
// get view instance
|
||||
const view = await this.getView(className, args, actions?.load, viewName, 'pages');
|
||||
|
||||
view.top = view.bottom = view.left = view.right = 0;
|
||||
// close current view
|
||||
this.clearAllDialog();
|
||||
await this.#currentView?.__close?.(view);
|
||||
await this.#currentView?.close?.(view);
|
||||
this.#viewLayer.removeChildren();
|
||||
|
||||
// open new view
|
||||
await view.init?.(args);
|
||||
|
||||
this.#currentView = view;
|
||||
this.#viewLayer.addChild(view);
|
||||
|
||||
view.__close = actions?.close;
|
||||
await actions?.open?.(view);
|
||||
await view.show?.();
|
||||
}
|
||||
|
||||
async getView(className, args, preload, viewName, type) {
|
||||
// check if view is already loaded
|
||||
let view = await this.#viewMap.get(className);
|
||||
|
||||
let timeout;
|
||||
if(this.#loading) {
|
||||
timeout = setTimeout(
|
||||
()=>this.#stage.addChild(this.#loading),
|
||||
3000
|
||||
);
|
||||
}
|
||||
const onProgress = this.#loading?.onProgress;
|
||||
|
||||
if(!view) {
|
||||
// load view
|
||||
const ViewClass = await this.loadView(className);
|
||||
const resourceList = await ViewClass.load?.(args);
|
||||
const scanedResourceList = this.#loading? this.scanResource(ViewClass.uiView): [];
|
||||
if(preload) {
|
||||
preload = [].concat(preload).concat(scanedResourceList);
|
||||
} else {
|
||||
preload = scanedResourceList;
|
||||
}
|
||||
await this.loadRes(resourceList, preload, onProgress);
|
||||
|
||||
// create view
|
||||
view = new ViewClass();
|
||||
// add view to map
|
||||
this.#viewMap.set(className, view);
|
||||
} else {
|
||||
// load resource
|
||||
const resourceList = await view.constructor.load?.(args);
|
||||
await this.loadRes(resourceList, preload, onProgress);
|
||||
}
|
||||
if(timeout) clearTimeout(timeout);
|
||||
this.#loading?.removeSelf();
|
||||
|
||||
this.#config(view, viewName, type);
|
||||
// return view
|
||||
return view;
|
||||
}
|
||||
|
||||
async loadView(className) {
|
||||
// load view
|
||||
if(this.#class.has(className)) return this.#class.get(className);
|
||||
const c = (await import(`./themes/${className}.js`)).default;
|
||||
this.#class.set(className, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
async loadRes(resourceList, preload, onProgress) {
|
||||
const cnt = (resourceList?.length || 0)
|
||||
+(preload?.length || 0);
|
||||
if(resourceList && resourceList.length) {
|
||||
const s = resourceList.length / cnt;
|
||||
await Laya.promises.loader.load(resourceList, Laya.Handler.create(null, prg=>onProgress?.(prg*s)));
|
||||
}
|
||||
if(preload && preload.length) {
|
||||
const s = 1 - preload.length / cnt;
|
||||
const l = preload.length / cnt;
|
||||
await Laya.promises.loader.load(preload, Laya.Handler.create(null, prg=>onProgress?.(prg*l+s)));
|
||||
}
|
||||
}
|
||||
|
||||
#showDialogStack() {
|
||||
if(this.#dialogStack.length == 0) {
|
||||
this.#dialogLayer.visible = false;
|
||||
return;
|
||||
}
|
||||
this.#dialogLayer.visible = true;
|
||||
this.#dialogStack.forEach((dialog, i)=>{
|
||||
this.#dialogLayer.addChild(dialog);
|
||||
dialog.zOrder = i;
|
||||
})
|
||||
this.#dialogLayer.addChild(this.#dialogMask);
|
||||
const l = this.#dialogStack.length;
|
||||
this.#dialogMask.zOrder = l -1;
|
||||
this.#dialogStack[l -1].zOrder = l;
|
||||
}
|
||||
|
||||
async showDialog(dialogName, args, actions) {
|
||||
const className = this.#pages[dialogName];
|
||||
const dialog = await this.getView(className, args, actions?.load, dialogName, 'pages');
|
||||
|
||||
const index = this.#dialogStack.indexOf(dialog);
|
||||
if(index != -1) {
|
||||
this.#dialogStack.splice(index, 1);
|
||||
}
|
||||
this.#dialogStack.push(dialog);
|
||||
dialog.init?.(args);
|
||||
dialog.centerX = dialog.centerY = 0;
|
||||
this.#showDialogStack();
|
||||
|
||||
const open = actions?.open || (async () => {
|
||||
dialog.scaleX = 0;
|
||||
dialog.scaleY = 0;
|
||||
await Laya.promises.Tween.to(dialog, { scaleX: 1, scaleY: 1 }, 300, Laya.Ease.backOut);
|
||||
});
|
||||
await open(dialog);
|
||||
dialog.mouseThrough = true;
|
||||
dialog.mouseEnabled = true;
|
||||
dialog.close = async ()=>{
|
||||
if(actions?.close) {
|
||||
await actions.close();
|
||||
} else {
|
||||
await Laya.promises.Tween.to(dialog, { scaleX: 0, scaleY: 0 }, 300, Laya.Ease.strongIn);
|
||||
}
|
||||
const index = this.#dialogStack.indexOf(dialog);
|
||||
if(index != -1) {
|
||||
this.#dialogStack.splice(index, 1);
|
||||
}
|
||||
this.#showDialogStack();
|
||||
}
|
||||
|
||||
this.#dialogLayer.addChild(dialog);
|
||||
}
|
||||
|
||||
async popup(type, args) {
|
||||
const className = this.#popups[type];
|
||||
const popup = await this.getView(className, args, null, type, 'popups');
|
||||
this.#popupLayer.addChild(popup);
|
||||
await popup.popup(args, this.#popupLayer);
|
||||
this.#popupLayer.removeChild(popup);
|
||||
}
|
||||
|
||||
clearAllDialog() {
|
||||
this.#dialogStack = [];
|
||||
this.#showDialogStack();
|
||||
}
|
||||
|
||||
#config(view, key, type) {
|
||||
const config = this.#configs?.[type]?.[key];
|
||||
if(!config) return;
|
||||
if(view.config && view.config(config)) return;
|
||||
const applyConfig = (target, config) => {
|
||||
if(!target) return;
|
||||
if(typeof config == 'string') {
|
||||
config = this.#configs?.class?.[config];
|
||||
}
|
||||
$_.deepMapSet(target, config);
|
||||
};
|
||||
|
||||
if(config.names)
|
||||
for(const name in config.names)
|
||||
this.#deepGetChildsByName(view, name)
|
||||
.forEach(child => applyConfig(child, config.names[name]));
|
||||
|
||||
if(config.vars)
|
||||
for(const key in config.vars)
|
||||
applyConfig(view[key], config.vars[key]);
|
||||
|
||||
}
|
||||
|
||||
#deepGetChildsByName(parent, name) {
|
||||
const list = [];
|
||||
if(!parent || !parent._childs) return list;
|
||||
|
||||
for(const child of parent._childs) {
|
||||
if(child.name == name) list.push(child);
|
||||
if(child._childs) list.push(...this.#deepGetChildsByName(child, name));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
#cutPath(path) {
|
||||
path = ''+path;
|
||||
let index = path.length;
|
||||
do {
|
||||
index --;
|
||||
if(path[index] == '.') {
|
||||
break;
|
||||
}
|
||||
} while (index>0)
|
||||
return [
|
||||
path.substring(0, index),
|
||||
path.substring(index, path.length)
|
||||
];
|
||||
}
|
||||
|
||||
#subSkin(skin, type) {
|
||||
if(!skin || !skin.replace(/\s/g, '')) return [];
|
||||
switch (type) {
|
||||
case 'ProgressBar':
|
||||
return [ skin, ...this.#progressBarSkin(skin) ];
|
||||
case 'ScrollBar':
|
||||
return [ skin, ...this.#scrollBarSkin(skin) ];
|
||||
default:
|
||||
return [skin]
|
||||
}
|
||||
}
|
||||
|
||||
#progressBarSkin(skin) {
|
||||
if(!skin.replace(/\s/g, '')) return [];
|
||||
let p = this.#cutPath(skin);
|
||||
return [`${p[0]}$bar${p[1]}`];
|
||||
}
|
||||
|
||||
#scrollBarSkin(skin) {
|
||||
if(!skin.replace(/\s/g, '')) return [];
|
||||
let p = this.#cutPath(skin);
|
||||
return [
|
||||
`${p[0]}$bar${p[1]}`,
|
||||
`${p[0]}$up${p[1]}`,
|
||||
`${p[0]}$down${p[1]}`
|
||||
];
|
||||
}
|
||||
|
||||
scanResource(uiView) {
|
||||
if(!uiView) return [];
|
||||
const resourceList = [];
|
||||
|
||||
resourceList.push(...this.#subSkin(uiView.props?.skin, uiView.type));
|
||||
resourceList.push(...this.#subSkin(uiView.props?.hScrollBarSkin, 'ScrollBar'));
|
||||
resourceList.push(...this.#subSkin(uiView.props?.vScrollBarSkin, 'ScrollBar'));
|
||||
|
||||
uiView.child?.forEach(child => {
|
||||
resourceList.push(...this.scanResource(child));
|
||||
});
|
||||
|
||||
return resourceList;
|
||||
}
|
||||
|
||||
get currentView() {
|
||||
return this.#currentView;
|
||||
}
|
||||
|
||||
get currentDialog() {
|
||||
return this.#dialogStack[this.#dialogStack.length -1];
|
||||
}
|
||||
|
||||
get theme() {
|
||||
return localStorage.getItem('theme');
|
||||
}
|
||||
set theme(value) {
|
||||
localStorage.setItem('theme', value);
|
||||
this.#stage.bgColor = this.#configs.bgColor;
|
||||
document?.querySelector?.('meta[name="theme-color"]')?.setAttribute?.('content', this.#configs.bgColor);
|
||||
}
|
||||
|
||||
get #pages() {
|
||||
return UIManager.theme(this.theme, 'pages');
|
||||
}
|
||||
get #popups() {
|
||||
return UIManager.theme(this.theme, 'popups');
|
||||
}
|
||||
get #configs() {
|
||||
return UIManager.theme(this.theme, 'configs');
|
||||
}
|
||||
get common() {
|
||||
return this.#configs.common;
|
||||
}
|
||||
gradeColor(grade) {
|
||||
return this.common.grade[grade];
|
||||
}
|
||||
gradeFilter(grade) {
|
||||
return this.common.filter[grade];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user