From a8838ac7ad238f617b8d938dd5a0c7f15c701457 Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Fri, 23 Oct 2015 02:09:09 -0400 Subject: [PATCH 01/14] Progress on hexaworld schema. Need to a) split schema into multiple files and b) convert .js to .json --- package.json | 22 ++++++ schema.js | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/all.js | 2 + 3 files changed, 238 insertions(+) create mode 100644 package.json create mode 100644 schema.js create mode 100644 test/all.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..1ba04b3 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "hexaworld-schema", + "version": "0.0.0", + "description": "A schema and validation functions for hexaworld levels ", + "main": "schema.js", + "scripts": { + "test": "node test/all.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/hexaworld/hexaworld-schema" + }, + "author": "Andrew Osheroff (http://andrewosh.com/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/hexaworld/hexaworld-schema/issues" + }, + "homepage": "https://github.com/hexaworld/hexaworld-schema", + "dependencies": { + "jsonschema": "^1.0.2" + } +} diff --git a/schema.js b/schema.js new file mode 100644 index 0000000..96f5253 --- /dev/null +++ b/schema.js @@ -0,0 +1,214 @@ +var hexaworld = { + + $schema: "http://json-schema.org/schema#", + id: "https://github.com/hexaworld/hexaworld-schema/schema.js", + + definitions: { + + // basic definitions + + pixelCoord: { + type: "array", + minItems: 2, + maxItems: 3 + items: { type: "number"} + }, + + axialCoord: { + type: "array", + minItems: 2, + maxItems: 3, + items: { type: "integer" } + }, + + color: { + oneOf: [ + { type: "object", + properties: { + hue: { + type: "number", + minimum: 0, + maximum: 360 + }, + saturation: { + type: "number", + minimum: 0, + maximum: 100 + }, + value: { + type: "number", + minimum: 0, + maximum: 100 + } + } + }, + { type: "object", + properties: { + r: { + type: "number", + minimum: 0, + maximum: 255 + }, + g: { + type: "number", + minimum: 0, + maximum: 255 + } + b: { + type: "number", + minimum: 0, + maximum: 255 + } + } + } + ] + }, + + // geometric definitions + + scaleFactor: { + type: "number", + minimum: 0, + maximum: 1 + }, + + rotationDegrees: { + type: "number", + minimum: -90, + maximum: 90 + }, + + transformation: { + scale: { + type: "object", + properties: { + x: { $ref: "#/definitions/scaleFactor" }, + y: { $ref: "#/definitions/scaleFactor" }, + z: { $ref: "#/definitions/scaleFactor" }, + } + }, + rotation: { + type: "object", + properties: { + x: { $ref: "#/definitions/rotationDegrees" }, + y: { $ref: "#/definitions/rotationDegrees" }, + z: { $ref: "#/definitions/rotationDegrees" }, + } + } + }, + + shape: { + color: { $ref: "#/definitions/color" }, + transformation: { $ref: "#/definitions/transformation" }, + + // TODO: how should we represent textures? + texture: { type: "string" } + }, + + ellipsoid: { + allOf: [ + { $ref: "#/definitions/shape" }, + center: { $ref: "#/definitions/pixelCoord" }, + a: { type: "number" }, + b: { type: "number" }, + c: { type: "number" } + ] + }, + + rectangle: { + allOf: [ + { $ref: "#/definitions/shape" }, + s1: { type: "number" }, + s2: { type: "number" }, + s3: { type: "number" } + ] + }, + + // not checking if valid polygon + polygon: { + allOf: [ + { $ref: "#/definitions/shape" }, + lines: { + type: "array", + items: { + p1: { $ref: "#/definitions/pixelCoord" }, + p2: { $ref: "#/definitions/pixelCoord" } + } + } + ] + } + + // game-specific definitions + + player: { + type: "object" + properties: { + start: { + type: "object", + properties: { + tile: { $ref: "#/definitions/axialCoord" }, + section: { $ref: "#/definitions/section" } + } + }, + shape: { $ref: "#/definitions/shape" } + } + }, + + camera: { $ref: "#/definitions/pixelCoord" }, + + section: { + type: "integer", + minimum: 0, + maximum: 7 + }, + + path: { + allOf: [ + { $ref: "#/definitions/shape" } + ] + } + + tile: { + type: "object" + properties: { + position: { $ref: "#/definitions/axialCoord" }, + sections: { + type: "array", + // no two sections can have the same position + uniqueItems: true, + items: { + type: "object", + properties: { + position: { $ref: "#/definitions/section" }, + path: { $ref: "#/definitions/path" }, + objects: { + type: "array", + items: { $ref: "#/definitions/shape" } + } + }, + required: ["position"] + } + } + }, + required: ["position"] + }, + }, + + allOf: [ + + // an optional array of tiles + { type: "array", + items: { + $ref: "#/definitions/tile" + } + }, + + // a starting position for the player + { $ref: "#/definitions/player" }, + + // a starting position for the camera + { $ref: "#/definitions/camera" } + // additional metadata? + + ] +} diff --git a/test/all.js b/test/all.js new file mode 100644 index 0000000..9faecc5 --- /dev/null +++ b/test/all.js @@ -0,0 +1,2 @@ + +var assert = require('assert') From f9047fc1820510c03a44492495e314bbf59e9684 Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Fri, 23 Oct 2015 02:17:29 -0400 Subject: [PATCH 02/14] Forgot we were in 3D for the polygon definition. Didn't add normals, but 'sokay --- schema.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/schema.js b/schema.js index 96f5253..222a2e9 100644 --- a/schema.js +++ b/schema.js @@ -128,11 +128,12 @@ var hexaworld = { polygon: { allOf: [ { $ref: "#/definitions/shape" }, - lines: { + faces: { type: "array", items: { p1: { $ref: "#/definitions/pixelCoord" }, - p2: { $ref: "#/definitions/pixelCoord" } + p2: { $ref: "#/definitions/pixelCoord" }, + p3: { $ref: "#/definitions/pixelCoord" } } } ] From b6f9aa8fe353f6ccb779ad4fb4c384dca0560e2d Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Fri, 23 Oct 2015 02:21:41 -0400 Subject: [PATCH 03/14] You can only have two axial coordinates --- schema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema.js b/schema.js index 222a2e9..c1ba3c4 100644 --- a/schema.js +++ b/schema.js @@ -17,7 +17,7 @@ var hexaworld = { axialCoord: { type: "array", minItems: 2, - maxItems: 3, + maxItems: 2, items: { type: "integer" } }, From 0f6d75748eca379b1bf566927ccb6d022e05d081 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 11:19:02 -0400 Subject: [PATCH 04/14] Added JSON schema and js -> json write function. Fixed some errors in the schema. --- js/.schema.js.un~ | Bin 0 -> 39666 bytes js/.write.js.un~ | Bin 0 -> 2299 bytes js/hexaworld.js | 229 +++++++++++++++++++++++++++++++++++ js/write.js | 12 ++ package.json | 2 +- schema/hexaworld.json | 271 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 513 insertions(+), 1 deletion(-) create mode 100644 js/.schema.js.un~ create mode 100644 js/.write.js.un~ create mode 100644 js/hexaworld.js create mode 100644 js/write.js create mode 100644 schema/hexaworld.json diff --git a/js/.schema.js.un~ b/js/.schema.js.un~ new file mode 100644 index 0000000000000000000000000000000000000000..167dc1e809214e74bdb12688de65368e72e32e95 GIT binary patch literal 39666 zcmeI5S&&rK8OLW3P+UL|MM2~;KxPqV1`!vGLL!QQ5fz=}C8gs`4>XzS9=m&hDT|0n z9<0(NDw=(%Z? z-!nZs20yoF)hitx9WRTkT`ieT@gcv1RJ~)UZ_lmsIl7_a&L{l`=J}L_LuZLEW#fNh zZVwyLPJ#kMeK#y|I66E2bG}^vO!39yzZM6@(!|-s@R41$!bEjzvU$t>jvEJ05m$rZ zmEy3A+z{cUnsB?yahsQNyF%`EmAG;{E9I8{d(<<7(R@=Z_>GF6#=aP9sBkh(m_6>8 zb)?LYe!uu{#0jU<#wg&bB_Qm*kHai^-Jhcqt$ zKW_noXI%Vgaj;yH0vsuimn&P7dz1B*!r0cNYu&(TVXRmx){5m)b-*3%N{()n6Sk!% z)GEWJ>R7olG0aC!c;?KH`Af)EItJ6r3=AZ<@7=L?YjU7`IH?{ePmPZzhYLxiFj*;7 z3#D38D;%j!Nq(E0v)11_-Nij?(~|`$ZM9Y@miEileVwC@E#xlV_(M_ZbhcxiLxmhx zS5mG)opY*6N}Y3gsdHawSLZgR9QilA-d)!?X=bIGd)>RNaj7}gzYUG^e6?&-2dQ(X zimOo{QO?!NSO-;>jA=+6{Bm<0JRmot-J|20Tf67m71+6fhol&MxoBjH8hI^*=~paM zPAG~i)4W}irwr9a=8u8+LGei0h>|%QLiuZ!GKA@7l=7TM4jwBQwX34^Am+LeD{ADm z5UgLf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1NMF5YE%hY0r$#GtOhDe#uO!Y`E%>4$~M)&DJ<3CU$z=(AF0(~H!&>#1xdM7Ez2tK zczJ(M*GPG4d^9PQYl#~tC-vcxUm8wo<)k~gIAOkOhEaZ~4B*>+kw}1FFIog{l*y6} z0silHz^~2$+!KcA9j5Tmrd-R|7YU<64htdtUq^U-IxKDu>FqfPkI9@^XFp&aGJgoj z>FAwB%&J7jw63I_&zP416?W)8k(SI*-=52CAoKPBoj5J`BJnO(JzWF6&%LlCPZAql zu*_?v3zkn^;#Wt7t9+oT#hx|sl@oT%ZCpTwncerxb==qJieow&kUcHxWp`*-e;?!&(S z;GME<;uxNgsIx}B4}0i5eOi?OImWK2UKUuk;}MOhDAAB$jln<>P0$@AF@*%vXPLJkYTl>Q#? z$}|>^~aFfi}} zF$lnDMj)FNECQiHY%o7e%iEI$A{&1Js(=|vgD8*`2!p|YAYee2g-MLkR0;uLbeMso zgMs0z1e%%PXaI}CBLt+vv=JO}ATbsoW&();0VtZ_>c9~P=Yi!%395zwFygGh5yyy# zI8YRD0Wmn>;n4|-AWo3o(1-)6f@MvRFf0-!L7dTu1BC)D0WjiR!4by{i8xU7fTDmK zWGOU?Kzw8XiY^|Qz-Sb~LV{K_Fp4~&brd)k!Gj)XAtG-fi^3ufxyS?MGf?Eh#YQ8J qRuKj>7Z`CC$h8?L=wZblh|Qt^1n?RSxwzy2$&@7)DVR1sUj+bVq(wgf literal 0 HcmV?d00001 diff --git a/js/hexaworld.js b/js/hexaworld.js new file mode 100644 index 0000000..f934780 --- /dev/null +++ b/js/hexaworld.js @@ -0,0 +1,229 @@ +var hexaworld = { + + $schema: "http://json-schema.org/schema#", + id: "https://github.com/hexaworld/hexaworld-schema/schema.js", + + definitions: { + + // basic definitions + + pixelCoord: { + type: "array", + minItems: 2, + maxItems: 3, + items: { type: "number"} + }, + + axialCoord: { + type: "array", + minItems: 2, + maxItems: 2, + items: { type: "integer" } + }, + + color: { + oneOf: [ + { type: "object", + properties: { + hue: { + type: "number", + minimum: 0, + maximum: 360 + }, + saturation: { + type: "number", + minimum: 0, + maximum: 100 + }, + value: { + type: "number", + minimum: 0, + maximum: 100 + } + } + }, + { type: "object", + properties: { + r: { + type: "number", + minimum: 0, + maximum: 255 + }, + g: { + type: "number", + minimum: 0, + maximum: 255 + }, + b: { + type: "number", + minimum: 0, + maximum: 255 + } + } + } + ] + }, + + // geometric definitions + + scaleFactor: { + type: "number", + minimum: 0, + maximum: 1 + }, + + rotationDegrees: { + type: "number", + minimum: -90, + maximum: 90 + }, + + transformation: { + scale: { + type: "object", + properties: { + x: { $ref: "#/definitions/scaleFactor" }, + y: { $ref: "#/definitions/scaleFactor" }, + z: { $ref: "#/definitions/scaleFactor" }, + } + }, + rotation: { + type: "object", + properties: { + x: { $ref: "#/definitions/rotationDegrees" }, + y: { $ref: "#/definitions/rotationDegrees" }, + z: { $ref: "#/definitions/rotationDegrees" }, + } + } + }, + + shape: { + type: "object", + properties: { + color: { $ref: "#/definitions/color" }, + transformation: { $ref: "#/definitions/transformation" }, + + // TODO: how should we represent textures? + texture: { type: "string" } + } + }, + + ellipsoid: { + allOf: [ + { $ref: "#/definitions/shape" }, + { properties: { + center: { $ref: "#/definitions/pixelCoord" }, + a: { type: "number" }, + b: { type: "number" }, + c: { type: "number" } + } + } + ] + }, + + rectangle: { + allOf: [ + { $ref: "#/definitions/shape" }, + { properties: { + s1: { type: "number" }, + s2: { type: "number" }, + s3: { type: "number" } + } + } + ] + }, + + // not checking if valid polygon + polygon: { + allOf: [ + { $ref: "#/definitions/shape" }, + { properties: { + faces: { + type: "array", + items: { + p1: { $ref: "#/definitions/pixelCoord" }, + p2: { $ref: "#/definitions/pixelCoord" }, + p3: { $ref: "#/definitions/pixelCoord" } + } + } + } + } + ] + }, + + // game-specific definitions + + player: { + type: "object", + properties: { + start: { + type: "object", + properties: { + tile: { $ref: "#/definitions/axialCoord" }, + section: { $ref: "#/definitions/section" } + } + }, + shape: { $ref: "#/definitions/shape" } + } + }, + + camera: { $ref: "#/definitions/pixelCoord" }, + + section: { + type: "integer", + minimum: 0, + maximum: 7 + }, + + path: { + allOf: [ + { $ref: "#/definitions/shape" } + ] + }, + + tile: { + type: "object", + properties: { + position: { $ref: "#/definitions/axialCoord" }, + sections: { + type: "array", + // no two sections can have the same position + uniqueItems: true, + items: { + type: "object", + properties: { + position: { $ref: "#/definitions/section" }, + path: { $ref: "#/definitions/path" }, + objects: { + type: "array", + items: { $ref: "#/definitions/shape" } + } + }, + required: ["position"] + } + } + }, + required: ["position"] + }, + }, + + allOf: [ + + // an optional array of tiles + { type: "array", + items: { + $ref: "#/definitions/tile" + } + }, + + // a starting position for the player + { $ref: "#/definitions/player" }, + + // a starting position for the camera + { $ref: "#/definitions/camera" } + // additional metadata? + + ] +} + +module.exports = hexaworld diff --git a/js/write.js b/js/write.js new file mode 100644 index 0000000..5bccc2d --- /dev/null +++ b/js/write.js @@ -0,0 +1,12 @@ +var fs = require('fs'), + path = require('path') + +var hexaworld = require('./hexaworld.js') + +var writeSchema = function (dir) { + var file = path.join(dir, 'hexaworld.json') + fs.writeFileSync(file, JSON.stringify(hexaworld, null, 2)) + console.log('schema files written to: ' + dir) +} + +module.exports = writeSchema diff --git a/package.json b/package.json index 1ba04b3..7e58b88 100644 --- a/package.json +++ b/package.json @@ -18,5 +18,5 @@ "homepage": "https://github.com/hexaworld/hexaworld-schema", "dependencies": { "jsonschema": "^1.0.2" - } + } diff --git a/schema/hexaworld.json b/schema/hexaworld.json new file mode 100644 index 0000000..f922a38 --- /dev/null +++ b/schema/hexaworld.json @@ -0,0 +1,271 @@ +{ + "$schema": "http://json-schema.org/schema#", + "id": "https://github.com/hexaworld/hexaworld-schema/schema.js", + "definitions": { + "pixelCoord": { + "type": "array", + "minItems": 2, + "maxItems": 3, + "items": { + "type": "number" + } + }, + "axialCoord": { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "type": "integer" + } + }, + "color": { + "oneOf": [ + { + "type": "object", + "properties": { + "hue": { + "type": "number", + "minimum": 0, + "maximum": 360 + }, + "saturation": { + "type": "number", + "minimum": 0, + "maximum": 100 + }, + "value": { + "type": "number", + "minimum": 0, + "maximum": 100 + } + } + }, + { + "type": "object", + "properties": { + "r": { + "type": "number", + "minimum": 0, + "maximum": 255 + }, + "g": { + "type": "number", + "minimum": 0, + "maximum": 255 + }, + "b": { + "type": "number", + "minimum": 0, + "maximum": 255 + } + } + } + ] + }, + "scaleFactor": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "rotationDegrees": { + "type": "number", + "minimum": -90, + "maximum": 90 + }, + "transformation": { + "scale": { + "type": "object", + "properties": { + "x": { + "$ref": "#/definitions/scaleFactor" + }, + "y": { + "$ref": "#/definitions/scaleFactor" + }, + "z": { + "$ref": "#/definitions/scaleFactor" + } + } + }, + "rotation": { + "type": "object", + "properties": { + "x": { + "$ref": "#/definitions/rotationDegrees" + }, + "y": { + "$ref": "#/definitions/rotationDegrees" + }, + "z": { + "$ref": "#/definitions/rotationDegrees" + } + } + } + }, + "shape": { + "type": "object", + "properties": { + "color": { + "$ref": "#/definitions/color" + }, + "transformation": { + "$ref": "#/definitions/transformation" + }, + "texture": { + "type": "string" + } + } + }, + "ellipsoid": { + "allOf": [ + { + "$ref": "#/definitions/shape" + }, + { + "properties": { + "center": { + "$ref": "#/definitions/pixelCoord" + }, + "a": { + "type": "number" + }, + "b": { + "type": "number" + }, + "c": { + "type": "number" + } + } + } + ] + }, + "rectangle": { + "allOf": [ + { + "$ref": "#/definitions/shape" + }, + { + "properties": { + "s1": { + "type": "number" + }, + "s2": { + "type": "number" + }, + "s3": { + "type": "number" + } + } + } + ] + }, + "polygon": { + "allOf": [ + { + "$ref": "#/definitions/shape" + }, + { + "properties": { + "faces": { + "type": "array", + "items": { + "p1": { + "$ref": "#/definitions/pixelCoord" + }, + "p2": { + "$ref": "#/definitions/pixelCoord" + }, + "p3": { + "$ref": "#/definitions/pixelCoord" + } + } + } + } + } + ] + }, + "player": { + "type": "object", + "properties": { + "start": { + "type": "object", + "properties": { + "tile": { + "$ref": "#/definitions/axialCoord" + }, + "section": { + "$ref": "#/definitions/section" + } + } + }, + "shape": { + "$ref": "#/definitions/shape" + } + } + }, + "camera": { + "$ref": "#/definitions/pixelCoord" + }, + "section": { + "type": "integer", + "minimum": 0, + "maximum": 7 + }, + "path": { + "allOf": [ + { + "$ref": "#/definitions/shape" + } + ] + }, + "tile": { + "type": "object", + "properties": { + "position": { + "$ref": "#/definitions/axialCoord" + }, + "sections": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "object", + "properties": { + "position": { + "$ref": "#/definitions/section" + }, + "path": { + "$ref": "#/definitions/path" + }, + "objects": { + "type": "array", + "items": { + "$ref": "#/definitions/shape" + } + } + }, + "required": [ + "position" + ] + } + } + }, + "required": [ + "position" + ] + } + }, + "allOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/tile" + } + }, + { + "$ref": "#/definitions/player" + }, + { + "$ref": "#/definitions/camera" + } + ] +} \ No newline at end of file From b07873d2d65f36fb3800c4938efa4d3e61764e01 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 11:25:47 -0400 Subject: [PATCH 05/14] Removed .js.un~ files --- js/.schema.js.un~ | Bin 39666 -> 0 bytes js/.write.js.un~ | Bin 2299 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 js/.schema.js.un~ delete mode 100644 js/.write.js.un~ diff --git a/js/.schema.js.un~ b/js/.schema.js.un~ deleted file mode 100644 index 167dc1e809214e74bdb12688de65368e72e32e95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 39666 zcmeI5S&&rK8OLW3P+UL|MM2~;KxPqV1`!vGLL!QQ5fz=}C8gs`4>XzS9=m&hDT|0n z9<0(NDw=(%Z? z-!nZs20yoF)hitx9WRTkT`ieT@gcv1RJ~)UZ_lmsIl7_a&L{l`=J}L_LuZLEW#fNh zZVwyLPJ#kMeK#y|I66E2bG}^vO!39yzZM6@(!|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ATbsoW&();0VtZ_>c9~P=Yi!%395zwFygGh5yyy# zI8YRD0Wmn>;n4|-AWo3o(1-)6f@MvRFf0-!L7dTu1BC)D0WjiR!4by{i8xU7fTDmK zWGOU?Kzw8XiY^|Qz-Sb~LV{K_Fp4~&brd)k!Gj)XAtG-fi^3ufxyS?MGf?Eh#YQ8J qRuKj>7Z`CC$h8?L=wZblh|Qt^1n?RSxwzy2$&@7)DVR1sUj+bVq(wgf From 703449f9a602282133c944ffe409e2c6ad1a6e0b Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 11:32:09 -0400 Subject: [PATCH 06/14] Removed top-level schema.js --- schema.js | 215 ------------------------------------------------------ 1 file changed, 215 deletions(-) delete mode 100644 schema.js diff --git a/schema.js b/schema.js deleted file mode 100644 index c1ba3c4..0000000 --- a/schema.js +++ /dev/null @@ -1,215 +0,0 @@ -var hexaworld = { - - $schema: "http://json-schema.org/schema#", - id: "https://github.com/hexaworld/hexaworld-schema/schema.js", - - definitions: { - - // basic definitions - - pixelCoord: { - type: "array", - minItems: 2, - maxItems: 3 - items: { type: "number"} - }, - - axialCoord: { - type: "array", - minItems: 2, - maxItems: 2, - items: { type: "integer" } - }, - - color: { - oneOf: [ - { type: "object", - properties: { - hue: { - type: "number", - minimum: 0, - maximum: 360 - }, - saturation: { - type: "number", - minimum: 0, - maximum: 100 - }, - value: { - type: "number", - minimum: 0, - maximum: 100 - } - } - }, - { type: "object", - properties: { - r: { - type: "number", - minimum: 0, - maximum: 255 - }, - g: { - type: "number", - minimum: 0, - maximum: 255 - } - b: { - type: "number", - minimum: 0, - maximum: 255 - } - } - } - ] - }, - - // geometric definitions - - scaleFactor: { - type: "number", - minimum: 0, - maximum: 1 - }, - - rotationDegrees: { - type: "number", - minimum: -90, - maximum: 90 - }, - - transformation: { - scale: { - type: "object", - properties: { - x: { $ref: "#/definitions/scaleFactor" }, - y: { $ref: "#/definitions/scaleFactor" }, - z: { $ref: "#/definitions/scaleFactor" }, - } - }, - rotation: { - type: "object", - properties: { - x: { $ref: "#/definitions/rotationDegrees" }, - y: { $ref: "#/definitions/rotationDegrees" }, - z: { $ref: "#/definitions/rotationDegrees" }, - } - } - }, - - shape: { - color: { $ref: "#/definitions/color" }, - transformation: { $ref: "#/definitions/transformation" }, - - // TODO: how should we represent textures? - texture: { type: "string" } - }, - - ellipsoid: { - allOf: [ - { $ref: "#/definitions/shape" }, - center: { $ref: "#/definitions/pixelCoord" }, - a: { type: "number" }, - b: { type: "number" }, - c: { type: "number" } - ] - }, - - rectangle: { - allOf: [ - { $ref: "#/definitions/shape" }, - s1: { type: "number" }, - s2: { type: "number" }, - s3: { type: "number" } - ] - }, - - // not checking if valid polygon - polygon: { - allOf: [ - { $ref: "#/definitions/shape" }, - faces: { - type: "array", - items: { - p1: { $ref: "#/definitions/pixelCoord" }, - p2: { $ref: "#/definitions/pixelCoord" }, - p3: { $ref: "#/definitions/pixelCoord" } - } - } - ] - } - - // game-specific definitions - - player: { - type: "object" - properties: { - start: { - type: "object", - properties: { - tile: { $ref: "#/definitions/axialCoord" }, - section: { $ref: "#/definitions/section" } - } - }, - shape: { $ref: "#/definitions/shape" } - } - }, - - camera: { $ref: "#/definitions/pixelCoord" }, - - section: { - type: "integer", - minimum: 0, - maximum: 7 - }, - - path: { - allOf: [ - { $ref: "#/definitions/shape" } - ] - } - - tile: { - type: "object" - properties: { - position: { $ref: "#/definitions/axialCoord" }, - sections: { - type: "array", - // no two sections can have the same position - uniqueItems: true, - items: { - type: "object", - properties: { - position: { $ref: "#/definitions/section" }, - path: { $ref: "#/definitions/path" }, - objects: { - type: "array", - items: { $ref: "#/definitions/shape" } - } - }, - required: ["position"] - } - } - }, - required: ["position"] - }, - }, - - allOf: [ - - // an optional array of tiles - { type: "array", - items: { - $ref: "#/definitions/tile" - } - }, - - // a starting position for the player - { $ref: "#/definitions/player" }, - - // a starting position for the camera - { $ref: "#/definitions/camera" } - // additional metadata? - - ] -} From 67fdea4b7e8412bb681e3654a2abac421f2de59e Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 11:55:24 -0400 Subject: [PATCH 07/14] Working on tests --- package.json | 5 +++-- test/all.js | 19 ++++++++++++++++++- test/bad.js | 6 ++++++ test/good.js | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/bad.js create mode 100644 test/good.js diff --git a/package.json b/package.json index 7e58b88..627dc74 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "homepage": "https://github.com/hexaworld/hexaworld-schema", "dependencies": { - "jsonschema": "^1.0.2" - + "jsonschema": "^1.0.2", + "lodash": "^3.10.1" + } } diff --git a/test/all.js b/test/all.js index 9faecc5..d84fccc 100644 --- a/test/all.js +++ b/test/all.js @@ -1,2 +1,19 @@ +var fs = require('fs'), + path = require('path') -var assert = require('assert') +var _ = require('lodash') + +var testAll = function () { + fs.readdir(__dirname, function (err, files) { + if (err) throw err + _.forEach(files, function (file) { + if (path.extname(file) === '.js' && file !== 'all.js') { + console.log('running test: ' + file) + var tests = require(path.join(__dirname, file)) + tests() + } + }) + }) +} + +testAll() diff --git a/test/bad.js b/test/bad.js new file mode 100644 index 0000000..a51b811 --- /dev/null +++ b/test/bad.js @@ -0,0 +1,6 @@ +var assert = require('assert') + +var badTest = function () { +} + +module.exports = badTest diff --git a/test/good.js b/test/good.js new file mode 100644 index 0000000..d091e2d --- /dev/null +++ b/test/good.js @@ -0,0 +1,15 @@ +var assert = require('assert') + +var validate = require('jsonschema').validate + +var hexaworld = require('../js/hexaworld') + +var schema = { + +} + +var goodTest = function () { + +} + +module.exports = goodTest From 333ac3592fa15d1fec4f4618a92949119e00908f Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 18:15:19 -0400 Subject: [PATCH 08/14] Changed main in package.json to js/hexaworld.js --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 627dc74..b1fc7fb 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "hexaworld-schema", "version": "0.0.0", "description": "A schema and validation functions for hexaworld levels ", - "main": "schema.js", + "main": "js/hexaworld.js", "scripts": { "test": "node test/all.js" }, From 29a2d2aa7039fd6dbe1de12a9d2c4a4282646704 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 18:29:12 -0400 Subject: [PATCH 09/14] A circle has 360 degrees in it. --- js/hexaworld.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/hexaworld.js b/js/hexaworld.js index f934780..1730c2a 100644 --- a/js/hexaworld.js +++ b/js/hexaworld.js @@ -74,8 +74,8 @@ var hexaworld = { rotationDegrees: { type: "number", - minimum: -90, - maximum: 90 + minimum: -180, + maximum: 180 }, transformation: { From 46696c27f842d0f85e14a848edf88ed472020399 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Fri, 23 Oct 2015 18:52:53 -0400 Subject: [PATCH 10/14] Camera now specified by tile/section/height --- js/hexaworld.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/js/hexaworld.js b/js/hexaworld.js index 1730c2a..940f61c 100644 --- a/js/hexaworld.js +++ b/js/hexaworld.js @@ -153,21 +153,28 @@ var hexaworld = { // game-specific definitions + start: { + type: "object", + properties: { + tile: { $ref: "#/definitions/axialCoord" }, + section: { $ref: "#/definitions/section" } + } + } + player: { type: "object", properties: { - start: { - type: "object", - properties: { - tile: { $ref: "#/definitions/axialCoord" }, - section: { $ref: "#/definitions/section" } - } - }, + start: { $ref: "#/definitions/start" }, shape: { $ref: "#/definitions/shape" } } }, - camera: { $ref: "#/definitions/pixelCoord" }, + camera: { + { $ref: "#/definitions/start" }, + { properties: + height: "number" + } + }, section: { type: "integer", From 41477612d60070e9b21bed69f56b5d1d1a4b02e2 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Sat, 24 Oct 2015 01:29:40 -0400 Subject: [PATCH 11/14] Removed geometry schemas. Items now specified by name and transformation --- js/hexaworld.js | 71 ++++--------------------- schema/hexaworld.json | 118 ++++++++++-------------------------------- 2 files changed, 37 insertions(+), 152 deletions(-) diff --git a/js/hexaworld.js b/js/hexaworld.js index 940f61c..ac6af25 100644 --- a/js/hexaworld.js +++ b/js/hexaworld.js @@ -97,60 +97,15 @@ var hexaworld = { } }, - shape: { + item: { type: "object", properties: { + name: { $ref: "string" }, color: { $ref: "#/definitions/color" }, transformation: { $ref: "#/definitions/transformation" }, - - // TODO: how should we represent textures? - texture: { type: "string" } } }, - ellipsoid: { - allOf: [ - { $ref: "#/definitions/shape" }, - { properties: { - center: { $ref: "#/definitions/pixelCoord" }, - a: { type: "number" }, - b: { type: "number" }, - c: { type: "number" } - } - } - ] - }, - - rectangle: { - allOf: [ - { $ref: "#/definitions/shape" }, - { properties: { - s1: { type: "number" }, - s2: { type: "number" }, - s3: { type: "number" } - } - } - ] - }, - - // not checking if valid polygon - polygon: { - allOf: [ - { $ref: "#/definitions/shape" }, - { properties: { - faces: { - type: "array", - items: { - p1: { $ref: "#/definitions/pixelCoord" }, - p2: { $ref: "#/definitions/pixelCoord" }, - p3: { $ref: "#/definitions/pixelCoord" } - } - } - } - } - ] - }, - // game-specific definitions start: { @@ -159,21 +114,23 @@ var hexaworld = { tile: { $ref: "#/definitions/axialCoord" }, section: { $ref: "#/definitions/section" } } - } + }, player: { type: "object", properties: { - start: { $ref: "#/definitions/start" }, - shape: { $ref: "#/definitions/shape" } + start: { $ref: "#/definitions/start" } } }, camera: { + allOf: [ { $ref: "#/definitions/start" }, - { properties: + { properties: { height: "number" + } } + ] }, section: { @@ -182,12 +139,6 @@ var hexaworld = { maximum: 7 }, - path: { - allOf: [ - { $ref: "#/definitions/shape" } - ] - }, - tile: { type: "object", properties: { @@ -200,10 +151,10 @@ var hexaworld = { type: "object", properties: { position: { $ref: "#/definitions/section" }, - path: { $ref: "#/definitions/path" }, - objects: { + path: { type: "boolean" }, + items: { type: "array", - items: { $ref: "#/definitions/shape" } + items: { $ref: "#/definitions/item" } } }, required: ["position"] diff --git a/schema/hexaworld.json b/schema/hexaworld.json index f922a38..6744b9a 100644 --- a/schema/hexaworld.json +++ b/schema/hexaworld.json @@ -69,8 +69,8 @@ }, "rotationDegrees": { "type": "number", - "minimum": -90, - "maximum": 90 + "minimum": -180, + "maximum": 180 }, "transformation": { "scale": { @@ -102,122 +102,56 @@ } } }, - "shape": { + "item": { "type": "object", "properties": { + "name": { + "$ref": "string" + }, "color": { "$ref": "#/definitions/color" }, "transformation": { "$ref": "#/definitions/transformation" - }, - "texture": { - "type": "string" } } }, - "ellipsoid": { - "allOf": [ - { - "$ref": "#/definitions/shape" + "start": { + "type": "object", + "properties": { + "tile": { + "$ref": "#/definitions/axialCoord" }, - { - "properties": { - "center": { - "$ref": "#/definitions/pixelCoord" - }, - "a": { - "type": "number" - }, - "b": { - "type": "number" - }, - "c": { - "type": "number" - } - } + "section": { + "$ref": "#/definitions/section" } - ] + } }, - "rectangle": { - "allOf": [ - { - "$ref": "#/definitions/shape" - }, - { - "properties": { - "s1": { - "type": "number" - }, - "s2": { - "type": "number" - }, - "s3": { - "type": "number" - } - } + "player": { + "type": "object", + "properties": { + "start": { + "$ref": "#/definitions/start" } - ] + } }, - "polygon": { + "camera": { "allOf": [ { - "$ref": "#/definitions/shape" + "$ref": "#/definitions/start" }, { "properties": { - "faces": { - "type": "array", - "items": { - "p1": { - "$ref": "#/definitions/pixelCoord" - }, - "p2": { - "$ref": "#/definitions/pixelCoord" - }, - "p3": { - "$ref": "#/definitions/pixelCoord" - } - } - } + "height": "number" } } ] }, - "player": { - "type": "object", - "properties": { - "start": { - "type": "object", - "properties": { - "tile": { - "$ref": "#/definitions/axialCoord" - }, - "section": { - "$ref": "#/definitions/section" - } - } - }, - "shape": { - "$ref": "#/definitions/shape" - } - } - }, - "camera": { - "$ref": "#/definitions/pixelCoord" - }, "section": { "type": "integer", "minimum": 0, "maximum": 7 }, - "path": { - "allOf": [ - { - "$ref": "#/definitions/shape" - } - ] - }, "tile": { "type": "object", "properties": { @@ -234,12 +168,12 @@ "$ref": "#/definitions/section" }, "path": { - "$ref": "#/definitions/path" + "type": "boolean" }, - "objects": { + "items": { "type": "array", "items": { - "$ref": "#/definitions/shape" + "$ref": "#/definitions/item" } } }, From 1cc507e3bab76908f4392a08f4643bfd4dff7826 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Sat, 24 Oct 2015 01:32:42 -0400 Subject: [PATCH 12/14] Added required properties to some sub-schemas --- js/hexaworld.js | 12 ++++++++---- schema/hexaworld.json | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/js/hexaworld.js b/js/hexaworld.js index ac6af25..5437acf 100644 --- a/js/hexaworld.js +++ b/js/hexaworld.js @@ -103,7 +103,8 @@ var hexaworld = { name: { $ref: "string" }, color: { $ref: "#/definitions/color" }, transformation: { $ref: "#/definitions/transformation" }, - } + }, + required: ["name"] }, // game-specific definitions @@ -113,14 +114,16 @@ var hexaworld = { properties: { tile: { $ref: "#/definitions/axialCoord" }, section: { $ref: "#/definitions/section" } - } + }, + required: ["tile", "section"] }, player: { type: "object", properties: { start: { $ref: "#/definitions/start" } - } + }, + required: ["start"] }, camera: { @@ -128,7 +131,8 @@ var hexaworld = { { $ref: "#/definitions/start" }, { properties: { height: "number" - } + }, + required: ["height"] } ] }, diff --git a/schema/hexaworld.json b/schema/hexaworld.json index 6744b9a..7fe869a 100644 --- a/schema/hexaworld.json +++ b/schema/hexaworld.json @@ -114,7 +114,10 @@ "transformation": { "$ref": "#/definitions/transformation" } - } + }, + "required": [ + "name" + ] }, "start": { "type": "object", @@ -125,7 +128,11 @@ "section": { "$ref": "#/definitions/section" } - } + }, + "required": [ + "tile", + "section" + ] }, "player": { "type": "object", @@ -133,7 +140,10 @@ "start": { "$ref": "#/definitions/start" } - } + }, + "required": [ + "start" + ] }, "camera": { "allOf": [ @@ -143,7 +153,10 @@ { "properties": { "height": "number" - } + }, + "required": [ + "height" + ] } ] }, From 078c91ccd1566c39e47027ee9572374c8ab7be1a Mon Sep 17 00:00:00 2001 From: andrewosh Date: Sat, 31 Oct 2015 15:33:04 -0400 Subject: [PATCH 13/14] Updated hexaworld schema --- js/hexaworld.js | 167 +++++++++++++++++------------------------- schema/hexaworld.json | 110 +++++++++++----------------- 2 files changed, 110 insertions(+), 167 deletions(-) diff --git a/js/hexaworld.js b/js/hexaworld.js index 5437acf..367d712 100644 --- a/js/hexaworld.js +++ b/js/hexaworld.js @@ -1,61 +1,61 @@ var hexaworld = { - $schema: "http://json-schema.org/schema#", - id: "https://github.com/hexaworld/hexaworld-schema/schema.js", + $schema: 'http://json-schema.org/schema#', + id: 'https://github.com/hexaworld/hexaworld-schema/schema.js', definitions: { // basic definitions - pixelCoord: { - type: "array", + pixel: { + type: 'array', minItems: 2, maxItems: 3, - items: { type: "number"} + items: { type: 'number'} }, - axialCoord: { - type: "array", + axial: { + type: 'array', minItems: 2, maxItems: 2, - items: { type: "integer" } + items: { type: 'integer' } }, color: { oneOf: [ - { type: "object", + { type: 'object', properties: { hue: { - type: "number", + type: 'number', minimum: 0, maximum: 360 }, saturation: { - type: "number", + type: 'number', minimum: 0, maximum: 100 }, value: { - type: "number", + type: 'number', minimum: 0, maximum: 100 } } }, - { type: "object", + { type: 'object', properties: { r: { - type: "number", + type: 'number', minimum: 0, maximum: 255 }, g: { - type: "number", + type: 'number', minimum: 0, maximum: 255 }, b: { - type: "number", + type: 'number', minimum: 0, maximum: 255 } @@ -67,125 +67,96 @@ var hexaworld = { // geometric definitions scaleFactor: { - type: "number", + type: 'number', + // TODO: do we want to limit the range of allowable scale factors? minimum: 0, maximum: 1 }, rotationDegrees: { - type: "number", - minimum: -180, - maximum: 180 + type: 'number', + minimum: 0, + maximum: 360 }, transformation: { + position: { + type: 'object', + properties: { + x: { type: 'number' }, + y: { type: 'number' }, + z: { type: 'number' } + } + }, scale: { - type: "object", + type: 'object', properties: { - x: { $ref: "#/definitions/scaleFactor" }, - y: { $ref: "#/definitions/scaleFactor" }, - z: { $ref: "#/definitions/scaleFactor" }, + x: { $ref: '#/definitions/scaleFactor' }, + y: { $ref: '#/definitions/scaleFactor' }, + z: { $ref: '#/definitions/scaleFactor' }, } }, rotation: { - type: "object", + type: 'object', properties: { - x: { $ref: "#/definitions/rotationDegrees" }, - y: { $ref: "#/definitions/rotationDegrees" }, - z: { $ref: "#/definitions/rotationDegrees" }, + x: { $ref: '#/definitions/rotationDegrees' }, + y: { $ref: '#/definitions/rotationDegrees' }, + z: { $ref: '#/definitions/rotationDegrees' }, } } }, - item: { - type: "object", + object: { + type: 'object', properties: { - name: { $ref: "string" }, - color: { $ref: "#/definitions/color" }, - transformation: { $ref: "#/definitions/transformation" }, + name: { $ref: 'string' }, + color: { $ref: '#/definitions/color' }, + transformation: { $ref: '#/definitions/transformation' }, }, - required: ["name"] - }, - - // game-specific definitions - - start: { - type: "object", - properties: { - tile: { $ref: "#/definitions/axialCoord" }, - section: { $ref: "#/definitions/section" } - }, - required: ["tile", "section"] + required: ['name'] }, - player: { - type: "object", + path: { + type: 'object', properties: { - start: { $ref: "#/definitions/start" } - }, - required: ["start"] - }, - - camera: { - allOf: [ - { $ref: "#/definitions/start" }, - { properties: { - height: "number" - }, - required: ["height"] + rotation: { + type: 'integer', + multipleOf: 60 } - ] + } }, - section: { - type: "integer", - minimum: 0, - maximum: 7 - }, + // game-specific definitions tile: { - type: "object", + type: 'object', properties: { - position: { $ref: "#/definitions/axialCoord" }, - sections: { - type: "array", - // no two sections can have the same position - uniqueItems: true, + position: { $ref: '#/definitions/axial' }, + objects: { + type: 'array', items: { - type: "object", - properties: { - position: { $ref: "#/definitions/section" }, - path: { type: "boolean" }, - items: { - type: "array", - items: { $ref: "#/definitions/item" } - } - }, - required: ["position"] + 'oneOf': [ + { $ref: '#/definitions/path' }, + { $ref: '#/definitions/object' } + ] } } }, - required: ["position"] + required: ['position'] }, }, - allOf: [ - - // an optional array of tiles - { type: "array", - items: { - $ref: "#/definitions/tile" - } - }, - - // a starting position for the player - { $ref: "#/definitions/player" }, - - // a starting position for the camera - { $ref: "#/definitions/camera" } + type: 'object', + properties: { + world: + { type: 'array', + items: { $ref: '#/definitions/tile' } + }, + player: { $ref: '#/definitions/player' }, + camera: { $ref: '#/definitions/camera' } // additional metadata? - - ] + }, + required: ['world', 'player', 'camera'] } module.exports = hexaworld diff --git a/schema/hexaworld.json b/schema/hexaworld.json index 7fe869a..6db86a1 100644 --- a/schema/hexaworld.json +++ b/schema/hexaworld.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/schema#", "id": "https://github.com/hexaworld/hexaworld-schema/schema.js", "definitions": { - "pixelCoord": { + "pixel": { "type": "array", "minItems": 2, "maxItems": 3, @@ -10,7 +10,7 @@ "type": "number" } }, - "axialCoord": { + "axial": { "type": "array", "minItems": 2, "maxItems": 2, @@ -69,10 +69,24 @@ }, "rotationDegrees": { "type": "number", - "minimum": -180, - "maximum": 180 + "minimum": 0, + "maximum": 360 }, "transformation": { + "position": { + "type": "object", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + }, + "z": { + "type": "number" + } + } + }, "scale": { "type": "object", "properties": { @@ -102,7 +116,7 @@ } } }, - "item": { + "object": { "type": "object", "properties": { "name": { @@ -119,79 +133,31 @@ "name" ] }, - "start": { - "type": "object", - "properties": { - "tile": { - "$ref": "#/definitions/axialCoord" - }, - "section": { - "$ref": "#/definitions/section" - } - }, - "required": [ - "tile", - "section" - ] - }, - "player": { + "path": { "type": "object", "properties": { - "start": { - "$ref": "#/definitions/start" + "rotation": { + "type": "integer", + "multipleOf": 60 } - }, - "required": [ - "start" - ] - }, - "camera": { - "allOf": [ - { - "$ref": "#/definitions/start" - }, - { - "properties": { - "height": "number" - }, - "required": [ - "height" - ] - } - ] - }, - "section": { - "type": "integer", - "minimum": 0, - "maximum": 7 + } }, "tile": { "type": "object", "properties": { "position": { - "$ref": "#/definitions/axialCoord" + "$ref": "#/definitions/axial" }, - "sections": { + "objects": { "type": "array", - "uniqueItems": true, "items": { - "type": "object", - "properties": { - "position": { - "$ref": "#/definitions/section" + "oneOf": [ + { + "$ref": "#/definitions/path" }, - "path": { - "type": "boolean" - }, - "items": { - "type": "array", - "items": { - "$ref": "#/definitions/item" - } + { + "$ref": "#/definitions/object" } - }, - "required": [ - "position" ] } } @@ -201,18 +167,24 @@ ] } }, - "allOf": [ - { + "type": "object", + "properties": { + "world": { "type": "array", "items": { "$ref": "#/definitions/tile" } }, - { + "player": { "$ref": "#/definitions/player" }, - { + "camera": { "$ref": "#/definitions/camera" } + }, + "required": [ + "world", + "player", + "camera" ] } \ No newline at end of file From 4abfb09c46b7fb6dc35f85feaaeec4fd42c7bc86 Mon Sep 17 00:00:00 2001 From: andrewosh Date: Sat, 31 Oct 2015 16:41:57 -0400 Subject: [PATCH 14/14] Added simple-good test/example and modified schema --- js/hexaworld.js | 46 ++++++++++++++++++++++++++++++---- test/bad.js | 6 ----- test/examples/simple-good.json | 32 +++++++++++++++++++++++ test/good.js | 15 ----------- test/simple-good.js | 18 +++++++++++++ 5 files changed, 91 insertions(+), 26 deletions(-) delete mode 100644 test/bad.js create mode 100644 test/examples/simple-good.json delete mode 100644 test/good.js create mode 100644 test/simple-good.js diff --git a/js/hexaworld.js b/js/hexaworld.js index 367d712..bd877f2 100644 --- a/js/hexaworld.js +++ b/js/hexaworld.js @@ -11,7 +11,7 @@ var hexaworld = { type: 'array', minItems: 2, maxItems: 3, - items: { type: 'number'} + items: { type: 'integer'} }, axial: { @@ -109,7 +109,7 @@ var hexaworld = { object: { type: 'object', properties: { - name: { $ref: 'string' }, + name: { type : 'string' }, color: { $ref: '#/definitions/color' }, transformation: { $ref: '#/definitions/transformation' }, }, @@ -136,21 +136,57 @@ var hexaworld = { type: 'array', items: { 'oneOf': [ - { $ref: '#/definitions/path' }, - { $ref: '#/definitions/object' } + { type: 'object', + properties: { + path: { $ref: '#/definitions/path' } + }, + required: ['path'] + }, + { type: 'object', + properties: { + object: { $ref: '#/definitions/object' } + }, + required: ['object'] + } ] } } }, required: ['position'] }, + + player: { + type: 'object', + properties: { + position: { $ref: '#/definitions/pixel' } + }, + required: ['position'] + }, + + camera: { + type: 'object', + properties: { + position: { $ref: '#/definitions/pixel' }, + height: { + type: 'number', + minimum: 0 + } + }, + required: ['position', 'height'] + } }, type: 'object', properties: { world: { type: 'array', - items: { $ref: '#/definitions/tile' } + items: { + type: 'object', + properties: { + tile: { $ref: '#/definitions/tile' } + }, + required: ['tile'] + } }, player: { $ref: '#/definitions/player' }, camera: { $ref: '#/definitions/camera' } diff --git a/test/bad.js b/test/bad.js deleted file mode 100644 index a51b811..0000000 --- a/test/bad.js +++ /dev/null @@ -1,6 +0,0 @@ -var assert = require('assert') - -var badTest = function () { -} - -module.exports = badTest diff --git a/test/examples/simple-good.json b/test/examples/simple-good.json new file mode 100644 index 0000000..ae2d8b0 --- /dev/null +++ b/test/examples/simple-good.json @@ -0,0 +1,32 @@ +{ + "world": [ + { + "tile": { "position": [0, 0], "objects": [ + { "path": { "rotation": 0 } }, + { "path": { "rotation": 60 } } + ] + } + }, + { + "tile": { "position": [0, 1], "objects": [ + { "path": { "rotation": 0 } }, + { "path": { "rotation": 60 } } + ] + } + }, + { + "tile": { "position": [0, 2], "objects": [ + { "path": { "rotation": 180 } }, + { "path": { "rotation": 60 } } + ] + } + }, + { "tile": { "position": [1, 1], "objects": [ + { "object": { "name": "tree" } } + ] + } + } + ], + "player": { "position": [0, 0] }, + "camera": { "position": [0, 0], "height": 1 } +} diff --git a/test/good.js b/test/good.js deleted file mode 100644 index d091e2d..0000000 --- a/test/good.js +++ /dev/null @@ -1,15 +0,0 @@ -var assert = require('assert') - -var validate = require('jsonschema').validate - -var hexaworld = require('../js/hexaworld') - -var schema = { - -} - -var goodTest = function () { - -} - -module.exports = goodTest diff --git a/test/simple-good.js b/test/simple-good.js new file mode 100644 index 0000000..66408a0 --- /dev/null +++ b/test/simple-good.js @@ -0,0 +1,18 @@ +var assert = require('assert') +var fs = require('fs') +var path = require('path') + +var Validator = require('jsonschema').Validator + +var hexaworld = require('../js/hexaworld.js') + +var runTest = function () { + var fileName = path.join(__dirname, 'examples', 'simple-good.json') + var goodJson = JSON.parse(fs.readFileSync(fileName)) + var v = new Validator() + var result = v.validate(goodJson, hexaworld) + assert.deepEqual(result.errors, []) +} + +module.exports = runTest +