vector/ogmo: Ogmo Editor 3 levels and projects read + write as a TileMap (tile / grid / entity / decal layers, every save layout, values; HaxeFlixel TurnBasedRPG sample, MIT)
This commit is contained in:
1 parent
1f74419ccf
commit
9c02ebdee5
15 files changed
+1596
-4
No files matched your search
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"ogmoVersion": "3.3.0",
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"layers": [
|
||||
{
|
||||
"name": "entities",
|
||||
"_eid": "40110095",
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"gridCellWidth": 16,
|
||||
"gridCellHeight": 16,
|
||||
"gridCellsX": 40,
|
||||
"gridCellsY": 30,
|
||||
"entities": [
|
||||
{"name": "player", "id": 0, "_eid": "40117707", "x": 128, "y": 144, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 1, "_eid": "40304284", "x": 320, "y": 96, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 2, "_eid": "40304284", "x": 352, "y": 80, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 3, "_eid": "40304284", "x": 192, "y": 144, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 4, "_eid": "40304284", "x": 224, "y": 144, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 5, "_eid": "40304284", "x": 256, "y": 144, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 6, "_eid": "40304284", "x": 288, "y": 144, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 7, "_eid": "40304284", "x": 304, "y": 160, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 8, "_eid": "40304284", "x": 304, "y": 192, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 9, "_eid": "40304284", "x": 304, "y": 224, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 10, "_eid": "40304284", "x": 304, "y": 256, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 11, "_eid": "40304284", "x": 304, "y": 304, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 12, "_eid": "40304284", "x": 320, "y": 288, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 13, "_eid": "40304284", "x": 336, "y": 304, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 14, "_eid": "40304284", "x": 288, "y": 288, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 15, "_eid": "40304284", "x": 272, "y": 304, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 16, "_eid": "40304284", "x": 256, "y": 224, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 17, "_eid": "40304284", "x": 256, "y": 192, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 18, "_eid": "40304284", "x": 208, "y": 192, "originX": 0, "originY": 0},
|
||||
{"name": "coin", "id": 19, "_eid": "40304284", "x": 208, "y": 224, "originX": 0, "originY": 0},
|
||||
{"name": "enemy", "id": 20, "_eid": "40444291", "x": 304, "y": 112, "originX": 0, "originY": 0},
|
||||
{"name": "enemy", "id": 21, "_eid": "40444291", "x": 272, "y": 208, "originX": 0, "originY": 0},
|
||||
{"name": "boss", "id": 22, "_eid": "40444462", "x": 304, "y": 288, "originX": 0, "originY": 0}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "walls",
|
||||
"_eid": "40116503",
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"gridCellWidth": 16,
|
||||
"gridCellHeight": 16,
|
||||
"gridCellsX": 40,
|
||||
"gridCellsY": 30,
|
||||
"tileset": "tiles",
|
||||
"data": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
|
||||
"exportMode": 0,
|
||||
"arrayMode": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
{
|
||||
"name": "HaxeFlixel Tutorial",
|
||||
"ogmoVersion": "3.3.0",
|
||||
"levelPaths": ["."],
|
||||
"backgroundColor": "#282c34ff",
|
||||
"gridColor": "#3c4049cc",
|
||||
"anglesRadians": true,
|
||||
"directoryDepth": 5,
|
||||
"layerGridDefaultSize": {"x": 8, "y": 8},
|
||||
"levelDefaultSize": {"x": 320, "y": 240},
|
||||
"levelMinSize": {"x": 640, "y": 480},
|
||||
"levelMaxSize": {"x": 640, "y": 480},
|
||||
"levelValues": [],
|
||||
"defaultExportMode": ".json",
|
||||
"compactExport": false,
|
||||
"externalScript": "",
|
||||
"playCommand": "",
|
||||
"entityTags": [],
|
||||
"layers": [
|
||||
{
|
||||
"definition": "entity",
|
||||
"name": "entities",
|
||||
"gridSize": {"x": 16, "y": 16},
|
||||
"exportID": "40110095",
|
||||
"requiredTags": [],
|
||||
"excludedTags": []
|
||||
},
|
||||
{
|
||||
"definition": "tile",
|
||||
"name": "walls",
|
||||
"gridSize": {"x": 16, "y": 16},
|
||||
"exportID": "40116503",
|
||||
"exportMode": 0,
|
||||
"arrayMode": 0,
|
||||
"defaultTileset": "tiles"
|
||||
}
|
||||
],
|
||||
"entities": [
|
||||
{
|
||||
"exportID": "40117707",
|
||||
"name": "player",
|
||||
"limit": -1,
|
||||
"size": {"x": 16, "y": 16},
|
||||
"origin": {"x": 0, "y": 0},
|
||||
"originAnchored": true,
|
||||
"shape": {
|
||||
"label": "Rectangle",
|
||||
"points": [
|
||||
{"x": -1, "y": -1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": 1}
|
||||
]
|
||||
},
|
||||
"color": "#ff0000ff",
|
||||
"tileX": false,
|
||||
"tileY": false,
|
||||
"tileSize": {"x": 16, "y": 16},
|
||||
"resizeableX": false,
|
||||
"resizeableY": false,
|
||||
"rotatable": false,
|
||||
"rotationDegrees": 360,
|
||||
"canFlipX": false,
|
||||
"canFlipY": false,
|
||||
"canSetColor": false,
|
||||
"hasNodes": false,
|
||||
"nodeLimit": 0,
|
||||
"nodeDisplay": 0,
|
||||
"nodeGhost": true,
|
||||
"tags": [],
|
||||
"values": []
|
||||
},
|
||||
{
|
||||
"exportID": "40304284",
|
||||
"name": "coin",
|
||||
"limit": -1,
|
||||
"size": {"x": 16, "y": 16},
|
||||
"origin": {"x": 0, "y": 0},
|
||||
"originAnchored": true,
|
||||
"shape": {
|
||||
"label": "Rectangle",
|
||||
"points": [
|
||||
{"x": -1, "y": -1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": 1}
|
||||
]
|
||||
},
|
||||
"color": "#ffcc00ff",
|
||||
"tileX": false,
|
||||
"tileY": false,
|
||||
"tileSize": {"x": 16, "y": 16},
|
||||
"resizeableX": false,
|
||||
"resizeableY": false,
|
||||
"rotatable": false,
|
||||
"rotationDegrees": 360,
|
||||
"canFlipX": false,
|
||||
"canFlipY": false,
|
||||
"canSetColor": false,
|
||||
"hasNodes": false,
|
||||
"nodeLimit": 0,
|
||||
"nodeDisplay": 0,
|
||||
"nodeGhost": true,
|
||||
"tags": [],
|
||||
"values": []
|
||||
},
|
||||
{
|
||||
"exportID": "40444291",
|
||||
"name": "enemy",
|
||||
"limit": -1,
|
||||
"size": {"x": 16, "y": 16},
|
||||
"origin": {"x": 0, "y": 0},
|
||||
"originAnchored": true,
|
||||
"shape": {
|
||||
"label": "Rectangle",
|
||||
"points": [
|
||||
{"x": -1, "y": -1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": 1}
|
||||
]
|
||||
},
|
||||
"color": "#0dbc0aff",
|
||||
"tileX": false,
|
||||
"tileY": false,
|
||||
"tileSize": {"x": 16, "y": 16},
|
||||
"resizeableX": false,
|
||||
"resizeableY": false,
|
||||
"rotatable": false,
|
||||
"rotationDegrees": 360,
|
||||
"canFlipX": false,
|
||||
"canFlipY": false,
|
||||
"canSetColor": false,
|
||||
"hasNodes": false,
|
||||
"nodeLimit": 0,
|
||||
"nodeDisplay": 0,
|
||||
"nodeGhost": true,
|
||||
"tags": [],
|
||||
"values": []
|
||||
},
|
||||
{
|
||||
"exportID": "40444462",
|
||||
"name": "boss",
|
||||
"limit": -1,
|
||||
"size": {"x": 16, "y": 16},
|
||||
"origin": {"x": 0, "y": 0},
|
||||
"originAnchored": true,
|
||||
"shape": {
|
||||
"label": "Rectangle",
|
||||
"points": [
|
||||
{"x": -1, "y": -1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": -1},
|
||||
{"x": -1, "y": 1},
|
||||
{"x": 1, "y": 1}
|
||||
]
|
||||
},
|
||||
"color": "#00e3ffff",
|
||||
"tileX": false,
|
||||
"tileY": false,
|
||||
"tileSize": {"x": 16, "y": 16},
|
||||
"resizeableX": false,
|
||||
"resizeableY": false,
|
||||
"rotatable": false,
|
||||
"rotationDegrees": 360,
|
||||
"canFlipX": false,
|
||||
"canFlipY": false,
|
||||
"canSetColor": false,
|
||||
"hasNodes": false,
|
||||
"nodeLimit": 0,
|
||||
"nodeDisplay": 0,
|
||||
"nodeGhost": true,
|
||||
"tags": [],
|
||||
"values": []
|
||||
}
|
||||
],
|
||||
"tilesets": [
|
||||
{"label": "tiles", "path": "../images/tiles.png", "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODRBQjNDODZENDhCMTFFMzk5N0RDMzAxQTc5NEM5RkMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODRBQjNDODdENDhCMTFFMzk5N0RDMzAxQTc5NEM5RkMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4NEFCM0M4NEQ0OEIxMUUzOTk3REMzMDFBNzk0QzlGQyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4NEFCM0M4NUQ0OEIxMUUzOTk3REMzMDFBNzk0QzlGQyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrOLMN8AAACUSURBVHja7JWhDoAgEEBPRrERbVYCX+If8Z8Eqo2IyYi7wOYYTncYuI3XD94bDKaUErSwWZtWY0izu3NAnc3zEhpBAVyIQvAeWuKPEEAAQ7I8IjjLswso5RHZq2iNUp7lFRoBI2AEQN+vEL5A+EM/MSvV7wm8ySNnjH0GfJGvRQhu8mWE/GPz2g/5hUVrkvw94hJgALO2Vr1s43dIAAAAAElFTkSuQmCC", "tileWidth": 16, "tileHeight": 16, "tileSeparationX": 0, "tileSeparationY": 0}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
-- vector/ogmo tests: Ogmo Editor 3 levels (HaxeFlixel's TurnBasedRPG and levels made in every save layout) against a
|
||||
-- Python reading of the editor's format; projects; our writer's output (level + project) read by the same Python;
|
||||
-- round trips; errors; fuzz. Fixtures: tools/fixtures/ogmo.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Ogmo = require("@rosetta/vector/ogmo")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Fx = require("@tests/gen/ogmo")
|
||||
local Ours = require("@tests/gen/ogmo_ours")
|
||||
|
||||
local t = T.suite("ogmo")
|
||||
|
||||
local function decode(s: string | buffer, opts: any?): (any, any)
|
||||
local b = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
return Ogmo.decode(Bytes.reader(b), opts)
|
||||
end
|
||||
|
||||
t:eq(Ogmo.name, "ogmo", "name")
|
||||
t:eq(Ogmo.category, "vector", "category")
|
||||
t:check(Ogmo.caps.decode and Ogmo.caps.encode, "caps")
|
||||
|
||||
local function fmt(v: number): string
|
||||
if v == math.floor(v) then
|
||||
return string.format("%d", v)
|
||||
end
|
||||
return string.format("%.6g", v)
|
||||
end
|
||||
|
||||
local function jsonValue(v: any): string
|
||||
if type(v) == "string" then
|
||||
return "\"" .. v .. "\""
|
||||
elseif type(v) == "boolean" then
|
||||
return tostring(v)
|
||||
end
|
||||
return if v == math.floor(v) then string.format("%d", v) else string.format("%.17g", v)
|
||||
end
|
||||
|
||||
local function valuesStr(props: any): string
|
||||
local keys = {}
|
||||
for k in props do
|
||||
table.insert(keys, k)
|
||||
end
|
||||
table.sort(keys)
|
||||
local out = {}
|
||||
for _, k in keys do
|
||||
table.insert(out, k .. "=" .. jsonValue(props[k]))
|
||||
end
|
||||
return table.concat(out, ",")
|
||||
end
|
||||
|
||||
-- our TileMap summarised like tools/fixtures/ogmo.py summarises a level
|
||||
local function stats(map: any): any
|
||||
local layers = {}
|
||||
for _, l in map.layers do
|
||||
local d: any = { name = l.name, kind = l.ogmoType }
|
||||
if l.ogmoType == "entity" then
|
||||
d.items = {}
|
||||
for _, o in l.objects do
|
||||
table.insert(d.items, string.format("%s@%s,%s %sx%s r%d n%d %s", o.class, fmt(o.x), fmt(o.y), fmt(o.width), fmt(o.height), math.floor(o.rotation + 0.5), if o.nodes then #o.nodes else 0, valuesStr(o.properties)))
|
||||
end
|
||||
elseif l.ogmoType == "decal" then
|
||||
d.items = {}
|
||||
for _, o in l.objects do
|
||||
table.insert(d.items, string.format("%s@%s,%s s%s,%s r%d", o.texture, fmt(o.x), fmt(o.y), fmt(o.scaleX), fmt(o.scaleY), math.floor(o.rotation + 0.5)))
|
||||
end
|
||||
elseif l.ogmoType == "grid" then
|
||||
d.cells = table.concat(l.grid)
|
||||
else
|
||||
local ts
|
||||
for _, x in map.tilesets do
|
||||
if x.name == l.tileset then
|
||||
ts = x
|
||||
end
|
||||
end
|
||||
local ne, ids, fl = 0, 0, 0
|
||||
for k, g in l.data do
|
||||
local gid = bit32.band(g, 0x0FFFFFFF)
|
||||
local id = if gid == 0 then -1 else gid - (if ts then ts.firstGid else 1)
|
||||
if id >= 0 then
|
||||
ne += 1
|
||||
end
|
||||
ids += (id + 1) * ((k - 1) % 7 + 1)
|
||||
local f = (if bit32.btest(g, 0x80000000) then 4 else 0) + (if bit32.btest(g, 0x40000000) then 2 else 0) + (if bit32.btest(g, 0x20000000) then 1 else 0)
|
||||
fl += f * ((k - 1) % 5 + 1)
|
||||
end
|
||||
d.tileset, d.nonEmpty, d.idSum, d.flagSum = l.tileset or "", ne, ids, fl
|
||||
end
|
||||
table.insert(layers, d)
|
||||
end
|
||||
return { width = map.pxWidth, height = map.pxHeight, values = valuesStr(map.properties), layers = layers }
|
||||
end
|
||||
|
||||
local function diff(a: any, b: any, path: string, out: { string })
|
||||
if #out > 6 then
|
||||
return
|
||||
end
|
||||
if type(a) == "table" and type(b) == "table" then
|
||||
for k, v in a do
|
||||
diff(v, b[k], path .. "." .. tostring(k), out)
|
||||
end
|
||||
for k, v in b do
|
||||
if a[k] == nil then
|
||||
diff(nil, v, path .. "." .. tostring(k), out)
|
||||
end
|
||||
end
|
||||
elseif a ~= b then
|
||||
table.insert(out, path .. ": " .. tostring(a) .. " vs " .. tostring(b))
|
||||
end
|
||||
end
|
||||
|
||||
local function same(got: any, want: any, label: string)
|
||||
-- w / h are compared through the layer data sizes
|
||||
for _, x in { got, want } do
|
||||
for _, l in x.layers do
|
||||
l.w, l.h = nil, nil
|
||||
end
|
||||
end
|
||||
local out = {}
|
||||
diff(got, want, "", out)
|
||||
t:check(#out == 0, label .. ": " .. table.concat(out, "; "))
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
local maps = {}
|
||||
for _, c in Fx.cases do
|
||||
local map, err = decode(c.data, { project = c.project })
|
||||
t:check(map, c.name .. ": decode: " .. tostring(err))
|
||||
if map then
|
||||
maps[c.name] = map
|
||||
same(stats(map), c.stats, c.name .. ": = the editor's layout (Python)")
|
||||
local out = assert(Ogmo.encode(map))
|
||||
local back = assert(decode(out, { project = c.project }))
|
||||
same(stats(back), c.stats, c.name .. ": round trip")
|
||||
end
|
||||
t:eq(Ogmo.sniff(Bytes.reader(buffer.fromstring(c.data))), 0.9, c.name .. ": sniff level")
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
for _, o in Ours do
|
||||
local want
|
||||
for _, c in Fx.cases do
|
||||
if c.name == o.name then
|
||||
want = c.stats
|
||||
end
|
||||
end
|
||||
same(o.stats, want, o.name .. ": our level + project (Python)")
|
||||
end
|
||||
t:eq(#Ours, #Fx.cases, "every level written")
|
||||
|
||||
for _, p in Fx.projects do
|
||||
local m, err = decode(p.data)
|
||||
t:check(m and m.meta.project, p.name .. ": project: " .. tostring(err))
|
||||
t:eq(Ogmo.sniff(Bytes.reader(buffer.fromstring(p.data))), 1, p.name .. ": sniff project")
|
||||
if m then
|
||||
local back = assert(decode(assert(Ogmo.encode(m))))
|
||||
t:check(back.meta.project and #back.layers == #m.layers and #back.tilesets == #m.tilesets, p.name .. ": project round trip")
|
||||
end
|
||||
table.insert(samples, p.data)
|
||||
end
|
||||
|
||||
do
|
||||
local m = maps["made/level0"]
|
||||
local ents
|
||||
for _, l in m.layers do
|
||||
if l.ogmoType == "entity" then
|
||||
ents = l
|
||||
end
|
||||
end
|
||||
local p = ents.objects[1]
|
||||
t:check(p.class == "player" and p.x == 16 and p.y == 16 and p.width == 8 and p.height == 16, "entity: origin, template size")
|
||||
t:check(math.abs(p.rotation - 90) < 1e-9 and p.flippedX == true and #p.nodes == 2, "entity: radians -> degrees, flip, nodes")
|
||||
t:eq(p.propertyTypes.hp, "int", "entity value types from the template")
|
||||
t:eq(m.propertyTypes.gravity, "float", "level value types")
|
||||
t:eq(m.layers[#m.layers].ogmoType, "entity", "Ogmo's first layer is on top")
|
||||
local small = m.tilesets[2]
|
||||
t:check(small.columns == 3 and small.imageWidth == 36 and type(small.imageData) == "buffer", "tileset from the embedded PNG")
|
||||
local rpg = maps["turnBasedRPG/room-001"]
|
||||
t:check(rpg.width == 80 and rpg.tileWidth == 8 and rpg.pxWidth == 640, "map size from the project grid")
|
||||
-- without the project: tiles keep their ids
|
||||
local c = Fx.cases[1]
|
||||
local bare = assert(decode(c.data))
|
||||
t:check(#bare.tilesets == 0 and bare.layers[1].data ~= nil, "level without a project")
|
||||
end
|
||||
|
||||
-- a Tiled-style map as an Ogmo level
|
||||
do
|
||||
local map = Types.TileMap.new(2, 2, 16, 16)
|
||||
table.insert(map.tilesets, { name = "t", firstGid = 1, tileWidth = 16, tileHeight = 16, columns = 2, count = 4 })
|
||||
table.insert(map.layers, { type = "tiles", name = "ground", width = 2, height = 2, visible = true, opacity = 1, properties = {}, data = { 1, 0, bit32.bor(4, 0x80000000), 2 } })
|
||||
table.insert(map.layers, { type = "objects", name = "things", visible = true, opacity = 1, properties = {}, objects = { { class = "coin", x = 4, y = 6, width = 8, height = 8, properties = { value = 10 } } } })
|
||||
local out = assert(F.save(map, nil, { format = "ogmo" }))
|
||||
local back = assert(decode(out, { project = assert(Ogmo.encode(map, { kind = "project" })) }))
|
||||
t:eq(back.layers[1].data[3], bit32.bor(4, 0x80000000), "tile + flip")
|
||||
t:check(back.layers[2].objects[1].properties.value == 10 and back.layers[2].objects[1].x == 4, "object")
|
||||
end
|
||||
|
||||
do
|
||||
local _, e = decode("{\"ogmoVersion\": \"3.4.0\"}")
|
||||
t:check(e and e.code == Err.CORRUPT, "no layers")
|
||||
local _, e2 = decode("[1]")
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "not an object")
|
||||
local _, e3 = Ogmo.encode({} :: any)
|
||||
t:check(e3 and e3.code == Err.ARG, "encode arg")
|
||||
local _, e4 = Ogmo.encode(maps["made/level0"], { kind = "x" :: any })
|
||||
t:check(e4 and e4.code == Err.ARG, "bad kind")
|
||||
end
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return decode(b, { project = Fx.projects[2].data })
|
||||
end, samples, { mutations = 60, garbage = 20 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user