dungeon is [{"x":1,"y":1},{"x":1,"y":2},{"x":1,"y":3},etc. ] where each coord represents SPACE and
Field is ["t100000111","t111000111","t111000111", etc.] where 1=SPACE and 0=WALL and tx is "tE,NE,N,NW,W,SW,S,SE,Centre"
coord of dungeon, the 2nd with the 2nd, etc. (thus logically "centre" in tx is thus ALWAYS "1")
Code: Select all
[h:'<!-- ------------------------------------ addBevel() ------------------------------------------------- -->']
[debug=0]
[h:dungeon = getLibProperty("DB3.dungeon","lib:DB3Test")]
[h:Field = getLibProperty("DB3.tField","lib:DB3Test")]
[h,foreach(tile, Field), CODE:{
<!-- create x and y coord of current Centre -->
[coord = json.get(dungeon, roll.count)]
[varsFromStrProp(json.toStrProp(coord))]
<!-- turn tile into separate variables -->
[varsFromStrProp(replace(
tile,
"t(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
"E=\$1;NE=\$2;N=\$3;NW=\$4;W=\$5;SW=\$6;S=\$7;SE=\$8;"
))]
<!-- EAST EDGE CHECK -->
[if(debug), CODE:{[position="EAST"][tmp = "t"+SE+E+NE]}]
[switch("t"+SE+E+NE), CODE:
case "t000":{
<!-- EV -->
[copyToken("BevelEV",1,"",json.set(coord, "useDistance",0,"facing",90))]
[if(debug):pause("coord", "tile","tmp","position")]
};
case "t100": {
<!-- EV CO(S) -->
[copyToken("BevelEV",1,"",json.set(coord, "useDistance",0,"facing",90))]
[copyToken("BevelOC",1,"",json.set(coord, "useDistance",0,"facing",0))]
[if(debug):pause("coord", "tile","tmp","position")]
};
case "t001": {
<!-- EV CO(N) -->
[copyToken("BevelEV",1,"",json.set(coord, "useDistance",0,"facing",90))]
[copyToken("BevelOC",1,"",json.set(coord, "y", json.get(coord,"y")-1, "useDistance",0,"facing",-90))]
[if(debug):pause("coord", "tile","tmp","position")]
};
case "t101": {
<!-- EV CO CO -->
[copyToken("BevelEV",1,"",json.set(coord, "useDistance", 0, "facing", 90))]
[copyToken("BevelOC",1,"",json.set(coord, "y", json.get(coord,"y")-1, "useDistance",0,"facing",-90))]
[copyToken("BevelOC",1,"",json.set(coord, "useDistance",0,"facing",0))]
[if(debug):pause("coord", "tile","tmp","position")]
};
default: {<!-- ignore -->
}]
<!-- NORTH EAST CORNER CHECK --><!-- IC ONLY -->
[if(debug), CODE:{[position="NORTH EAST CORNER"][tmp = "t"+E+NE+N]}]
[if(E+NE+N == 0), CODE:{
[copyToken("BevelIC",1,"",json.set(coord, "x", json.get(coord,"x")+1, "y", json.get(coord,"y")-1, "useDistance",0,"facing",180))]
[if(debug):pause("coord", "tile","tmp","position")]
}]
<!-- NORTH EDGE CHECK Do not add OC as this is already done in East and West, hence only place vertical bevel is south = wall = 0 = !1 = !S -->
[if(!N): copyToken("BevelEH",1,"",json.set(coord, "y", json.get(coord,"y")-1, "useDistance", 0, "facing", -90))]
[if(debug), CODE:{[position="NORTH"][tmp = "t"+NE+N+NW]pause("coord", "tile","tmp","position")}]
<!-- NORTH WEST CORNER CHECK --><!-- IC ONLY -->
[if(debug), CODE:{[position="NORTH WEST CORNER"][tmp = "t"+N+NW+W]}]
[if(N+NW+W == 0), CODE:{
[tok=copyToken("BevelIC",1,"",json.set(coord, "x", json.get(coord,"x")-1, "y", json.get(coord,"y")-1, "useDistance",0,"facing",-90))]
[if(debug):pause("coord", "tile","tmp","position","tok")]
}]
<!-- WEST EDGE CHECK -->
[if(debug), CODE:{[position="WEST"][tmp = "t"+NW+W+SW]}]
[switch("t"+NW+W+SW), CODE:
case "t000":{
<!-- EV -->
[copyToken("BevelEV",1,"",json.set(coord, "x", json.get(coord,"x")-1, "useDistance", 0, "facing", -90))]
[if(debug):pause("coord", "tile","tmp","position")]
};
case "t001": {
<!-- EV CO(SW) -->
[copyToken("BevelEV",1,"",json.set(coord, "x", json.get(coord,"x")-1, "useDistance", 0, "facing", -90))]
[copyToken("BevelOC",1,"",json.set(coord, "x", json.get(coord,"x")-1, "useDistance", 0, "facing", 90))]
[if(debug):pause("coord", "tile","tmp","position")]
};
case "t100": {
<!-- EV CO(NW) -->
[copyToken("BevelEV",1,"",json.set(coord, "x", json.get(coord,"x")-1, "useDistance", 0, "facing", -90))]
[copyToken("BevelOC",1,"",json.set(coord, "x", json.get(coord,"x")-1, "y", json.get(coord,"y")-1, "useDistance",0,"facing",180))]
[if(debug):pause("coord", "tile","tmp","position")]
};
case "t101": {
<!-- EV CO CO -->
[copyToken("BevelEV",1,"",json.set(coord, "x", json.get(coord,"x")-1, "useDistance", 0, "facing", -90))]
[copyToken("BevelOC",1,"",json.set(coord, "x", json.get(coord,"x")-1, "useDistance", 0, "facing", 90))]
[copyToken("BevelOC",1,"",json.set(coord, "x", json.get(coord,"x")-1, "y", json.get(coord,"y")-1, "useDistance",0,"facing",180))]
[if(debug):pause("coord", "tile","tmp","position")]
};
default: {<!-- ignore -->
}]
<!-- SOUTH WEST CORNER CHECK --><!-- IC ONLY -->
[if(debug), CODE:{[position="SOUTH WEST CORNER"][tmp = "t"+W+SW+S]}]
[if(W+SW+S == 0), CODE:{
[copyToken("BevelIC",1,"",json.set(coord, "x", json.get(coord,"x")-1, "y", json.get(coord,"y")+1, "useDistance",0,"facing",0))]
[if(debug):pause("coord", "tile","tmp","position")]
}]
<!-- SOUTH EDGE CHECK Do not add OC as this is already done in East and West, hence only place vertical bevel is south = wall = 0 = !1 = !S -->
[if(!S): copyToken("BevelEH",1,"",json.set(coord, "useDistance", 0, "facing", 90))]
[if(debug), CODE:{[position="SOUTH"][tmp = "t"+SW+S+SE]pause("coord", "tile","tmp","position")}]
<!-- SOUTH EAST CORNER CHECK --><!-- IC ONLY -->
[if(debug), CODE:{[position=""][tmp = "t"+S+SE+E]}]
[if(S+SE+E == 0), CODE:{
[copyToken("BevelIC",1,"",json.set(coord, "x", json.get(coord,"x")+1, "y", json.get(coord,"y")+1, "useDistance",0,"facing",90))]
[if(debug):pause("coord", "tile","tmp","position")]
}]
}]