-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: op render on preparing buy, merge, sell, place back, change cor * fix: add import back * feat: add op render check
- Loading branch information
Showing
19 changed files
with
602 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Entity } from "@latticexyz/recs"; | ||
|
||
export const initEntity: Entity = | ||
"0x0000000000000000000000000000000000000000000000000000000000000000" as Entity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMUD } from "@/MUDContext"; | ||
import { useEntityQuery } from "@latticexyz/react"; | ||
import { Has, getComponentValueStrict } from "@latticexyz/recs"; | ||
import { useEffect, useMemo } from "react"; | ||
|
||
export function useCreatureMap() { | ||
const { | ||
components: { Creature }, | ||
} = useMUD(); | ||
const _Creature = useEntityQuery([Has(Creature)], { | ||
updateOnValueChange: true, | ||
}); | ||
|
||
const creatureMap = useMemo(() => { | ||
return new Map( | ||
_Creature | ||
.map((row) => ({ | ||
...getComponentValueStrict(Creature, row), | ||
key: row, | ||
})) | ||
.map((c) => [Number(c.key), c]) | ||
); | ||
}, [_Creature, Creature]); | ||
|
||
return creatureMap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { decodeHero } from "@/lib/ulits"; | ||
import { useSystemConfig } from "./useSystemConfig"; | ||
import { HeroBaseAttr } from "./useChessboard"; | ||
import { useCreatureMap } from "./useCreatureMap"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export interface srcObjType { | ||
ava: string; | ||
color: string; | ||
mono: string; | ||
void: string; | ||
perUrl: string; | ||
} | ||
|
||
export const srcObj = { | ||
ava: "/avatar.gif", | ||
color: "/colorful.png", | ||
mono: "/monochrome.png", | ||
void: "/void.png", | ||
perUrl: "https://autochessia.4everland.store/creatures/", | ||
}; | ||
|
||
export function useHeroesAttr(arr: number[]): HeroBaseAttr[] { | ||
const creatureMap = useCreatureMap(); | ||
|
||
const { shopConfig } = useSystemConfig(); | ||
|
||
const [attrs, setAttrs] = useState<HeroBaseAttr[]>([]); | ||
|
||
useEffect(() => { | ||
setAttrs( | ||
arr | ||
?.map((item: number) => decodeHero(item)) | ||
?.map((item: number[]) => { | ||
const creature = creatureMap.get(item?.[2]); | ||
|
||
if (creature) { | ||
return { | ||
cost: shopConfig?.tierPrice?.[item?.[0] - 1], | ||
lv: item?.[0], | ||
url: item?.[0] > 0 ? srcObj.perUrl + item?.[1] + srcObj.ava : "", | ||
image: | ||
item?.[0] > 0 ? srcObj.perUrl + item?.[1] + srcObj.color : "", | ||
creature: item?.[0], | ||
oriHero: item?.[2], | ||
...creature, | ||
maxHealth: creature?.health, | ||
}; | ||
} | ||
return {}; | ||
}) as HeroBaseAttr[] | ||
); | ||
}, [arr, creatureMap, shopConfig?.tierPrice]); | ||
|
||
return attrs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useMUD } from "@/MUDContext"; | ||
import { initEntity } from "@/constant"; | ||
import { useComponentValue } from "@latticexyz/react"; | ||
|
||
export function useSystemConfig() { | ||
const { | ||
components: { ShopConfig, GameConfig }, | ||
} = useMUD(); | ||
|
||
const shopConfig = useComponentValue(ShopConfig, initEntity); | ||
const gameConfig = useComponentValue(GameConfig, initEntity); | ||
|
||
return { shopConfig, gameConfig }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { SetupNetworkResult } from "./setupNetwork"; | ||
import { overridableComponent } from "@latticexyz/recs"; | ||
|
||
export type ClientComponents = ReturnType<typeof createClientComponents>; | ||
|
||
export function createClientComponents({ components }: SetupNetworkResult) { | ||
return { | ||
...components, | ||
Board: overridableComponent(components.Board), | ||
Player: overridableComponent(components.Player), | ||
Hero: overridableComponent(components.Hero), | ||
// add your client components or overrides here | ||
}; | ||
} |
Oops, something went wrong.