diff --git a/src/app.js b/src/app.js
index 57f94d5..66ca813 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1,3 +1,5 @@
+import { max } from './functions/util.js';
+import { summary } from './functions/summary.js'
import Life from './life.js'
class App{
constructor(){
@@ -9,12 +11,16 @@ class App{
#talentSelected = new Set();
#totalMax=20;
#isEnd = false;
+ #selectedExtendTalent = null;
async initial() {
this.initPages();
this.switch('loading');
await this.#life.initial();
this.switch('index');
+ window.onerror = (event, source, lineno, colno, error) => {
+ this.hint(`[ERROR] at (${source}:${lineno}:${colno})\n\n${error?.stack||error||'unknow Error'}`);
+ }
}
initPages() {
@@ -58,20 +64,7 @@ class App{
// Talent
const createTalent = ({ grade, name, description }) => {
- const element = $(`
${name}(${description})`)
- switch(grade) {
- case 1:
- element.addClass('sprcial_blue');
- break;
- case 2:
- element.addClass('sprcial_purple');
- break;
- case 3:
- element.addClass('sprcial_orange');
- break;
- default: break;
- }
- return element;
+ return $(`${name}(${description})`)
};
talentPage
@@ -86,14 +79,14 @@ class App{
li.click(()=>{
if(li.hasClass('selected')) {
li.removeClass('selected')
- this.#talentSelected.delete(talent.id);
+ this.#talentSelected.delete(talent);
} else {
if(this.#talentSelected.size==3) {
this.hint('只能选3个天赋');
return;
}
li.addClass('selected');
- this.#talentSelected.add(talent.id);
+ this.#talentSelected.add(talent);
}
});
});
@@ -106,7 +99,7 @@ class App{
this.hint('请选择3个天赋');
return;
}
- this.#totalMax = 20 + this.#life.getTalentAllocationAddition(Array.from(this.#talentSelected));
+ this.#totalMax = 20 + this.#life.getTalentAllocationAddition(Array.from(this.#talentSelected).map(({id})=>id));
this.switch('property');
})
@@ -162,6 +155,18 @@ class App{
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};
}
@@ -186,9 +191,9 @@ class App{
const select = Math.floor(Math.random() * 4) % 4;
if(arr[select] - sub <0) continue;
arr[select] -= sub;
+ t -= sub;
break;
}
- t -= sub;
}
groups.CHR.set(arr[0]);
groups.INT.set(arr[1]);
@@ -198,13 +203,17 @@ class App{
propertyPage.find('#start')
.click(()=>{
+ if(total()!=this.#totalMax) {
+ this.hint(`你还有${this.#totalMax-total()}属性点没有分配完`);
+ return;
+ }
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),
+ TLT: Array.from(this.#talentSelected).map(({id})=>id),
});
this.switch('trajectory');
this.#pages.trajectory.born();
@@ -246,9 +255,35 @@ class App{
trajectoryPage.find('#summary')
.click(()=>{
-
+ this.switch('summary');
})
+ const summaryPage = $(`
+
+
人生总结
+
+ - 颜值:9级 美若天仙
+ - 智力:4级 智力一般
+ - 体质:1级 极度虚弱
+ - 家境:6级 小康之家
+ - 享年:3岁 早夭
+ - 快乐:3级 不太幸福的人生
+
+
天赋,你可以选一个,下辈子还能抽到
+
+
+
+ `);
+
+ summaryPage.find('#again')
+ .click(()=>{
+ this.times ++;
+ this.#life.talentExtend(this.#selectedExtendTalent);
+ this.switch('index');
+ });
+
this.#pages = {
loading: {
page: loadingPage,
@@ -259,28 +294,28 @@ class App{
btnRank: indexPage.find('#rank'),
btnRestart: indexPage.find('#restart'),
hint: indexPage.find('.hint'),
- cnt: indexPage.find('.cnt'),
+ cnt: indexPage.find('#cnt'),
clear: ()=>{
indexPage.find('.hint').hide();
const times = this.times;
const btnRank = indexPage.find('#rank');
- const cnt = indexPage.find('.cnt');
- if(times < 0) {
- btnRank.hide();
- cnt.hide();
+ const cnt = indexPage.find('#cnt');
+ if(times > 0) {
+ btnRank.show();
+ cnt.show();
+ cnt.text(`已重开${times}次`);
return;
}
- btnRank.show();
- cnt.show();
- cnt.text(`已重开${times}次`);
+ btnRank.hide();
+ cnt.hide();
},
},
talent: {
page: talentPage,
clear: ()=>{
- talentPage.find('ul.selectlist').children().remove();
+ talentPage.find('ul.selectlist').empty();
talentPage.find('#random').show();
this.#totalMax = 20;
},
@@ -294,7 +329,7 @@ class App{
trajectory: {
page: trajectoryPage,
clear: ()=>{
- trajectoryPage.find('#lifeTrajectory').children().remove();
+ trajectoryPage.find('#lifeTrajectory').empty();
trajectoryPage.find('#summary').hide();
this.#isEnd = false;
},
@@ -302,17 +337,80 @@ class App{
trajectoryPage.find('#lifeTrajectory').trigger("click");
}
},
+ summary: {
+ page: summaryPage,
+ clear: ()=>{
+ const judge = summaryPage.find('#judge');
+ const talents = summaryPage.find('#talents');
+ judge.empty();
+ talents.empty();
+ this.#talentSelected.forEach(talent=>{
+ 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');
+ }
+ });
+ });
+
+ const records = this.#life.getRecord();
+ const s = (type, func)=>{
+ const value = func(records.map(({[type]:v})=>v));
+ const { judge, grade } = summary(type, value);
+ return { judge, grade, value };
+ };
+ console.table(records);
+ console.debug(records);
+
+ judge.append([
+ (()=>{
+ const { judge, grade, value } = s('CHR', max);
+ return `颜值:${value} ${judge}`
+ })(),
+ (()=>{
+ const { judge, grade, value } = s('INT', max);
+ return `智力:${value} ${judge}`
+ })(),
+ (()=>{
+ const { judge, grade, value } = s('STR', max);
+ return `体质:${value} ${judge}`
+ })(),
+ (()=>{
+ const { judge, grade, value } = s('MNY', max);
+ return `家境:${value} ${judge}`
+ })(),
+ (()=>{
+ const { judge, grade, value } = s('AGE', max);
+ return `享年:${value} ${judge}`
+ })(),
+ (()=>{
+ const { judge, grade, value } = s('SPR', max);
+ return `快乐:${value} ${judge}`
+ })(),
+ ].join(''));
+ }
+ }
}
}
switch(page) {
const p = this.#pages[page];
if(!p) return;
- $('#main').remove();
+ $('#main').detach();
p.clear();
p.page.appendTo('body');
}
+
+
hint(str) {
alert(str);
}
@@ -322,4 +420,5 @@ class App{
}
-export default App;
\ No newline at end of file
+export default App;
+
diff --git a/src/functions/summary.js b/src/functions/summary.js
index 0f58a30..3122ea7 100644
--- a/src/functions/summary.js
+++ b/src/functions/summary.js
@@ -73,4 +73,6 @@ function summary(type, value) {
const {min, judge, grade} = data[type][length];
if(min==void 0 || value >= min) return {judge, grade};
}
-}
\ No newline at end of file
+}
+
+export { summary };
\ No newline at end of file
diff --git a/src/functions/util.js b/src/functions/util.js
index bfbb061..b1f7489 100644
--- a/src/functions/util.js
+++ b/src/functions/util.js
@@ -9,4 +9,23 @@ function clone(value) {
}
}
-export { clone };
\ No newline at end of file
+function max(...arr) {
+ return Math.max(...arr.flat());
+}
+
+function min(...arr) {
+ return Math.min(...arr.flat());
+}
+
+function sum(...arr) {
+ let s = 0;
+ arr.flat().forEach(v=>s+=v);
+ return s;
+}
+
+function average(...arr) {
+ const s = sum(...arr);
+ return s / arr.flat().length;
+}
+
+export { clone, max, min, sum, average };
\ No newline at end of file
diff --git a/src/life.js b/src/life.js
index 0536854..6420d08 100644
--- a/src/life.js
+++ b/src/life.js
@@ -99,7 +99,11 @@ class Life {
}
talentRandom() {
- return this.#talent.talentRandom();
+ return this.#talent.talentRandom(localStorage.extendTalent);
+ }
+
+ talentExtend(talentId) {
+ localStorage.extendTalent = talentId;
}
getRecord() {
diff --git a/src/talent.js b/src/talent.js
index 8f41de2..b16b1e0 100644
--- a/src/talent.js
+++ b/src/talent.js
@@ -29,17 +29,22 @@ class Talent {
return { grade, name, description };
}
- talentRandom() {
+ talentRandom(include) {
// 1000, 100, 10, 1
const talentList = {};
for(const talentId in this.#talents) {
const { id, grade, name, description } = this.#talents[talentId];
+ if(id == include) {
+ include = { grade, name, description, id };
+ continue;
+ }
if(!talentList[grade]) talentList[grade] = [{ grade, name, description, id }];
else talentList[grade].push({ grade, name, description, id });
}
return new Array(10)
- .fill(1).map(()=>{
+ .fill(1).map((i)=>{
+ if(!i && include) return include;
const gradeRandom = Math.random();
let grade;
if(gradeRandom>=0.111) grade = 0;
diff --git a/view/index.html b/view/index.html
index 5fa600f..a7d3ca6 100644
--- a/view/index.html
+++ b/view/index.html
@@ -14,8 +14,6 @@