Skip to content

Commit

Permalink
begin splitting up the simulation schema
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak committed Oct 16, 2020
1 parent 515fdb8 commit bfa08c7
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 134 deletions.
137 changes: 3 additions & 134 deletions src/components/ide/Simulator/simulation/schema/index.js
@@ -1,136 +1,5 @@
// @flow

export type Point = {|
x: number,
y: number,
|};

export type Pose = {|
x: number,
y: number,
angle: number,
|};

type Translation = {|
position: Point,
|};

type Rotation = {|
angle: number,
|};

type RenderColor = {|
fillStyle?: string,
|};

type RenderVisibility = {|
opacity?: number,
visible?: boolean,
|};

type RenderSprite = {|
sprite?: {
texture?: string,
},
|};

type Static = {|
isStatic?: boolean,
|};

type Sensor = {|
isSensor?: boolean,
|};

type Line = {|
plugin?: {
hedgehog: {
isLine?: boolean,
},
},
|};

type Density = {|
density?: number,
|};

type FrictionAir = {|
frictionAir?: number,
|};

type Label = {|
label?: string,
|};

export type RobotProps = {|
...Translation,
...Rotation,
render?: {
...RenderColor,
...RenderSprite,
},
|};

type AllProps = {|
...RobotProps,
render?: {
...RenderColor,
...RenderVisibility,
...RenderSprite,
},
...Static,
...Sensor,
...Line,
...Density,
...FrictionAir,
...Label,
|};

export type Rectangle = {
type: 'rectangle',
width: number,
height: number,
...AllProps,
};

export type Circle = {
type: 'circle',
radius: number,
...AllProps,
};

export type Svg = {
type: 'svg',
src: string,
scale: number,
granularity: number,
...AllProps,
};

export type TouchSensor = {
type: 'touch',
port: number,
objects: Object[],
};

export type RobotPart = TouchSensor;

export type Robot = {
type: 'robot',
name: string,
...RobotProps,
parts: RobotPart[],
};

export type Simulation = {
center: Point,
width: number,
height: number,
};

export type Object = Rectangle | Circle | Svg | Robot;

export type SimulatorJson = {
simulation: Simulation,
objects: Object[],
};
export * from './misc';
export * from './objects';
export * from './simulation';
11 changes: 11 additions & 0 deletions src/components/ide/Simulator/simulation/schema/misc.js
@@ -0,0 +1,11 @@
// @flow

export type Point = {|
x: number,
y: number,
|};

export type Pose = {|
...Point,
angle: number,
|};
116 changes: 116 additions & 0 deletions src/components/ide/Simulator/simulation/schema/objects.js
@@ -0,0 +1,116 @@
// @flow

import type { Point } from './misc';

type Translation = {|
position: Point,
|};

type Rotation = {|
angle: number,
|};

type RenderColor = {|
fillStyle?: string,
|};

type RenderVisibility = {|
opacity?: number,
visible?: boolean,
|};

type RenderSprite = {|
sprite?: {
texture?: string,
},
|};

type Static = {|
isStatic?: boolean,
|};

type Sensor = {|
isSensor?: boolean,
|};

type Line = {|
plugin?: {
hedgehog: {
isLine?: boolean,
},
},
|};

type Density = {|
density?: number,
|};

type FrictionAir = {|
frictionAir?: number,
|};

type Label = {|
label?: string,
|};

export type RobotProps = {|
...Translation,
...Rotation,
render?: {
...RenderColor,
...RenderSprite,
},
|};

type AllProps = {|
...RobotProps,
render?: {
...RenderColor,
...RenderVisibility,
...RenderSprite,
},
...Static,
...Sensor,
...Line,
...Density,
...FrictionAir,
...Label,
|};

export type Rectangle = {
type: 'rectangle',
width: number,
height: number,
...AllProps,
};

export type Circle = {
type: 'circle',
radius: number,
...AllProps,
};

export type Svg = {
type: 'svg',
src: string,
scale: number,
granularity: number,
...AllProps,
};

export type TouchSensor = {
type: 'touch',
port: number,
objects: Object[],
};

export type RobotPart = TouchSensor;

export type Robot = {
type: 'robot',
name: string,
...RobotProps,
parts: RobotPart[],
};

export type Object = Rectangle | Circle | Svg | Robot;
15 changes: 15 additions & 0 deletions src/components/ide/Simulator/simulation/schema/simulation.js
@@ -0,0 +1,15 @@
// @flow

import type { Point } from './misc';
import type { Object } from './objects';

export type Simulation = {
center: Point,
width: number,
height: number,
};

export type SimulatorJson = {
simulation: Simulation,
objects: Object[],
};

0 comments on commit bfa08c7

Please sign in to comment.