Skip to content

Commit

Permalink
Merge 25d8a1c into 11f2a40
Browse files Browse the repository at this point in the history
  • Loading branch information
jjg1914 committed Apr 21, 2018
2 parents 11f2a40 + 25d8a1c commit 5e568df
Show file tree
Hide file tree
Showing 31 changed files with 2,795 additions and 1,167 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
coverage/
node_modules/
lib/
yarn-error.log
8 changes: 8 additions & 0 deletions assets.config.json
@@ -0,0 +1,8 @@
{
"include": [
"lib/entities/*.js"
],
"exclude": [
"**/entity.js"
]
}
16 changes: 10 additions & 6 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "mu-engine",
"version": "0.12.0",
"version": "0.13.0",
"description": "mu-engine",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -46,24 +46,28 @@
},
"devDependencies": {
"@types/chai": "^4.0.5",
"@types/mocha": "^2.2.44",
"@types/chai-subset": "^1.3.1",
"@types/mocha": "^5.2.0",
"@types/sinon": "^4.0.0",
"@types/sinon-chai": "^2.7.29",
"chai": "^4.1.2",
"chai-iterator": "^1.1.4",
"chai-subset": "^1.6.0",
"coveralls": "^3.0.0",
"jsdom": "^9.0",
"jsdom": "^11.8.0",
"mocha": "^5.0.1",
"mocha-jsdom": "^1.1.0",
"nyc": "^11.3.0",
"sinon": "^4.1.2",
"sinon-chai": "^2.14.0",
"sinon-chai": "^3.0.0",
"source-map-support": "^0.5.0",
"ts-node": "^5.0.1",
"ts-node": "^6.0.0",
"tslint": "^5.8.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.4.1"
},
"dependencies": {
"global-jsdom": "^4.2.0",
"jsdom-global": "^3.0.2",
"json": "^9.0.6",
"npm": "^5.7.1"
}
Expand Down
29 changes: 29 additions & 0 deletions src/behaviors/negate-behavior.ts
@@ -0,0 +1,29 @@
import {
Behavior,
BehaviorState,
BehaviorOptions,
} from "./behavior";

