From 6d96189b40c9c42fdaf943f09984f14ab07a0425 Mon Sep 17 00:00:00 2001 From: Loaf <90423308+ponderingdemocritus@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:37:28 +1100 Subject: [PATCH 1/9] realm trade (#2539) * realm trade * component work * ad * updates * checkbox * check * Handle multicall * fix dyn amount * donk * donk * Add loading state * transfer info * donkeys * transfer * Styling + UX improvements --------- Co-authored-by: Bob --- client/package.json | 3 +- .../ui/components/resources/ResourceChip.tsx | 105 +++---- .../components/resources/realm-transfer.tsx | 265 ++++++++++++++++++ client/src/ui/elements/Switch.tsx | 27 ++ pnpm-lock.yaml | 29 +- 5 files changed, 368 insertions(+), 61 deletions(-) create mode 100644 client/src/ui/components/resources/realm-transfer.tsx create mode 100644 client/src/ui/elements/Switch.tsx diff --git a/client/package.json b/client/package.json index bc711ec33..e81b9c38c 100644 --- a/client/package.json +++ b/client/package.json @@ -20,17 +20,18 @@ "@cartridge/connector": "0.5.5", "@cartridge/controller": "0.5.5", "@dojoengine/core": "1.0.3-alpha.2", - "@dojoengine/torii-wasm": "1.0.3-alpha.2", "@dojoengine/create-burner": "1.0.3-alpha.2", "@dojoengine/react": "1.0.3-alpha.2", "@dojoengine/recs": "^2.0.13", "@dojoengine/state": "1.0.3-alpha.2", "@dojoengine/torii-client": "1.0.3-alpha.2", + "@dojoengine/torii-wasm": "1.0.3-alpha.2", "@dojoengine/utils": "1.0.3-alpha.2", "@headlessui/react": "^1.7.18", "@latticexyz/utils": "^2.0.0-next.12", "@radix-ui/react-collapsible": "^1.1.1", "@radix-ui/react-select": "^2.0.0", + "@radix-ui/react-switch": "^1.1.1", "@radix-ui/react-tabs": "^1.1.0", "@react-three/drei": "^9.101.0", "@react-three/fiber": "^8.16.1", diff --git a/client/src/ui/components/resources/ResourceChip.tsx b/client/src/ui/components/resources/ResourceChip.tsx index 0bc72baa7..7cddae57f 100644 --- a/client/src/ui/components/resources/ResourceChip.tsx +++ b/client/src/ui/components/resources/ResourceChip.tsx @@ -6,6 +6,7 @@ import useUIStore from "@/hooks/store/useUIStore"; import { useCallback, useEffect, useMemo, useState } from "react"; import { ResourceIcon } from "../../elements/ResourceIcon"; import { currencyFormat, currencyIntlFormat, formatTime, gramToKg, TimeFormat } from "../../utils/utils"; +import { RealmTransfer } from "./realm-transfer"; export const ResourceChip = ({ isLabor = false, @@ -148,56 +149,66 @@ export const ResourceChip = ({ setShowPerHour(true); }, [setTooltip]); + const togglePopup = useUIStore((state) => state.togglePopup); + return ( -
- {icon} -
-
{currencyFormat(balance ? Number(balance) : 0, 0)}
- -
- {timeUntilValueReached !== 0 - ? formatTime(timeUntilValueReached, TimeFormat.D | TimeFormat.H | TimeFormat.M) - : ""} -
+ <> + +
{ + togglePopup(resourceId.toString()); + }} + > + {icon} +
+
{currencyFormat(balance ? Number(balance) : 0, 0)}
+ +
+ {timeUntilValueReached !== 0 + ? formatTime(timeUntilValueReached, TimeFormat.D | TimeFormat.H | TimeFormat.M) + : ""} +
- {isProducingOrConsuming ? ( -
-
- {parseFloat(netRate.toString()) < 0 ? "" : "+"} - {showPerHour ? `${currencyIntlFormat(netRate * 3.6, 2)}/h` : `${currencyIntlFormat(netRate / 1000, 2)}/s`} + {isProducingOrConsuming ? ( +
+
+ {parseFloat(netRate.toString()) < 0 ? "" : "+"} + {showPerHour + ? `${currencyIntlFormat(netRate * 3.6, 2)}/h` + : `${currencyIntlFormat(netRate / 1000, 2)}/s`} +
-
- ) : ( -
{ - setTooltip({ - position: "top", - content: ( - <> - {isConsumingInputsWithoutOutput - ? "Production has stopped because inputs have been depleted" - : "Production has stopped because the max balance has been reached"} - - ), - }); - }} - onMouseLeave={() => { - setTooltip(null); - }} - className="self-center px-2 col-span-3 mx-auto" - > - {isConsumingInputsWithoutOutput || reachedMaxCap ? "⚠️" : ""} -
- )} + ) : ( +
{ + setTooltip({ + position: "top", + content: ( + <> + {isConsumingInputsWithoutOutput + ? "Production has stopped because inputs have been depleted" + : "Production has stopped because the max balance has been reached"} + + ), + }); + }} + onMouseLeave={() => { + setTooltip(null); + }} + className="self-center px-2 col-span-3 mx-auto" + > + {isConsumingInputsWithoutOutput || reachedMaxCap ? "⚠️" : ""} +
+ )} +
-
+ ); }; diff --git a/client/src/ui/components/resources/realm-transfer.tsx b/client/src/ui/components/resources/realm-transfer.tsx new file mode 100644 index 000000000..9999ee307 --- /dev/null +++ b/client/src/ui/components/resources/realm-transfer.tsx @@ -0,0 +1,265 @@ +import { useDojo } from "@/hooks/context/DojoContext"; +import { PlayerStructure, useEntities } from "@/hooks/helpers/useEntities"; +import { useResourceManager } from "@/hooks/helpers/useResources"; +import useUIStore from "@/hooks/store/useUIStore"; +import Button from "@/ui/elements/Button"; +import { NumberInput } from "@/ui/elements/NumberInput"; +import { ResourceIcon } from "@/ui/elements/ResourceIcon"; +import { calculateDonkeysNeeded, currencyFormat, getTotalResourceWeight, multiplyByPrecision } from "@/ui/utils/utils"; +import { ResourcesIds, findResourceById } from "@bibliothecadao/eternum"; +import { Dispatch, SetStateAction, memo, useCallback, useEffect, useMemo, useState } from "react"; + +import { ID } from "@bibliothecadao/eternum"; +import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; +import { num } from "starknet"; +import { OSWindow } from "../navigation/OSWindow"; + +type transferCall = { + structureId: ID; + sender_entity_id: num.BigNumberish; + recipient_entity_id: num.BigNumberish; + resources: num.BigNumberish[]; + realmName: string; +}; + +export const RealmTransfer = memo( + ({ resource, balance, tick }: { resource: ResourcesIds; balance: number; tick: number }) => { + const { + setup: { + systemCalls: { send_resources_multiple }, + }, + account: { account }, + } = useDojo(); + const togglePopup = useUIStore((state) => state.togglePopup); + + const isOpen = useUIStore((state) => state.isPopupOpen(resource.toString())); + const selectedStructureEntityId = useUIStore((state) => state.structureEntityId); + + const { playerStructures } = useEntities(); + + const [isLoading, setIsLoading] = useState(false); + const [calls, setCalls] = useState([]); + + const [type, setType] = useState<"send" | "receive">("send"); + + const [resourceWeight, setResourceWeight] = useState(0); + + const neededDonkeys = useMemo(() => calculateDonkeysNeeded(resourceWeight), [resourceWeight]); + + useEffect(() => { + const resources = calls.map((call) => { + return { + resourceId: Number(call.resources[0]), + amount: Number(call.resources[1]), + }; + }); + const totalWeight = getTotalResourceWeight(resources); + const multipliedWeight = multiplyByPrecision(totalWeight); + + setResourceWeight(multipliedWeight); + }, [calls]); + + const handleTransfer = useCallback(() => { + setIsLoading(true); + const cleanedCalls = calls.map(({ sender_entity_id, recipient_entity_id, resources }) => ({ + sender_entity_id, + recipient_entity_id, + resources, + })); + + send_resources_multiple({ + signer: account, + calls: cleanedCalls, + }).finally(() => { + setIsLoading(false); + }); + }, [calls]); + + return ( + togglePopup(resource.toString())} + show={isOpen} + > +
+ +
+
+
+ +
{currencyFormat(balance ? Number(balance) : 0, 0)}
+
+ + {playerStructures().map((structure) => ( + + ))} + +
+
+ Transfers {calls.length} | + {" "} + {neededDonkeys.toString()} +
+ +
+ {calls.map((call, index) => ( +
+
{call.realmName}
+
+ {call.resources[1].toLocaleString()} +
+ +
+ ))} +
+
+ +
+ +
+
+
+ ); + }, +); + +export const RealmTransferBalance = memo( + ({ + resource, + structure, + selectedStructureEntityId, + add, + tick, + type, + }: { + resource: ResourcesIds; + structure: PlayerStructure; + selectedStructureEntityId: number; + add: Dispatch>; + tick: number; + type: "send" | "receive"; + }) => { + const [input, setInput] = useState(0); + + const resourceManager = useResourceManager(structure.entity_id, resource); + const donkeyManager = useResourceManager(structure.entity_id, ResourcesIds.Donkey); + + const getBalance = useCallback(() => { + return resourceManager.balance(tick); + }, [resourceManager, tick]); + + const getDonkeyBalance = useCallback(() => { + return donkeyManager.balance(tick); + }, [donkeyManager, tick]); + + const [resourceWeight, setResourceWeight] = useState(0); + + useEffect(() => { + const totalWeight = getTotalResourceWeight([{ resourceId: resource, amount: input }]); + const multipliedWeight = multiplyByPrecision(totalWeight); + + setResourceWeight(multipliedWeight); + }, [input]); + + const neededDonkeys = useMemo(() => { + if (type === "receive") { + return calculateDonkeysNeeded(resourceWeight); + } + return 0; + }, [resourceWeight]); + + const canCarry = useMemo(() => { + return getDonkeyBalance() >= neededDonkeys; + }, [getDonkeyBalance, neededDonkeys]); + + if (structure.entity_id === selectedStructureEntityId) { + return; + } + + return ( +
+
+
+
{structure.name}
+
{currencyFormat(getBalance() ? Number(getBalance()) : 0, 0)}
+
+ + { + setInput(amount); + add((prev) => { + const existingIndex = prev.findIndex((call) => call.structureId === structure.entity_id); + + if (amount === 0) { + return prev.filter((_, i) => i !== existingIndex); + } + + const newCall = { + structureId: structure.entity_id, + sender_entity_id: type === "send" ? selectedStructureEntityId : structure.entity_id, + recipient_entity_id: type === "send" ? structure.entity_id : selectedStructureEntityId, + resources: [resource, amount], + realmName: structure.name, + }; + + return existingIndex === -1 + ? [...prev, newCall] + : [...prev.slice(0, existingIndex), newCall, ...prev.slice(existingIndex + 1)]; + }); + }} + /> +
+
+
+
getDonkeyBalance() || getDonkeyBalance() === 0 ? "text-red" : "text-green" + }`} + > + {neededDonkeys.toLocaleString()} 🔥🫏 [{getDonkeyBalance().toLocaleString()}] +
+
+
+
+ ); + }, +); diff --git a/client/src/ui/elements/Switch.tsx b/client/src/ui/elements/Switch.tsx new file mode 100644 index 000000000..e3ea99498 --- /dev/null +++ b/client/src/ui/elements/Switch.tsx @@ -0,0 +1,27 @@ +import * as SwitchPrimitives from "@radix-ui/react-switch"; +import * as React from "react"; + +import { cn } from "./lib/utils"; + +const Switch = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)); +Switch.displayName = SwitchPrimitives.Root.displayName; + +export { Switch }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b2507c2d..53e3a5c7c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -144,13 +144,13 @@ importers: version: 1.0.3-alpha.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) '@dojoengine/react': specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) + version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/recs': specifier: ^2.0.13 version: 2.0.13(typescript@5.7.2)(zod@3.24.1) '@dojoengine/state': specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + version: 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': specifier: 1.0.3-alpha.2 version: 1.0.3-alpha.2 @@ -172,6 +172,9 @@ importers: '@radix-ui/react-select': specifier: ^2.0.0 version: 2.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-switch': + specifier: ^1.1.1 + version: 1.1.1(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@radix-ui/react-tabs': specifier: ^1.1.0 version: 1.1.1(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -282,7 +285,7 @@ importers: version: 0.20.5(@vite-pwa/assets-generator@0.2.6)(vite@5.4.11(@types/node@20.17.10)(terser@5.37.0))(workbox-build@7.3.0(@types/babel__core@7.20.5))(workbox-window@7.3.0) vitest-canvas-mock: specifier: ^0.3.3 - version: 0.3.3(vitest@2.1.8) + version: 0.3.3(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0)) wouter: specifier: ^2.12.1 version: 2.12.1(react@18.3.1) @@ -322,7 +325,7 @@ importers: version: 4.3.4(vite@5.4.11(@types/node@20.17.10)(terser@5.37.0)) '@vitest/coverage-v8': specifier: ^2.0.5 - version: 2.1.8(vitest@2.1.8) + version: 2.1.8(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0)) '@vitest/ui': specifier: ^2.0.1 version: 2.1.8(vitest@2.1.8) @@ -434,13 +437,13 @@ importers: version: 1.0.3-alpha.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) '@dojoengine/react': specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) + version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/recs': specifier: ^2.0.13 version: 2.0.13(typescript@5.7.2)(zod@3.24.1) '@dojoengine/state': specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + version: 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': specifier: 1.0.3-alpha.2 version: 1.0.3-alpha.2 @@ -10681,10 +10684,10 @@ snapshots: - typescript - utf-8-validate - '@dojoengine/react@1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1)': + '@dojoengine/react@1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1)': dependencies: '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) - '@dojoengine/state': 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + '@dojoengine/state': 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': 1.0.3-alpha.2 '@dojoengine/utils': 1.0.3-alpha.2(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1) '@latticexyz/utils': 2.2.14 @@ -10743,12 +10746,12 @@ snapshots: - utf-8-validate - zod - '@dojoengine/state@1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1)': + '@dojoengine/state@1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1)': dependencies: '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': 1.0.3-alpha.2 starknet: 6.11.0(encoding@0.1.13) - vitest: 1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0) + vitest: 1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(terser@5.37.0) transitivePeerDependencies: - '@edge-runtime/vm' - '@types/node' @@ -14167,7 +14170,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@vitest/coverage-v8@2.1.8(vitest@2.1.8)': + '@vitest/coverage-v8@2.1.8(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 @@ -19949,12 +19952,12 @@ snapshots: tsx: 4.19.2 yaml: 2.6.1 - vitest-canvas-mock@0.3.3(vitest@2.1.8): + vitest-canvas-mock@0.3.3(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0)): dependencies: jest-canvas-mock: 2.5.2 vitest: 2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0) - vitest@1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0): + vitest@1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(terser@5.37.0): dependencies: '@vitest/expect': 1.6.0 '@vitest/runner': 1.6.0 From d42f2eef029d978b7527d116591a4dcb038de710 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 16 Dec 2024 20:17:11 +0100 Subject: [PATCH 2/9] Setup --- client/src/dojo/queries.ts | 78 +++++++++++++++++++++++++++++++++ client/src/dojo/setup.ts | 57 ++++++++++++++++++++++-- client/src/main.tsx | 3 ++ client/src/ui/layouts/World.tsx | 27 +++++++++++- 4 files changed, 160 insertions(+), 5 deletions(-) diff --git a/client/src/dojo/queries.ts b/client/src/dojo/queries.ts index 5d3e3a50f..f0bb950a8 100644 --- a/client/src/dojo/queries.ts +++ b/client/src/dojo/queries.ts @@ -20,6 +20,7 @@ export const getEntities = async ( let continueFetching = true; while (continueFetching) { + const start = performance.now(); const entities = await client.getEntities({ limit, offset, @@ -29,6 +30,8 @@ export const getEntities = async ( }); setEntities(entities, components); + const end = performance.now(); + console.log("GetEntitiesEnd", end - start); if (Object.keys(entities).length < limit) { continueFetching = false; @@ -38,12 +41,82 @@ export const getEntities = async ( } }; +export const syncPosition = async ( + client: ToriiClient, + components: Component[], + entityID: string, +) => { + await getEntities( + client, + { + Keys: { + keys: [entityID], + pattern_matching: "FixedLen" as PatternMatching, + models: ["s0_eternum-Position"], + }, + }, + components, + 30_000, + false, + ); +}; +export const syncBuildingQty = async ( + client: ToriiClient, + components: Component[], + entityID: string, +) => { + await getEntities( + client, + { + Keys: { + keys: [entityID, undefined], + pattern_matching: "FixedLen" as PatternMatching, + models: ["s0_eternum-BuildingQuantityv2"], + }, + }, + components, + 30_000, + false, + ); +}; + +export const addToSubscriptionBuildingQty = async ( + client: ToriiClient, + components: Component[], + entityID: string[], +) => { + const start = performance.now(); + await getEntities( + client, + { + Composite: { + operator: "Or", + clauses: [ + ...entityID.map((id) => ({ + Keys: { + keys: [id, undefined], + pattern_matching: "VariableLen" as PatternMatching, + models: ["s0_eternum-BuildingQuantityv2"], + }, + })), + ], + }, + }, + components, + 30_000, + false, + ); + const end = performance.now(); + console.log("AddToSubscription Building qty", end - start); +}; + export const addToSubscription = async ( client: ToriiClient, components: Component[], entityID: string[], position?: { x: number; y: number }[], ) => { + const start = performance.now(); await getEntities( client, { @@ -73,12 +146,15 @@ export const addToSubscription = async ( 30_000, false, ); + const end = performance.now(); + console.log("AddToSubscriptionEnd", end - start); }; export const addMarketSubscription = async ( client: ToriiClient, components: Component[], ) => { + const start = performance.now(); await getEntities( client, { @@ -92,4 +168,6 @@ export const addMarketSubscription = async ( 30_000, false, ); + const end = performance.now(); + console.log("MarketEnd", end - start); }; diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index 27c5d6767..3de5ee7b0 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -1,6 +1,7 @@ import { BUILDING_CATEGORY_POPULATION_CONFIG_ID, HYPERSTRUCTURE_CONFIG_ID, + POPULATION_CONFIG_ID, WORLD_CONFIG_ID, } from "@bibliothecadao/eternum"; import { DojoConfig } from "@dojoengine/core"; @@ -30,7 +31,7 @@ export const syncEntitiesDebounced = async ( const debouncedSetEntities = debounce(() => { if (Object.keys(entityBatch).length > 0) { - console.log("Applying batch update", entityBatch); + // console.log("Applying batch update", entityBatch); setEntities(entityBatch, components, logging); entityBatch = {}; // Clear the batch after applying } @@ -79,7 +80,7 @@ export async function setup({ ...config }: DojoConfig) { const configClauses: Clause[] = [ { Keys: { - keys: [WORLD_CONFIG_ID.toString(), undefined, undefined], + keys: [WORLD_CONFIG_ID.toString()], pattern_matching: "FixedLen", models: [], }, @@ -91,6 +92,20 @@ export async function setup({ ...config }: DojoConfig) { models: [], }, }, + { + Keys: { + keys: [undefined, undefined], + pattern_matching: "FixedLen", + models: ["s0_eternum-TickConfig"], + }, + }, + { + Keys: { + keys: [WORLD_CONFIG_ID.toString(), undefined, undefined], + pattern_matching: "FixedLen", + models: [], + }, + }, { Keys: { keys: [BUILDING_CATEGORY_POPULATION_CONFIG_ID.toString(), undefined], @@ -107,28 +122,59 @@ export async function setup({ ...config }: DojoConfig) { }, ]; + const CompositeStart = performance.now(); await getEntities( network.toriiClient, { Composite: { operator: "Or", clauses: configClauses } }, network.contractComponents as any, ); + const CompositeEnd = performance.now(); // fetch all existing entities from torii + const SingleKeyStart = performance.now(); await getEntities( network.toriiClient, { Keys: { keys: [undefined], pattern_matching: "FixedLen", - models: [], + models: [ + "s0_eternum-AddressName", + "s0_eternum-Realm", + "s0_eternum-PopulationConfig", + "s0_eternum-CapacityConfig", + "s0_eternum-ProductionConfig", + "s0_eternum-RealmLevelConfig", + "s0_eternum-Army", + //ResourceCost + ], + }, + }, + network.contractComponents as any, + 40_000, + false, + ); + const SingleKeyEnd = performance.now(); + + const DoubleKeyStart = performance.now(); + await getEntities( + network.toriiClient, + { + Keys: { + keys: [undefined, undefined], + pattern_matching: "FixedLen", + models: ["s0_eternum-CapacityConfigCategory"], }, }, network.contractComponents as any, 40_000, false, ); + const DoubleKeyEnd = performance.now(); + const SyncStart = performance.now(); const sync = await syncEntitiesDebounced(network.toriiClient, network.contractComponents as any, [], false); + const SyncEnd = performance.now(); configManager.setDojo(components); @@ -159,6 +205,11 @@ export async function setup({ ...config }: DojoConfig) { false, ); + console.log("CompositeEnd", CompositeEnd - CompositeStart); + console.log("SyncEnd", SyncEnd - SyncStart); + console.log("SingleKeyEnd", SingleKeyEnd - SingleKeyStart); + console.log("DoubleKeyEnd", DoubleKeyEnd - DoubleKeyStart); + return { network, components, diff --git a/client/src/main.tsx b/client/src/main.tsx index f756ca640..4d97dc4ce 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -62,7 +62,10 @@ async function init() { root.render(); + const setupStart = performance.now(); const setupResult = await setup(dojoConfig); + const setupEnd = performance.now(); + console.log("SetupEnd", setupEnd - setupStart); const graphic = new GameRenderer(setupResult); diff --git a/client/src/ui/layouts/World.tsx b/client/src/ui/layouts/World.tsx index 129cd5083..3511530e0 100644 --- a/client/src/ui/layouts/World.tsx +++ b/client/src/ui/layouts/World.tsx @@ -3,19 +3,20 @@ import { lazy, Suspense, useEffect, useMemo, useState } from "react"; import { Redirect } from "wouter"; import useUIStore from "../../hooks/store/useUIStore"; -import { addMarketSubscription, addToSubscription } from "@/dojo/queries"; +import { addMarketSubscription, addToSubscription, addToSubscriptionBuildingQty, syncBuildingQty } from "@/dojo/queries"; import { useDojo } from "@/hooks/context/DojoContext"; import { PlayerStructure, useEntities } from "@/hooks/helpers/useEntities"; import { useStructureEntityId } from "@/hooks/helpers/useStructureEntityId"; import { useFetchBlockchainData } from "@/hooks/store/useBlockchainStore"; import { useWorldStore } from "@/hooks/store/useWorldLoading"; -import { ADMIN_BANK_ENTITY_ID } from "@bibliothecadao/eternum"; +import { ADMIN_BANK_ENTITY_ID, BuildingType } from "@bibliothecadao/eternum"; import { getComponentValue } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { env } from "../../../env"; import { IS_MOBILE } from "../config"; import { LoadingOroborus } from "../modules/loading-oroborus"; import { LoadingScreen } from "../modules/LoadingScreen"; +import { useBuildings } from "@/hooks/helpers/use-buildings"; // Lazy load components const SelectedArmy = lazy(() => @@ -116,6 +117,12 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { [structures, subscriptions], ); + // const { getBuildings } = useBuildings(); + // filteredStructures.forEach((structure) => { + // console.log("Buildings", getBuildings(structure.position.x, structure.position.y)); + // }); + + // console.log("FilteredStructures", filteredStructures); useEffect(() => { if ( !structureEntityId || @@ -126,6 +133,13 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { return; } + // syncBuildingQty(dojo.network.toriiClient, dojo.network.contractComponents as any, structureEntityId.toString()); + // filteredStructures.forEach((structure) => { + // syncBuildingQty(dojo.network.toriiClient, dojo.network.contractComponents as any, structure.entity_id.toString()); + // }); + + + const position = getComponentValue( dojo.setup.components.Position, getEntityIdFromKeys([BigInt(structureEntityId)]), @@ -141,7 +155,13 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { const fetch = async () => { try { + const start = performance.now(); await Promise.all([ + addToSubscriptionBuildingQty( + dojo.network.toriiClient, + dojo.network.contractComponents as any, + [...filteredStructures.map((structure) => structure.entity_id.toString())], + ), addToSubscription( dojo.network.toriiClient, dojo.network.contractComponents as any, @@ -159,11 +179,14 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { ), addMarketSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any), ]); + const end = performance.now(); + console.log("FetchEnd", end - start); } catch (error) { console.error("Fetch failed", error); } finally { setWorldLoading(false); setMarketLoading(false); + console.log("Done fetching") } }; From 9d1b10ed0215476971bd88756f37a7e52abc3fc7 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 16 Dec 2024 20:51:15 +0100 Subject: [PATCH 3/9] rem --- client/src/dojo/setup.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index 3de5ee7b0..96b241f7e 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -92,13 +92,6 @@ export async function setup({ ...config }: DojoConfig) { models: [], }, }, - { - Keys: { - keys: [undefined, undefined], - pattern_matching: "FixedLen", - models: ["s0_eternum-TickConfig"], - }, - }, { Keys: { keys: [WORLD_CONFIG_ID.toString(), undefined, undefined], @@ -145,7 +138,7 @@ export async function setup({ ...config }: DojoConfig) { "s0_eternum-CapacityConfig", "s0_eternum-ProductionConfig", "s0_eternum-RealmLevelConfig", - "s0_eternum-Army", + // "s0_eternum-Army", //ResourceCost ], }, From 099f4187bba4d7af9edb2e6e305d1895713613e8 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Tue, 17 Dec 2024 07:56:07 +1100 Subject: [PATCH 4/9] precision --- client/src/ui/components/resources/realm-transfer.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/ui/components/resources/realm-transfer.tsx b/client/src/ui/components/resources/realm-transfer.tsx index 9999ee307..4560f3418 100644 --- a/client/src/ui/components/resources/realm-transfer.tsx +++ b/client/src/ui/components/resources/realm-transfer.tsx @@ -9,6 +9,7 @@ import { calculateDonkeysNeeded, currencyFormat, getTotalResourceWeight, multipl import { ResourcesIds, findResourceById } from "@bibliothecadao/eternum"; import { Dispatch, SetStateAction, memo, useCallback, useEffect, useMemo, useState } from "react"; +import { configManager } from "@/dojo/setup"; import { ID } from "@bibliothecadao/eternum"; import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; import { num } from "starknet"; @@ -50,7 +51,7 @@ export const RealmTransfer = memo( const resources = calls.map((call) => { return { resourceId: Number(call.resources[0]), - amount: Number(call.resources[1]), + amount: Number(call.resources[1]) * configManager.getResourceMultiplier(), }; }); const totalWeight = getTotalResourceWeight(resources); @@ -73,6 +74,8 @@ export const RealmTransfer = memo( }).finally(() => { setIsLoading(false); }); + + setCalls([]); }, [calls]); return ( From 084ff81ed6e2fd2f5236f652d9604999d130dafa Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 16 Dec 2024 22:03:50 +0100 Subject: [PATCH 5/9] add missing models --- client/src/dojo/setup.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index 96b241f7e..f0acdcbc7 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -1,7 +1,6 @@ import { BUILDING_CATEGORY_POPULATION_CONFIG_ID, HYPERSTRUCTURE_CONFIG_ID, - POPULATION_CONFIG_ID, WORLD_CONFIG_ID, } from "@bibliothecadao/eternum"; import { DojoConfig } from "@dojoengine/core"; @@ -138,8 +137,9 @@ export async function setup({ ...config }: DojoConfig) { "s0_eternum-CapacityConfig", "s0_eternum-ProductionConfig", "s0_eternum-RealmLevelConfig", - // "s0_eternum-Army", - //ResourceCost + "s0_eternum-BankConfig", + "s0_eternum-Bank", + "s0_eternum-Trade", // Probably load this w/ market ], }, }, @@ -156,7 +156,7 @@ export async function setup({ ...config }: DojoConfig) { Keys: { keys: [undefined, undefined], pattern_matching: "FixedLen", - models: ["s0_eternum-CapacityConfigCategory"], + models: ["s0_eternum-CapacityConfigCategory", "s0_eternum-ResourceCost"], }, }, network.contractComponents as any, @@ -190,7 +190,6 @@ export async function setup({ ...config }: DojoConfig) { "s0_eternum-SwapEvent", "s0_eternum-LiquidityEvent", "s0_eternum-HyperstructureContribution", - "s0_eternum-MapExplored", ], }, }, From a9cd8949343814b28fe36d87bad5de06c6e6b7f7 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 16 Dec 2024 16:19:05 -0500 Subject: [PATCH 6/9] bump dojo + start chunk loading --- client/package.json | 14 +- client/src/dojo/queries.ts | 53 ++--- client/src/dojo/setup.ts | 6 + client/src/three/scenes/Worldmap.ts | 64 +++++- .../world-structures/WorldStructuresMenu.tsx | 2 + pnpm-lock.yaml | 195 +++++++++++++++--- 6 files changed, 259 insertions(+), 75 deletions(-) diff --git a/client/package.json b/client/package.json index e81b9c38c..9f8810e0e 100644 --- a/client/package.json +++ b/client/package.json @@ -19,14 +19,14 @@ "@bibliothecadao/eternum": "workspace:^", "@cartridge/connector": "0.5.5", "@cartridge/controller": "0.5.5", - "@dojoengine/core": "1.0.3-alpha.2", - "@dojoengine/create-burner": "1.0.3-alpha.2", - "@dojoengine/react": "1.0.3-alpha.2", + "@dojoengine/core": "1.0.4-alpha.3.1.0", + "@dojoengine/create-burner": "1.0.4-alpha.3.1.0", + "@dojoengine/react": "1.0.4-alpha.3.1.0", "@dojoengine/recs": "^2.0.13", - "@dojoengine/state": "1.0.3-alpha.2", - "@dojoengine/torii-client": "1.0.3-alpha.2", - "@dojoengine/torii-wasm": "1.0.3-alpha.2", - "@dojoengine/utils": "1.0.3-alpha.2", + "@dojoengine/state": "1.0.4-alpha.3.1.0", + "@dojoengine/torii-client": "1.0.4-alpha.3.1.0", + "@dojoengine/torii-wasm": "1.0.4-alpha.3.1.0", + "@dojoengine/utils": "1.0.4-alpha.3.1.0", "@headlessui/react": "^1.7.18", "@latticexyz/utils": "^2.0.0-next.12", "@radix-ui/react-collapsible": "^1.1.1", diff --git a/client/src/dojo/queries.ts b/client/src/dojo/queries.ts index f0bb950a8..2657e67a0 100644 --- a/client/src/dojo/queries.ts +++ b/client/src/dojo/queries.ts @@ -1,46 +1,13 @@ // onload -> fetch single key entities import { Component, Metadata, Schema } from "@dojoengine/recs"; -import { setEntities } from "@dojoengine/state"; -import { Clause, PatternMatching, ToriiClient } from "@dojoengine/torii-client"; +import { getEntities } from "@dojoengine/state"; +import { PatternMatching, ToriiClient } from "@dojoengine/torii-client"; // on hexception -> fetch below queries based on entityID // background sync after load -> -export const getEntities = async ( - client: ToriiClient, - clause: Clause | undefined, - components: Component[], - limit: number = 100, - logging: boolean = false, -) => { - if (logging) console.log("Starting getEntities"); - let offset = 0; - let continueFetching = true; - - while (continueFetching) { - const start = performance.now(); - const entities = await client.getEntities({ - limit, - offset, - clause, - dont_include_hashed_keys: false, - order_by: [], - }); - - setEntities(entities, components); - const end = performance.now(); - console.log("GetEntitiesEnd", end - start); - - if (Object.keys(entities).length < limit) { - continueFetching = false; - } else { - offset += limit; - } - } -}; - export const syncPosition = async ( client: ToriiClient, components: Component[], @@ -56,8 +23,9 @@ export const syncPosition = async ( }, }, components, + [], + [], 30_000, - false, ); }; export const syncBuildingQty = async ( @@ -75,8 +43,9 @@ export const syncBuildingQty = async ( }, }, components, + [], + [], 30_000, - false, ); }; @@ -103,8 +72,9 @@ export const addToSubscriptionBuildingQty = async ( }, }, components, + [], + [], 30_000, - false, ); const end = performance.now(); console.log("AddToSubscription Building qty", end - start); @@ -142,9 +112,10 @@ export const addToSubscription = async ( ], }, }, - components, + components as any, + [], + [], 30_000, - false, ); const end = performance.now(); console.log("AddToSubscriptionEnd", end - start); @@ -165,6 +136,8 @@ export const addMarketSubscription = async ( }, }, components, + [], + [], 30_000, false, ); diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index f0acdcbc7..d2d4a8729 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -144,6 +144,8 @@ export async function setup({ ...config }: DojoConfig) { }, }, network.contractComponents as any, + [], + [], 40_000, false, ); @@ -160,6 +162,8 @@ export async function setup({ ...config }: DojoConfig) { }, }, network.contractComponents as any, + [], + [], 40_000, false, ); @@ -174,6 +178,8 @@ export async function setup({ ...config }: DojoConfig) { const eventSync = getEvents( network.toriiClient, network.contractComponents.events as any, + [], + [], 20000, { Keys: { diff --git a/client/src/three/scenes/Worldmap.ts b/client/src/three/scenes/Worldmap.ts index 3a3c7b6c2..7bb807b4f 100644 --- a/client/src/three/scenes/Worldmap.ts +++ b/client/src/three/scenes/Worldmap.ts @@ -676,8 +676,6 @@ export default class WorldmapScene extends HexagonScene { // Create a unique key for this chunk range const chunkKey = `${startCol - range},${startCol + range},${startRow - range},${startRow + range}`; - console.log(chunkKey); - // Skip if we've already fetched this chunk if (this.fetchedChunks.has(chunkKey)) { console.log("Already fetched"); @@ -686,9 +684,10 @@ export default class WorldmapScene extends HexagonScene { // Add to fetched chunks before the query to prevent concurrent duplicate requests this.fetchedChunks.add(chunkKey); + console.log(startCol, startRow, range); try { - await getEntities( + const promiseTiles = getEntities( this.dojo.network.toriiClient, { Composite: { @@ -730,9 +729,68 @@ export default class WorldmapScene extends HexagonScene { }, }, this.dojo.network.contractComponents as any, + [], + ["s0_eternum-Tile"], 1000, false, ); + const promisePositions = getEntities( + this.dojo.network.toriiClient, + { + Composite: { + operator: "And", + clauses: [ + { + Composite: { + operator: "And", + clauses: [ + { + Member: { + model: "s0_eternum-Position", + member: "x", + operator: "Gte", + value: { Primitive: { U32: startCol - range } }, + }, + }, + { + Member: { + model: "s0_eternum-Position", + member: "x", + operator: "Lte", + value: { Primitive: { U32: startCol + range } }, + }, + }, + { + Member: { + model: "s0_eternum-Position", + member: "y", + operator: "Gte", + value: { Primitive: { U32: startRow - range } }, + }, + }, + { + Member: { + model: "s0_eternum-Position", + member: "y", + operator: "Lte", + value: { Primitive: { U32: startRow + range } }, + }, + }, + ], + }, + }, + ], + }, + }, + this.dojo.network.contractComponents as any, + [], + ["s0_eternum-Tile"], + 1000, + false, + ); + Promise.all([promiseTiles, promisePositions]).then(([tiles, positions]) => { + console.log(tiles, positions); + }); } catch (error) { // If there's an error, remove the chunk from cached set so it can be retried this.fetchedChunks.delete(chunkKey); diff --git a/client/src/ui/modules/world-structures/WorldStructuresMenu.tsx b/client/src/ui/modules/world-structures/WorldStructuresMenu.tsx index db712e55f..830290638 100644 --- a/client/src/ui/modules/world-structures/WorldStructuresMenu.tsx +++ b/client/src/ui/modules/world-structures/WorldStructuresMenu.tsx @@ -374,6 +374,8 @@ const fetchHyperstructureData = async (client: ToriiClient, components: Componen }, }, components as any, + [], + [], 40_000, false, ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 53e3a5c7c..6c891eee0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -137,29 +137,29 @@ importers: specifier: 0.5.5 version: 0.5.5(encoding@0.1.13) '@dojoengine/core': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) '@dojoengine/create-burner': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) '@dojoengine/react': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/recs': specifier: ^2.0.13 version: 2.0.13(typescript@5.7.2)(zod@3.24.1) '@dojoengine/state': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2 + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0 '@dojoengine/torii-wasm': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2 + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0 '@dojoengine/utils': - specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1) + specifier: 1.0.4-alpha.3.1.0 + version: 1.0.4-alpha.3.1.0(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1) '@headlessui/react': specifier: ^1.7.18 version: 1.7.19(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -285,7 +285,7 @@ importers: version: 0.20.5(@vite-pwa/assets-generator@0.2.6)(vite@5.4.11(@types/node@20.17.10)(terser@5.37.0))(workbox-build@7.3.0(@types/babel__core@7.20.5))(workbox-window@7.3.0) vitest-canvas-mock: specifier: ^0.3.3 - version: 0.3.3(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0)) + version: 0.3.3(vitest@2.1.8) wouter: specifier: ^2.12.1 version: 2.12.1(react@18.3.1) @@ -325,7 +325,7 @@ importers: version: 4.3.4(vite@5.4.11(@types/node@20.17.10)(terser@5.37.0)) '@vitest/coverage-v8': specifier: ^2.0.5 - version: 2.1.8(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0)) + version: 2.1.8(vitest@2.1.8) '@vitest/ui': specifier: ^2.0.1 version: 2.1.8(vitest@2.1.8) @@ -437,13 +437,13 @@ importers: version: 1.0.3-alpha.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) '@dojoengine/react': specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) + version: 1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/recs': specifier: ^2.0.13 version: 2.0.13(typescript@5.7.2)(zod@3.24.1) '@dojoengine/state': specifier: 1.0.3-alpha.2 - version: 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + version: 1.0.3-alpha.2(@types/node@20.17.10)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': specifier: 1.0.3-alpha.2 version: 1.0.3-alpha.2 @@ -1502,6 +1502,12 @@ packages: peerDependencies: starknet: 6.11.0 + '@dojoengine/core@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-tUlM0xT5ZDVtjM8gETDVl5pdmbGyVtXDZ+O1JOslMT/eyO425UiFH9Ovsc20HFH+Bg8X4RfAxSkuLSmR453HZQ==} + hasBin: true + peerDependencies: + starknet: 6.11.0 + '@dojoengine/create-burner@1.0.3-alpha.2': resolution: {integrity: sha512-vZnH8tVRp+ZY6Fl1ql+proYbxbf22RNXngfdE/pAgnQG2qS/0lDsoP2O7N4h+LJDKyVGjHxY01+JPhDU6kMzeA==} peerDependencies: @@ -1509,6 +1515,13 @@ packages: react-dom: ^18.2.0 starknet: 6.11.0 + '@dojoengine/create-burner@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-8oU8KOxBoD2v5gdrXVztCC6pA4Mvi8N3Ocjlt7vTqBSiwaxJljX7oW8pQ7JDaSBFSqmSr89erJHGzsQA/CpZlg==} + peerDependencies: + react: ^18.2.0 + react-dom: ^18.2.0 + starknet: 6.11.0 + '@dojoengine/react@1.0.3-alpha.2': resolution: {integrity: sha512-Fj0jKXqsFB3c8crNngwlfjtqIB1NwISf9pQkrzjzSAlkC171NjPyIxA5qbXCfhVYs7XYGi3Ka26piJj3r0yPhA==} peerDependencies: @@ -1516,6 +1529,13 @@ packages: starknet: 6.11.0 type-fest: ^2.14.0 + '@dojoengine/react@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-Ll9saYr/6HJNO1YrBtMealjYvT05UBKT4kCONw5EVxjz+HqHdCU7UqnfmmBPTKs8RTSAP1LeRKnfS7QY84DH5w==} + peerDependencies: + react: ^18.2.0 + starknet: 6.11.0 + type-fest: ^2.14.0 + '@dojoengine/recs@2.0.13': resolution: {integrity: sha512-Cgz4Unlnk2FSDoFTYKrJexX/KiSYPMFMxftxQkC+9LUKS5yNGkgFQM7xu4/L1HvpDAenL7NjUmH6ynRAS7Iifw==} @@ -1524,17 +1544,33 @@ packages: peerDependencies: starknet: 6.11.0 + '@dojoengine/state@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-nTKYX09ffpKvXvq2wJA3kNVLc0ZUkvkCg1ha7cajVaauhvSQAXRl1cPQQSf3rGzhqz4EwHpXNn3nGry2qsXdaQ==} + peerDependencies: + starknet: 6.11.0 + '@dojoengine/torii-client@1.0.3-alpha.2': resolution: {integrity: sha512-wJxixfj33CNnKEIOKTwI4tgNPDZq/3uiBh9qCz+buDiCjkWvbAiUlwwLUZj9a9PFG+TAQWB6SpjWzFwOwNpejA==} + '@dojoengine/torii-client@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-fW8MmcagcqI0BTxkIxmrUw+hBQ7NdoNvhg9FrW2st38jfGMz0txdWdhKXOiUTkpaNXW/C4PeKe9sa9wVn7Bp5g==} + '@dojoengine/torii-wasm@1.0.3-alpha.2': resolution: {integrity: sha512-9eQc4eTV53+DNtnrMRTddTYA1kG4285OF1qNOUrAZJstLPNcLzIboJtejVcXA6v5Kb+vkI70ypdp2A+QprEDdw==} + '@dojoengine/torii-wasm@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-17dB5tD+DS1gAUnWCAXKpKo2+FNc6Q06wBgrGHCzKAC+6qWdXCuHqlx1IZjiZbUNm/3kB1VoYO55G46vjsozTQ==} + '@dojoengine/utils@1.0.3-alpha.2': resolution: {integrity: sha512-NulEGvwArNhaSF9dkq5zuK/dWPu+Ri6NyMJcPsy2v0/6voP2ecQ0SKNMPDlBqX7GNC5Rrpr+mY9q1StYHtprNA==} peerDependencies: starknet: 6.11.0 + '@dojoengine/utils@1.0.4-alpha.3.1.0': + resolution: {integrity: sha512-CnudTUoFK7UyNEDuMZ6kHtw+jbx/k/9YZzC/+QgHs2Wm/FW0K3oo+nQMlijE2f/OIFeQYph+g8y1HpUWtevapw==} + peerDependencies: + starknet: 6.11.0 + '@emotion/hash@0.9.2': resolution: {integrity: sha512-MyqliTZGuOm3+5ZRSaaBGP3USLw6+EGykkwZns2EPC5g8jJ4z9OrdZY9apkl3+UP9+sdz76YYkwCKP5gh8iY3g==} @@ -10668,6 +10704,16 @@ snapshots: - typescript - utf-8-validate + '@dojoengine/core@1.0.4-alpha.3.1.0(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)': + dependencies: + '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) + starknet: 6.11.0(encoding@0.1.13) + zod: 3.24.1 + transitivePeerDependencies: + - bufferutil + - typescript + - utf-8-validate + '@dojoengine/create-burner@1.0.3-alpha.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)': dependencies: '@dojoengine/core': 1.0.3-alpha.2(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) @@ -10684,10 +10730,26 @@ snapshots: - typescript - utf-8-validate - '@dojoengine/react@1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1)': + '@dojoengine/create-burner@1.0.4-alpha.3.1.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)': + dependencies: + '@dojoengine/core': 1.0.4-alpha.3.1.0(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) + '@scure/bip32': 1.6.0 + '@starknet-react/core': 2.3.0(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13)) + encoding: 0.1.13 + get-starknet-core: 3.3.4(starknet@6.11.0(encoding@0.1.13)) + js-cookie: 3.0.5 + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + starknet: 6.11.0(encoding@0.1.13) + transitivePeerDependencies: + - bufferutil + - typescript + - utf-8-validate + + '@dojoengine/react@1.0.3-alpha.2(@types/node@20.17.10)(@types/react@18.3.16)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1)': dependencies: '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) - '@dojoengine/state': 1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + '@dojoengine/state': 1.0.3-alpha.2(@types/node@20.17.10)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': 1.0.3-alpha.2 '@dojoengine/utils': 1.0.3-alpha.2(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1) '@latticexyz/utils': 2.2.14 @@ -10722,6 +10784,44 @@ snapshots: - utf-8-validate - zod + '@dojoengine/react@1.0.4-alpha.3.1.0(@types/node@20.17.10)(@types/react@18.3.16)(@vitest/ui@2.1.8)(jsdom@24.1.3)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(type-fest@2.19.0)(typescript@5.7.2)(zod@3.24.1)': + dependencies: + '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) + '@dojoengine/state': 1.0.4-alpha.3.1.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1) + '@dojoengine/torii-client': 1.0.4-alpha.3.1.0 + '@dojoengine/utils': 1.0.4-alpha.3.1.0(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1) + '@latticexyz/utils': 2.2.14 + encoding: 0.1.13 + fast-deep-equal: 3.1.3 + get-starknet-core: 3.3.4(starknet@6.11.0(encoding@0.1.13)) + js-cookie: 3.0.5 + react: 18.3.1 + rxjs: 7.5.5 + starknet: 6.11.0(encoding@0.1.13) + type-fest: 2.19.0 + zustand: 4.5.5(@types/react@18.3.16)(react@18.3.1) + transitivePeerDependencies: + - '@edge-runtime/vm' + - '@types/node' + - '@types/react' + - '@vitest/browser' + - '@vitest/ui' + - bufferutil + - happy-dom + - immer + - jsdom + - less + - lightningcss + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + - typescript + - utf-8-validate + - zod + '@dojoengine/recs@2.0.13(typescript@5.4.4)(zod@3.24.1)': dependencies: '@latticexyz/schema-type': 2.0.12(typescript@5.4.4)(zod@3.24.1) @@ -10746,12 +10846,38 @@ snapshots: - utf-8-validate - zod - '@dojoengine/state@1.0.3-alpha.2(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1)': + '@dojoengine/state@1.0.3-alpha.2(@types/node@20.17.10)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1)': dependencies: '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) '@dojoengine/torii-client': 1.0.3-alpha.2 starknet: 6.11.0(encoding@0.1.13) - vitest: 1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(terser@5.37.0) + vitest: 1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0) + transitivePeerDependencies: + - '@edge-runtime/vm' + - '@types/node' + - '@vitest/browser' + - '@vitest/ui' + - bufferutil + - happy-dom + - jsdom + - less + - lightningcss + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + - typescript + - utf-8-validate + - zod + + '@dojoengine/state@1.0.4-alpha.3.1.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(starknet@6.11.0(encoding@0.1.13))(terser@5.37.0)(typescript@5.7.2)(zod@3.24.1)': + dependencies: + '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) + '@dojoengine/torii-client': 1.0.4-alpha.3.1.0 + starknet: 6.11.0(encoding@0.1.13) + vitest: 1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0) transitivePeerDependencies: - '@edge-runtime/vm' - '@types/node' @@ -10776,8 +10902,14 @@ snapshots: dependencies: '@dojoengine/torii-wasm': 1.0.3-alpha.2 + '@dojoengine/torii-client@1.0.4-alpha.3.1.0': + dependencies: + '@dojoengine/torii-wasm': 1.0.4-alpha.3.1.0 + '@dojoengine/torii-wasm@1.0.3-alpha.2': {} + '@dojoengine/torii-wasm@1.0.4-alpha.3.1.0': {} + '@dojoengine/utils@1.0.3-alpha.2(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1)': dependencies: '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) @@ -10791,6 +10923,19 @@ snapshots: - utf-8-validate - zod + '@dojoengine/utils@1.0.4-alpha.3.1.0(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2)(zod@3.24.1)': + dependencies: + '@dojoengine/recs': 2.0.13(typescript@5.7.2)(zod@3.24.1) + '@latticexyz/utils': 2.2.14 + mathjs: 12.4.3 + micro-starknet: 0.2.3 + starknet: 6.11.0(encoding@0.1.13) + transitivePeerDependencies: + - bufferutil + - typescript + - utf-8-validate + - zod + '@emotion/hash@0.9.2': {} '@esbuild/aix-ppc64@0.19.12': @@ -14170,7 +14315,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@vitest/coverage-v8@2.1.8(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0))': + '@vitest/coverage-v8@2.1.8(vitest@2.1.8)': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 @@ -19952,12 +20097,12 @@ snapshots: tsx: 4.19.2 yaml: 2.6.1 - vitest-canvas-mock@0.3.3(vitest@2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0)): + vitest-canvas-mock@0.3.3(vitest@2.1.8): dependencies: jest-canvas-mock: 2.5.2 vitest: 2.1.8(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0) - vitest@1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8(vitest@2.1.8))(jsdom@24.1.3)(terser@5.37.0): + vitest@1.6.0(@types/node@20.17.10)(@vitest/ui@2.1.8)(jsdom@24.1.3)(terser@5.37.0): dependencies: '@vitest/expect': 1.6.0 '@vitest/runner': 1.6.0 From 68c7d8e2871f9f9c4231d342912df7749946acd8 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 16 Dec 2024 22:35:43 +0100 Subject: [PATCH 7/9] fetch armies --- client/src/dojo/setup.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index f0acdcbc7..31307bc9c 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -139,7 +139,9 @@ export async function setup({ ...config }: DojoConfig) { "s0_eternum-RealmLevelConfig", "s0_eternum-BankConfig", "s0_eternum-Bank", - "s0_eternum-Trade", // Probably load this w/ market + "s0_eternum-Trade", + "s0_eternum-Army", + // Probably load this w/ market ], }, }, From 8329d9746d17f82db5e38af80cf19f4543d58669 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Tue, 17 Dec 2024 08:51:29 +1100 Subject: [PATCH 8/9] precision --- client/src/ui/components/resources/realm-transfer.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/src/ui/components/resources/realm-transfer.tsx b/client/src/ui/components/resources/realm-transfer.tsx index 4560f3418..038c28805 100644 --- a/client/src/ui/components/resources/realm-transfer.tsx +++ b/client/src/ui/components/resources/realm-transfer.tsx @@ -9,7 +9,6 @@ import { calculateDonkeysNeeded, currencyFormat, getTotalResourceWeight, multipl import { ResourcesIds, findResourceById } from "@bibliothecadao/eternum"; import { Dispatch, SetStateAction, memo, useCallback, useEffect, useMemo, useState } from "react"; -import { configManager } from "@/dojo/setup"; import { ID } from "@bibliothecadao/eternum"; import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; import { num } from "starknet"; @@ -51,7 +50,7 @@ export const RealmTransfer = memo( const resources = calls.map((call) => { return { resourceId: Number(call.resources[0]), - amount: Number(call.resources[1]) * configManager.getResourceMultiplier(), + amount: Number(call.resources[1]), }; }); const totalWeight = getTotalResourceWeight(resources); @@ -65,7 +64,7 @@ export const RealmTransfer = memo( const cleanedCalls = calls.map(({ sender_entity_id, recipient_entity_id, resources }) => ({ sender_entity_id, recipient_entity_id, - resources, + resources: [resources[0], BigInt(resources[1]) * BigInt(1000)], })); send_resources_multiple({ From 7e00f41716b83759e8c9d702ab7fdf0703267697 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Tue, 17 Dec 2024 08:59:43 +1100 Subject: [PATCH 9/9] remove and add --- client/src/dojo/setup.ts | 4 +- client/src/three/scenes/Worldmap.ts | 112 ++++++++++++++-------------- 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index 469b145e4..8f1f1db6a 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -141,7 +141,9 @@ export async function setup({ ...config }: DojoConfig) { "s0_eternum-Bank", "s0_eternum-Trade", "s0_eternum-Army", - // Probably load this w/ market + "s0_eternum-Structure", + "s0_eternum-Battle", + // Probably load this w/ market ], }, }, diff --git a/client/src/three/scenes/Worldmap.ts b/client/src/three/scenes/Worldmap.ts index 7bb807b4f..6af004669 100644 --- a/client/src/three/scenes/Worldmap.ts +++ b/client/src/three/scenes/Worldmap.ts @@ -734,62 +734,62 @@ export default class WorldmapScene extends HexagonScene { 1000, false, ); - const promisePositions = getEntities( - this.dojo.network.toriiClient, - { - Composite: { - operator: "And", - clauses: [ - { - Composite: { - operator: "And", - clauses: [ - { - Member: { - model: "s0_eternum-Position", - member: "x", - operator: "Gte", - value: { Primitive: { U32: startCol - range } }, - }, - }, - { - Member: { - model: "s0_eternum-Position", - member: "x", - operator: "Lte", - value: { Primitive: { U32: startCol + range } }, - }, - }, - { - Member: { - model: "s0_eternum-Position", - member: "y", - operator: "Gte", - value: { Primitive: { U32: startRow - range } }, - }, - }, - { - Member: { - model: "s0_eternum-Position", - member: "y", - operator: "Lte", - value: { Primitive: { U32: startRow + range } }, - }, - }, - ], - }, - }, - ], - }, - }, - this.dojo.network.contractComponents as any, - [], - ["s0_eternum-Tile"], - 1000, - false, - ); - Promise.all([promiseTiles, promisePositions]).then(([tiles, positions]) => { - console.log(tiles, positions); + // const promisePositions = getEntities( + // this.dojo.network.toriiClient, + // { + // Composite: { + // operator: "And", + // clauses: [ + // { + // Composite: { + // operator: "And", + // clauses: [ + // { + // Member: { + // model: "s0_eternum-Position", + // member: "x", + // operator: "Gte", + // value: { Primitive: { U32: startCol - range } }, + // }, + // }, + // { + // Member: { + // model: "s0_eternum-Position", + // member: "x", + // operator: "Lte", + // value: { Primitive: { U32: startCol + range } }, + // }, + // }, + // { + // Member: { + // model: "s0_eternum-Position", + // member: "y", + // operator: "Gte", + // value: { Primitive: { U32: startRow - range } }, + // }, + // }, + // { + // Member: { + // model: "s0_eternum-Position", + // member: "y", + // operator: "Lte", + // value: { Primitive: { U32: startRow + range } }, + // }, + // }, + // ], + // }, + // }, + // ], + // }, + // }, + // this.dojo.network.contractComponents as any, + // [], + // ["s0_eternum-Tile"], + // 1000, + // false, + // ); + Promise.all([promiseTiles]).then(([tiles]) => { + // console.log(tiles, positions); }); } catch (error) { // If there's an error, remove the chunk from cached set so it can be retried