Skip to content

Commit 2c03bb6

Browse files
committed
implement integration with createjs
1 parent 7125c7e commit 2c03bb6

File tree

122 files changed

+15711
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+15711
-0
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# RobotlegsJS CreateJS Changelog:
2+
3+
## Robotlegs-CreateJS 1.0.0
4+
5+
### v1.0.0 - Planned stable version
6+
7+
- [x] Add instructions of how to install the **@robotlegsjs/createjs** package into **README.md**.
8+
9+
- [ ] Use [**Function Types**](https://www.typescriptlang.org/docs/handbook/functions.html) for handlers and callbacks instead of generic **Function** type.
10+
11+
- [ ] Evaluate if **IMediator** interface should be mandatory.
12+
13+
- [x] Update **Prettier** rules:
14+
15+
- [x] **printWidth** should be around **140** characters per line.
16+
17+
- [ ] Improve Code Coverage to reach 100%.
18+
19+
- [ ] Migrate [original documentation](https://github.com/robotlegs/robotlegs-framework/blob/master/src/readme.md) and adapt it to TypeScript and CreateJS.
20+
21+
## Robotlegs-CreateJS 0.2.0
22+
23+
### v0.2.0
24+
25+
- Added integration with `createjs` library (see #1).

example/Game.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
import { Context, MVCSBundle } from "@robotlegsjs/core";
9+
10+
import { ContextView, CreateJSBundle } from "../src";
11+
12+
import { MyConfig } from "./config/MyConfig";
13+
14+
import { RobotlegsView } from "./view/RobotlegsView";
15+
16+
export class Game {
17+
18+
private _canvas: HTMLCanvasElement;
19+
private _stage: createjs.Stage;
20+
21+
private _context: Context;
22+
23+
constructor () {
24+
this.init();
25+
}
26+
27+
private init(): void {
28+
this._canvas = <HTMLCanvasElement>(document.getElementById("canvas"));
29+
this._stage = new createjs.Stage(this._canvas);
30+
31+
this._context = new Context();
32+
this._context.install(MVCSBundle, CreateJSBundle).
33+
configure(new ContextView(this._stage)).
34+
configure(MyConfig).
35+
initialize();
36+
37+
// enable touch interactions if supported on the current device:
38+
createjs.Touch.enable(this._stage);
39+
40+
// enabled mouse over / out events
41+
this._stage.enableMouseOver(10);
42+
this._stage.mouseMoveOutside = true; // keep tracking the mouse even when it leaves the canvas
43+
44+
let robotlegs: RobotlegsView = new RobotlegsView();
45+
46+
robotlegs.x = this._canvas.width / 2;
47+
robotlegs.y = this._canvas.height / 2;
48+
49+
this._stage.addChild(robotlegs);
50+
51+
window.addEventListener("resize", this.handleResize.bind(this));
52+
createjs.Ticker.addEventListener("tick", this.tick.bind(this));
53+
}
54+
55+
private handleResize(): void {
56+
this._stage.update();
57+
}
58+
59+
private tick(event: Object): void {
60+
this._stage.update(event);
61+
}
62+
}

example/config/MyConfig.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
import { inject, injectable, IConfig } from "@robotlegsjs/core";
9+
10+
import { IMediatorMap } from "../../src/index";
11+
12+
import { RobotlegsMediator } from "../mediator/RobotlegsMediator";
13+
import { SmileyMediator } from "../mediator/SmileyMediator";
14+
15+
import { RobotlegsView } from "../view/RobotlegsView";
16+
import { SmileyView } from "../view/SmileyView";
17+
18+
@injectable()
19+
export class MyConfig implements IConfig {
20+
@inject(IMediatorMap)
21+
private _mediatorMap: IMediatorMap;
22+
23+
public configure(): void {
24+
this._mediatorMap.map(RobotlegsView).toMediator(RobotlegsMediator);
25+
this._mediatorMap.map(SmileyView).toMediator(SmileyMediator);
26+
}
27+
}

example/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
import "reflect-metadata";
9+
10+
import { Game } from "./Game";
11+
12+
(<any>window).initGame = () => {
13+
let game: Game = new Game();
14+
(<any>window).game = game;
15+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
import { Mediator } from "../../src/index";
9+
10+
import { RobotlegsView } from "../view/RobotlegsView";
11+
import { SmileyView } from "../view/SmileyView";
12+
13+
export class RobotlegsMediator extends Mediator<RobotlegsView> {
14+
public initialize(): void {
15+
console.log("RobotlegsMediator initialized!");
16+
17+
this.view.on("click", this.onClick, this);
18+
}
19+
20+
public onClick(event: createjs.Event): void {
21+
let radius: number = 50 + Math.random() * 50;
22+
this.view.stage.addChild(new SmileyView(radius));
23+
}
24+
25+
public destroy(): void {
26+
console.log("RobotlegsMediator destroyed!");
27+
}
28+
}

example/mediator/SmileyMediator.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
import { Mediator } from "../../src/index";
9+
10+
import { SmileyView } from "../view/SmileyView";
11+
12+
export class SmileyMediator extends Mediator<SmileyView> {
13+
public initialize(): void {
14+
console.log("SmileyMediator initialized!");
15+
16+
this.view.on("click", this.onClick, this);
17+
}
18+
19+
public onClick(event: createjs.Event): void {
20+
this.view.parent.removeChild(this.view);
21+
}
22+
23+
public destroy(): void {
24+
console.log("SmileyMediator destroyed!");
25+
}
26+
}

example/view/RobotlegsView.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
export class RobotlegsView extends createjs.Container {
9+
constructor() {
10+
super();
11+
12+
this.loadLogo();
13+
}
14+
15+
private loadLogo(): void {
16+
let logo: HTMLImageElement = new Image();
17+
18+
logo.onload = this.logoLoaded.bind(this);
19+
logo.crossOrigin = "anonymous";
20+
logo.src = "images/robotlegs.png";
21+
}
22+
23+
private logoLoaded(event: Event): void {
24+
let logo: HTMLImageElement = <HTMLImageElement>event.target;
25+
let bitmap: createjs.Bitmap = new createjs.Bitmap(event.target);
26+
27+
bitmap.x = -(logo.width / 2);
28+
bitmap.y = -(logo.height / 2);
29+
30+
this.addChild(bitmap);
31+
32+
let area: createjs.Shape = new createjs.Shape();
33+
let graphics: createjs.Graphics = area.graphics;
34+
35+
graphics.beginFill("#f00");
36+
graphics.drawRect(bitmap.x, bitmap.y, logo.width, logo.height);
37+
38+
this.hitArea = area;
39+
40+
this.mouseEnabled = true;
41+
this.mouseChildren = false;
42+
}
43+
}

example/view/SmileyView.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
3+
//
4+
// NOTICE: You are permitted to use, modify, and distribute this file
5+
// in accordance with the terms of the license agreement accompanying it.
6+
// ------------------------------------------------------------------------------
7+
8+
export class SmileyView extends createjs.Container {
9+
private _radius: number;
10+
11+
constructor(radius: number) {
12+
super();
13+
14+
this._radius = Math.max(radius, 50);
15+
16+
this.drawSmiley();
17+
this.move();
18+
}
19+
20+
private drawSmiley(): void {
21+
let shape: createjs.Shape = new createjs.Shape();
22+
let graphics: createjs.Graphics = shape.graphics;
23+
24+
// Head
25+
graphics.setStrokeStyle(10, "round", "round");
26+
graphics.beginStroke("#000");
27+
graphics.beginFill("#FC0");
28+
graphics.drawCircle(0, 0, this._radius);
29+
30+
// Mouth
31+
graphics.beginFill("FC0");
32+
graphics.arc(0, 0, this._radius * 0.65, 0, Math.PI, false);
33+
34+
// Right eye
35+
graphics.beginStroke("FC0");
36+
graphics.beginFill("#000");
37+
graphics.drawCircle(-(this._radius / 3), -(this._radius / 4), this._radius / 8);
38+
39+
// Left eye
40+
graphics.beginStroke("FC0");
41+
graphics.beginFill("#000");
42+
graphics.drawCircle(this._radius / 3, -(this._radius / 4), this._radius / 8);
43+
44+
this.addChild(shape);
45+
}
46+
47+
private move(): void {
48+
this.x = Math.random() * 960;
49+
this.y = Math.random() * 400;
50+
}
51+
}

karma.conf.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
process.env.TEST = true;
2+
process.env.NODE_ENV = "test";
3+
4+
const webpackConfig = require("./webpack.config.js")({ production: false, karma: true });
5+
6+
delete webpackConfig.entry;
7+
8+
module.exports = config => {
9+
10+
var configuration = {
11+
basePath: "",
12+
frameworks: [
13+
"mocha",
14+
"chai",
15+
"sinon",
16+
"es6-shim"
17+
],
18+
files: [
19+
{ pattern: "node_modules/reflect-metadata/Reflect.js", include: true },
20+
{ pattern: "node_modules/bluebird/js/browser/bluebird.js", include: true },
21+
{ pattern: "node_modules/createjs/builds/1.0.0/createjs.js", include: true },
22+
{ pattern: "./test/**/**/**.test.ts", include: true },
23+
{ pattern: '**/*.map', served: true, included: false, watched: true }
24+
],
25+
preprocessors: {
26+
"./**/**/**/**.ts": ["sourcemap"],
27+
"./test/**/**/**.test.ts": ["webpack"]
28+
},
29+
webpack: webpackConfig,
30+
webpackMiddleware: {
31+
noInfo: true
32+
},
33+
plugins: [
34+
"karma-webpack",
35+
"karma-sourcemap-writer",
36+
"karma-sourcemap-loader",
37+
"karma-remap-istanbul",
38+
"karma-mocha-reporter",
39+
"karma-mocha",
40+
"karma-chai",
41+
"karma-sinon",
42+
"karma-es6-shim",
43+
"karma-coverage-istanbul-reporter"
44+
],
45+
reporters: (
46+
config.singleRun ?
47+
["dots", "mocha", "coverage-istanbul"] :
48+
["dots", "mocha"]
49+
),
50+
coverageIstanbulReporter: {
51+
reports: ["html", "lcov", "lcovonly", "text-summary"],
52+
dir: "coverage",
53+
fixWebpackSourcePaths: true,
54+
"report-config": {
55+
html: {
56+
subdir: "html-report"
57+
}
58+
}
59+
},
60+
port: 9876,
61+
colors: true,
62+
logLevel: config.LOG_INFO,
63+
autoWatch: true,
64+
browsers: [],
65+
browserNoActivityTimeout: 50000
66+
};
67+
68+
if (process.env.TRAVIS) {
69+
configuration.browsers.push("PhantomJS");
70+
configuration.plugins.push("karma-phantomjs-launcher");
71+
} else {
72+
configuration.browsers.push("PhantomJS");
73+
configuration.plugins.push("karma-phantomjs-launcher");
74+
}
75+
76+
config.set(configuration);
77+
};

0 commit comments

Comments
 (0)