Skip to content

Commit

Permalink
add back fragment mines and put HS access
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Dec 11, 2024
1 parent 725e29b commit 1df6050
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 55 deletions.
6 changes: 4 additions & 2 deletions client/src/hooks/helpers/useHyperstructures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ export const useHyperstructures = () => {
const {
account: { account },
setup: {
components: { Structure, Contribution, Position, Owner, EntityName },
components: { Structure, Contribution, Position, Owner, EntityName, Hyperstructure },
},
} = useDojo();

const { getAddressNameFromEntity } = useEntitiesUtils();

const hyperstructures = useEntityQuery([Has(Structure), HasValue(Structure, { category: "Hyperstructure" })]).map(
(hyperstructureEntityId) => {
const hyperstructure = getComponentValue(Structure, hyperstructureEntityId);
const hyperstructure = getComponentValue(Hyperstructure, hyperstructureEntityId);
const structure = getComponentValue(Structure, hyperstructureEntityId);
const position = getComponentValue(Position, hyperstructureEntityId);
const contributions = getContributions(hyperstructure!.entity_id, Contribution);
const ownerEntityIds = runQuery([Has(Owner), HasValue(Owner, { entity_id: hyperstructure!.entity_id })])
Expand All @@ -45,6 +46,7 @@ export const useHyperstructures = () => {

return {
...hyperstructure,
...structure,
...position,
...contributions,
owner,
Expand Down
33 changes: 17 additions & 16 deletions client/src/ui/components/hyperstructures/HyperstructurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ContributionSummary } from "./ContributionSummary";
import { HyperstructureDetails } from "./HyperstructureDetails";
import { HyperstructureResourceChip } from "./HyperstructureResourceChip";

enum DisplayedAccess {
export enum DisplayedAccess {
Public = "Public",
Private = "Private",
GuildOnly = "Tribe Only",
Expand Down 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
18 changes: 5 additions & 13 deletions client/src/ui/components/list/EntityList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { ReactComponent as ArrowRight } from "@/assets/icons/common/arrow-right.svg";
import { DUMMY_HYPERSTRUCTURE_ENTITY_ID } from "@/three/scenes/constants";
import Button from "@/ui/elements/Button";
import { ID } from "@bibliothecadao/eternum";
import clsx from "clsx";
import React, { useEffect, useState } from "react";
import { NavigateToPositionIcon } from "../military/ArmyChip";
import { ViewOnMapIcon } from "../military/ArmyManagementCard";

interface EntityListProps {
title: string;
Expand All @@ -18,6 +15,7 @@ interface EntityListProps {
list: any[];
previous?: any[];
current?: ID;
entityHeader: (props: { id: any }) => React.ReactElement | null;
entityContent?: (props: { id: any }) => React.ReactElement | null;
questing?: boolean;
className?: string;
Expand All @@ -31,6 +29,7 @@ export const EntityList = ({
list,
headerPanel,
current,
entityHeader,
entityContent,
questing,
className,
Expand All @@ -40,6 +39,8 @@ export const EntityList = ({
const [selectedEntity, setSelectedEntity] = useState<any>(null);
const [searchTerm, setSearchTerm] = useState("");

console.log({ list });

useEffect(() => {
const entity = list.find((entity) => entity.entity_id === current);
if (entity) setSelectedEntity(entity || null);
Expand Down Expand Up @@ -90,16 +91,7 @@ export const EntityList = ({
onClick={() => setSelectedEntity(entity)}
>
<div className="flex flex-col space-y-2">
<div className="flex flex-row justify-between items-center">
<div className="flex flex-row space-x-5 items-center">
<h5>{entity.name}</h5>
<div className="flex flex-row ">
{entity?.position && <ViewOnMapIcon className={"my-auto"} position={entity.position} />}
{entity?.position && <NavigateToPositionIcon className="h-6 w-6" position={entity?.position} />}
</div>
</div>
<ArrowRight className="w-2 fill-current" />
</div>
{entityHeader(entity.id)}

{entity.id !== Number(DUMMY_HYPERSTRUCTURE_ENTITY_ID) && (
<div className="border border-gold/20 bg-gold/10 rounded p-2">
Expand Down
115 changes: 91 additions & 24 deletions client/src/ui/modules/world-structures/WorldStructuresMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import { useHyperstructureProgress, useHyperstructures } from "@/hooks/helpers/u
import { useResourceBalance } from "@/hooks/helpers/useResources";
import { FragmentMinePanel } from "@/ui/components/fragmentMines/FragmentMinePanel";
import { HintSection } from "@/ui/components/hints/HintModal";
import { HyperstructurePanel } from "@/ui/components/hyperstructures/HyperstructurePanel";
import { DisplayedAccess, HyperstructurePanel } from "@/ui/components/hyperstructures/HyperstructurePanel";
import { EntityList } from "@/ui/components/list/EntityList";
import { NavigateToPositionIcon } from "@/ui/components/military/ArmyChip";
import { ViewOnMapIcon } from "@/ui/components/military/ArmyManagementCard";
import { Checkbox } from "@/ui/elements/Checkbox";
import { HintModalButton } from "@/ui/elements/HintModalButton";
import { ResourceIcon } from "@/ui/elements/ResourceIcon";
import { currencyFormat, currencyIntlFormat, divideByPrecision } from "@/ui/utils/utils";
import { BattleSide, ContractAddress, findResourceById, ID, ResourcesIds } from "@bibliothecadao/eternum";
import { useMemo, useState } from "react";
import { ArrowRight } from "lucide-react";
import { useCallback, useMemo, useState } from "react";
import { Tabs } from "../../elements/tab";

export const WorldStructuresMenu = ({ className }: { className?: string }) => {
Expand All @@ -31,27 +34,51 @@ export const WorldStructuresMenu = ({ className }: { className?: string }) => {
const { fragmentMines } = useFragmentMines();

const myHyperstructures = useGetHyperstructuresWithContributionsFromPlayer();
const hyperstructureExtraContent = useCallback(
(entityId: any) => {
const hyperstructure = hyperstructures.find((hyperstructure) => hyperstructure.entity_id === entityId);
if (!hyperstructure) return null;
return (
<HyperStructureExtraContent
hyperstructureEntityId={hyperstructure.entity_id!}
x={hyperstructure.x!}
y={hyperstructure.y!}
/>
);
},
[hyperstructures],
);

const hyperstructureExtraContent = (entityId: any) => {
const hyperstructure = hyperstructures.find((hyperstructure) => hyperstructure.entity_id === entityId);
if (!hyperstructure) return null;
return (
<HyperStructureExtraContent
hyperstructureEntityId={hyperstructure.entity_id!}
x={hyperstructure.x!}
y={hyperstructure.y!}
/>
);
};
const fragmentMineExtraContent = useCallback(
(entityId: any) => {
const fragmentMine = fragmentMines.find((fragmentMine) => fragmentMine.entity_id === entityId);
if (!fragmentMine) return null;

const fragmentMineExtraContent = (entityId: any) => {
const fragmentMine = fragmentMines.find((fragmentMine) => fragmentMine.entity_id === entityId);
if (!fragmentMine) return null;
return <FragmentMineExtraContent x={Number(fragmentMine.x!)} y={Number(fragmentMine.y!)} entityId={entityId!} />;
},
[fragmentMines],
);

fragmentMine.production_rate;
const hyperstructureEntityHeader = useCallback(
(entityId: any) => {
const entity = hyperstructures.find((hyperstructure) => hyperstructure.entity_id === entityId);

return <FragmentMineExtraContent x={Number(fragmentMine.x!)} y={Number(fragmentMine.y!)} entityId={entityId!} />;
};
if (!entity) return null;

return <EntityHeader entity={entity} />;
},
[hyperstructures],
);

const fragmentMineEntityHeader = useCallback(
(entityId: any) => {
const entity = fragmentMines.find((fragmentMine) => fragmentMine.entity_id === entityId);
if (!entity) return null;

return <EntityHeader entity={entity} />;
},
[fragmentMines],
);

const tabs = useMemo(
() => [
Expand All @@ -73,6 +100,7 @@ export const WorldStructuresMenu = ({ className }: { className?: string }) => {
<EntityList
title="Hyperstructures"
panel={({ entity }) => <HyperstructurePanel entity={entity} />}
entityHeader={hyperstructureEntityHeader}
entityContent={hyperstructureExtraContent}
list={hyperstructures
.filter((hyperstructure) => hyperstructure.created_at)
Expand Down Expand Up @@ -105,6 +133,7 @@ export const WorldStructuresMenu = ({ className }: { className?: string }) => {
<EntityList
title="FragmentMines"
panel={({ entity }) => <FragmentMinePanel entity={entity} />}
entityHeader={fragmentMineEntityHeader}
entityContent={fragmentMineExtraContent}
list={fragmentMines
.sort((a, b) => Number(a.entity_id) - Number(b.entity_id))
Expand All @@ -114,11 +143,13 @@ export const WorldStructuresMenu = ({ className }: { className?: string }) => {
...fragmentMine,
}))}
filterEntityIds={
fragmentMines
.filter((mine) => {
mine.owner === account.address;
})
.map((mine) => mine.entity_id) as ID[]
showOnlyMine
? (fragmentMines
.filter((mine) => {
mine.owner === account.address;
})
.map((mine) => mine.entity_id) as ID[])
: undefined
}
/>
</>
Expand Down Expand Up @@ -297,3 +328,39 @@ const FragmentMineExtraContent = ({ x, y, entityId }: { x: number; y: number; en
</BaseStructureExtraContent>
);
};

const EntityHeader = ({ entity }: { entity: any }) => {
const position = { x: entity.x, y: entity.y };

const access = entity?.access ? DisplayedAccess[entity.access as keyof typeof DisplayedAccess] : undefined;

return (
<div className="flex flex-row justify-between items-center">
<div className="flex flex-row space-x-5 items-center">
<div className="flex flex-row items-center gap-2">
<h5 className="font-semibold text-gold">{entity.name}</h5>
{access && (
<span
className={`text-xs px-2 py-0.5 rounded-md font-medium ${
access === "Public"
? "text-green border border-green"
: access === "Private"
? "text-red border border-red"
: access === "Tribe Only"
? "text-gold border border-gold"
: ""
}`}
>
{access}
</span>
)}
<div className="flex flex-row ">
<ViewOnMapIcon className={"my-auto"} position={position} />
<NavigateToPositionIcon className="h-6 w-6" position={position} />
</div>
</div>
</div>
<ArrowRight className="w-2 fill-current" />
</div>
);
};

0 comments on commit 1df6050

Please sign in to comment.