{"id":0,"registry":{"0":{"submorphs":[],"scripts":[],"id":"A864F251-4CAF-49FB-8F27-E3F52656D2AC","shape":{"__isSmartRef__":true,"id":1},"__layered_droppingEnabled__":true,"halosEnabled":true,"eventHandler":{"__isSmartRef__":true,"id":13},"showsHalos":false,"name":"CommanderTrait","partsBinMetaInfo":{"__isSmartRef__":true,"id":14},"controlPoints":[{"__isSmartRef__":true,"id":22},{"__isSmartRef__":true,"id":23},{"__isSmartRef__":true,"id":24},{"__isSmartRef__":true,"id":25},{"__isSmartRef__":true,"id":26},{"__isSmartRef__":true,"id":27},{"__isSmartRef__":true,"id":28},{"__isSmartRef__":true,"id":29},{"__isSmartRef__":true,"id":30},{"__isSmartRef__":true,"id":31},{"__isSmartRef__":true,"id":32}],"layout":{"__isSmartRef__":true,"id":33},"_ClipMode":"visible","isBeingDragged":false,"derivationIds":[1630,"D0C9B8B6-1252-42B9-A8F2-8407CF7E08AE","166A65DA-236E-4BB6-A3FA-2F91961501E6","0A0B4BBD-45E2-4A50-B7AB-3C5869665545"],"moved":true,"prevScroll":[0,0],"commandedClones":[],"methodsWrappedForClones":["setFill","morphicSetter"],"#startLetters":"setFill","_Rotation":2.8736773725336153,"_Scale":0.2341502441118476,"eventsAreIgnored":true,"__serializedExpressions__":["_Position","distanceToDragEvent"],"__serializedLivelyClosures__":{"__isSmartRef__":true,"id":34},"__LivelyClassName__":"lively.morphic.Path","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs","withLayers":["Global.NoMagnetsLayer"],"_Position":"lively.pt(0.0,0.0)","distanceToDragEvent":"lively.pt(20.0,-24.5)"},"1":{"dontChangeShape":false,"cachedVertices":[],"_PathElements":[{"__isSmartRef__":true,"id":2},{"__isSmartRef__":true,"id":3},{"__isSmartRef__":true,"id":4},{"__isSmartRef__":true,"id":5},{"__isSmartRef__":true,"id":6},{"__isSmartRef__":true,"id":7},{"__isSmartRef__":true,"id":8},{"__isSmartRef__":true,"id":9},{"__isSmartRef__":true,"id":10},{"__isSmartRef__":true,"id":11},{"__isSmartRef__":true,"id":12}],"_BorderWidth":0.444,"_BorderRadius":0,"_Opacity":1,"_BorderStyle":"solid","_ClipMode":"visible","_AppearanceStylingMode":false,"_BorderStylingMode":false,"__serializedExpressions__":["_Position","_Extent","_BorderColor","_Fill","_Padding"],"__LivelyClassName__":"lively.morphic.Shapes.Path","__SourceModuleName__":"Global.lively.morphic.PathShapes","_Position":"lively.pt(-101.0,-96.1)","_Extent":"lively.pt(181.9,191.2)","_BorderColor":"Color.rgb(0,0,0)","_Fill":"Color.rgb(122,122,15)","_Padding":"lively.rect(0,0,0,0)"},"2":{"isAbsolute":true,"x":39,"y":0,"__LivelyClassName__":"lively.morphic.Shapes.MoveTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"3":{"isAbsolute":true,"x":80.90169943749474,"y":58.778525229247315,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"4":{"isAbsolute":true,"x":12.051662780622951,"y":37.091204135510985,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"5":{"isAbsolute":true,"x":-30.901699437494734,"y":95.10565162951536,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"6":{"isAbsolute":true,"x":-31.551662780622944,"y":22.923624839406457,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"7":{"isAbsolute":true,"x":-100,"y":1.2246063538223773e-14,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"8":{"isAbsolute":true,"x":-31.551662780622955,"y":-22.923624839406447,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"9":{"isAbsolute":true,"x":-30.901699437494756,"y":-95.10565162951535,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"10":{"isAbsolute":true,"x":12.051662780622943,"y":-37.09120413551099,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"11":{"isAbsolute":true,"x":80.90169943749473,"y":-58.778525229247336,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"12":{"isAbsolute":true,"x":39,"y":-9.551929559814543e-15,"__LivelyClassName__":"lively.morphic.Shapes.LineTo","__SourceModuleName__":"Global.lively.morphic.PathShapes"},"13":{"morph":{"__isSmartRef__":true,"id":0},"__LivelyClassName__":"lively.morphic.EventHandler","__SourceModuleName__":"Global.lively.morphic.Events"},"14":{"requiredModules":[],"migrationLevel":4,"partsSpaceName":"PartsBin/Tools/","partName":"CommanderTrait","comment":"This object defines a -commander- trait in the style of the original Commander Turtle in Smalltalk.  It keeps track of its clones, and forwards appropriate state-changing methods (wrappedMethods) to them.  Note that it applies to an entire morphic structure.\nThis is used for the replication in the Kaleidoscope\n","changes":[{"__isSmartRef__":true,"id":15},{"__isSmartRef__":true,"id":17},{"__isSmartRef__":true,"id":19}],"lastModifiedDate":{"__isSmartRef__":true,"id":21},"revisionOnLoad":195075,"__LivelyClassName__":"lively.PartsBin.PartsBinMetaInfo","__SourceModuleName__":"Global.lively.PartsBin"},"15":{"date":{"__isSmartRef__":true,"id":16},"author":"Fern","message":"no comment","id":"209710A4-1E91-4E84-B078-317116079785"},"16":{"isSerializedDate":true,"string":"Wed Jul 25 2012 14:52:58 GMT-0700 (PDT)"},"17":{"date":{"__isSmartRef__":true,"id":18},"author":"Dan","message":"no comment","id":"A9A0EAB8-624D-4320-8647-C1088DDFD65A"},"18":{"isSerializedDate":true,"string":"Sat Apr 13 2013 10:52:40 GMT-0700 (PDT)"},"19":{"date":{"__isSmartRef__":true,"id":20},"author":"Dan","message":"no comment","id":"68A24A41-A987-4E35-9D2C-7E2EE79D5F23"},"20":{"isSerializedDate":true,"string":"Sat Apr 13 2013 11:49:52 GMT-0700 (PDT)"},"21":{"isSerializedDate":true,"string":"Sat Apr 13 2013 10:49:43 GMT-0700 (PDT)"},"22":{"morph":{"__isSmartRef__":true,"id":0},"index":0,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"23":{"morph":{"__isSmartRef__":true,"id":0},"index":1,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"24":{"morph":{"__isSmartRef__":true,"id":0},"index":2,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"25":{"morph":{"__isSmartRef__":true,"id":0},"index":3,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"26":{"morph":{"__isSmartRef__":true,"id":0},"index":4,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"27":{"morph":{"__isSmartRef__":true,"id":0},"index":5,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"28":{"morph":{"__isSmartRef__":true,"id":0},"index":6,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"29":{"morph":{"__isSmartRef__":true,"id":0},"index":7,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"30":{"morph":{"__isSmartRef__":true,"id":0},"index":8,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"31":{"morph":{"__isSmartRef__":true,"id":0},"index":9,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"32":{"morph":{"__isSmartRef__":true,"id":0},"index":10,"__LivelyClassName__":"lively.morphic.ControlPoint","__SourceModuleName__":"Global.lively.morphic.AdditionalMorphs"},"33":{},"34":{"aboutMe":{"__isSmartRef__":true,"id":35},"beCommanderMorph":{"__isSmartRef__":true,"id":39},"makeNewClone":{"__isSmartRef__":true,"id":43},"yetToDo":{"__isSmartRef__":true,"id":47},"prepareToCommand":{"__isSmartRef__":true,"id":51},"wrapForClones":{"__isSmartRef__":true,"id":55},"unwrapForClones":{"__isSmartRef__":true,"id":59},"testing":{"__isSmartRef__":true,"id":63},"copyTraitTo":{"__isSmartRef__":true,"id":67},"removeCloneReferences":{"__isSmartRef__":true,"id":71},"wrapAddMorph":{"__isSmartRef__":true,"id":75}},"35":{"varMapping":{"__isSmartRef__":true,"id":36},"source":"function aboutMe() {\n    // This object defines a -commander- trait in the style of the \n    // original CommanderTurtle in Smalltalk\n    // It keeps track of its clones, and forwards appropriate\n    // state-changing methods (wrappedMethods) to them\n    // Note that it applies to an entire morphic structure\n    // This is used for the replication in the Kaleidoscope\n}","funcProperties":{"__isSmartRef__":true,"id":37},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"36":{"this":{"__isSmartRef__":true,"id":0}},"37":{"timestamp":{"__isSmartRef__":true,"id":38},"user":"Dan","tags":[]},"38":{"isSerializedDate":true,"string":"Sat Apr 13 2013 10:46:40 GMT-0700 (PDT)"},"39":{"varMapping":{"__isSmartRef__":true,"id":40},"source":"function beCommanderMorph() {\n    // Each node in this morphic structure must have its methods\n    // wrapped to delegate them on to all the clones\n    // It should be possible to run this method repeatedly as,\n    // for instance, to change the set of methods to wrap and delegate\n    this.withAllSubmorphsDo(function(ea) {\n        this.prepareToCommand.call(ea, this) }.bind(this)); \n}","funcProperties":{"__isSmartRef__":true,"id":41},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"40":{"this":{"__isSmartRef__":true,"id":0}},"41":{"timestamp":{"__isSmartRef__":true,"id":42},"user":"Dan","tags":[]},"42":{"isSerializedDate":true,"string":"Sun Mar 24 2013 11:09:50 GMT-0700 (PDT)"},"43":{"varMapping":{"__isSmartRef__":true,"id":44},"source":"function makeNewClone() {\n    // Add a new clone to the array of clones and return it\n    var newClone = this.copy();\n\n    // Every node (morph) in the clone must be added to the\n    // list of clones for the corresponding node in the commander\n    var flatCommander = [];\n    this.withAllSubmorphsDo(function (ea) {\n        flatCommander.push(ea)});\n    var flatClone = [];\n    newClone.withAllSubmorphsDo(function (ea) {\n        ea.stopStepping();  // clone nodes don't tick\n        flatClone.push(ea)});\n    for (var i=0; i<flatCommander.length; i++) {\n        flatCommander[i].commandedClones.push(flatClone[i]) }\n\n    return newClone\n}","funcProperties":{"__isSmartRef__":true,"id":45},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"44":{"this":{"__isSmartRef__":true,"id":0}},"45":{"timestamp":{"__isSmartRef__":true,"id":46},"user":"Dan","tags":[]},"46":{"isSerializedDate":true,"string":"Thu Mar 21 2013 15:08:04 GMT-0700 (PDT)"},"47":{"varMapping":{"__isSmartRef__":true,"id":48},"source":"function yetToDo() {\n    // [X] Write the actual wrap and unwrap code\n    // [X] Save the world and execute...\n    // [X] this.beCommanderMorph();  // should not crash\n    // [X] this.makeNewClone().openInWorld();  // make another on top\n    // [X] move the new copy where it can be seen\n    // [X] this.setFill(Color.green);  // should do this and clone\n    // [X] make another clone, move it and change color again\n    // [X] this.beCommanderMorph();  // should be able to repeat\n    // [X] this.beCommanderMorph();  // add \"morphicSetter\"\n    // [X] Test it out for, eg, transformation, fill, etc\n    // [X] Make a new Kaleidoscope using clones\n    // [X] Handle, eg, addMorph and remove\n    // [ ] Make sure it works recursively - that clones can be commanders\n    // [ ] Package up as a trait or method with local methods\n}","funcProperties":{"__isSmartRef__":true,"id":49},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"48":{"this":{"__isSmartRef__":true,"id":0}},"49":{"timestamp":{"__isSmartRef__":true,"id":50},"user":"Dan","tags":[]},"50":{"isSerializedDate":true,"string":"Sun Mar 24 2013 16:23:00 GMT-0700 (PDT)"},"51":{"varMapping":{"__isSmartRef__":true,"id":52},"source":"function prepareToCommand(commander) {\n    // Install an array of the clones of this morph\n    if (this.commandedClones == null) this.commandedClones = [];\n    \n    // Unwrap any methods previously wrapped\n    (this.methodsWrappedForClones || []).forEach(function(ea) {\n        commander.unwrapForClones.call(this, ea);\n        }.bind(this));\n    this.methodsWrappedForClones = [];\n    // Then wrap this new set of methods to be passed on to all clones\n    [\"setFill\", \"morphicSetter\", \"remove\"].forEach(function (ea) {\n        commander.wrapForClones.call(this, ea);\n        this.methodsWrappedForClones.push(ea);\n        }.bind(this));\n    commander.wrapAddMorph.call(this, commander);\n    this.methodsWrappedForClones.push(\"addMorph\");\n}","funcProperties":{"__isSmartRef__":true,"id":53},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"52":{"this":{"__isSmartRef__":true,"id":0}},"53":{"timestamp":{"__isSmartRef__":true,"id":54},"user":"Dan","tags":[]},"54":{"isSerializedDate":true,"string":"Sat Apr 13 2013 11:40:14 GMT-0700 (PDT)"},"55":{"varMapping":{"__isSmartRef__":true,"id":56},"source":"function wrapForClones(methodName) {\n    var method = this[methodName];\n    if (!method) return console.log(\"method \" + methodName + \"could not be found in -wrapFor-\");\n    this[methodName] = method.wrap(function(originalMethod) {\n        var incomingArgs = Array.from(arguments).slice(1);\n        this.commandedClones.forEach(function (ea) {\n            ea[methodName].apply(ea, incomingArgs) });\n        if(methodName == \"remove\") {  // ugh\n            this.withAllSubmorphsDo(function(ea) {\n                ea.commandedClones = new Array(0); })\n           };\n        originalMethod.apply(this, incomingArgs);\n        });\n}","funcProperties":{"__isSmartRef__":true,"id":57},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"56":{"this":{"__isSmartRef__":true,"id":0}},"57":{"timestamp":{"__isSmartRef__":true,"id":58},"user":"Dan","tags":[]},"58":{"isSerializedDate":true,"string":"Mon Mar 25 2013 23:33:35 GMT-0700 (PDT)"},"59":{"varMapping":{"__isSmartRef__":true,"id":60},"source":"function unwrapForClones(methodName) {\n    var method = this[methodName];\n    if (!method) return\n    if (method.isWrapped) this[methodName] = method.originalFunction;\n}","funcProperties":{"__isSmartRef__":true,"id":61},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"60":{"this":{"__isSmartRef__":true,"id":0}},"61":{"timestamp":{"__isSmartRef__":true,"id":62},"user":"Dan","tags":[]},"62":{"isSerializedDate":true,"string":"Tue Mar 12 2013 12:17:51 GMT-0700 (PDT)"},"63":{"varMapping":{"__isSmartRef__":true,"id":64},"source":"function testing() {\n    // this.beCommanderMorph()\n    // this.makeNewClone().openInWorld()\n    // this.removeAllCLones()\n}","funcProperties":{"__isSmartRef__":true,"id":65},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"64":{"this":{"__isSmartRef__":true,"id":0}},"65":{"timestamp":{"__isSmartRef__":true,"id":66},"user":"Dan","tags":[]},"66":{"isSerializedDate":true,"string":"Sat Apr 13 2013 10:40:18 GMT-0700 (PDT)"},"67":{"varMapping":{"__isSmartRef__":true,"id":68},"source":"function copyTraitTo(morph) {\n    var self = this;\n    ['beCommanderMorph', 'copyTraitTo', 'makeNewClone', 'prepareToCommand', 'removeCloneReferences', 'unwrapForClones', 'wrapForClones', 'wrapAddMorph'].forEach(function(method) {\n        morph.addScript(self[method]);\n    });\n}","funcProperties":{"__isSmartRef__":true,"id":69},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"68":{"this":{"__isSmartRef__":true,"id":0}},"69":{"timestamp":{"__isSmartRef__":true,"id":70},"user":"Dan","tags":[]},"70":{"isSerializedDate":true,"string":"Sat Apr 13 2013 11:42:20 GMT-0700 (PDT)"},"71":{"varMapping":{"__isSmartRef__":true,"id":72},"source":"function removeCloneReferences() {  // this.removeAllClones()\n   this.withAllSubmorphsDo(function (ea) {\n        if (ea.commandedClones) ea.commandedClones = [];\n        })\n}","funcProperties":{"__isSmartRef__":true,"id":73},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"72":{"this":{"__isSmartRef__":true,"id":0}},"73":{"timestamp":{"__isSmartRef__":true,"id":74},"user":"Dan","tags":[]},"74":{"isSerializedDate":true,"string":"Sun Mar 24 2013 08:51:17 GMT-0700 (PDT)"},"75":{"varMapping":{"__isSmartRef__":true,"id":76},"source":"function wrapAddMorph(commander) {\n    var methodName = \"addMorph\";\n    var method = this[methodName];\n    this[methodName] = method.wrap(function(originalMethod) {\n        var incomingArgs = Array.from(arguments).slice(1);\n        var morphToAdd = incomingArgs[0];\n        commander.copyTraitTo(morphToAdd);\n        commander.beCommanderMorph.call(morphToAdd);\n        // needs to come first, else will run remove\n        originalMethod.apply(this, incomingArgs);  // this.addMorph\n        this.commandedClones.forEach(function (ea) {\n            var argsForClone = [morphToAdd.makeNewClone()];\n            if (incomingArgs.length > 1) {\n                // for now we don't handle arg2 positioning\n                // would use # of this clone\n                // and then use clone of arg2 with that index\n                }\n            return ea[methodName].apply(ea, argsForClone);  // clone.addMorph\n            });\n        return morphToAdd});\n}","funcProperties":{"__isSmartRef__":true,"id":77},"__LivelyClassName__":"lively.Closure","__SourceModuleName__":"Global.lively.lang.Closure"},"76":{"this":{"__isSmartRef__":true,"id":0}},"77":{"timestamp":{"__isSmartRef__":true,"id":78},"user":"Dan","tags":[]},"78":{"isSerializedDate":true,"string":"Mon Mar 25 2013 23:05:10 GMT-0700 (PDT)"},"isSimplifiedRegistry":true}}