This commit is contained in:
Alex 2024-05-12 09:22:49 +08:00
parent 65b0db1b48
commit 368adb80fa
8 changed files with 63 additions and 30 deletions

View file

@ -82,7 +82,7 @@ export class TrackWidget extends WidgetType {
const btnEl = document.createElement("button");
btnEl.classList.add("clickable-icon", "srt-track-btn");
btnEl.onclick = () => {
if (this.value === i + 1) {
if (this.value >= i + 1) {
this.value = i;
} else {
this.value = i + 1;

View file

@ -5,7 +5,7 @@
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: var(--size-4-4);
gap: var(--size-2-2);
white-space: nowrap;
.deck-size {

View file

@ -5,7 +5,7 @@
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: var(--size-4-4);
gap: var(--size-2-2);
}
.word-results {

View file

@ -1,4 +1,3 @@
import oracle from './oracle';
import adjectives from "./adjectives";
import adverbs from "./adverbs";
import nouns from "./nouns";
@ -13,7 +12,6 @@ import hairs from "./hairs";
import settlement from "./settlement";
export const dictionary = {
oracle,
adjectives,
adverbs,
nouns,

View file

@ -1,15 +0,0 @@
export default [
[
"extreme no",
"no",
"yes",
"no",
"yes",
"no",
"yes",
"no",
"yes",
"extreme yes",
],
["but", "", "", "", "", "and"],
];

56
src/utils/oracle.ts Normal file
View file

@ -0,0 +1,56 @@
import { random } from "./dice";
const FACTOR_CHANGE = 20;
const YES_NO_CHANCE = 50;
const AND_BUT_CHANCE = 16;
const EXTREME_CHANCE = 16;
export class Oracle {
factor = 0;
getAnswer(): string {
const yn = this.yesNo();
const ab = this.andBut();
const ex = this.extreme();
let result = `${ex} ${yn}`;
if (ab) result += `, ${ab}`;
return result.trim();
}
yesNo(): string {
if (this.roll(YES_NO_CHANCE + this.factor)) {
this.factor -= FACTOR_CHANGE;
if (this.factor <= 0) this.factor = 0;
return "yes";
} else {
this.factor += FACTOR_CHANGE;
return "no";
}
}
andBut(): string {
if (this.roll(AND_BUT_CHANCE)) {
if (this.roll(50)) {
return "and";
} else {
return "but";
}
} else {
return "";
}
}
extreme(): string {
if (this.roll(EXTREME_CHANCE)) {
return "extreme";
} else {
return "";
}
}
private roll(target: number): boolean {
return random(1, 100) <= target;
}
}

View file

@ -1,16 +1,10 @@
import { Oracle } from "./oracle";
import { dictionary } from "./dictionary";
import { randomFrom } from "./dice";
import { capitalize } from "./helpers";
const getOracle = () => {
const answer1 = randomFrom(dictionary.oracle[0]);
const answer2 = randomFrom(dictionary.oracle[1]);
if (answer2) {
return capitalize(`${answer1}, ${answer2}`);
} else {
return capitalize(answer1);
}
};
const oracle = new Oracle();
const getOracle = () => capitalize(oracle.getAnswer());
const getNoun = () => randomFrom(dictionary.nouns);
const getVerb = () => randomFrom(dictionary.verbs);

View file

@ -19,5 +19,5 @@
]
},
"include": ["src/**/*"],
"exclude": ["./dist/api.d.ts"]
"exclude": ["node_modules"]
}