Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active August 29, 2018 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/bdd87230bacc981ec836786bfcf82cd0 to your computer and use it in GitHub Desktop.
Save kenwebb/bdd87230bacc981ec836786bfcf82cd0 to your computer and use it in GitHub Desktop.
Island B1
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Wed Aug 29 2018 07:34:28 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Island B1
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: bdd87230bacc981ec836786bfcf82cd0
Keywords:
My Notes
--------
July 31, 2018
This is a reboot of the Island project.
The earlier prototypes, "Island 1", "Island 2", and "Island 3", were developed to explore possibilities, to test new capabilities in Xholon, and to give us an early implementation to play with, demonstrate, and play with.
This workbook starts with the decisions that Jen and I made at our meeting on July 26, as documented in Jen's July 26 email - "preliminary object hierarchy".
`Object
(Cell)
Plant
Tree
GreenTree
RedTree
(Weed)
Produce
Fruit
PricklyFruit
Berry
JuicyBerry
(Flowers)
(ChewyFlower)
Material
Stick
Thorn
Vine
Water
Animal
Fish
Artifacts
Tools
Fishing Rod
Basket
Structures
Hut
Geography
Spring
I will use this to create a Xholon Inheritance Hierarchy (IH), and an example of a Xholon Composite Structure Hierarchy (CSH). I will write these using an XML format.
I will use the singular form of each noun.
For items that Jen places in parentheses to show uncertaity, I will use XML comments.
I've changed "Geography" to "GeoFeature".
github Revisions
----------------
1. initial commit to github
An inheritance hierarchy (IH) with Jen's types, plus Xholon framework types and other types suggested by Ken.
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/d0785bc7c703cc805a02e0b7bf912f585e597e94
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/d0785bc7c703cc805a02e0b7bf912f585e597e94&src=gist&gui=clsc
2. added github ID bdd87230bacc981ec836786bfcf82cd0
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/6095937648822299f6db0643eea9be8e8243c028
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/6095937648822299f6db0643eea9be8e8243c028#file-xholonworkbook-xml
3. added Class Details: colors, symbols, default content
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/997758bafa41704f2fa91e669ce36f4724a32486
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/997758bafa41704f2fa91e669ce36f4724a32486&src=gist&gui=clsc
4. added basic Composite Structure Hierarchy: grid with grid cells, GridCellPatterns that describe each island, other nodes needed by the Xholon framework
Running the app shows a large blue rectangle, an ocean with nothing in it yet.
The islands won't display until I write a JavaScript behavior.
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/ad2f00d5aaffc281471260448bc40df6a48f9334
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/ad2f00d5aaffc281471260448bc40df6a48f9334&src=gist&gui=none
5. added the Ocean and Island part of the CSH
View this entire subtree using d3cp, to confirm that everything is being created and that the colors are OK.
There are still no JavaScript behaviors, so Ocean and Island nodes have not yet been added to the grid.
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/8bc4a6fac2086ed5929af7b99907ab62cbd06e7a
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/8bc4a6fac2086ed5929af7b99907ab62cbd06e7a&src=gist&gui=none
6. added a simple MinecraftStyleRecipeBook, with recipes for making FishingRod and Hut
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/f69f07c3ff662cfdbc225cfdc3120051d8c6bd28
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/f69f07c3ff662cfdbc225cfdc3120051d8c6bd28&src=gist&gui=none
7. added default SVG
8. added JavaScript behaviors
These are mostly the same behaviors in "Island 3".
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/e670b7428bb36ea641d3f6bb840ec39db99a411e
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/e670b7428bb36ea641d3f6bb840ec39db99a411e&src=gist&gui=none
9. added Minecraft-style recipe for Hut. It requires 3 sticks and 3 vines.
use multi-line string to define avatarKeyMap
added separate "Whack" keys in avatarKeyMap to clone: "c" Stick, "k" Vine, "o" Thorn
start the app with the "out" tab displayed
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/0d1b36a3682deef91983239dbaec7ac636a0f351
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/0d1b36a3682deef91983239dbaec7ac636a0f351&src=gist&gui=none
10.added a JsonRulesEngineRecipeBook with a recipe for FishingRod (not yet active)
added //ava.action('param recipebook JsonRulesEngineRecipeBook-Island;');
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/70e411ad49af0c0f974be64ac28f0e5ac3cf40d3
11.added "NOSCROLL":"true" to avatarKeyMap, to prevent entire screen from scrolling when player presses arrow and space keys
added avatarKeyMap keys for "help commands" and "help keymap"
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/7f13e0f40c942f081333fad6b3f6e13488eaac36
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/7f13e0f40c942f081333fad6b3f6e13488eaac36&src=gist&gui=none
12.player's Avatar needs to be able to "die" if calories == 0
to get started on this, I've added the following IFLang code to all 4 arrow keys in the avatarKeyMap ";ifeq xpath(Avatar) calories 0 exit Space;"
and when the Avatar eats something, the ";become this calories +=50"
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/8b63a450ea1f3960f631b5a58b2a7cad2dd695a4
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/8b63a450ea1f3960f631b5a58b2a7cad2dd695a4&src=gist&gui=none
13.misc
14.Avatar Logger
15.Avatar Logger
16.Avatar Logger
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/9adb7710268260462f5447f8d145fd15fbd931c1
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/9adb7710268260462f5447f8d145fd15fbd931c1&src=gist&gui=none
17.//ava.action('param meteorattr one,two,three,calories'); // testing
"E":"eat;become this calories +=50", "e":"eat xpath(*);become this calories +=25"
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/be479fc0ddfd65861be4a0eb0a7d757d1fa43742
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/be479fc0ddfd65861be4a0eb0a7d757d1fa43742&src=gist&gui=none
18.Spring, FreshWater
Avatar can exit to FieldRow if not near *Tree when presses "c" key; I fixed this for all materials
be able to make Basket out of 2 vines; "b" key
changed Vine key to "v"
place Avatar on a specified island
- give each GridCellPattern (GCP) an islandID starting with 0
- GCP should create a data structure that can later be used to place Avatar in a CoastalCell of a specified island
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/0a4a8d84be155a497a69ac8767d912971cf870a4
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/0a4a8d84be155a497a69ac8767d912971cf870a4&src=gist&gui=none
19.use GridCellPatterns as a container for all GridCellPattern instances
generate array in GridCellPatterns to hold random CoastalCell for each island
avatarKeyMap "0":"out transcript 0;go link0;step", \ etc.
start Avatar as a child of GridCellPatterns
display an initial menu where player can specify which island the Avatar inhabits
commented out these 3 lines:
var ix = $wnd.Math.floor($wnd.Math.random() * coastalCellArr.length);
var fcell = coastalCellArr[ix];
fcell.append(ava.remove());
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/c5fc2799ce4e0d50c88d119dea7a759445452aa9
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/c5fc2799ce4e0d50c88d119dea7a759445452aa9&src=gist&gui=none
20.add a third island
add ShiftMenuHandler node, to handle Shift-D Shift-E Shift-T (Drop Eat Take)
these 3 keys will set an Avatar property "shiftkey" ex: become this shiftkey D
ShiftMenuHandler.act() will check if Avatar["shiftkey"] has a value, and if so then it will present a menu of things to drop eat take
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/ebfe5d790bc5949a71c1390083d20cc985a74a75
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/ebfe5d790bc5949a71c1390083d20cc985a74a75&src=gist&gui=none
21.show maxClones for Material and other cloneable nodes
add Shift-C to select from among cloneable materials such as Stick, Vine, Thorn, FreshWater
https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0/c3b16443c1a7dd9a59e201821e584d4e394cf628
https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0/c3b16443c1a7dd9a59e201821e584d4e394cf628&src=gist&gui=none
22.fiddling with this and that
23.added caption just above grid, to show current game state
caption updates with each change, including each arrow movement
made Avatar color more distinct from Ocean color
References
----------
(1) https://gist.github.com/kenwebb/bdd87230bacc981ec836786bfcf82cd0
The main URL for the latest revision of this workbook (source code) at github.
(2) https://xholon.meteorapp.com/Xholon.html?app=bdd87230bacc981ec836786bfcf82cd0&src=gist&gui=none
URL to run the latest revision of this workbook as a Meteor app.
]]></Notes>
<_-.XholonClass>
<!-- Types of things needed by the Xholon framework =============================================== -->
<IslandSystem/>
<!-- containers for objects that will be placed in the Ocean and Island parts of the grid; only used for initial setup -->
<Ocean/>
<Island/>
<IslandGridCell>
<OceanCell/> <!-- OceanCell is the default -->
<LandCell/>
<CoastalCell/>
</IslandGridCell>
<GridCellPattern superClass="Attribute_String"/>
<GridCellPatterns/>
<!-- containers for behaviors -->
<PlantBehaviors/>
<FishBehaviors/>
<AnimalBehaviors/> <!-- ex: cat behaviors -->
<!-- end of Types of things needed by the Xholon framework =============================================== -->
<!-- Jen's List =============================================== -->
<!-- <Cell/> see IslandGridCell above -->
<Plant>
<Tree>
<GreenTree/>
<RedTree/>
</Tree>
<!-- <Weed/> -->
</Plant>
<Produce>
<Fruit/>
<PricklyFruit/>
</Produce>
<Berry>
<JuicyBerry/>
</Berry>
<!-- <Flower>
<ChewyFlower/>
</Flower> -->
<Material>
<Stick/>
<Thorn/>
<Vine/>
<!-- <Leaves/> Ken ? -->
<FreshWater/>
</Material>
<Animal>
<Fish/>
</Animal>
<Artifact>
<Tool>
<FishingRod/>
<Basket/>
</Tool>
<Structure>
<Hut/>
</Structure>
</Artifact>
<GeoFeature> <!-- Geography -->
<Spring/> <!-- a place where fresh water might be located -->
</GeoFeature>
<!-- end of Jen's List =============================================== -->
<!-- Other things that Ken needs or is experimenting with =========================== -->
<!-- environment -->
<Weather/>
<!-- Ken's black cat Licorice who insists on being part of any project Ken works on. He aimlessly wanders around on the land, and has no effect other than being visible and sometimes annoying. -->
<Cat/>
<!-- Island Control Centre; a hidden place -->
<City/>
<University/>
<Library/>
<CoffeeShop/>
<IslandControlCentre/>
<!-- an artifact that provides some useful items for free, for now -->
<TreasureChest/>
<TreasureChests/>
<!-- a node I can create to test <Symbol>js:...</Symbol> -->
<Jackal/>
<!-- use TestTool to test the Avatar apply command; TestTool has to be a GWT behavior -->
<TestTool superClass="Script"/>
<!-- Island 4 - experimental: try to parse Ceptre syntax into JavaScript objects -->
<stageCeptre/>
<StageCeptreRunner/>
<!-- log Avatar state and actions -->
<AvatarLogger/>
<!-- handle menus for shift keys Shift-D Shift-E Shift-T (Drop Eat Take) -->
<ShiftMenuHandler/>
</_-.XholonClass>
<xholonClassDetails>
<LandCell><Color>PaleGoldenRod</Color></LandCell> <!-- PaleGoldenRod -->
<CoastalCell><Color>#d0c883</Color></CoastalCell> <!-- #d0c883(olive) -->
<Avatar><Color>RoyalBlue</Color></Avatar>
<GreenTree><DefaultContent><![CDATA[
<_-.treedc>
<Fruit maxClones="10"/>
<JuicyBerry maxClones="10"/>
<Stick maxClones="10"/>
</_-.treedc>
]]></DefaultContent></GreenTree>
<RedTree><DefaultContent><![CDATA[
<_-.treedc>
<PricklyFruit maxClones="10"/>
<Thorn maxClones="10"/>
<Vine maxClones="10"/>
</_-.treedc>
]]></DefaultContent></RedTree>
<TreasureChest><DefaultContent><![CDATA[
<_-.tcdc>
<Stick/>
<Vine/>
<Thorn/>
</_-.tcdc>
]]></DefaultContent></TreasureChest>
<Spring><DefaultContent><![CDATA[
<_-.springdc>
<FreshWater maxClones="100"/>
</_-.springdc>
]]></DefaultContent></Spring>
<Stick>
<!-- Symbol + Color -->
<Symbol>Triangle</Symbol>
<Color>Sienna</Color>
</Stick>
<Fish><Symbol>LRTriangle</Symbol><Color>SteelBlue</Color></Fish> <!-- Tuna silver,SteelBlue -->
<GreenTree><Symbol>Circle</Symbol><Color>Green</Color></GreenTree>
<RedTree><Symbol>Circle</Symbol><Color>Red</Color></RedTree>
<Vine><Symbol>SmallRectangle</Symbol><Color>DarkGreen</Color></Vine>
<Thorn><Symbol>SmallCircle</Symbol><Color>DarkOliveGreen</Color></Thorn>
<Fruit><Symbol>Cross</Symbol><Color>Orange</Color></Fruit>
<PricklyFruit><Symbol>Cross</Symbol><Color>DeepPink</Color></PricklyFruit>
<JuicyBerry><Symbol>ReverseTriangle</Symbol><Color>Violet</Color></JuicyBerry>
<Cat><Symbol>Wye</Symbol><Color>black</Color></Cat>
<City>
<Color>gold</Color>
<Symbol>js:ctx.fillRect(x+1,y+1,cellSize-2,cellSize-2);</Symbol> <!-- this works; it uses the fillStyle specified in <Color> -->
</City>
<Hut>
<Color>DarkGoldenRod</Color>
<!--<Symbol>js:ctx.fillRect(x,y,3,3);ctx.fillRect(x+5,y,3,3);ctx.fillRect(x,y+5,3,3);ctx.fillRect(x+5,y+5,3,3);</Symbol>--> <!-- this works -->
<Symbol>
js:ctx.fillStyle='rgba(255,0,0,1.0)';ctx.fillRect(x,y,3,3);
ctx.fillStyle='rgba(0,255,0,1.0)';ctx.fillRect(x+5,y,3,3);
ctx.fillStyle='rgba(0,0,255,1.0)';ctx.fillRect(x,y+5,3,3);
ctx.fillStyle='rgba(255,255,0,1.0)';ctx.fillRect(x+5,y+5,3,3);
</Symbol> <!-- this works -->
</Hut>
<FishingRod><Color>Orange</Color></FishingRod>
<Basket><Color>Coral</Color></Basket>
<Spring><Color>Chocolate</Color></Spring>
<FreshWater><Color>Aqua</Color></FreshWater>
<TreasureChest>
<Color>Fuchsia</Color>
<Symbol>js:ctx.fillRect(x+1,y+1,cellSize-2,cellSize-2);</Symbol>
</TreasureChest>
<Jackal>
<Color>purple</Color>
<Symbol>js:ctx.fillRect(x+1,y+1,cellSize-2,cellSize-2);</Symbol>
</Jackal>
<TestTool><DefaultContent><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode;
$wnd.console.log(me.name());
},
processReceivedSyncMessage: function(msg) {
var data = msg.data;
$wnd.console.log(data);
var str = "TestTool received message";
if (data && (data.length)) {
for (var i = 0; i < data.length; i++) {
str += " " + data[i];
}
}
return str;
}
}
]]></DefaultContent></TestTool>
</xholonClassDetails>
<IslandSystem>
<!-- rows and cols must be same as const ROWS and const COLS in Behaviors -->
<GridGenerator rows="80" cols="120" gridType="Gmt" names="Space,FieldRow,OceanCell" columnColor="171c8f" gridViewerParams="IslandSystem/Space,10,Island Viewer,true" cellsCanSupplyOwnColor="true">
<Attribute_String>TODO CellPattern ?</Attribute_String>
</GridGenerator>
<!-- L = LandCell C = CoastalCell -->
<GridCellPatterns>
<GridCellPattern xpos="20" ypos="15" islandID="0"><![CDATA[
..CCCCCCCCCCCC
..CLLCLLLCCLLC
CCCCLLLLLLLLCCCC
CLLLLLLLLLLLLLLC
CLLLLLLLLLLLLLLC
CCCCLLLLLLLLLCCC
..CCCCCLLLLCCC
..CLL.LLLLLLC
.CCCLLLLLLLLC
.CLLLLLLLLLLCCC
.CCLLLLLLLLLLLCCCCCCCCC
..CCCLLLLLLLLLLLLLLLLLC
...CLLLLLLLLLLLLLLLLCCC
...CCCLLLLLLLLLLLLLCC
...CLLLLLLLLLCCCCCCC
..CCCCCLLLLCCC
..CLL.LLLLLLLC
CCCCLLLLLLLLCCCC
CLLLLLLLLLLLLLLC
CLLLLLLLLLLLLLLC
CCCCLLLLLLLLLCCC
...CCCCLLLLCCC
......CCCCCC
]]></GridCellPattern>
<GridCellPattern xpos="50" ypos="40" islandID="1"><![CDATA[
..........CCCCC.CCC..CCCCCCC
.........CCLCLCCCLCCCCLCCLLCC
........CCCLLLLLLLLLLLLLLLLLC
......CCCLLLLLLLLLLLLLLLLLCCC
......CLLLLLLLLLLLLLLLLLCCC
..CCCCCCLLLLLLLLLLLLLLLLLLCC
CCCLLLLLLLLLLLLLLLLLLLLLLLLCCC
CLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCCCCCC
CCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCC
.CCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLC
..CCCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCCCC
...CLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCC
...CCCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCC
...CLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCCC
...CCCCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCC
......CCCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLC
.......CLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCC
.......CCCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCC
.......CLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLCCCC
.......CCCCCCCLLLLLLLLLLLLLLLLLLLLLCCCC
............CLLLLLLLLLLLLLLLLLLLLLLLC
............CCCLLLCCCCCCCCCCCCLLLLCCC
..............CCCCC..........CCCCCC
]]></GridCellPattern>
<GridCellPattern xpos="80" ypos="5" islandID="2"><![CDATA[
..CCCCCCCCCCCC
..CLLCLLLCCLLC
CCCCLLLLLLLLCCCC
CLLLLLLLLLLLLLLC
CLLLLLLLLLLLLLLC
CCCCLLLLLLLLLCCC
..CCCCCLLLLCCC
..CLL.LLLLLLC
.CCCLLLLLLLLC
.CLLLLLLLLLLCCC
.CCLLLLLLLLLLLCCCCCCCCC
..CCCLLLLLLLLLLLLLLLLLC
...CLLLLLLLLLLLLLLLLCCC
...CCCLLLLLLLLLLLLLCC
...CLLLLLLLLLCCCCCCC
..CCCCCLLLLCCC
..CLL.LLLLLLLC
CCCCLLLLLLLLCCCC
CLLLLLLLLLLLLLLC
CLLLLLLLLLLLLLLC
CCCCLLLLLLLLLCCC
...CCCCLLLLCCC
......CCCCCC
]]></GridCellPattern>
</GridCellPatterns>
<!-- each PlantBehavior and FishBehavior node moves itself into one of these containers at runtime -->
<PlantBehaviors/>
<FishBehaviors/>
<AnimalBehaviors/>
<!-- see Xml2Xholon - DefaultContent only works if I include RoomModel somewhere before I need to use DefaultContent -->
<RoomModel/>
<Ocean>
<Fish multiplicity="100"/>
<Island>
<Cat roleName="Licorice"/>
<!-- TODO multiplicity causes DefaultContent content to be duplicated in each instance node -->
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<GreenTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<RedTree/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<Spring/>
<City roleName="Ottawa">
<University roleName="Carleton">
<Library>
<CoffeeShop roleName="Starbucks">
<!-- param caption #xhgraph; works -->
<Avatar roleName="Troll" params="param transcript false;param repeat true;param debug false;param speech false;param caption false;"><Attribute_String><![CDATA[
[Troll will repeatedly look for and take students from anywhere in the city, and will drop them in the IslandControlCentre];
wait 1;
exit;
take *treeWanderer;
exit;
wait 1;
enter library;
wait 1;
enter *coffeeShop;
wait 1;
enter islandControlCentre;
drop *treeWanderer;
wait 1;
exit;
wait 1;
]]></Attribute_String></Avatar>
<IslandControlCentre/>
</CoffeeShop>
</Library>
</University>
<!-- TreeWanderer nodes must be last children -->
<TreeWanderer prob="0.1,0.1,0.05,0.05" roleName="Able" exclude="Avatar,TreeWanderer"/>
<TreeWanderer prob="0.1,0.1,0.05,0.05" roleName="Baker" exclude="Avatar,TreeWanderer"/>
<TreeWanderer prob="0.1,0.1,0.05,0.05" roleName="Jen" exclude="Avatar,TreeWanderer"/>
<TreeWanderer prob="0.1,0.1,0.05,0.05" roleName="Ken" exclude="Avatar,TreeWanderer"/>
</City>
<TreasureChests>
<TreasureChest/>
<TreasureChest/>
<TreasureChest/>
<TreasureChest/>
<TreasureChest/>
</TreasureChests>
</Island>
</Ocean>
<Weather state="sunny and windy"/>
<MinecraftStyleRecipeBook roleName="Island"><Attribute_String><![CDATA[
{
"FishingRod": [
{
"ingredients": [
"Stick",
"Vine",
"Thorn"
],
"result": {
"multiplicity": 1,
"xhc": "FishingRod"
}
}
],
"Hut": [
{
"ingredients": [
"Stick",
"Stick",
"Stick",
"Vine",
"Vine",
"Vine"
],
"result": {
"multiplicity": 1,
"xhc": "Hut",
"role": "Cottage"
}
}
],
"Basket": [
{
"ingredients": [
"Vine",
"Vine"
],
"result": {
"multiplicity": 1,
"xhc": "Basket"
}
}
]
}
]]></Attribute_String></MinecraftStyleRecipeBook>
<!-- this is not active yet -->
<JsonRulesEngineRecipeBook roleName="Island"><Attribute_String><![CDATA[
[
{
"conditions": {
"any": [{
"all": [{
"fact": "inventory",
"operator": "contains",
"value": "Stick",
"fate": "remove"
}, {
"fact": "inventory",
"operator": "contains",
"value": "Vine",
"fate": "remove"
}, {
"fact": "inventory",
"operator": "contains",
"value": "Thorn",
"fate": "remove"
}, {
"fact": "wants",
"operator": "equal",
"value": "FishingRod"
}]
}]
},
"event": {
"type": "fishingRod",
"params": {
"message": "A FishingRod can be created."
}
}
}
]
]]></Attribute_String></JsonRulesEngineRecipeBook>
<AvatarLogger formatName="_other,SExpression"/> <!-- _other,Newick _other,SExpression -->
<ShiftMenuHandler/>
<!--<TestTool/> have Avatar build this -->
<!-- Prevent children and siblings from running their act(), to prevent navigating through the large grid each timestep. -->
<ActRegulator val="1.0"/>
<!-- the Space grid is inserted here at runtime -->
<!-- work-around - use "pointer-events: none;" to prevent d3 gui from searching the entire tree when the mouse is hovering -->
<!--<Animate selection="#xhanim" xpath="./IslandSystem/Ocean" duration="1" cssStyle=".d3cpnode circle {pointer-events: none;stroke-width: 0px;} .d3cpdummy circle {pointer-events: none;}" efParams="{&quot;selection&quot;:&quot;#xhanim&quot;,&quot;sort&quot;:&quot;disable&quot;,&quot;width&quot;:2000,&quot;height&quot;:1500,&quot;mode&quot;:&quot;tween&quot;,&quot;labelContainers&quot;:true,&quot;includeId&quot;:true,&quot;shape&quot;:&quot;circle&quot;,&quot;useIcons&quot;:false,&quot;maxChars&quot;:4}"/>-->
</IslandSystem>
<IslandSystembehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
const ROWS = 80; // same as value in GridGenerator
const COLS = 120;
//$wnd.xh.param("RandomNumberSeed", "123"); // the effect happens too late
$wnd.xh.seed(234); // 200 12345
$wnd.xh.param("TimeStepInterval","100"); // "500" "100"
$wnd.xh.param("AppM","true");
if ($wnd.xh.html["selectTab"]) {
$wnd.xh.html.selectTab(0); // display contents of the "out" tab
}
$wnd.xh.css.style("#xhchart {font-family: monospace; font-size: 13.3333px; font-weight: 400;}");
// commands for built-in Avatar
var akm = '{ \
"SHIFT":"true", \
"NOSCROLL":"true", \
"UP":"go port0;if xpath(Avatar/ancestor::OceanCell) go port2;become this calories --;ifeq xpath(Avatar) calories 0 exit Space;", \
"DOWN":"go port2;if xpath(Avatar/ancestor::OceanCell) go port0;become this calories --;ifeq xpath(Avatar) calories 0 exit Space;", \
"LEFT":"if xpath(preceding-sibling::OceanCell) wait else prev;become this calories --;ifeq xpath(Avatar) calories 0 exit Space;", \
"RIGHT":"if xpath(following-sibling::OceanCell) wait else next;become this calories --;ifeq xpath(Avatar) calories 0 exit Space;", \
"b":"recipe Basket; take basket", \
"C":"become this shiftkey C", \
"c":"if xpath(GreenTree) enter *Tree;takeclone stick;if xpath(Stick) exit;", \
"D":"become this shiftkey D", \
"d":"drop first", \
"E":"become this shiftkey E", \
"e":"eat xpath(*);become this calories +=25", \
"f":"follow prev", \
"F":"unfollow", \
"g":"recipe FishingRod;take fishingRod;", \
"h":"recipe Hut;", \
"i":"inventory", \
"J":"build Jackal", \
"l":"look", \
"L":"look all", \
"n":"enter nextprev", \
"o":"if xpath(RedTree) enter *Tree;takeclone thorn;if xpath(Thorn) exit;", \
"p":"pause", \
"q":"out transcript remaining Avatar calories;get this calories", \
"r":"if xpath(Spring) enter spring;takeclone freshWater;if xpath(FreshWater) exit;", \
"s":"step", \
" ":"step", \
"T":"become this shiftkey T", \
"t":"take nextprev", \
"v":"if xpath(RedTree) enter *Tree;takeclone vine;if xpath(Vine) exit;", \
"w":"who;where;", \
"x":"if xpath(../../FieldRow) wait else exit", \
"z":"param transcript toggle;", \
"<":"flip prev", \
">":"flip next", \
",":"flip prev", \
".":"flip next", \
"?":"help keymap", \
"/":"help commands", \
"0":"out transcript 0;go link0;pause", \
"1":"out transcript 1;go link1;pause", \
"2":"out transcript 2;go link2;pause", \
"3":"out transcript 3;go link3;pause", \
"4":"out transcript 4;go link4;pause", \
"5":"out transcript 5;go link5;pause" \
}';
$wnd.xh.avatarKeyMap(akm);
var ava = $wnd.xh.avatar();
//ava.action('enter;enter space_;enter;enter;appear;');
ava.action('param transcript false;');
ava.action('param caption #xhchart;out caption Castaway;');
ava.action('param meteor true;');
//ava.action('param meteormove true;');
//ava.action('param meteorattr one,two,three,calories'); // testing
//ava.action('param recipebook Island;');
ava.action('param recipebook MinecraftStyleRecipeBook-Island;');
//ava.action('param recipebook JsonRulesEngineRecipeBook-Island;');
// Add a TestTool to Avatar's inventory
//ava.action("build TestTool; take testTool;");
ava.action('become this role Castaway;');
ava.action('become this calories 100;'); // 1000
ava.action('enter;enter gridCellPatterns;appear;');
ava.action('step');
// allow player to select which island their Avatar will inhabit
ava.println("Welcome castaway. Which Island would you like to inhabit.");
var gcps = $wnd.xh.root().first().xpath("GridCellPatterns");
var gcp = gcps.first();
while (gcp) {
if (gcp.xhc().name() == "GridCellPattern") {
ava.println("" + gcp.islandID + ": inhabit Island " + gcp.islandID);
}
gcp = gcp.next();
}
ava.print("?- ");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify Plant behavior
$wnd.xh.Plantbehavior = function Plantbehavior() {}
$wnd.xh.Plantbehavior.prototype.postConfigure = function() {
this.plant = this.cnode.parent();
this.plant.calories = 0;
this.plant.xpath("ancestor::IslandSystem/PlantBehaviors").append(this.cnode.remove());
};
$wnd.xh.Plantbehavior.prototype.act = function() {
//this.plant.println("I am " + this.plant.name() + " calories:" + this.plant.calories);
if (this.plant.parent() == null) {
// I've been eaten, so remove this behavior from the simulation
this.cnode.remove();
}
else if (this.plant.parent().xhc().name() == "Avatar") {
// I've been picked
this.plant.calories--;
if (this.plant.calories <= 0) {
// I've gone bad
this.plant.remove();
this.cnode.remove();
}
}
else if (this.plant.parent().xhc().name() == "Island") {
this.plant.calories++;
this.moveSelfToGrid();
}
else {
this.plant.calories++;
}
};
$wnd.xh.Plantbehavior.prototype.moveSelfToGrid = function() {
// DO NOT run this code in postConfigure(); it prevents a next Plant node from obtaining a Plantbehavior
// move this.plant to a random position within the land part of the grid
var ix = $wnd.Math.floor($wnd.xh.random() * landCellArr.length);
var fcell = landCellArr[ix];
fcell.append(this.plant.remove());
};
// specify Fruit behavior
//$wnd.xh.Fruitbehavior = function Fruitbehavior() {};
//$wnd.xh.Fruitbehavior.prototype = $wnd.Object.create($wnd.xh.Plantbehavior.prototype);
// specify Vegetables behavior
//$wnd.xh.Vegetablesbehavior = function Vegetablesbehavior() {};
//$wnd.xh.Vegetablesbehavior.prototype = $wnd.Object.create($wnd.xh.Plantbehavior.prototype);
// specify Lumber behavior
//$wnd.xh.Lumberbehavior = function Lumberbehavior() {};
//$wnd.xh.Lumberbehavior.prototype = $wnd.Object.create($wnd.xh.Plantbehavior.prototype);
// specify GreenTree behavior
$wnd.xh.GreenTreebehavior = function GreenTreebehavior() {};
$wnd.xh.GreenTreebehavior.prototype = $wnd.Object.create($wnd.xh.Plantbehavior.prototype);
// specify RedTree behavior
$wnd.xh.RedTreebehavior = function RedTreebehavior() {};
$wnd.xh.RedTreebehavior.prototype = $wnd.Object.create($wnd.xh.Plantbehavior.prototype);
// specify Spring behavior; for now make it a type of plant
$wnd.xh.Springbehavior = function Springbehavior() {};
$wnd.xh.Springbehavior.prototype = $wnd.Object.create($wnd.xh.Plantbehavior.prototype);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify Fish Grow behavior
$wnd.xh.FishGrowbehavior = function FishGrowbehavior() {}
$wnd.xh.FishGrowbehavior.prototype.postConfigure = function() {
this.fish = this.cnode.parent();
this.fish.calories = 0;
this.fish.xpath("ancestor::IslandSystem/FishBehaviors").append(this.cnode.remove());
};
$wnd.xh.FishGrowbehavior.prototype.act = function() {
//this.fish.println("I am " + this.fish.name() + " calories:" + this.fish.calories);
if (this.fish.parent() == null) {
// I've been eaten, so remove this behavior from the simulation
this.cnode.remove();
}
else if (this.fish.parent().xhc().name() == "Avatar") {
// I've been caught
this.fish.calories--;
if (this.fish.calories <= 0) {
// I've gone bad
this.fish.remove();
this.cnode.remove();
}
}
else if (this.fish.parent().xhc().name() == "Ocean") {
this.fish.calories++;
//this.moveSelfToGrid();
}
else if (this.fish.parent().xhc().name() == "OceanCell") {
this.fish.calories++;
//this.moveSelfToGrid();
}
else {
// I've probably been caught and am now somewhere on land in a hut, or maybe in a boat
this.fish.calories--;
if (this.fish.calories <= 0) {
// I've gone bad :-(
this.fish.remove();
this.cnode.remove();
}
}
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify Fish Move behavior
$wnd.xh.FishMovebehavior = function FishMovebehavior() { // (destCellTypeNot) {
//$wnd.xh.FishMovebehavior.destCellTypeNot = destCellTypeNot;
}
$wnd.xh.FishMovebehavior.prototype.postConfigure = function() {
this.fish = this.cnode.parent();
this.fish.xpath("ancestor::IslandSystem/FishBehaviors").append(this.cnode.remove());
};
$wnd.xh.FishMovebehavior.prototype.act = function() {
//this.fish.println("I am " + this.fish.name() + " moving");
if (this.fish.parent() == null) {
// I've been eaten, so remove this behavior from the simulation
this.cnode.remove();
return;
}
var pname = this.fish.parent().xhc().name();
if (pname == "Ocean") {
this.moveSelfToGrid();
}
else if ((pname == "OceanCell") || (pname == "CoastalCell")) {
// move randomly in the grid
if (!this.nibble()) {
this.move();
}
}
else if (pname == "Avatar") {
// I've been caught, so don't move
}
else {
//$wnd.console.log("ERROR " + this.fish.parent().name()); // Hut, LandCell, etc.
}
};
$wnd.xh.FishMovebehavior.prototype.moveSelfToGrid = function() {
// DO NOT run this code in postConfigure(); it prevents a next Fish node from obtaining a Fishbehavior
// move this.fish to a random position within the ocean part of the grid
var ix = $wnd.Math.floor($wnd.xh.random() * oceanCellArr.length);
var fcell = oceanCellArr[ix];
fcell.append(this.fish.remove());
};
$wnd.xh.FishMovebehavior.prototype.nibble = function() {
// a fish nibbles everything it's near, to see if it's food
// there's a higher probability of stopping to nibble if the Avatar has a FishingRod, than if the Avatar has no FishingRod
var neighbor = this.fish.prev();
if (!neighbor) {return false;}
var rnum = $wnd.xh.random();
var fishingRod = null;
var nname = neighbor.xhc().name();
switch (nname) {
case "Avatar": // possibly nibble the avatar/player
//this.fish.println("rnum: " + rnum);
fishingRod = neighbor.xpath("FishingRod");
if (fishingRod) {
if (rnum > 0.99) { // 0.9
return false;
}
}
else {
if (rnum > 0.9) { // 0.5
return false;
}
}
break;
//case "FishingRod":
// //this.fish.println("rnum: " + rnum);
// if (rnum > 0.99) { // 0.9
// return false;
// }
// break;
default:
//this.fish.println(this.fish.name() + " is co-located with " + neighbor.name());
return false;
}
this.fish.println(this.fish.name() + " is nibbling a " + nname + (fishingRod ? " who is using a fishing rod" : ""));
// become the first child in the current cell, making it possible for the Avatar to "take prev;"
//this.fish.parent().prepend(this.fish.remove());
return true;
};
$wnd.xh.FishMovebehavior.prototype.move = function() {
var foundNewLocation = false;
var count = 0;
while ((!foundNewLocation) && (count < 1)) { // 10
var moveX = $wnd.Math.floor($wnd.xh.random() * 3) - 1;
var moveY = $wnd.Math.floor($wnd.xh.random() * 3) - 1;
if ((moveX == 0) && (moveY == 0)) {
return;
}
var portX = -1;
var portY = -1;
if (moveX > 0) {
portX = 1; //IGrid.P_EAST
}
else {
portX = 3; //IGrid.P_WEST
}
if (moveY > 0) {
portY = 0; //IGrid.P_NORTH
}
else {
portY = 2; //IGrid.P_SOUTH
}
count++;
var destination = this.fish.parent();
if (moveX != 0) {
destination = destination.port(portX);
}
if (moveY != 0) {
destination = destination.port(portY);
}
if (destination && (destination.xhc().name() != "LandCell")) { //$wnd.xh.FishMovebehavior.destCellTypeNot)) {
destination.append(this.fish.remove());
foundNewLocation = true;
}
}
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify Cat Move behavior
$wnd.xh.CatMovebehavior = function CatMovebehavior() {}
$wnd.xh.CatMovebehavior.prototype.postConfigure = function() {
this.cat = this.cnode.parent();
this.cat.xpath("ancestor::IslandSystem/AnimalBehaviors").append(this.cnode.remove());
};
$wnd.xh.CatMovebehavior.prototype.act = function() {
//this.cat.println("I am " + this.cat.name() + " moving");
if (this.cat.parent() == null) {
// I've been eaten, so remove this behavior from the simulation
this.cnode.remove();
}
else if (this.cat.parent().xhc().name() == "Island") {
this.moveSelfToGrid();
}
else if (this.cat.parent().xhc().name().endsWith("Cell")) { // FieldCell OceanCell LandCell
// move randomly in the grid
this.move();
}
else if (this.cat.parent().xhc().name() == "Avatar") {
// I've been caught, so don't move
}
else {
$wnd.console.log("ERROR " + this.cat.parent().name());
}
};
$wnd.xh.CatMovebehavior.prototype.moveSelfToGrid = function() {
// DO NOT run this code in postConfigure(); it prevents a next Cat node from obtaining a Catbehavior
// move this.cat to a random position within the ocean part of the grid
var ix = $wnd.Math.floor($wnd.xh.random() * landCellArr.length);
var fcell = landCellArr[ix];
fcell.append(this.cat.remove());
};
$wnd.xh.CatMovebehavior.prototype.move = function() {
var foundNewLocation = false;
var count = 0;
while ((!foundNewLocation) && (count < 1)) { // 10
var moveX = $wnd.Math.floor($wnd.xh.random() * 3) - 1;
var moveY = $wnd.Math.floor($wnd.xh.random() * 3) - 1;
if ((moveX == 0) && (moveY == 0)) {
return;
}
var portX = -1;
var portY = -1;
if (moveX > 0) {
portX = 1; //IGrid.P_EAST
}
else {
portX = 3; //IGrid.P_WEST
}
if (moveY > 0) {
portY = 0; //IGrid.P_NORTH
}
else {
portY = 2; //IGrid.P_SOUTH
}
count++;
var destination = this.cat.parent();
if (moveX != 0) {
destination = destination.port(portX);
}
if (moveY != 0) {
destination = destination.port(portY);
}
if (destination && (destination.xhc().name() != "OceanCell")) {
destination.append(this.cat.remove());
foundNewLocation = true;
}
}
};
var oceanCellArr = [];
var landCellArr = [];
var coastalCellArr = [];
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify behavior to add all Cell nodes into class-specific arrays, for use by moveSelfToGrid functions
// position system Avatar
$wnd.xh.CellArraybehavior = function CellArraybehavior() {}
$wnd.xh.CellArraybehavior.prototype.postConfigure = function() {
this.isys = this.cnode.parent();
var space = this.isys.xpath("Space");
var row = space.first();
while (row) {
var cell = row.first();
while (cell) {
switch (cell.xhc().name()) {
case "OceanCell":
oceanCellArr.push(cell);
break;
case "LandCell":
landCellArr.push(cell);
break;
case "CoastalCell":
coastalCellArr.push(cell);
break;
default: break;
}
cell = cell.next();
}
row = row.next();
}
//ava.action('go xpath()');
// each Avatar should go in it's own random coastalCell, so use Math.random() rather than xh.random()
//var ix = $wnd.Math.floor($wnd.Math.random() * coastalCellArr.length);
//var fcell = coastalCellArr[ix];
//fcell.append(ava.remove());
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify City behavior
$wnd.xh.Citybehavior = function Citybehavior() {}
$wnd.xh.Citybehavior.prototype.postConfigure = function() {
this.city = this.cnode.parent();
//this.plant.calories = 0;
//this.plant.xpath("ancestor::IslandSystem/PlantBehaviors").append(this.cnode.remove());
var ix = $wnd.Math.floor($wnd.xh.random() * coastalCellArr.length);
var ccell = coastalCellArr[ix];
ccell.append(this.city.remove());
this.cnode.remove();
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// specify TreasureChests behavior
$wnd.xh.TreasureChestsbehavior = function TreasureChestsbehavior() {}
$wnd.xh.TreasureChestsbehavior.prototype.postConfigure = function() {
this.treasureChests = this.cnode.parent();
var tchest = this.treasureChests.first();
while (tchest && tchest.xhc().name() == "TreasureChest") {
var ix = $wnd.Math.floor($wnd.xh.random() * coastalCellArr.length);
var ccell = coastalCellArr[ix];
var tchestNext = tchest.next();
ccell.append(tchest.remove());
tchest = tchestNext;
}
this.cnode.remove();
};
//# sourceURL=IslandSystembehavior.js
]]></IslandSystembehavior>
<GreenTreebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.GreenTreebehavior();
//# sourceURL=GreenTreebehavior.js
]]></GreenTreebehavior>
<RedTreebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.RedTreebehavior();
//# sourceURL=RedTreebehavior.js
]]></RedTreebehavior>
<Fishbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.FishGrowbehavior();
//# sourceURL=FishGrowbehavior.js
]]></Fishbehavior>
<Fishbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.FishMovebehavior(); //("LandCell");
//# sourceURL=FishMovebehavior.js
]]></Fishbehavior>
<Catbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.CatMovebehavior();
//# sourceURL=CatMovebehavior.js
]]></Catbehavior>
<Springbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.Springbehavior();
//# sourceURL=Springbehavior.js
]]></Springbehavior>
<GridCellPatternbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode.parent();
this.cnode.remove();
//me.println("xpos:" + me.xpos + " ypos:" + me.ypos);
var gcpstr = me.text().trim();
var gcparr = gcpstr.split("\n");
var row = me.xpath("../../Space/FieldRow[" + me.ypos + "]");
var fcol = row.xpath("OceanCell[" + me.xpos + "]");
var col = fcol;
var ccArr = []; // cache CoastalCells
for (var i = 0; i < gcparr.length; i++) {
var gcpline = gcparr[i].trim();
//me.println(gcpline);
for (var j = 0; j < gcpline.length; j++) {
switch (gcpline[j]) {
case "L":
col.xhc("LandCell");
break;
case "C":
col.xhc("CoastalCell");
ccArr.push(col);
break;
default: // "."
break;
}
col = col.next();
}
fcol = fcol.port(2);
col = fcol;
}
// randomly select a CoastalCell where Avatar might start
var ccNode = ccArr[Math.floor(Math.random() * ccArr.length)];
var pNode = me.parent(); // GridCellPatterns node
if (!pNode["avatarStartArr"]) {
pNode["avatarStartArr"] = [];
}
pNode["avatarStartArr"].push(ccNode);
}
}
//# sourceURL=GridCellPatternbehavior.js
]]></GridCellPatternbehavior>
<IslandSystembehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.CellArraybehavior();
//# sourceURL=IslandSystembehavior2.js
]]></IslandSystembehavior>
<Citybehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.Citybehavior();
//# sourceURL=Citybehavior.js
]]></Citybehavior>
<TreasureChestsbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var beh = new $wnd.xh.TreasureChestsbehavior();
//# sourceURL=TreasureChestsbehavior.js
]]></TreasureChestsbehavior>
<IslandControlCentrebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, count, beh = {
postConfigure: function() {
me = this.cnode.parent();
count = 0;
//this.cnode.remove();
//$wnd.console.log("IslandControlCentrebehavior starting...");
},
act: function() {
// don't let Meteor start until the app has a chance to deploy everything to their initial/default GridCells
if (count < 2) {
//$wnd.console.log("IslandControlCentrebehavior waiting...");
count++;
}
else if (count >= 2) {
//$wnd.console.log("IslandControlCentrebehavior ReadyForMeteor true");
$wnd.xh.param("ReadyForMeteor","true");
this.cnode.remove();
}
}
}
//# sourceURL=IslandControlCentrebehavior.js
]]></IslandControlCentrebehavior>
<AvatarLoggerbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, ava, newState, prevState, newCalories, prevCalories, beh = {
postConfigure: function() {
me = this.cnode.parent();
ava = $wnd.xh.avatar();
// formatName, node, efParams, writeToTab, returnString
//prevState = this.getXport();
newState = "";
this.hashifySXpres(ava.parent());
prevState = newState;
newCalories = ava.calories;
prevCalories = newCalories;
var jsonStr = '"timestep":"' + $wnd.xh.param("TimeStep") + '",';
jsonStr += '"state":"' + prevState + '",';
jsonStr += '"calories":"' + prevCalories + '"';
this.saveToDB("{" + jsonStr + "}");
},
act: function() {
newState = "";
newCalories = ava.calories;
this.hashifySXpres(ava.parent());
if ((newState != prevState) || (prevCalories != newCalories)) {
prevState = newState;
prevCalories = newCalories;
var jsonStr = '"timestep":"' + $wnd.xh.param("TimeStep") + '",';
jsonStr += '"state":"' + prevState + '",';
jsonStr += '"calories":"' + ava.calories + '"';
this.saveToDB("{" + jsonStr + "}");
}
},
/**
* Recursively hashify a Xholon subtree, with output in a Lisp S-expression format.
* @param node A node in the Xholon hierarchy.
* @param sb A String instance.
*/
hashifySXpres: function(node) {
newState += node.name("R^^^^^");
if (node.xhc().name() == "Space") {
newState += (" (Avatar)");
}
else if (node.first()) {
newState += " (";
var childNode = node.first();
while (childNode != null) {
this.hashifySXpres(childNode);
childNode = childNode.next();
if (childNode != null) {
newState += " ";
}
}
newState += ")";
}
else if (node["maxClones"] && (node.parent().xhc().name() != "Avatar")) {
newState += "*" + node["maxClones"];
}
},
saveToDB: function(str) {
if (ava.parent().xhc().name() != "GridCellPatterns") {
//me.println(str);
ava.action("out caption " + str);
}
}
}
//# sourceURL=AvatarLoggerbehavior.js
]]></AvatarLoggerbehavior>
<ShiftMenuHandlerbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
// default Avatar name template "r:c_i^"
var me, ava, akmObj, initialized, beh = {
postConfigure: function() {
me = this.cnode.parent();
ava = $wnd.xh.avatar();
ava["shiftkey"] = null;
initialized = false;
},
act: function() {
if (!initialized && (ava.parent().xhc().name() != "GridCellPatterns")) {
akmObj = $wnd.JSON.parse($wnd.xh.avatarKeyMap());
// remove all the numbered keys in the key map
for (var i = 0; i < 10; i++) {
akmObj[i] = "";
}
$wnd.xh.avatarKeyMap($wnd.JSON.stringify(akmObj));
initialized = true;
}
var key = ava["shiftkey"];
if (key) {
akmObj = $wnd.JSON.parse($wnd.xh.avatarKeyMap());
//$wnd.console.log(akmObj);
switch (key) {
case "C": // "takeclone;"
// "if xpath(GreenTree) enter *Tree;takeclone stick;if xpath(Stick) exit;"
ava.action("pause;");
//akmObj["*"] = "out transcript *;takeclone;pause;";
me.print("TAKECLONE" + this.makeCloneablesStr("takeclone", "") + " p:none ?- ");
break;
case "D": // "drop;"
ava.action("pause;");
akmObj["*"] = "out transcript *;drop;pause;";
me.print("DROP" + this.makeInventoryStr("drop", "") + " *:all p:none ?- ");
break;
case "E": // "eat;become this calories +=50"
ava.action("pause;");
akmObj["*"] = "out transcript *;eat;become this calories +=50;pause;";
me.print("EAT" + this.makeInventoryStr("eat", "become this calories +=25;") + " *:all p:none ?- ");
break;
case "T": // "take;"
ava.action("pause;");
akmObj["*"] = "out transcript *;take;pause;";
me.print("TAKE" + this.makeSiblingsStr("take") + " *:all p:none ?- ");
break;
default: break;
}
ava["shiftkey"] = null;
$wnd.xh.avatarKeyMap($wnd.JSON.stringify(akmObj));
}
},
// drop 0:fish 1:fishingRod 2:fish 3:stick
makeInventoryStr: function(command, extras) {
var str = "";
var item = ava.first();
var counter = 0;
while (item) {
str += " " + counter + ":" + item.name("R^^^^^");
akmObj[counter] = "out transcript " + counter + ";" + command + " " + item.name("r:c_i^") + ";" + extras + "start;";
counter++;
item = item.next();
}
return str;
},
makeSiblingsStr: function(command) {
var str = "";
var item = ava.parent().first();
var counter = 0;
while (item) {
if (item != ava) {
str += " " + counter + ":" + item.name("R^^^^^");
akmObj[counter] = "out transcript " + counter + ";" + command + " " + item.name("r:c_i^") + ";start;";
counter++;
}
item = item.next();
}
return str;
},
makeCloneablesStr: function(command) {
var str = "";
var item = ava.parent().first();
var counter = 0;
while (item) {
var done = false;
if (item != ava && (item.first())) {
var cloneable = item.first();
while (cloneable) {
if (cloneable["maxClones"]) {
str += " " + counter + ":" + cloneable.name("R^^^^^");
// "if xpath(GreenTree) enter *Tree;takeclone stick;if xpath(Stick) exit;"
akmObj[counter] = "out transcript " + counter + ";enter " + item.name("r:c_i^") + ";" + command + " " + cloneable.name("r:c_i^") + ";exit;start;";
counter++;
done = true;
}
cloneable = cloneable.next();
}
}
if (done) {
item = item.next(); //null;
}
else {
item = item.next();
}
}
return str;
}
}
//# sourceURL=ShiftMenuHandlerbehavior.js
]]></ShiftMenuHandlerbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="180" height="10" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Ocean</title>
<rect id="IslandSystem/Ocean" fill="#98FB98" height="10" width="50" x="0" y="0"/>
<g>
<title>Island</title>
<rect id="IslandSystem/Ocean/Island" fill="#6AB06A" height="10" width="10" x="55" y="0"/>
</g>
<g>
<title>PlantBehaviors</title>
<rect id="IslandSystem/PlantBehaviors" fill="orange" height="10" width="10" x="75" y="0"/>
</g>
<g>
<title>FishBehaviors</title>
<rect id="IslandSystem/FishBehaviors" fill="orange" height="10" width="10" x="95" y="0"/>
</g>
<g>
<title>GridCellPatterns</title>
<rect id="IslandSystem/GridCellPatterns" fill="blue" height="10" width="10" x="115" y="0"/>
</g>
<g>
<title>City</title>
<rect id="IslandSystem/Space/descendant::City" fill="purple" height="10" width="10" x="135" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment