mirror of
https://github.com/Pandipipas/scoreko-dev.git
synced 2026-06-06 03:32:06 +00:00
Merge pull request #18 from Pandipipas/actualizar-scoreboard-en-tiempo-real
Save dashboard updates to NodeCG replicants for realtime graphics
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import type { Ref } from 'vue';
|
|
||||||
import { playersReplicant } from '../../../browser_shared/replicants';
|
import { playersReplicant } from '../../../browser_shared/replicants';
|
||||||
import type { Schemas } from '../../../types';
|
import type { Schemas } from '../../../types';
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ const writeStorage = (value: PlayersMap) => {
|
|||||||
|
|
||||||
export const usePlayersStore = defineStore('players', () => {
|
export const usePlayersStore = defineStore('players', () => {
|
||||||
const players = ref<PlayersMap>({});
|
const players = ref<PlayersMap>({});
|
||||||
const replicantRef = playersReplicant?.data as unknown as Ref<PlayersMap | undefined> | undefined;
|
const replicant = playersReplicant;
|
||||||
const storageSnapshot = readStorage();
|
const storageSnapshot = readStorage();
|
||||||
if (storageSnapshot) {
|
if (storageSnapshot) {
|
||||||
players.value = storageSnapshot;
|
players.value = storageSnapshot;
|
||||||
@@ -75,7 +74,7 @@ export const usePlayersStore = defineStore('players', () => {
|
|||||||
const isApplyingReplicant = ref(false);
|
const isApplyingReplicant = ref(false);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => replicantRef?.value,
|
() => replicant?.data,
|
||||||
(value) => {
|
(value) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return;
|
return;
|
||||||
@@ -92,12 +91,13 @@ export const usePlayersStore = defineStore('players', () => {
|
|||||||
players,
|
players,
|
||||||
(value) => {
|
(value) => {
|
||||||
writeStorage(value);
|
writeStorage(value);
|
||||||
if (isApplyingReplicant.value || !replicantRef) {
|
if (isApplyingReplicant.value || !replicant) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
replicantRef.value = normalizePlayers(value);
|
replicant.data = normalizePlayers(value);
|
||||||
|
replicant.save();
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true, flush: 'sync' }
|
||||||
);
|
);
|
||||||
|
|
||||||
const setPlayers = (value: PlayersMap) => {
|
const setPlayers = (value: PlayersMap) => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import type { Ref } from 'vue';
|
|
||||||
import { scoreboardReplicant } from '../../../browser_shared/replicants';
|
import { scoreboardReplicant } from '../../../browser_shared/replicants';
|
||||||
import type { Schemas } from '../../../types';
|
import type { Schemas } from '../../../types';
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ const writeStorage = (value: Scoreboard) => {
|
|||||||
|
|
||||||
export const useScoreboardStore = defineStore('scoreboard', () => {
|
export const useScoreboardStore = defineStore('scoreboard', () => {
|
||||||
const scoreboard = ref<Scoreboard>({ ...defaultScoreboard });
|
const scoreboard = ref<Scoreboard>({ ...defaultScoreboard });
|
||||||
const replicantRef = scoreboardReplicant?.data as unknown as Ref<Scoreboard | undefined> | undefined;
|
const replicant = scoreboardReplicant;
|
||||||
const storageSnapshot = readStorage();
|
const storageSnapshot = readStorage();
|
||||||
if (storageSnapshot) {
|
if (storageSnapshot) {
|
||||||
scoreboard.value = storageSnapshot;
|
scoreboard.value = storageSnapshot;
|
||||||
@@ -69,7 +68,7 @@ export const useScoreboardStore = defineStore('scoreboard', () => {
|
|||||||
const isApplyingReplicant = ref(false);
|
const isApplyingReplicant = ref(false);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => replicantRef?.value,
|
() => replicant?.data,
|
||||||
(value) => {
|
(value) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return;
|
return;
|
||||||
@@ -86,10 +85,11 @@ export const useScoreboardStore = defineStore('scoreboard', () => {
|
|||||||
scoreboard,
|
scoreboard,
|
||||||
(value) => {
|
(value) => {
|
||||||
writeStorage(value);
|
writeStorage(value);
|
||||||
if (isApplyingReplicant.value || !replicantRef) {
|
if (isApplyingReplicant.value || !replicant) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
replicantRef.value = normalizeScoreboard(value);
|
replicant.data = normalizeScoreboard(value);
|
||||||
|
replicant.save();
|
||||||
},
|
},
|
||||||
{ deep: true, flush: 'sync' }
|
{ deep: true, flush: 'sync' }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useHead } from '@unhead/vue';
|
import { useHead } from '@unhead/vue';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import type { Ref } from 'vue';
|
|
||||||
import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants';
|
import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants';
|
||||||
import type { Schemas } from '../../types';
|
import type { Schemas } from '../../types';
|
||||||
|
|
||||||
@@ -17,11 +16,8 @@ const defaultScoreboard: Schemas.Scoreboard = {
|
|||||||
round: '',
|
round: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const playersData = playersReplicant?.data as unknown as Ref<Schemas.Players | undefined> | undefined;
|
const players = computed<Schemas.Players>(() => playersReplicant?.data ?? {});
|
||||||
const scoreboardData = scoreboardReplicant?.data as unknown as Ref<Schemas.Scoreboard | undefined> | undefined;
|
const scoreboard = computed<Schemas.Scoreboard>(() => scoreboardReplicant?.data ?? defaultScoreboard);
|
||||||
|
|
||||||
const players = computed<Schemas.Players>(() => playersData?.value ?? {});
|
|
||||||
const scoreboard = computed<Schemas.Scoreboard>(() => scoreboardData?.value ?? defaultScoreboard);
|
|
||||||
|
|
||||||
const leftName = computed(() => {
|
const leftName = computed(() => {
|
||||||
if (scoreboard.value.leftNameOverride) {
|
if (scoreboard.value.leftNameOverride) {
|
||||||
|
|||||||
Reference in New Issue
Block a user