forked from joelhooks/robotlegs-examples-ModularDoodads
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiple doodads cookin and talkin to one another. more logging. upda…
…tes in line with updates to Modular fork. Sure hope the hasMapping getInstance in SwiftSuspenders is fixed to allow crawling up the chain.
- Loading branch information
Showing
12 changed files
with
454 additions
and
4 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
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,174 @@ | ||
/** | ||
* stats.as | ||
* http://github.com/mrdoob/stats.as | ||
* | ||
* Released under MIT license: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* | ||
* How to use: | ||
* | ||
* addChild( new Stats() ); | ||
* | ||
**/ | ||
|
||
package net.hires.debug | ||
{ | ||
import flash.display.BitmapData; | ||
import flash.display.Sprite; | ||
import flash.events.Event; | ||
import flash.events.MouseEvent; | ||
import flash.geom.Matrix; | ||
import flash.geom.Rectangle; | ||
import flash.system.System; | ||
import flash.text.StyleSheet; | ||
import flash.text.TextField; | ||
import flash.utils.getTimer; | ||
|
||
public class Stats extends Sprite | ||
{ | ||
protected const WIDTH : uint = 70; | ||
protected const HEIGHT : uint = 100; | ||
|
||
protected var xml : XML; | ||
|
||
protected var text : TextField; | ||
protected var style : StyleSheet; | ||
|
||
protected var timer : uint; | ||
protected var fps : uint; | ||
protected var ms : uint; | ||
protected var ms_prev : uint; | ||
protected var mem : Number; | ||
protected var mem_max : Number; | ||
|
||
protected var graph : BitmapData; | ||
protected var rectangle : Rectangle; | ||
|
||
protected var fps_graph : uint; | ||
protected var mem_graph : uint; | ||
protected var mem_max_graph : uint; | ||
|
||
protected var theme : Object = { bg: 0x000033, fps: 0xffff00, ms: 0x00ff00, mem: 0x00ffff, memmax: 0xff0070 }; | ||
|
||
/** | ||
* <b>Stats</b> FPS, MS and MEM, all in one. | ||
* | ||
* @param _theme Example: { bg: 0x202020, fps: 0xC0C0C0, ms: 0x505050, mem: 0x707070, memmax: 0xA0A0A0 } | ||
*/ | ||
public function Stats( _theme : Object = null ) : void | ||
{ | ||
if (_theme) | ||
{ | ||
if (_theme.bg != null) theme.bg = _theme.bg; | ||
if (_theme.fps != null) theme.fps = _theme.fps; | ||
if (_theme.ms != null) theme.ms = _theme.ms; | ||
if (_theme.mem != null) theme.mem = _theme.mem; | ||
if (_theme.memmax != null) theme.memmax = _theme.memmax; | ||
} | ||
|
||
mem_max = 0; | ||
|
||
xml = <xml><fps>FPS:</fps><ms>MS:</ms><mem>MEM:</mem><memMax>MAX:</memMax></xml>; | ||
|
||
style = new StyleSheet(); | ||
style.setStyle("xml", {fontSize:'9px', fontFamily:'_sans', leading:'-2px'}); | ||
style.setStyle("fps", {color: hex2css(theme.fps)}); | ||
style.setStyle("ms", {color: hex2css(theme.ms)}); | ||
style.setStyle("mem", {color: hex2css(theme.mem)}); | ||
style.setStyle("memMax", {color: hex2css(theme.memmax)}); | ||
|
||
text = new TextField(); | ||
text.width = WIDTH; | ||
text.height = 50; | ||
text.styleSheet = style; | ||
text.condenseWhite = true; | ||
text.selectable = false; | ||
text.mouseEnabled = false; | ||
|
||
rectangle = new Rectangle( WIDTH - 1, 0, 1, HEIGHT - 50 ); | ||
|
||
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true); | ||
addEventListener(Event.REMOVED_FROM_STAGE, destroy, false, 0, true); | ||
} | ||
|
||
private function init(e : Event) : void | ||
{ | ||
graphics.beginFill(theme.bg); | ||
graphics.drawRect(0, 0, WIDTH, HEIGHT); | ||
graphics.endFill(); | ||
|
||
addChild(text); | ||
|
||
graph = new BitmapData(WIDTH, HEIGHT - 50, false, theme.bg); | ||
graphics.beginBitmapFill (graph, new Matrix (1, 0, 0, 1, 0, 50)); | ||
graphics.drawRect(0, 50, WIDTH, HEIGHT - 50); | ||
|
||
addEventListener(MouseEvent.CLICK, onClick); | ||
addEventListener(Event.ENTER_FRAME, update); | ||
} | ||
|
||
private function destroy(e : Event) : void | ||
{ | ||
graphics.clear(); | ||
|
||
while(numChildren > 0) | ||
removeChildAt(0); | ||
|
||
graph.dispose(); | ||
|
||
removeEventListener(MouseEvent.CLICK, onClick); | ||
removeEventListener(Event.ENTER_FRAME, update); | ||
} | ||
|
||
private function update(e : Event) : void | ||
{ | ||
timer = getTimer(); | ||
|
||
if( timer - 1000 > ms_prev ) | ||
{ | ||
ms_prev = timer; | ||
mem = Number((System.totalMemory * 0.000000954).toFixed(3)); | ||
mem_max = mem_max > mem ? mem_max : mem; | ||
|
||
fps_graph = Math.min( graph.height, ( fps / stage.frameRate ) * graph.height ); | ||
mem_graph = Math.min( graph.height, Math.sqrt( Math.sqrt( mem * 5000 ) ) ) - 2; | ||
mem_max_graph = Math.min( graph.height, Math.sqrt( Math.sqrt( mem_max * 5000 ) ) ) - 2; | ||
|
||
graph.scroll( -1, 0 ); | ||
|
||
graph.fillRect( rectangle , theme.bg ); | ||
graph.setPixel( graph.width - 1, graph.height - fps_graph, theme.fps); | ||
graph.setPixel( graph.width - 1, graph.height - ( ( timer - ms ) >> 1 ), theme.ms ); | ||
graph.setPixel( graph.width - 1, graph.height - mem_graph, theme.mem); | ||
graph.setPixel( graph.width - 1, graph.height - mem_max_graph, theme.memmax); | ||
|
||
xml.fps = "FPS: " + fps + " / " + stage.frameRate; | ||
xml.mem = "MEM: " + mem; | ||
xml.memMax = "MAX: " + mem_max; | ||
|
||
fps = 0; | ||
} | ||
|
||
fps++; | ||
|
||
xml.ms = "MS: " + (timer - ms); | ||
ms = timer; | ||
|
||
text.htmlText = xml; | ||
} | ||
|
||
private function onClick(e : MouseEvent) : void | ||
{ | ||
mouseY / height > .5 ? stage.frameRate-- : stage.frameRate++; | ||
xml.fps = "FPS: " + fps + " / " + stage.frameRate; | ||
text.htmlText = xml; | ||
} | ||
|
||
// .. Utils | ||
|
||
private function hex2css( color : int ) : String | ||
{ | ||
return "#" + color.toString(16); | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/robotlegs/examples/modulardoodads/common/events/ModuleCommandTriggerEvent.as
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,19 @@ | ||
package robotlegs.examples.modulardoodads.common.events | ||
{ | ||
import flash.events.Event; | ||
|
||
public class ModuleCommandTriggerEvent extends Event | ||
{ | ||
public static const TRIGGER_MODULE_COMMAND:String = "triggerModuleCommand"; | ||
|
||
public function ModuleCommandTriggerEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) | ||
{ | ||
super(type, bubbles, cancelable); | ||
} | ||
|
||
override public function clone():Event | ||
{ | ||
return new ModuleCommandTriggerEvent(type,bubbles,cancelable); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/robotlegs/examples/modulardoodads/modules/doodad/DoodadModule.mxml
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,67 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" | ||
xmlns:s="library://ns.adobe.com/flex/spark" implements="org.robotlegs.utilities.modular.core.IModule" | ||
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="100" height="100"> | ||
|
||
<fx:Declarations> | ||
<!-- Place non-visual elements (e.g., services, value objects) here --> | ||
</fx:Declarations> | ||
<fx:Script> | ||
<![CDATA[ | ||
import mx.core.IVisualElementContainer; | ||
import org.robotlegs.core.IContext; | ||
import org.robotlegs.core.IInjector; | ||
import org.robotlegs.utilities.modular.core.IModule; | ||
import org.robotlegs.utilities.modular.core.IModuleContext; | ||
import robotlegs.examples.modulardoodads.modules.doodad.events.DoodadModuleEvent; | ||
[Bindable] | ||
public var color:uint = 0x000000; | ||
protected var context:IModuleContext; | ||
/** | ||
* We need to initialize our context by setting the parent | ||
* injector for the module. This is actually injected by the | ||
* shell, so no need to worry about it! | ||
*/ | ||
[Inject] | ||
public function set parentInjector(value:IInjector):void | ||
{ | ||
context = new DoodadModuleContext(this,value); | ||
} | ||
protected function doStuff_clickHandler(event:MouseEvent):void | ||
{ | ||
dispatchEvent(new DoodadModuleEvent(DoodadModuleEvent.DO_STUFF_REQUESTED)); | ||
} | ||
protected function killModule_clickHandler(event:MouseEvent):void | ||
{ | ||
dispatchEvent(new DoodadModuleEvent(DoodadModuleEvent.REMOVE)); | ||
} | ||
public function dispose():void | ||
{ | ||
if(parent && parent.contains(this)) | ||
IVisualElementContainer(parent).removeElement(this); | ||
context.dispose(); | ||
context = null; | ||
} | ||
]]> | ||
</fx:Script> | ||
<s:Group width="100%" height="100%"> | ||
<s:Rect width="100%" height="100%"> | ||
<s:fill> | ||
<s:SolidColor color="{color}"/> | ||
</s:fill> | ||
</s:Rect> | ||
</s:Group> | ||
<s:Button id="killModule" label="x" right="2" top="2" width="30" click="killModule_clickHandler(event)"/> | ||
<s:VGroup width="100%" height="100%" verticalAlign="middle" horizontalAlign="center"> | ||
<s:Button id="doStuff" label="request" click="doStuff_clickHandler(event)"/> | ||
</s:VGroup> | ||
</mx:Module> |
22 changes: 22 additions & 0 deletions
22
src/robotlegs/examples/modulardoodads/modules/doodad/DoodadModuleCommand.as
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,22 @@ | ||
package robotlegs.examples.modulardoodads.modules.doodad | ||
{ | ||
import org.robotlegs.mvcs.Command; | ||
import org.robotlegs.utilities.modular.core.IModuleEventDispatcher; | ||
|
||
import robotlegs.examples.modulardoodads.common.events.LoggingEvent; | ||
import robotlegs.examples.modulardoodads.common.events.ModuleCommandTriggerEvent; | ||
|
||
public class DoodadModuleCommand extends Command | ||
{ | ||
[Inject] | ||
public var event:ModuleCommandTriggerEvent; | ||
|
||
[Inject] | ||
public var moduleDispatcher:IModuleEventDispatcher; | ||
|
||
override public function execute():void | ||
{ | ||
moduleDispatcher.dispatchEvent(new LoggingEvent(LoggingEvent.MESSAGE, "Module Command Executed!")); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/robotlegs/examples/modulardoodads/modules/doodad/DoodadModuleContext.as
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,31 @@ | ||
package robotlegs.examples.modulardoodads.modules.doodad | ||
{ | ||
import flash.display.DisplayObjectContainer; | ||
|
||
import org.robotlegs.core.IInjector; | ||
import org.robotlegs.utilities.modular.mvcs.ModuleContext; | ||
|
||
import robotlegs.examples.modulardoodads.common.events.LoggingEvent; | ||
import robotlegs.examples.modulardoodads.common.events.ModuleCommandTriggerEvent; | ||
|
||
public class DoodadModuleContext extends ModuleContext | ||
{ | ||
public function DoodadModuleContext(contextView:DisplayObjectContainer, injector:IInjector) | ||
{ | ||
super(contextView, true, injector); | ||
} | ||
|
||
override public function startup():void | ||
{ | ||
mediatorMap.mapView(DoodadModule, DoodadModuleMediator); | ||
moduleCommandMap.mapEvent(ModuleCommandTriggerEvent.TRIGGER_MODULE_COMMAND, DoodadModuleCommand); | ||
dispatchToModules(new LoggingEvent(LoggingEvent.MESSAGE, "New Doodad Added")); | ||
} | ||
|
||
override public function dispose():void | ||
{ | ||
mediatorMap.removeMediatorByView(contextView); | ||
super.dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.