Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Functions not in TS definition files #60 #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions react-native-game-engine.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(entities: any[], screen: ScaledSize, layout:LayoutRectangle): Component;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no such type LayoutRectangle

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also no Component


export function DefaultRenderer(defaultRendererOptions: DefaultRendererOptions): any;

export class DefaultTimer {}
export class DefaultTimer {
loop: (time:number) => void;
start: () => void;
stop: () => void;
subscribe: (callback: () => void) => void;
unsubscribe: (callback: () => void) => void;
}

interface TouchProcessorOptions {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like arguments for this interface may be optional because there are default values provided:

export default ({
	triggerPressEventBefore = 200,
	triggerLongPressEventAfter = 700,
	moveThreshold = 0
}) => {

triggerPressEventBefore: number;
Expand All @@ -38,20 +39,32 @@ declare module "react-native-game-engine" {
}

export type GameEngineSystem = (entities: any, update: GameEngineUpdateEventOptionType) => any;

interface GameEngineEntity {
[key:string]: any;
renderer?: JSX.Element | React.ComponentClass<any. any>;
Copy link

@drplauska drplauska May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React.ComponentClass<any>

}

type GameEngineEntities = Record<string | number, GameEngineEntity>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for? Doesn't look like it's used anywhere


export interface GameEngineProperties {
systems?: any[];
entities?: {} | Promise<any>;
renderer?: any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @SimpleProgrammingAU - this all looks really good. Quick question, should this line be: renderer?: DefaultRenderer | any; ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be renderer: Renderer and change the type definition for DefaultRenderer to Renderer to make it a bit more inclusive.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.. I ask because of this change that you made: timer?: DefaultTimer | any; - hence I was thinking we do the same for the renderer for the sake of consistency..

What exactly did you mean by:

and change the type definition for DefaultRenderer to Renderer to make it a bit more inclusive.

Are you saying that the Default in DefaultRenderer is redundant from a naming convention point of view? As in, the DefaultRenderer function should simple adhere to a Renderer function signature?

Lastly, since I'm not 100% across TS, would changing the name break anything from a backwards compatibility, tooling and intellisense (VS Code?) perspective?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me have a play around with somethings myself because I'm not 100%, either! I'll get back to you tomorrow (I'm UTC+11) with either a new commit or more commentary =)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimpleProgrammingAU I'm curious where this ended up. Any updates on your findings?

touchProcessor?: any;
timer?: any;
timer?: DefaultTimer | any;
running?: boolean;
onEvent?: any;
style?: StyleProp<ViewStyle>;
children?: React.ReactNode;
}

export class GameEngine extends React.Component<GameEngineProperties> {}
export class GameEngine extends React.Component<GameEngineProperties> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add
render: () => JSX.Element;

dispatch: (event:any) => void;
start: () => void;
stop: () => void;
swap: ({}:any | Promise) => void | Promise<void>
Copy link

@drplauska drplauska May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap: ({}:any | Promise<any>) => void | Promise<void>

as Promise shall have 1 argument

}

export type TouchEventType = 'start' | 'end' | 'move' | 'press' | 'long-press';

Expand Down Expand Up @@ -86,13 +99,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<ViewStyle>;
children?: React.ReactNode;
}

export class GameLoop extends React.Component<GameLoopProperties> {}
export class GameLoop extends React.Component<GameLoopProperties> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render: () => JSX.Element;
here too

start: () => void;
stop: () => void;
}
}