mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-06-28 06:34:13 +00:00
refactor: remove solid textures
This commit is contained in:
parent
dae3a88734
commit
f3441d8033
3 changed files with 6 additions and 51 deletions
|
|
@ -6,14 +6,10 @@ import { LoadingContext } from "./Loading";
|
|||
import spritesheet from "@/data/blocks/spritesheet.json";
|
||||
import programmerArtSpritesheet from "@/data/blocks/programmer-art/spritesheet.json";
|
||||
|
||||
import _blockData from "@/data/blocks/data.json";
|
||||
const blockData: BlockData = _blockData;
|
||||
|
||||
interface Context {
|
||||
missingTexture: PIXI.Texture;
|
||||
textures: Record<string, PIXI.Texture>;
|
||||
programmerArtTextures: Record<string, PIXI.Texture>;
|
||||
solidTextures: Record<string, PIXI.Texture>;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
|
|
@ -35,7 +31,6 @@ export const TexturesProvider = ({ children }: Props) => {
|
|||
);
|
||||
const texturesRef = useRef<Record<string, PIXI.Texture>>({});
|
||||
const programmerArtTexturesRef = useRef<Record<string, PIXI.Texture>>({});
|
||||
const solidTexturesRef = useRef<Record<string, PIXI.Texture>>({});
|
||||
|
||||
// Load textures
|
||||
useEffect(() => {
|
||||
|
|
@ -52,30 +47,6 @@ export const TexturesProvider = ({ children }: Props) => {
|
|||
programmerArtSheet.parse().then((t) => {
|
||||
programmerArtTexturesRef.current = { ...t, "air.png": airTexture };
|
||||
});
|
||||
|
||||
// Load solid textures
|
||||
const solidTexturesCollection: Record<string, PIXI.Texture> = {};
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = 16;
|
||||
canvas.height = 16;
|
||||
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
|
||||
Object.entries(blockData).forEach(([blockName, data]) => {
|
||||
ctx.fillStyle = `rgb(${data.color[0]}, ${data.color[1]}, ${data.color[2]}, ${data.color[3]})`;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
const image = new Image();
|
||||
image.src = canvas.toDataURL();
|
||||
|
||||
const baseTexture = new PIXI.BaseTexture(image);
|
||||
const texture = new PIXI.Texture(baseTexture);
|
||||
solidTexturesCollection[blockName] = texture;
|
||||
});
|
||||
|
||||
solidTexturesRef.current = solidTexturesCollection;
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
|
|
@ -85,7 +56,6 @@ export const TexturesProvider = ({ children }: Props) => {
|
|||
missingTexture: missingTextureRef.current,
|
||||
textures: texturesRef.current,
|
||||
programmerArtTextures: programmerArtTexturesRef.current,
|
||||
solidTextures: solidTexturesRef.current,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue