feat: add trainer sound mode and manual danger ratings

This commit is contained in:
nyan404 committed 2026-11-22 16:58:47 +03:00
1 parent 9be0bb48c8
commit ad8e2d1438
13 files changed
+466 -58

No files matched your search

+15 -4
View File
@@ -61,6 +61,7 @@ export class Training {
#field;
#opened = new Set();
#marks = new Set();
#ratings = new Map();
#position = START;
#status = 'ready';
#hit = null;
@@ -115,22 +116,32 @@ export class Training {
this.#win();
return {code: marked ? 'marked' : 'unmarked', id};
}
rate(id, rating) {
const rejected = this.#guard(id);
if (rejected) return rejected;
if (rating !== null && (!Number.isInteger(rating) || rating < 0 || rating > 7)) return {code: 'invalid-level'};
if ((this.#ratings.get(id) ?? null) === rating) return {code: 'unchanged'};
if (rating === null) this.#ratings.delete(id); else this.#ratings.set(id, rating);
const code = rating === null ? 'unrated' : 'rated';
this.#history.push({type: code, id, rating});
return {code, id, rating};
}
clearMarks() {
if (this.#finished()) return {code: 'finished'};
if (!this.#marks.size) return {code: 'empty'};
this.#marks.clear(); this.#history.push({type: 'cleared'});
if (!this.#marks.size && !this.#ratings.size) return {code: 'empty'};
this.#marks.clear(); this.#ratings.clear(); this.#history.push({type: 'cleared'});
return {code: 'cleared'};
}
view() {
const ended = this.#finished();
return {
options: {...this.#options}, start: START, exit: this.#field.exit, status: this.#status, position: this.#position, hit: this.#hit,
hazards: this.#field.hazards.size, marks: this.#marks.size, opened: this.#opened.size,
hazards: this.#field.hazards.size, marks: this.#marks.size, ratings: this.#ratings.size, opened: this.#opened.size,
safe: ROWS * COLS - 2 - this.#field.hazards.size,
history: this.#history.map(item => ({...item})),
cells: Array.from({length: ROWS * COLS}, (_,id) => ({
id, entrance: id === START, exit: id === this.#field.exit, transition: this.#transition(id), base: this.#field.base.includes(id),
opened: this.#opened.has(id), marked: this.#marks.has(id),
opened: this.#opened.has(id), marked: this.#marks.has(id), rating: this.#ratings.get(id) ?? null,
available: !ended && this.#available(id),
value: this.#opened.has(id) || ended ? this.#field.values[id] : null,
...(ended ? {hazard: this.#field.hazards.has(id), wrong: this.#marks.has(id) && !this.#field.hazards.has(id)} : {}),