Skip to content

Commit 78adc75

Browse files
committed
Command messaging visualization added.
1 parent e2dc35d commit 78adc75

File tree

8 files changed

+94
-3
lines changed

8 files changed

+94
-3
lines changed

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/screens/MvcExpressVisualizerScreen.as

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,35 @@ public class MvcExpressVisualizerScreen extends Sprite {
171171
}
172172
}
173173
}
174+
// handle message from command
175+
messageFromObject = messageLogObj.messageFromCommand;
176+
if (messageFromObject) {
177+
for (var m:int = 0; m < commands.length; m++) {
178+
if (commands[m].commandObject == messageFromObject) {
179+
var sourceCommandLabel:Label = commands[m].view;
180+
if (sourceCommandLabel) {
181+
182+
messageShape = new Shape();
183+
messageShape.graphics.lineStyle(2, 0xD2D2FF, 0.3);
184+
messageShape.graphics.lineTo(50, (sourceCommandLabel.y - mediatorLabel.y) * 0.2);
185+
messageShape.graphics.lineTo(450 - 300 - sourceCommandLabel.width / 2, sourceCommandLabel.y - mediatorLabel.y);
186+
187+
messageShape.graphics.moveTo(0, 0);
188+
messageShape.graphics.lineTo(10, -2);
189+
messageShape.graphics.lineTo(10, 2);
190+
messageShape.graphics.lineTo(0, 0);
191+
192+
messageShape.x = mediatorLabel.width;
193+
messageShape.y = 10;
194+
mediatorLabel.addChild(messageShape);
195+
196+
setTimeout(hideShape, 1500, messageShape);
197+
}
198+
break;
199+
}
200+
}
201+
}
202+
174203
}
175204
}
176205
}
@@ -331,6 +360,34 @@ public class MvcExpressVisualizerScreen extends Sprite {
331360
}
332361
}
333362

