From 368adb80fa79d16507ea37e06f2e6bbd96d2c818 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 May 2024 09:22:49 +0800 Subject: [PATCH] Update --- src/extension/track.ts | 2 +- src/styles/deck.css | 2 +- src/styles/word.css | 2 +- src/utils/dictionary/index.ts | 2 -- src/utils/dictionary/oracle.ts | 15 --------- src/utils/oracle.ts | 56 ++++++++++++++++++++++++++++++++++ src/utils/word.ts | 12 ++------ tsconfig.json | 2 +- 8 files changed, 63 insertions(+), 30 deletions(-) delete mode 100644 src/utils/dictionary/oracle.ts create mode 100644 src/utils/oracle.ts diff --git a/src/extension/track.ts b/src/extension/track.ts index 6453a5c..171c07a 100644 --- a/src/extension/track.ts +++ b/src/extension/track.ts @@ -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; diff --git a/src/styles/deck.css b/src/styles/deck.css index da6ab79..27027ac 100644 --- a/src/styles/deck.css +++ b/src/styles/deck.css @@ -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 { diff --git a/src/styles/word.css b/src/styles/word.css index 16e9bc8..b6609e4 100644 --- a/src/styles/word.css +++ b/src/styles/word.css @@ -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 { diff --git a/src/utils/dictionary/index.ts b/src/utils/dictionary/index.ts index 3248f22..b35816c 100644 --- a/src/utils/dictionary/index.ts +++ b/src/utils/dictionary/index.ts @@ -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, diff --git a/src/utils/dictionary/oracle.ts b/src/utils/dictionary/oracle.ts deleted file mode 100644 index 6035574..0000000 --- a/src/utils/dictionary/oracle.ts +++ /dev/null @@ -1,15 +0,0 @@ -export default [ - [ - "extreme no", - "no", - "yes", - "no", - "yes", - "no", - "yes", - "no", - "yes", - "extreme yes", - ], - ["but", "", "", "", "", "and"], -]; diff --git a/src/utils/oracle.ts b/src/utils/oracle.ts new file mode 100644 index 0000000..46e1be7 --- /dev/null +++ b/src/utils/oracle.ts @@ -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; + } +} diff --git a/src/utils/word.ts b/src/utils/word.ts index 71d240b..3a39a86 100644 --- a/src/utils/word.ts +++ b/src/utils/word.ts @@ -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); diff --git a/tsconfig.json b/tsconfig.json index 9bf6699..2b560d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,5 +19,5 @@ ] }, "include": ["src/**/*"], - "exclude": ["./dist/api.d.ts"] + "exclude": ["node_modules"] }