mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-06-28 06:34:13 +00:00
feat: use programmer art textures when on versions 1.13 and below
This commit is contained in:
parent
dca9e43e99
commit
0bfe70809d
13 changed files with 97 additions and 53 deletions
18
src/hooks/useBlockData.ts
Normal file
18
src/hooks/useBlockData.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { useMemo } from "react";
|
||||
|
||||
import _blockData from "@/data/blocks/data.json";
|
||||
const blockData: BlockData = _blockData;
|
||||
|
||||
export function useBlockData(version: number): BlockData {
|
||||
return useMemo(() => {
|
||||
const result: BlockData = {};
|
||||
|
||||
for (const key in blockData) {
|
||||
if (blockData[key].version <= version) {
|
||||
result[key] = blockData[key];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}, [version]);
|
||||
}
|
||||
23
src/hooks/useTextures.ts
Normal file
23
src/hooks/useTextures.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { useContext, useMemo } from "react";
|
||||
import { BaseTexture, Texture } from "pixi.js";
|
||||
|
||||
import { TexturesContext } from "@/context/Textures";
|
||||
import { useBlockData } from "./useBlockData";
|
||||
|
||||
export function useTextures(version: number, blocks?: string[]): Record<string, Texture> {
|
||||
const { missingTexture, textures, programmerArtTextures } = useContext(TexturesContext);
|
||||
|
||||
const blockData = useBlockData(version);
|
||||
const blocksToUse = blocks || Object.keys(blockData);
|
||||
|
||||
return useMemo(() => {
|
||||
return blocksToUse.reduce<Record<string, Texture>>((textureMap, block) => {
|
||||
if (version <= 1130) {
|
||||
textureMap[block] = programmerArtTextures[`${block}.png`] ?? missingTexture;
|
||||
} else {
|
||||
textureMap[block] = textures[`${block}.png`] ?? missingTexture;
|
||||
}
|
||||
return textureMap;
|
||||
}, {});
|
||||
}, [blocksToUse, version, missingTexture, textures, programmerArtTextures]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue