Skip to content

Commit

Permalink
Frontend: use the step of 0.05 for buffs.
Browse files Browse the repository at this point in the history
  • Loading branch information
paveloom committed Jun 17, 2024
1 parent 751bd6a commit 024c527
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions frontend/src/components/Counter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ function toggleStopping() {
isStopping.value = !isStopping.value;
}
function switchBuff() {
const [buff, prevBuff] = state.switchBuff();
function nextBuff() {
const [buff, prevBuff] = state.nextBuff();
const difference = state.refs.targetDate.value - nowTime.value;
let distance = Math.abs(difference);
if (difference < 0) {
distance *= prevBuff;
distance /= buff;
distance = distance * prevBuff / buff;
state.refs.targetDate.value = nowTime.value - distance;
}
}
Expand All @@ -140,7 +139,7 @@ function switchBuff() {
<Button @click="startGame">
<PlayIcon />
</Button>
<BuffButton @click="switchBuff" />
<BuffButton @click="nextBuff" />
<Button
:disabled="state.refs.maxTime.value === MAX_MAX_TIME"
@click="increaseMaxTime"
Expand All @@ -162,7 +161,7 @@ function switchBuff() {
<BackwardIcon v-if="state.refs.isReverseOn.value" />
<ForwardIcon v-else />
</Button>
<BuffButton @click="switchBuff" />
<BuffButton @click="nextBuff" />
<Button @click="toggleStopping">
<StopIcon />
</Button>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { hoursToMilliseconds } from "@/utils";

export class State {
consts = {
availableBuffs: [1.00, 1.25, 1.50, 1.75, 2.00],
buffs: Array(1 / 0.05 + 1).fill(undefined).map((_, i) => 1 + Math.round(0.05 * i * 100) / 100),
};

refs = {
Expand All @@ -16,14 +16,14 @@ export class State {

computed = {
buff: computed(() => {
return this.consts.availableBuffs[this.refs.buffIndex.value]!;
return this.consts.buffs[this.refs.buffIndex.value]!;
}),
};

switchBuff(): [number, number] {
const prevBuff = this.consts.availableBuffs[this.refs.buffIndex.value]!;
this.refs.buffIndex.value = (this.refs.buffIndex.value + 1) % this.consts.availableBuffs.length;
const buff = this.consts.availableBuffs[this.refs.buffIndex.value]!;
nextBuff(): [number, number] {
const prevBuff = this.consts.buffs[this.refs.buffIndex.value]!;
this.refs.buffIndex.value = (this.refs.buffIndex.value + 1) % this.consts.buffs.length;
const buff = this.consts.buffs[this.refs.buffIndex.value]!;
return [buff, prevBuff];
}

Expand Down

0 comments on commit 024c527

Please sign in to comment.