Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Dec 11, 2024
1 parent 6f4918f commit e3b2744
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 292 deletions.
16 changes: 8 additions & 8 deletions client/src/dojo/modelManager/__tests__/BattleManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ import { describe, it } from "vitest";
// });

describe("getBattle", () => {
it("should return a valid battle for a valid mock", () => {
// const mockBattle = generateMockBatle(true);
// vi.mocked(getComponentValue).mockReturnValueOnce(mockBattle);
// const battleManager = new BattleManager(BATTLE_ENTITY_ID, mockDojoResult);
// const battle = battleManager.getBattle();
// expect(battle).toBeDefined();
// expect(battle).toBe(mockBattle);
});
it("should return a valid battle for a valid mock", () => {
// const mockBattle = generateMockBatle(true);
// vi.mocked(getComponentValue).mockReturnValueOnce(mockBattle);
// const battleManager = new BattleManager(BATTLE_ENTITY_ID, mockDojoResult);
// const battle = battleManager.getBattle();
// expect(battle).toBeDefined();
// expect(battle).toBe(mockBattle);
});
});

// describe("isBattle", () => {
Expand Down
12 changes: 5 additions & 7 deletions client/src/hooks/helpers/useQuests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export const useQuests = () => {
};

const useQuestDependencies = () => {
const {
setup,
} = useDojo();
const { setup } = useDojo();

const structureEntityId = useUIStore((state) => state.structureEntityId);

Expand Down Expand Up @@ -203,10 +201,10 @@ export const useQuestClaimStatus = () => {

const questClaimStatus = useMemo(() => {
const entityBigInt = BigInt(structureEntityId || 0);
const checkPrizesClaimed = (prizes: Prize[]) =>
prizes.every((prize) =>
getComponentValue(Quest, getEntityIdFromKeys([entityBigInt, BigInt(prize.id)]))?.completed

const checkPrizesClaimed = (prizes: Prize[]) =>
prizes.every(
(prize) => getComponentValue(Quest, getEntityIdFromKeys([entityBigInt, BigInt(prize.id)]))?.completed,
);

return Array.from(questDetails.keys()).reduce(
Expand Down
48 changes: 2 additions & 46 deletions client/src/hooks/helpers/useResources.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { configManager } from "@/dojo/setup";
import {
CapacityConfigCategory,
ContractAddress,
ID,
Position,
ResourcesIds,
resources,
type Resource,
type Resource
} from "@bibliothecadao/eternum";
import { useComponentValue } from "@dojoengine/react";
import { Has, HasValue, Not, getComponentValue, runQuery, type Entity } from "@dojoengine/recs";
import { Has, HasValue, getComponentValue, runQuery, type Entity } from "@dojoengine/recs";
import { useEffect, useMemo, useState } from "react";
import { ResourceManager } from "../../dojo/modelManager/ResourceManager";
import { getEntityIdFromKeys } from "../../ui/utils/utils";
Expand Down Expand Up @@ -182,45 +180,3 @@ export const useResourceManager = (entityId: ID, resourceId: ResourcesIds) => {

return resourceManager;
};

export function useOwnedEntitiesOnPosition() {
const {
account: { account },
setup: {
components: { Owner, Position, Movable, Bank, Army },
},
} = useDojo();

const getOwnedEntitiesOnPosition = (address: ContractAddress, position: Position) => {
const { x, y } = position;

const entities = runQuery([
HasValue(Owner, { address }),
Not(Movable),
Not(Army),
// @note: safer to do like this rather than deconstruct because there's a chance entity_id is also there
HasValue(Position, { x, y }),
]);

return Array.from(entities)
.map((entityId) => {
const position = getComponentValue(Position, entityId);
if (!position) return;
return position?.entity_id;
})
.filter(Boolean) as ID[];
};

const getOwnedEntityOnPosition = (entityId: ID) => {
const position = getComponentValue(Position, getEntityIdFromKeys([BigInt(entityId)]));
const depositEntityIds = position
? getOwnedEntitiesOnPosition(ContractAddress(account.address), { x: Number(position.x), y: Number(position.y) })
: [];
return depositEntityIds[0];
};

return {
getOwnedEntitiesOnPosition,
getOwnedEntityOnPosition,
};
}
31 changes: 16 additions & 15 deletions client/src/ui/components/hyperstructures/HyperstructurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ export const HyperstructurePanel = ({ entity }: any) => {
setNewContributions({});
setResetContributions(false);
}

};

const [selectedAccess, setSelectedAccess] = useState<"Public" | "Private" | "GuildOnly">(
hyperstructure ? (DisplayedAccess[hyperstructure.access as keyof typeof DisplayedAccess] as "Public" | "Private" | "GuildOnly") : "Private"
hyperstructure
? (DisplayedAccess[hyperstructure.access as keyof typeof DisplayedAccess] as "Public" | "Private" | "GuildOnly")
: "Private",
);

return (
Expand Down Expand Up @@ -207,21 +208,19 @@ export const HyperstructurePanel = ({ entity }: any) => {
<div className="flex gap-2 justify-between w-full">
<div className="flex items-center justify-between">
<div className="flex flex-col items-center gap-1">

<h4 className="truncate">{entity.name}</h4>
<Button size="xs" onClick={updateLeaderboard}>Reload</Button>
<Button size="xs" onClick={updateLeaderboard}>
Reload
</Button>
</div>


</div>

{account.address === entity.owner && (
<div className="flex flex-col gap-2">

{hyperstructure && entity.isOwner && isLoading !== Loading.SetPrivate ? (
<Select
onValueChange={(access: keyof typeof Access) => {
setSelectedAccess(access);
setSelectedAccess(access);
setAccess(BigInt(Access[access]));
}}
>
Expand All @@ -248,13 +247,15 @@ export const HyperstructurePanel = ({ entity }: any) => {
))}
</SelectContent>
</Select>
) : <div className="text-gold text-sm">Loading...</div>}

{account.address === entity.owner && (
<Button size="xs" variant="default" onClick={() => setEditName(!editName)}>
edit name
</Button>
)}
) : (
<div className="text-gold text-sm">Loading...</div>
)}

{account.address === entity.owner && (
<Button size="xs" variant="default" onClick={() => setEditName(!editName)}>
edit name
</Button>
)}
</div>
)}
</div>
Expand Down
8 changes: 0 additions & 8 deletions client/src/ui/components/trading/ResourceArrivals.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { ArrivalInfo } from "@/hooks/helpers/use-resource-arrivals";
import { Headline } from "@/ui/elements/Headline";
import { HintModalButton } from "@/ui/elements/HintModalButton";
import { ID, Resource } from "@bibliothecadao/eternum";
import { EntityArrival } from "../entities/Entity";
import { HintSection } from "../hints/HintModal";

export type EntityReadyForDeposit = {
carrierId: ID;
senderEntityId: ID;
recipientEntityId: ID;
resources: Resource[];
};

export const AllResourceArrivals = ({ arrivals, className }: { arrivals: ArrivalInfo[]; className?: string }) => {
return (
<div className={`p-2 flex flex-col space-y-1 overflow-y-auto gap-2 ${className ? className : ""}`}>
Expand Down
Loading

0 comments on commit e3b2744

Please sign in to comment.