Skip to content

Commit

Permalink
Merge pull request #149 from remarkablegames/fix/render
Browse files Browse the repository at this point in the history
fix(render): instantiate Rectangle in gameobject
  • Loading branch information
remarkablemark authored Apr 7, 2024
2 parents 26fcd6d + 80ba8e2 commit 78ca4b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/render/gameobject.test.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import Phaser from 'phaser';
import type { JSX } from 'react';

import { Container, GameObject, Text } from '..';
import { Container, GameObject, Rectangle, Text } from '..';
import { createGameObject, setProps } from '.';

jest.mock('phaser', () => {
const GameObject = jest.fn();
class Container extends GameObject {
add = jest.fn();
}
class Rectangle extends GameObject {}
class Text extends GameObject {}

return {
GameObjects: {
Container,
GameObject,
Particles: {},
Rectangle,
Text,
},

Expand Down Expand Up @@ -53,8 +55,8 @@ describe('invalid element', () => {
});
});

it('creates game object from element', () => {
expect(createGameObject(<Text />, scene)).toBeInstanceOf(GameObject);
it.each([Rectangle, Text])('creates game object from %p', (Component) => {
expect(createGameObject(<Component />, scene)).toBeInstanceOf(GameObject);
});

it('creates game object from component', () => {
Expand Down
12 changes: 12 additions & 0 deletions src/render/gameobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export function createGameObject(element: JSX.Element, scene: Phaser.Scene) {
gameObject = new element.type(scene, props.x, props.y, text, style);
break;

case element.type === Phaser.GameObjects.Rectangle:
gameObject = new element.type(
scene,
props.x,
props.y,
props.width,
props.height,
props.fillColor,
props.fillAlpha,
);
break;

case gameObjects.indexOf(element.type) > -1:
gameObject = new element.type(scene);
break;
Expand Down

0 comments on commit 78ca4b6

Please sign in to comment.