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

fix: minor fixes on production #1252

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion client/src/hooks/helpers/useArmies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export const getArmyByEntityId = () => {
)[0];
};

const getArmy = (entity_id: ID) => {
const getArmy = (entity_id: ID): ArmyInfo | undefined => {
const armiesEntityIds = runQuery([Has(Army), HasValue(Army, { entity_id: entity_id })]);

return formatArmies(
Expand Down
11 changes: 6 additions & 5 deletions client/src/ui/components/construction/SelectPreviewBuilding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
BuildingEnumToString,
BuildingType,
EternumGlobalConfig,
RESOURCE_INPUTS,
ID,
RESOURCE_INPUTS,
RESOURCE_INPUTS_SCALED,
RESOURCE_OUTPUTS,
ResourcesIds,
Expand All @@ -24,6 +24,7 @@ import { getResourceBalance } from "@/hooks/helpers/useResources";
import { useQuestStore } from "@/hooks/store/useQuestStore";

import { usePlayResourceSound } from "@/hooks/useUISound";
import { ResourceMiningTypes } from "@/types";
import { QuestId } from "@/ui/components/quest/questDetails";
import { BUILDING_IMAGES_PATH } from "@/ui/config";
import { Headline } from "@/ui/elements/Headline";
Expand All @@ -36,7 +37,6 @@ import { ResourceIdToMiningType } from "@/ui/utils/utils";
import { BUILDING_COSTS_SCALED } from "@bibliothecadao/eternum";
import React, { useMemo, useState } from "react";
import { HintSection } from "../hints/HintModal";
import { ResourceMiningTypes } from "@/types";

// TODO: THIS IS TERRIBLE CODE, PLEASE REFACTOR

Expand Down Expand Up @@ -444,10 +444,11 @@ export const BuildingInfo = ({

const population = BUILDING_POPULATION[buildingId] || 0;
const capacity = BUILDING_CAPACITY[buildingId] || 0;
const perTick = RESOURCE_OUTPUTS[buildingId] || 0;
const resourceProduced = BUILDING_RESOURCE_PRODUCED[buildingId];
const ongoingCost = RESOURCE_INPUTS[resourceProduced] || 0;

const perTick = RESOURCE_OUTPUTS[resourceProduced] || 0;

const { getBalance } = getResourceBalance();

return (
Expand Down Expand Up @@ -497,7 +498,7 @@ export const BuildingInfo = ({
const balance = getBalance(entityId || 0, ongoingCost[Number(resourceId)].resource);
return (
<ResourceCost
key={index}
key={`ongoing-cost-${index}`}
type="horizontal"
resourceId={ongoingCost[Number(resourceId)].resource}
amount={ongoingCost[Number(resourceId)].amount}
Expand All @@ -519,7 +520,7 @@ export const BuildingInfo = ({
const balance = getBalance(entityId || 0, cost[Number(resourceId)].resource);
return (
<ResourceCost
key={index}
key={`fixed-cost-${index}`}
type="horizontal"
resourceId={cost[Number(resourceId)].resource}
amount={cost[Number(resourceId)].amount}
Expand Down
4 changes: 2 additions & 2 deletions client/src/ui/components/entities/Entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const Entity = ({ entityId, ...props }: EntityProps) => {
);
};

const name = entity.entityType === EntityType.TROOP ? army.name : entityName[entity.entityType];
const name = entity.entityType === EntityType.TROOP ? army?.name : entityName[entity.entityType];

const bgColour = entityState === EntityState.Traveling ? "bg-gold/10" : "bg-green/10 animate-pulse";

Expand All @@ -130,7 +130,7 @@ export const Entity = ({ entityId, ...props }: EntityProps) => {
<DepositResources
entityId={entityId}
battleInProgress={battleInProgress}
armyInBattle={Boolean(army.battle_id)}
armyInBattle={Boolean(army?.battle_id)}
/>
)}
</div>
Expand Down
22 changes: 14 additions & 8 deletions client/src/ui/components/resources/ResourceChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export const ResourceChip = ({

const [displayBalance, setDisplayBalance] = useState(balance);

const icon = useMemo(
() => (
<ResourceIcon
isLabor={isLabor}
withTooltip={false}
resource={findResourceById(getIconResourceId(resourceId, isLabor))?.trait as string}
size="sm"
className="mr-3 self-center"
/>
),
[resourceId],
);

useEffect(() => {
const interval = setInterval(() => {
setDisplayBalance((prevDisplayBalance) => {
Expand Down Expand Up @@ -77,14 +90,7 @@ export const ResourceChip = ({
setTooltip(null);
}}
>
<ResourceIcon
isLabor={isLabor}
withTooltip={false}
resource={findResourceById(getIconResourceId(resourceId, isLabor))?.trait as string}
size="sm"
className="mr-3 self-center"
/>

{icon}
<div className="flex justify-between w-full">
<div className=" self-center text-sm font-bold">
{currencyFormat(displayBalance ? Number(displayBalance) : 0, 0)}
Expand Down
16 changes: 8 additions & 8 deletions client/src/ui/modules/entity-details/BuildingEntityDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import useUIStore from "@/hooks/store/useUIStore";
import { ID } from "@bibliothecadao/eternum";
import { useState, useEffect } from "react";
import { TileManager } from "@/dojo/modelManager/TileManager";
import { useDojo } from "@/hooks/context/DojoContext";
import { useEntities } from "@/hooks/helpers/useEntities";
import useUIStore from "@/hooks/store/useUIStore";
import { soundSelector, useUiSounds } from "@/hooks/useUISound";
import { ResourceMiningTypes } from "@/types";
import { BuildingInfo, ResourceInfo } from "@/ui/components/construction/SelectPreviewBuilding";
import { BuildingType, ResourcesIds } from "@bibliothecadao/eternum";
import Button from "@/ui/elements/Button";
import { TileManager } from "@/dojo/modelManager/TileManager";
import { getEntityIdFromKeys, ResourceIdToMiningType } from "@/ui/utils/utils";
import { ResourceMiningTypes } from "@/types";
import { BuildingType, ID, ResourcesIds } from "@bibliothecadao/eternum";
import { getComponentValue } from "@dojoengine/recs";
import { useEntities } from "@/hooks/helpers/useEntities";
import { useEffect, useState } from "react";
import { View } from "../navigation/LeftNavigationModule";
import { soundSelector, useUiSounds } from "@/hooks/useUISound";

export const BuildingEntityDetails = () => {
const dojo = useDojo();
Expand Down Expand Up @@ -50,6 +49,7 @@ export const BuildingEntityDetails = () => {

const destroyButton = canBeDestroyed && selectedBuildingHex && (
<Button
key="destroy-button"
onClick={() => {
const tileManager = new TileManager(dojo.setup, {
col: selectedBuildingHex.outerCol,
Expand Down
15 changes: 11 additions & 4 deletions client/src/ui/modules/onboarding/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,17 @@ export const Naming = ({ onNext }: { onNext: () => void }) => {
<div className="flex space-x-2 py-2">
<ListSelect
title="Active Account: "
options={list().map((account) => ({
id: account.address,
label: <div className="w-[225px]">{displayAddress(account.address)}</div>,
}))}
options={list().map((account) => {
const addressName = getAddressName(ContractAddress(account.address));
return {
id: account.address,
label: (
<div className="w-[225px]">{`${addressName || "unknown"} (${displayAddress(
account.address,
)})`}</div>
),
};
})}
value={account.address}
onChange={select}
/>
Expand Down
Loading