From ba9cd2d9b162db876b64c5c309343b97d13b7f60 Mon Sep 17 00:00:00 2001 From: Sam <10446022+SimpleProgrammingAU@users.noreply.github.com> Date: Sat, 26 Dec 2020 10:46:49 +1100 Subject: [PATCH 1/2] Fixes Functions not in TS definition files #60 --- react-native-game-engine.d.ts | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/react-native-game-engine.d.ts b/react-native-game-engine.d.ts index 08d5047..7edc5cc 100644 --- a/react-native-game-engine.d.ts +++ b/react-native-game-engine.d.ts @@ -5,14 +5,15 @@ declare module "react-native-game-engine" { import * as React from "react"; import { StyleProp, ViewStyle, ScaledSize } from "react-native"; - interface DefaultRendererOptions { - state: any; - screen: ScaledSize; - } - - export function DefaultRenderer(defaultRendererOptions: DefaultRendererOptions): any; + export function DefaultRenderer(entities: any[], screen: ScaledSize, layout:LayoutRectangle): Component; - export class DefaultTimer {} + export class DefaultTimer { + loop: (time:number) => void; + start: () => void; + stop: () => void; + subscribe: (callback: () => void) => void; + unsubscribe: (callback: () => void) => void; + } interface TouchProcessorOptions { triggerPressEventBefore: number; @@ -44,14 +45,19 @@ declare module "react-native-game-engine" { entities?: {} | Promise; renderer?: any; touchProcessor?: any; - timer?: any; + timer?: DefaultTimer | any; running?: boolean; onEvent?: any; style?: StyleProp; children?: React.ReactNode; } - export class GameEngine extends React.Component {} + export class GameEngine extends React.Component { + dispatch: (event:any) => void; + start: () => void; + stop: () => void; + swap: ({}:any | Promise) => void | Promise + } export type TouchEventType = 'start' | 'end' | 'move' | 'press' | 'long-press'; @@ -86,13 +92,16 @@ declare module "react-native-game-engine" { export interface GameLoopProperties { touchProcessor?: any; - timer?: any; + timer?: DefaultTimer | any; running?: boolean; onUpdate?: (args: GameLoopUpdateEventOptionType) => void; style?: StyleProp; children?: React.ReactNode; } - export class GameLoop extends React.Component {} + export class GameLoop extends React.Component { + start: () => void; + stop: () => void; + } } From af80426fa82397b3b7b90c3630c2b93ae566e45e Mon Sep 17 00:00:00 2001 From: Sam <10446022+SimpleProgrammingAU@users.noreply.github.com> Date: Sun, 27 Dec 2020 08:28:46 +0000 Subject: [PATCH 2/2] Allows for type checking on the renderer property Performs type checking for the renderer property, thus preventing anything other than JSX, or a reference to the React component class. Using the component class rather than a JSX element avoids issues with required props. --- react-native-game-engine.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/react-native-game-engine.d.ts b/react-native-game-engine.d.ts index 7edc5cc..47b54f0 100644 --- a/react-native-game-engine.d.ts +++ b/react-native-game-engine.d.ts @@ -39,7 +39,14 @@ declare module "react-native-game-engine" { } export type GameEngineSystem = (entities: any, update: GameEngineUpdateEventOptionType) => any; + + interface GameEngineEntity { + [key:string]: any; + renderer?: JSX.Element | React.ComponentClass; + } + type GameEngineEntities = Record; + export interface GameEngineProperties { systems?: any[]; entities?: {} | Promise;