363+
// handle message from command
364+
messageFromObject = commandLogObj.messageFromCommand;
365+
if (messageFromObject) {
366+
for (var m:int = 0; m < commands.length; m++) {
367+
if (commands[m].commandObject == messageFromObject) {
368+
var anotherCommandLabel:Label = commands[m].view;
369+
if (anotherCommandLabel) {
370+
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.3);
371+
commandLabel.graphics.moveTo(0, 10);
372+
commandLabel.graphics.lineTo( - anotherCommandLabel.width / 2 + commandLabel.width / 2 - 30, //
373+
//-commandLabel.y + anotherCommandLabel.y + anotherCommandLabel.height - 10 //
374+
5
375+
);
376+
377+
commandLabel.graphics.lineTo( - anotherCommandLabel.width / 2 + commandLabel.width / 2, //
378+
-commandLabel.y + anotherCommandLabel.y + anotherCommandLabel.height - 10 //
379+
);
380+
381+
commandLabel.graphics.moveTo(0, 10);
382+
commandLabel.graphics.lineTo(0 - 10, 10 - 2);
383+
commandLabel.graphics.lineTo(0 - 10, 10 + 2);
384+
commandLabel.graphics.lineTo(0, 10);
385+
}
386+
break;
387+
}
388+
}
389+
}
390+
334391
setTimeout(removeObject, 1500, commandPosition, commandLogObj);
335392
}
336393

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/visualizer/VisualizerManager.as

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public class VisualizerManager {
146146
logObj.messageFromMediator = topObject.mediatorObject;
147147
} else if (topObject.proxyObject) {
148148
logObj.messageFromProxy = topObject.proxyObject;
149+
} else if (topObject.commandObject) {
150+
logObj.messageFromCommand = topObject.commandObject;
149151
} else {
150152
CONFIG::debug {
151153
throw Error("NOT HANDLED:" + logObj);
@@ -170,10 +172,12 @@ public class VisualizerManager {
170172
break;
171173
case "Mediator.sendMessage":
172174
case "Proxy.sendMessage":
175+
case "Command.sendMessage":
173176
sendMessageStack.push(logObj);
174177
break;
175178
case "Mediator.sendMessage.CLEAN":
176179
case "Proxy.sendMessage.CLEAN":
180+
case "Command.sendMessage.CLEAN":
177181
topObject = sendMessageStack.pop();
178182
if (logObj.type != topObject.type) {
179183
CONFIG::debug {
@@ -243,14 +247,15 @@ public class VisualizerManager {
243247
logObj.messageFromMediator = topObject.mediatorObject;
244248
} else if (topObject.proxyObject) {
245249
logObj.messageFromProxy = topObject.proxyObject;
250+
} else if (topObject.commandObject) {
251+
logObj.messageFromCommand = topObject.commandObject;
246252
} else {
247253
CONFIG::debug {
248254
throw Error("NOT HANDLED:" + logObj);
249255
}
250256
}
251257
this.mvcExpressVisualizerScreen.drawMessageToMediator(logObj, l);
252258
}
253-
254259
}
255260
}
256261
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/VisualLoggerTestModule.as

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class VisualLoggerTestModule extends ModuleSprite {
6363
commandMap.map(Message.TEST_MEDIATOR_A_COMMAND, TestCommandA);
6464
commandMap.map(Message.TEST_MEDIATOR_B_COMMAND, TestCommandB);
6565
commandMap.map(Message.TEST_PROXY_TO_COMMAND, TestCommandBlank);
66+
commandMap.map(Message.TEST_COMMAND_TO_COMMAND, TestCommandBlank);
6667

6768
// set up data
6869
proxyMap.map(new TestProxyA());

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/controller/TestCommandA.as

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.mvcExpressVisualizer.controller {
2+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
23
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyA;
34
import org.mvcexpress.mvc.Command;
45

@@ -12,7 +13,7 @@ public class TestCommandA extends Command {
1213
public var testProxyA:TestProxyA;
1314

1415
public function execute(testText:String):void {
15-
16+
sendMessage(Message.TEST_COMMAND_TO_MEDIATOR);
1617
}
1718

1819
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/controller/TestCommandB.as

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.mvcExpressVisualizer.controller {
2+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
23
import com.mindScriptAct.mvcExpressVisualizer.model.ITestProxyB;
34
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyA;
45
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyB;
@@ -18,7 +19,7 @@ public class TestCommandB extends Command {
1819
public var testProxyB:ITestProxyB;
1920

2021
public function execute(testPoint:Point):void {
21-
22+
sendMessage(Message.TEST_COMMAND_TO_COMMAND);
2223
}
2324

2425
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/messages/Message.as

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ package com.mindScriptAct.mvcExpressVisualizer.messages {
66
*/
77
public class Message {
88
static public const TEST_COMMAND_B:String = "testCommandB";
9+
910
static public const TEST_MEDIATOR_A_COMMAND:String = "testMediatorACommand";
1011
static public const TEST_MEDIATOR_B_COMMAND:String = "testMediatorBCommand";
12+
1113
static public const TEST_MESSAGE_TO_MEDIATORS_B:String = "testMessageToMediatorsB";
1214
static public const TEST_MESSAGE_TO_MEDIATORS_A:String = "testMessageToMediatorsA";
15+
1316
static public const TEST_PROXY_TO_MEDIATOR:String = "testProxyToMediator";
1417
static public const TEST_PROXY_TO_COMMAND:String = "testProxyToCommand";
1518

19+
static public const TEST_COMMAND_TO_MEDIATOR:String = "testCommandToMediator";
20+
static public const TEST_COMMAND_TO_COMMAND:String = "testCommandToCommand";
21+
1622

1723
}
1824
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/view/testB/TestViewBMediator.as

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class TestViewBMediator extends Mediator {
2929

3030
addHandler(Message.TEST_MESSAGE_TO_MEDIATORS_B, handleMediatorTest);
3131
addHandler(Message.TEST_PROXY_TO_MEDIATOR, handleProxyTest);
32+
addHandler(Message.TEST_COMMAND_TO_MEDIATOR, handleCommandTest);
3233
}
3334

3435
private function handleSendCommandMessage(event:Event):void {
@@ -54,5 +55,9 @@ public class TestViewBMediator extends Mediator {
5455
private function handleMediatorTest(blank:Object):void {
5556
// do nothing.
5657
}
58+
59+
private function handleCommandTest(blank:Object):void {
60+
// do nothing.
61+
}
5762
}
5863
}

src/org/mvcexpress/mvc/Command.as

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.mvcexpress.core.MediatorMap;
55
import org.mvcexpress.core.messenger.Messenger;
66
import org.mvcexpress.core.namespace.pureLegsCore;
77
import org.mvcexpress.core.ProxyMap;
8+
import org.mvcexpress.MvcExpress;
89

910
/**
1011
* Command, handles business logic of your application. </br>
@@ -43,8 +44,22 @@ dynamic public class Command {
4344
* @param params Object that will be passed to Command execute() function and to handle functions.
4445
*/
4546
protected function sendMessage(type:String, params:Object = null):void {
47+
// log the action
48+
CONFIG::debug {
49+
if (MvcExpress.loggerFunction != null) {
50+
MvcExpress.loggerFunction({action: "Command.sendMessage", commandObject: this, type: type, params: params});
51+
}
52+
}
53+
//
4654
use namespace pureLegsCore;
4755
messenger.send(type, params);
56+
//
57+
// clean up loging the action
58+
CONFIG::debug {
59+
if (MvcExpress.loggerFunction != null) {
60+
MvcExpress.loggerFunction({action: "Command.sendMessage.CLEAN", commandObject: this, type: type, params: params});
61+
}
62+
}
4863
}
4964

5065
/**

0 commit comments

Comments
 (0)