Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updae #2470

Merged
merged 9 commits into from
Dec 13, 2024
Merged

updae #2470

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"@bibliothecadao/eternum": "workspace:^",
"@cartridge/connector": "0.5.5",
"@cartridge/controller": "0.5.5",
"@dojoengine/core": "1.0.3-alpha.1",
"@dojoengine/torii-wasm": "1.0.3-alpha.1",
"@dojoengine/create-burner": "1.0.3-alpha.1",
"@dojoengine/react": "1.0.3-alpha.1",
"@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.1",
"@dojoengine/torii-client": "1.0.3-alpha.1",
"@dojoengine/utils": "1.0.3-alpha.1",
"@dojoengine/state": "1.0.3-alpha.2",
"@dojoengine/torii-client": "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",
Expand Down
24 changes: 15 additions & 9 deletions client/src/dojo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ export const addToSubscription = async <S extends Schema>(
},
};

await getEntities(
client,
{
...positionClause,
},
components,
10_000,
false,
);
position &&
(await getEntities(
client,
{
...positionClause,
},
components,
10_000,
false,
));

await getEntities(
client,
Expand All @@ -89,7 +90,12 @@ export const addToSubscription = async <S extends Schema>(
10_000,
false,
);
};

export const addMarketSubscription = async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
) => {
await getEntities(
client,
{
Expand Down
4 changes: 2 additions & 2 deletions client/src/dojo/setupNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as torii from "@dojoengine/torii-client";
import { Account } from "starknet";

import { env } from "./../../env";
const { VITE_VRF_PROVIDER_ADDRESS } = env;
const { VITE_VRF_PROVIDER_ADDRESS, VITE_PUBLIC_DEV } = env;

export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;

Expand All @@ -31,7 +31,7 @@ export async function setupNetwork({ ...config }: DojoConfig) {

try {
await burnerManager.init();
if (burnerManager.list().length === 0) {
if (VITE_PUBLIC_DEV === true && burnerManager.list().length === 0) {
await burnerManager.create();
}
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/hooks/context/DojoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const DojoContextProvider = ({
}
} else {
if (controllerAccount) {
console.log("Setting account from controllerAccount:", controllerAccount);
// console.log("Setting account from controllerAccount:", controllerAccount);
useAccountStore.getState().setAccount(controllerAccount);

const addressName = runQuery([
Expand All @@ -239,7 +239,7 @@ const DojoContextProvider = ({

setAccountsInitialized(true);
} else {
console.log("ControllerAccount is null in production or not connected.");
// console.log("ControllerAccount is null in production or not connected.");
setTimeout(() => {
setRetries((prevRetries) => {
if (prevRetries < 10) {
Expand Down
4 changes: 4 additions & 0 deletions client/src/hooks/store/useWorldLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { create } from "zustand";

interface WorldState {
isWorldLoading: boolean;
isMarketLoading: boolean;
setWorldLoading: (loading: boolean) => void;
setMarketLoading: (loading: boolean) => void;
}

export const useWorldStore = create<WorldState>((set) => ({
isWorldLoading: true,
isMarketLoading: true,
setWorldLoading: (loading: boolean) => set({ isWorldLoading: loading }),
setMarketLoading: (loading: boolean) => set({ isMarketLoading: loading }),
}));
6 changes: 5 additions & 1 deletion client/src/three/components/BattleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ export class BattleManager {
removeBattle(entityId: ID) {
const meshMatrixIndex = this.battles.getBattleIndex(entityId);

if (meshMatrixIndex === undefined) throw new Error(`meshMatrixIndex not found for entityId ${entityId}`);
if (meshMatrixIndex === undefined) {
// console.warn(`meshMatrixIndex not found for entityId ${entityId}`);
return;
}

const newMatrix = new THREE.Matrix4().scale(new THREE.Vector3(0, 0, 0));
this.battleModel.mesh.setMatrixAt(meshMatrixIndex, newMatrix);
Expand All @@ -113,6 +116,7 @@ export class BattleManager {
this.battles.removeBattle(entityId);

const label = this.labels.get(entityId);

if (!label) throw new Error(`Label not found for entityId ${entityId}`);

this.labelManager.removeLabel(label, this.scene);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useUIStore from "@/hooks/store/useUIStore";
import { Headline } from "@/ui/elements/Headline";
import { ResourceCost } from "@/ui/elements/ResourceCost";
import { multiplyByPrecision } from "@/ui/utils/utils";
import { ID, ResourcesIds, StructureType } from "@bibliothecadao/eternum";
import { HYPERSTRUCTURE_CONSTRUCTION_COSTS_SCALED, HYPERSTRUCTURE_CREATION_COSTS, ID, ResourceTier, ResourcesIds, StructureType } from "@bibliothecadao/eternum";
import React from "react";
import { StructureCard } from "./StructureCard";

Expand Down Expand Up @@ -43,7 +43,7 @@ export const StructureConstructionMenu = ({ className, entityId }: { className?:

// if is hyperstructure, the construction cost are only fragments
const isHyperstructure = building === StructureType["Hyperstructure"];
const cost = configManager.structureCosts[building].filter(
const cost = HYPERSTRUCTURE_CONSTRUCTION_COSTS_SCALED.filter(
(cost) => !isHyperstructure || cost.resource === ResourcesIds.AncientFragment,
);

Expand Down Expand Up @@ -85,8 +85,8 @@ const StructureInfo = ({
}) => {
// if is hyperstructure, the construction cost are only fragments
const isHyperstructure = structureId === StructureType["Hyperstructure"];
const cost = configManager.structureCosts[structureId].filter(
(cost) => !isHyperstructure || cost.resource === ResourcesIds.AncientFragment,
const cost = HYPERSTRUCTURE_CREATION_COSTS.filter(
(cost) => !isHyperstructure || cost.resource_tier === ResourceTier.Lords,
);

const perTick =
Expand All @@ -110,13 +110,13 @@ const StructureInfo = ({
<div className="pt-3 font-bold uppercase text-xs"> One time cost</div>
<div className="grid grid-cols-1 gap-2 text-sm">
{Object.keys(cost).map((resourceId, index) => {
const balance = getBalance(entityId || 0, cost[Number(resourceId)].resource);
const balance = getBalance(entityId || 0, ResourcesIds.AncientFragment);
return (
<ResourceCost
key={index}
type="horizontal"
resourceId={cost[Number(resourceId)].resource}
amount={cost[Number(resourceId)].amount}
resourceId={ResourcesIds.AncientFragment}
amount={cost[Number(resourceId)].min_amount * 1000}
balance={balance.balance}
/>
);
Expand Down
22 changes: 14 additions & 8 deletions client/src/ui/components/trading/MarketModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useSetMarket } from "@/hooks/helpers/useTrade";
import useMarketStore from "@/hooks/store/useMarketStore";
import { useModalStore } from "@/hooks/store/useModalStore";
import useUIStore from "@/hooks/store/useUIStore";
import { useWorldStore } from "@/hooks/store/useWorldLoading";
import { BuildingThumbs } from "@/ui/config";
import CircleButton from "@/ui/elements/CircleButton";
import { LoadingAnimation } from "@/ui/elements/LoadingAnimation";
Expand Down Expand Up @@ -53,21 +54,18 @@ export const MarketModal = () => {
const [selectedTab, setSelectedTab] = useState(0);

const { playerStructures } = useEntities();

const { toggleModal } = useModalStore();

const banks = useGetBanks();

const bank = banks.length === 1 ? banks[0] : null;

const { bidOffers, askOffers } = useSetMarket();

const bank = banks.length === 1 ? banks[0] : null;
const battles = useBattlesByPosition(bank?.position || { x: 0, y: 0 });

const isMarketLoading = useWorldStore((state) => state.isMarketLoading);

const currentBlockTimestamp = useUIStore.getState().nextBlockTimestamp || 0;

const getStructure = useStructureByPosition();

const bankStructure = getStructure(bank?.position || { x: 0, y: 0 });

const battle = useMemo(() => {
Expand Down Expand Up @@ -144,7 +142,7 @@ export const MarketModal = () => {
</div>
),
component: bank && (
<Suspense fallback={<LoadingAnimation />}>
<Suspense fallback={ <LoadingAnimation />}>
<BankPanel
bankEntityId={bank.entityId}
structureEntityId={structureEntityId}
Expand Down Expand Up @@ -201,7 +199,7 @@ export const MarketModal = () => {

return (
<ModalContainer>
<div className="market-modal-selector container border mx-auto grid grid-cols-12 bg-dark border-gold/30 h-full row-span-12 rounded-2xl ">
<div className="market-modal-selector container border mx-auto grid grid-cols-12 bg-dark border-gold/30 h-full row-span-12 rounded-2xl relative">
<div className="col-span-3 p-1 row-span-10 overflow-y-auto ">
<div className="market-realm-selector self-center text-xl justify-between flex gap-2 items-center bg-brown p-4 rounded-xl w-full mb-4">
<div className="">
Expand Down Expand Up @@ -344,6 +342,14 @@ export const MarketModal = () => {
</Tabs>
</div>
</div>
{isMarketLoading && (
<div className="absolute bottom-4 inset-x-0 z-10 flex justify-center pointer-events-none">
<div className="bg-brown/90 text-sm px-4 py-1 rounded-t-lg border border-gold/30 flex items-center gap-2">
<div className="w-2 h-2 bg-gold/50 rounded-full animate-pulse" />
<span>Syncing market data...</span>
</div>
</div>
)}
</ModalContainer>
);
};
28 changes: 25 additions & 3 deletions client/src/ui/layouts/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { lazy, Suspense, useEffect, useMemo, useState } from "react";
import { Redirect } from "wouter";
import useUIStore from "../../hooks/store/useUIStore";

import { addToSubscription } from "@/dojo/queries";
import { addMarketSubscription, addToSubscription } 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 { getComponentValue } from "@dojoengine/recs";
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { env } from "../../../env";
Expand Down Expand Up @@ -102,6 +103,7 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {

const worldLoading = useWorldStore((state) => state.isWorldLoading);
const setWorldLoading = useWorldStore((state) => state.setWorldLoading);
const setMarketLoading = useWorldStore((state) => state.setMarketLoading);

const dojo = useDojo();
const structureEntityId = useUIStore((state) => state.structureEntityId);
Expand All @@ -115,7 +117,12 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {
);

useEffect(() => {
if (!structureEntityId || subscriptions[structureEntityId.toString()] || structureEntityId === 999999998) {
if (
!structureEntityId ||
subscriptions[structureEntityId.toString()] ||
subscriptions[ADMIN_BANK_ENTITY_ID.toString()] ||
structureEntityId === 999999999
) {
return;
}

Expand All @@ -125,7 +132,7 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {
);

setWorldLoading(true);
setSubscriptions((prev) => ({ ...prev, [structureEntityId.toString()]: true }));
setSubscriptions((prev) => ({ ...prev, [structureEntityId.toString()]: true, [ADMIN_BANK_ENTITY_ID.toString()]: true }));
const fetch = async () => {
try {
await addToSubscription(
Expand All @@ -134,13 +141,28 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {
structureEntityId.toString(),
{ x: position?.x || 0, y: position?.y || 0 },
);

await addToSubscription(
dojo.network.toriiClient,
dojo.network.contractComponents as any,
ADMIN_BANK_ENTITY_ID.toString(),
{ x: 0, y: 0 },
);
} catch (error) {
console.error("Fetch failed", error);
} finally {
setWorldLoading(false);
}

console.log("world loading", worldLoading);

try {
await addMarketSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any);
} catch (error) {
console.error("Fetch failed", error);
} finally {
setMarketLoading(false);
}
};

fetch();
Expand Down
12 changes: 6 additions & 6 deletions landing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"@bibliothecadao/eternum": "workspace:^",
"@cartridge/connector": "^0.5.3",
"@cartridge/controller": "^0.5.3",
"@dojoengine/core": "1.0.3-alpha.1",
"@dojoengine/create-burner": "1.0.3-alpha.1",
"@dojoengine/react": "1.0.3-alpha.1",
"@dojoengine/core": "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.1",
"@dojoengine/torii-client": "1.0.3-alpha.1",
"@dojoengine/utils": "1.0.3-alpha.1",
"@dojoengine/state": "1.0.3-alpha.2",
"@dojoengine/torii-client": "1.0.3-alpha.2",
"@dojoengine/utils": "1.0.3-alpha.2",
"@graphql-codegen/schema-ast": "^4.1.0",
"@graphql-typed-document-node/core": "^3.2.0",
"@headlessui/react": "^1.7.18",
Expand Down
Loading
Loading