sync the timers with sorting to avoid weird desyncs between them

This commit is contained in:
2025-12-20 21:21:09 +01:00
parent ea74bbea90
commit 9e5580836c
4 changed files with 25 additions and 7 deletions
+1 -1
View File
@@ -91,7 +91,7 @@ export default defineComponent({
this.eorzeaTime = new EorzeaTime();
setInterval(() => {
this.eorzeaTime = new EorzeaTime();
}, 500);
}, 1000);
const itemData: Response | null = await fetch("/data/items.json")
.catch((): null => {
+22 -2
View File
@@ -8,7 +8,7 @@
>
<div class="timer">
{{
prettyTimer(gatheringNode.getSecondsToNextActiveTime(eorzeaTime))
prettyTimer(secondsToNextActiveTime)
}}
</div>
</div>
@@ -19,7 +19,7 @@
Active
<div class="countdown">
{{
prettyTimer(gatheringNode.getSecondsToNextInactiveTime(eorzeaTime))
prettyTimer(secondsToNextInactiveTime)
}}
</div>
</div>
@@ -69,6 +69,12 @@ import Zone from "@/entities/Zone";
export default defineComponent({
name: "GatheringNode",
data() {
return {
secondsToNextInactiveTime: 0 as number,
secondsToNextActiveTime: 0 as number,
};
},
props: {
gatheringNode: {
type: Object as PropType<Node>,
@@ -83,13 +89,27 @@ export default defineComponent({
required: true
},
},
watch: {
eorzeaTime: {
handler() {
this.calculateTimers()
}
}
},
methods: {
prettyTimer(seconds: number): string {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
},
calculateTimers() {
this.secondsToNextInactiveTime = this.gatheringNode.getSecondsToNextInactiveTime(this.eorzeaTime);
this.secondsToNextActiveTime = this.gatheringNode.getSecondsToNextActiveTime(this.eorzeaTime);
}
},
mounted() {
this.calculateTimers();
}
});
</script>
+1 -3
View File
@@ -49,9 +49,7 @@ export default defineComponent(
}
},
eorzeaTime: {
handler(newValue, oldValue) {
if (oldValue === undefined) return;
if (newValue?.getMinutes() === oldValue?.getMinutes()) return;
handler() {
this.sortListByTime();
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ export default class TimeRange {
public isWithinTimeFrame(hour: number, minute: number): boolean {
return (
this.from[0] < hour || this.from[0] == hour && this.from[1] <= minute)
&& (hour < this.to[0] || hour == this.to[0] && minute <= this.to[1]
&& (hour < this.to[0] || hour == this.to[0] && minute < this.to[1]
);
}