export class NegateBehavior implements Behavior {
private _negate: Behavior;

constructor(negate: Behavior) {
this._negate = negate;
}

reset(): void {
this._negate.reset();
}

call(options: BehaviorOptions): BehaviorState {
const tmp = this._negate.call(options);

if (tmp === "success") {
return "failure";
} else if (tmp === "failure") {
return "success";
} else {
return "pending";
}
}
}
9 changes: 9 additions & 0 deletions src/behaviors/phase-behavior.ts
Expand Up @@ -6,6 +6,7 @@ import {

export interface PhaseBehaviorConfig {
period: number | (() => number);
leading?: boolean;
}

export class PhaseBehavior implements Behavior {
Expand All @@ -17,6 +18,14 @@ export class PhaseBehavior implements Behavior {
this._t = 0;
this._child = child;
this._config = config;

if (this._config.leading) {
if (typeof this._config.period === "function") {
this._t = this._config.period();
} else {
this._t = this._config.period;
}
}
}

reset(): void {
Expand Down
31 changes: 28 additions & 3 deletions src/behaviors/repeat-behavior.ts
@@ -1,16 +1,25 @@
import { Behavior, BehaviorState, BehaviorOptions } from "./behavior";

export interface RepeatBehaviorConfig {
count: number;
}

export class RepeatBehavior implements Behavior {
private _pending: boolean;
private _child: Behavior;
private _count: number;
private _countMax: number;

constructor(arg: Behavior) {
constructor(arg: Behavior, config?: Partial<RepeatBehaviorConfig>) {
this._pending = false;
this._child = arg;
this._count = config && config.count || 1;
this._countMax = config && config.count || 1;
}

reset(): void {
this._pending = false;
this._count = this._countMax;

this._child.reset();
}
Expand All @@ -23,10 +32,26 @@ export class RepeatBehavior implements Behavior {
switch (this._child.call(options)) {
case "success":
this._pending = false;
return "success";
this._count -= 1;

if (this._count === 0) {
return "success";
} else {
this._pending = false;
this._child.reset();
return "pending";
}
case "failure":
this._pending = false;
return "failure";
this._count -= 1;

if (this._count === 0) {
return "failure";
} else {
this._pending = false;
this._child.reset();
return "pending";
}
case "pending":
this._pending = true;
return "pending";
Expand Down
31 changes: 31 additions & 0 deletions src/behaviors/until-behavior.ts
@@ -0,0 +1,31 @@
import {
Behavior,
BehaviorState,
BehaviorOptions,
} from "./behavior";

export class UntilBehavior implements Behavior {
private _until: Behavior;

constructor(until: Behavior) {
this._until = until;
}

reset(): void {
this._until.reset();
}

call(options: BehaviorOptions): BehaviorState {
const tmp = this._until.call(options);

if (tmp === "success") {
return tmp;
} else {
if (tmp === "failure") {
this._until.reset();
}

return "pending";
}
}
}
15 changes: 8 additions & 7 deletions src/behaviors/whilst-behavior.ts
Expand Up @@ -2,25 +2,26 @@ import { Behavior, BehaviorState, BehaviorOptions } from "./behavior";

export class WhilstBehavior implements Behavior {
private _whilst: Behavior;
private _loop: Behavior;

constructor(whilst: Behavior, loop: Behavior) {
constructor(whilst: Behavior) {
this._whilst = whilst;
this._loop = loop;
}

reset(): void {
this._whilst.reset();
this._loop.reset();
}

call(options: BehaviorOptions): BehaviorState {
const tmp = this._whilst.call(options);

if (tmp === "success") {
return this._loop.call(options);
if (tmp === "failure") {
return "success";
} else {
return tmp;
if (tmp === "success") {
this._whilst.reset();
}

return "pending";
}
}
}
25 changes: 25 additions & 0 deletions src/components/background-component.ts
@@ -0,0 +1,25 @@
export interface BackgroundData {
fixed: boolean;
xPeriod: number;
yPeriod: number;
xAmp: number;
yAmp: number;
}

export class BackgroundComponent implements BackgroundData {
fixed: boolean;
xPeriod: number;
yPeriod: number;
xAmp: number;
yAmp: number;

constructor(options?: Partial<BackgroundData>) {
this.fixed = false;
this.xPeriod = 0;
this.yPeriod = 0;
this.xAmp = 0;
this.yAmp = 0;

Object.assign(this, options);
}
}
47 changes: 47 additions & 0 deletions src/components/particle-component.ts
@@ -0,0 +1,47 @@
export type ParticleField = "LIFETIME" |
"X" | "Y" |
"X_SUBPIXEL" | "Y_SUBPIXEL" |
"X_SPEED" | "Y_SPEED" |
"X_ACCEL" | "Y_ACCEL" |
"SPRITE_FRAME";

export const PARTICLE_FIELDS = [
"LIFETIME",
"X",
"Y",
"X_SUBPIXEL",
"Y_SUBPIXEL",
"X_SPEED",
"Y_SPEED",
"X_ACCEL",
"Y_ACCEL",
"SPRITE_FRAME",
] as ParticleField[];

export const PARTICLE_FIELDS_ENUM = {} as { [key in ParticleField]: number };
for (let i = 0; i < PARTICLE_FIELDS.length; ++i) {
PARTICLE_FIELDS_ENUM[PARTICLE_FIELDS[i]] = i;
}

export interface ParticleData {
sprite: string;
length: number;
capacity: number;
data: number[];
}

export class ParticleComponent implements ParticleData {
sprite: string;
length: number;
capacity: number;
data: number[];

constructor(options?: Partial<ParticleData>) {
this.sprite = "";
this.length = 0;
this.capacity = 0;
this.data = [];

Object.assign(this, options);
}
}
7 changes: 7 additions & 0 deletions src/components/render-component.ts
@@ -1,8 +1,14 @@
import { Assets } from "../util/assets";
import { Transform } from "../util/matrix";
import { Shape, Dimensions } from "../util/shape";

export interface PaintFunction {
(ctx: CanvasRenderingContext2D, assets: Assets): void;
}

export interface RenderData {
visible?: boolean;
paint?: PaintFunction;
wraparound?: boolean;
stroke?: string;
fill?: string;
Expand All @@ -19,6 +25,7 @@ export interface RenderData {

export class RenderComponent implements RenderData {
visible?: boolean;
paint?: PaintFunction;
wraparound?: boolean;
stroke?: string;
fill?: string;
Expand Down
25 changes: 25 additions & 0 deletions src/components/stage-component.ts
@@ -0,0 +1,25 @@
import { Assets } from "../util/assets";
import { Stage } from "../util/stage";

export interface StageData {
name: string;
assets: Assets;
stage: Stage;
gravity: number;
}

export class StageComponent implements StageData {
name: string;
assets: Assets;
stage: Stage;
gravity: number;

constructor(options?: Partial<StageData>) {
this.name = "";
this.assets = new Assets();
this.stage = new Stage(0, 0);
this.gravity = 0;

Object.assign(this, options);
}
}
21 changes: 21 additions & 0 deletions src/components/tileset-component.ts
@@ -0,0 +1,21 @@
import { Assets } from "../util/assets";

export interface TilesetData {
assets: { load(asset: string): any };
tileset: string;
data: number[][];
}

export class TilesetComponent implements TilesetData {
assets: { load(asset: string): any };
tileset: string;
data: number[][];

constructor(options?: Partial<TilesetData>) {
this.assets = new Assets();
this.tileset = "";
this.data = [];

Object.assign(this, options);
}
}

0 comments on commit 5e568df

Please sign in to comment.