-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit. extract ContextView from robotlegs frameowrk.
- Loading branch information
0 parents
commit 21eae0f
Showing
19 changed files
with
698 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
typings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Contributing to RobotlegsJS | ||
|
||
## Setup | ||
|
||
1 - Clone your fork of the repository: | ||
``` | ||
$ git clone https://github.com/YOUR_USERNAME/RobotlegsJS.git | ||
``` | ||
|
||
2 - Install typings: | ||
``` | ||
$ npm install -g typings | ||
``` | ||
|
||
3 - Install type definitions: | ||
``` | ||
$ typings install | ||
``` | ||
|
||
4 - Install npm dependencies: | ||
``` | ||
$ npm install | ||
``` | ||
|
||
5 - Run build process | ||
``` | ||
$ npm run build | ||
``` | ||
|
||
## Guidelines | ||
|
||
- Please try to [combine multiple commits before | ||
pushing](http://stackoverflow.com/questions/6934752/combining-multiple-commits-before-pushing-in-git) | ||
|
||
- Please use `TDD` when fixing bugs. This means that you should write a unit | ||
test that fails because it reproduces the issue, then fix the issue finally run | ||
the test to ensure that the issue has been resolved. This helps us to prevent | ||
fixed bugs from happening again in the future. | ||
- Always format your code using `./node_modules/.bin/tsfmt -r`. | ||
- Please keep the test coverage at 100%. Write additional unit test if | ||
necessary | ||
- Please create an issue before sending a PR ff your it is going to change the | ||
public interface of RobotlegsJS or it includes significant architecture | ||
changes. | ||
- Feel free to ask for help from other members of the RobotlegsJS team via the | ||
chat or github issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Goodgame Studios https://www.goodgamestudios.com | ||
Copyright (c) 2009 - 2013 the original author or authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
robotlegs-pixi | ||
=== | ||
|
||
Integrate [RobotlegsJS](https://github.com/goodgamestudios/RobotlegsJs) | ||
framework with [PixiJS v4](https://github.com/pixijs/pixi.js). | ||
|
||
Usage | ||
--- | ||
|
||
```ts | ||
/// <reference path="node_modules/robotlegs-pixi/definitions/pixi.d.ts" /> | ||
|
||
import { Context, MVCSBundle } from "robotlegs"; | ||
import { ContextView } from "robotlegs-pixi"; | ||
|
||
let context = new Context(); | ||
context. | ||
install( MVCSBundle ). | ||
configure( new ContextView((<any>this.renderer).plugins.interaction) ); | ||
``` | ||
|
||
|
||
License | ||
--- | ||
|
||
[MIT](LICENSE.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// <reference path="../lib/index.d.ts" /> | ||
|
||
import { IEvent } from "robotlegs"; | ||
|
||
/** | ||
* Augment PIXI module to recognize IEventDispatcher patch. | ||
*/ | ||
declare module "pixi.js" { | ||
|
||
interface IEventDispatcher { | ||
addEventListener(type: string, listener?: Function): void; | ||
hasEventListener(type: string, listener?: Function): boolean; | ||
removeEventListener(type: string, listener?: Function): void; | ||
willTrigger(type: string): void; | ||
dispatchEvent(event: IEvent): void; | ||
} | ||
|
||
export interface DisplayObject extends IEventDispatcher {} | ||
export interface SystemRenderer extends IEventDispatcher {} | ||
|
||
export interface BaseTexture extends IEventDispatcher {} | ||
export interface Texture extends IEventDispatcher {} | ||
|
||
export namespace loaders { | ||
export interface Loader extends IEventDispatcher {} | ||
export interface Resource extends IEventDispatcher {} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const webpack = require("webpack") | ||
const path = require("path") | ||
|
||
const webpackConfig = require('./webpack.config.js') | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
basePath: "", | ||
frameworks: ["mocha", "chai", "sinon"], | ||
files: [ | ||
"./test/**.test.ts" | ||
], | ||
preprocessors: { | ||
"./test/**.test.ts": ["webpack"] | ||
}, | ||
webpack: webpackConfig, | ||
webpackMiddleware: { | ||
noInfo: true | ||
}, | ||
plugins: [ | ||
require("karma-webpack"), | ||
require("karma-mocha"), | ||
require("karma-chai"), | ||
require("karma-sinon"), | ||
require("karma-chrome-launcher"), | ||
], | ||
reporters: ["dots"], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ["Chrome"], | ||
singleRun: false | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "robotlegs-pixi", | ||
"version": "0.1.0", | ||
"description": "PIXI v4 integration with for RobotlegsJS", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"scripts": { | ||
"test": "mocha test/**/*.test.ts --require ts-node/register", | ||
"build": "cp node_modules/inversify-dts/inversify/inversify.d.ts . && tsc -d", | ||
"prepublish": "publish-please guard && rimraf ./lib && npm run build", | ||
"publish-please": "publish-please" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@source.services.ggs-net.com:game-core/typescript-robotlegs-framework.git" | ||
}, | ||
"keywords": [ | ||
"TypeScript", | ||
"Robotlegs", | ||
"IoC" | ||
], | ||
"author": "Goodgame Studios", | ||
"license": "MIT", | ||
"dependencies": { | ||
"robotlegs": "file:../robotlegsjs" | ||
}, | ||
"devDependencies": { | ||
"awesome-typescript-loader": "^1.1.1", | ||
"browserify-versionify": "^1.0.6", | ||
"glslify": "^5.1.0", | ||
"inversify-dts": "^2.2.0", | ||
"pixi.js": "^4.0.0", | ||
"publish-please": "^2.1.4", | ||
"reflect-metadata": "^0.1.8", | ||
"rimraf": "^2.5.2", | ||
"typescript": "^2.1.0-dev.20160811", | ||
"webpack": "^2.1.0-beta.20", | ||
"webpack-dev-server": "^2.1.0-beta.0" | ||
}, | ||
"peerDependencies": { | ||
"pixi.js": "*", | ||
"eventemitter3": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ------------------------------------------------------------------------------ | ||
// Copyright (c) 2016 Goodgame Studios. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// ------------------------------------------------------------------------------ | ||
|
||
/** | ||
* The Context View represents the root any for a Context | ||
*/ | ||
export class ContextView { | ||
|
||
/*============================================================================*/ | ||
/* Public Properties */ | ||
/*============================================================================*/ | ||
|
||
private _view: any; | ||
|
||
/** | ||
* The root DisplayObjectContainer for this Context | ||
*/ | ||
public get view(): any { | ||
return this._view; | ||
} | ||
|
||
/*============================================================================*/ | ||
/* Constructor */ | ||
/*============================================================================*/ | ||
|
||
/** | ||
* The Context View represents the root any for a Context | ||
* @param view The root any for this Context | ||
*/ | ||
constructor(view: any) { | ||
this._view = view; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// ------------------------------------------------------------------------------ | ||
// Copyright (c) 2016 Goodgame Studios. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// ------------------------------------------------------------------------------ | ||
|
||
import { instanceOfType, IContext, IExtension, IInjector, ILogger } from "robotlegs"; | ||
|
||
import { ContextView } from "./ContextView"; | ||
import { applyPixiPatch } from "./pixiPatch"; | ||
|
||
/** | ||
* <p>This Extension waits for a ContextView to be added as a configuration | ||
* and maps it into the context's injector.</p> | ||
* | ||
* <p>It should be installed before context initialization.</p> | ||
*/ | ||
export class ContextViewExtension implements IExtension { | ||
|
||
/*============================================================================*/ | ||
/* Private Properties */ | ||
/*============================================================================*/ | ||
|
||
private _injector: IInjector; | ||
|
||
private _logger: ILogger; | ||
|
||
/*============================================================================*/ | ||
/* Public Functions */ | ||
/*============================================================================*/ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public extend(context: IContext): void { | ||
this._injector = context.injector; | ||
this._logger = context.getLogger(this); | ||
context.beforeInitializing(this.beforeInitializing.bind(this)); | ||
context.addConfigHandler(instanceOfType(ContextView), this.handleContextView.bind(this)); | ||
} | ||
|
||
/*============================================================================*/ | ||
/* Private Functions */ | ||
/*============================================================================*/ | ||
|
||
private handleContextView(contextView: ContextView): void { | ||
if (this._injector.isBound(ContextView)) { | ||
this._logger.warn('A contextView has already been installed, ignoring {0}', [contextView.view]); | ||
} | ||
else { | ||
this._logger.debug("Mapping {0} as contextView", [contextView.view]); | ||
|
||
applyPixiPatch(contextView.view); | ||
|
||
// this._injector.map(ContextView).toValue(contextView); | ||
this._injector.bind(ContextView).toConstantValue(contextView); | ||
} | ||
} | ||
|
||
private beforeInitializing(): void { | ||
if (!this._injector.isBound(ContextView)) { | ||
this._logger.error("A ContextView must be installed if you install the ContextViewExtension."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ------------------------------------------------------------------------------ | ||
// Copyright (c) 2016 Goodgame Studios. All Rights Reserved. | ||
// | ||
// NOTICE: You are permitted to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// ------------------------------------------------------------------------------ | ||
|
||
import { injectable, inject, IConfig, IViewManager } from "robotlegs"; | ||
import { ContextView } from "./ContextView"; | ||
|
||
/** | ||
* This configuration file adds the ContextView to the viewManager. | ||
* | ||
* It requires that the ViewManagerExtension, ContextViewExtension | ||
* and a ContextView have been installed. | ||
*/ | ||
@injectable() | ||
export class ContextViewListenerConfig implements IConfig { | ||
|
||
/*============================================================================*/ | ||
/* Public Properties */ | ||
/*============================================================================*/ | ||
|
||
@inject(ContextView) | ||
private _contextView: ContextView; | ||
|
||
@inject(IViewManager) | ||
private _viewManager: IViewManager; | ||
|
||
/*============================================================================*/ | ||
/* Public Functions */ | ||
/*============================================================================*/ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public configure(): void { | ||
// Adds the Context View to the View Manager at startup | ||
this._viewManager.addContainer(this._contextView.view); | ||
} | ||
} |
Oops, something went wrong.