Skip to content

Commit

Permalink
Fixed useTexture hook
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Oct 13, 2023
1 parent 66426a4 commit 401eab1
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 29 deletions.
5 changes: 3 additions & 2 deletions dist/components/texture.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { TextureProps } from '../types/texture';
type Props = TextureProps;
type Props = {
name: string;
};
export declare const Texture: React.FC<Props>;
export {};
3 changes: 1 addition & 2 deletions dist/hooks/use-texture.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import { TextureProps } from '../types/texture';
export declare function useTexture({ name, frame }: TextureProps): HTMLImageElement;
export declare function useTexture(name: string): HTMLImageElement;
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions dist/types/texture.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "phaser-react-ui",
"description": "React interface render for Phaser engine",
"version": "1.9.4",
"version": "1.9.5",
"keywords": [
"phaser",
"interface",
Expand Down
9 changes: 5 additions & 4 deletions src/components/texture.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useRef, useLayoutEffect } from 'react';
import { useTexture } from '../hooks';
import { TextureProps } from '../types/texture';

type Props = TextureProps;
type Props = {
name: string
};

export const Texture: React.FC<Props> = (props) => {
const image = useTexture(props);
export const Texture: React.FC<Props> = ({ name }) => {
const image = useTexture(name);

const ref = useRef<HTMLDivElement>(null);

Expand Down
12 changes: 3 additions & 9 deletions src/hooks/use-texture.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { useMemo } from 'react';
import { useGame } from './use-game';
import { TextureProps } from '../types/texture';

export function useTexture({ name, frame }: TextureProps) {
export function useTexture(name: string) {
const game = useGame();

return useMemo(() => {
const texture = game.textures.get(name);

if (frame === undefined) {
return texture.getSourceImage() as HTMLImageElement;
}

// @ts-ignore
return texture.frames[frame].source.image as HTMLImageElement;
}, [name, frame]);
return texture.getSourceImage() as HTMLImageElement;
}, [name]);
}
4 changes: 0 additions & 4 deletions src/types/texture.ts

This file was deleted.

0 comments on commit 401eab1

Please sign in to comment.