From 6eab8270b4d1d3c02c281c1fcdd349c859712fc8 Mon Sep 17 00:00:00 2001 From: Noy <59097122+noyyyy@users.noreply.github.com> Date: Thu, 17 Oct 2024 02:15:44 +0800 Subject: [PATCH] feat: next round loading --- packages/client/src/dojo/createSystemCalls.ts | 1 + .../src/ui/features/inventory/InvHero.tsx | 1 - .../src/ui/features/settle/SettleDialog.tsx | 235 +++++++++--------- 3 files changed, 125 insertions(+), 112 deletions(-) diff --git a/packages/client/src/dojo/createSystemCalls.ts b/packages/client/src/dojo/createSystemCalls.ts index d392826..71a12df 100644 --- a/packages/client/src/dojo/createSystemCalls.ts +++ b/packages/client/src/dojo/createSystemCalls.ts @@ -66,6 +66,7 @@ export function createSystemCalls( const nextRound = async (account: Account, choice: number) => { try { + // TODO: check when object received logDebug(`call next round, ${choice}`); return await client.home.nextRound({ account, choice }); } catch (e) { diff --git a/packages/client/src/ui/features/inventory/InvHero.tsx b/packages/client/src/ui/features/inventory/InvHero.tsx index cb89646..79af210 100644 --- a/packages/client/src/ui/features/inventory/InvHero.tsx +++ b/packages/client/src/ui/features/inventory/InvHero.tsx @@ -62,7 +62,6 @@ export const InvHero = ({ ]); useDrag(pieceAttr, dragRef, { - dragImage: { image: "/undefined" }, onDragStart: (e) => { if (pieceAttr?.isOverride) { e.preventDefault(); diff --git a/packages/client/src/ui/features/settle/SettleDialog.tsx b/packages/client/src/ui/features/settle/SettleDialog.tsx index 22e82da..98264a5 100644 --- a/packages/client/src/ui/features/settle/SettleDialog.tsx +++ b/packages/client/src/ui/features/settle/SettleDialog.tsx @@ -4,130 +4,143 @@ import { zeroEntity } from "../../../utils"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { cn, logDebug } from "../../lib/utils"; import { ChoiceList } from "./ChoiceList"; -import { useCallback, useMemo } from "react"; +import { useCallback, useMemo, useState } from "react"; import { ShowItem, UIStore, useUIStore } from "../../../store"; import { useHotkeys } from "react-hotkeys-hook"; import { GreenButton } from "../../components/GreenButton"; import useCountdown from "ahooks/lib/useCountDown"; import { useCountDown } from "ahooks"; +import { LoadingShade } from "../../components/LoadingShade"; export function SettleDialog() { - const { - systemCalls: { nextRound }, - account: { - account, - account: { address }, - playerEntity, - }, - clientComponents: { GameStatus, BattleLogs, Player, InningBattle }, - } = useDojo(); - - const setShow = useUIStore((state) => state.setShow); - const getShow = useUIStore((state: UIStore) => state.getShow); - - const status = useComponentValue(GameStatus, zeroEntity); - const player = useComponentValue(Player, playerEntity); - - const inningBattleEntity = getEntityIdFromKeys([ - BigInt(status?.currentMatch || 0), - BigInt(status?.currentRound || 0), - ]); - - const battleResult = useComponentValue(BattleLogs, inningBattleEntity); - - const inningBattle = useComponentValue(InningBattle, inningBattleEntity); - - useMemo(() => { - if (status?.status === 3) { - setShow(ShowItem.SettleDialog, true); - } else { - setShow(ShowItem.SettleDialog, false); - setShow(ShowItem.MakeChoice, false); + const { + systemCalls: { nextRound }, + account: { + account, + account: { address }, + playerEntity, + }, + clientComponents: { GameStatus, BattleLogs, Player, InningBattle }, + } = useDojo(); + + const setShow = useUIStore((state) => state.setShow); + const getShow = useUIStore((state: UIStore) => state.getShow); + + const status = useComponentValue(GameStatus, zeroEntity); + const player = useComponentValue(Player, playerEntity); + + const inningBattleEntity = getEntityIdFromKeys([ + BigInt(status?.currentMatch || 0), + BigInt(status?.currentRound || 0), + ]); + + const battleResult = useComponentValue(BattleLogs, inningBattleEntity); + + const inningBattle = useComponentValue(InningBattle, inningBattleEntity); + + useMemo(() => { + if (status?.status === 3) { + setShow(ShowItem.SettleDialog, true); + } else { + setShow(ShowItem.SettleDialog, false); + setShow(ShowItem.MakeChoice, false); + } + }, [status?.status, setShow]); + + const win = battleResult?.winner === BigInt(address); + + const text = win ? "VICTORY" : "LOSE"; + + const descText = win + ? "Oh, Adventurer, so you do have some skill after all. But don't celebrate too soon. The next beasts are fiercer. Do you dare to continue?" + : "You couldn't make it, Adventurer. Your strength isn't enough. Better leave now before you die. The beasts ahead are even more dangerous."; + + if (!getShow(ShowItem.SettleDialog)) { + return
; } - }, [status?.status, setShow]); - - const win = battleResult?.winner === BigInt(address); - - const text = win ? "VICTORY" : "LOSE"; - - const descText = win - ? "Oh, Adventurer, so you do have some skill after all. But don't celebrate too soon. The next beasts are fiercer. Do you dare to continue?" - : "You couldn't make it, Adventurer. Your strength isn't enough. Better leave now before you die. The beasts ahead are even more dangerous."; - - if (!getShow(ShowItem.SettleDialog)) { - return ; - } - - return ( -