Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft of hexaworld schema #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions js/hexaworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
var hexaworld = {

$schema: 'http://json-schema.org/schema#',
id: 'https://github.com/hexaworld/hexaworld-schema/schema.js',

definitions: {

// basic definitions

pixel: {
type: 'array',
minItems: 2,
maxItems: 3,
items: { type: 'integer'}
},

axial: {
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',
// TODO: do we want to limit the range of allowable scale factors?
minimum: 0,
maximum: 1
},

rotationDegrees: {
type: 'number',
minimum: 0,
maximum: 360
},

transformation: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't position be added into transformation too

position: {
type: 'object',
properties: {
x: { type: 'number' },
y: { type: 'number' },
z: { type: 'number' }
}
},
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' },
}
}
},

object: {
type: 'object',
properties: {
name: { type : 'string' },
color: { $ref: '#/definitions/color' },
transformation: { $ref: '#/definitions/transformation' },
},
required: ['name']
},

path: {
type: 'object',
properties: {
rotation: {
type: 'integer',
multipleOf: 60
}
}
},

// game-specific definitions

tile: {
type: 'object',
properties: {
position: { $ref: '#/definitions/axial' },
objects: {
type: 'array',
items: {
'oneOf': [
{ 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: {
type: 'object',
properties: {
tile: { $ref: '#/definitions/tile' }
},
required: ['tile']
}
},
player: { $ref: '#/definitions/player' },
camera: { $ref: '#/definitions/camera' }
// additional metadata?
},
required: ['world', 'player', 'camera']
}

module.exports = hexaworld
12 changes: 12 additions & 0 deletions js/write.js
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "hexaworld-schema",
"version": "0.0.0",
"description": "A schema and validation functions for hexaworld levels ",
"main": "js/hexaworld.js",
"scripts": {
"test": "node test/all.js"
},
"repository": {
"type": "git",
"url": "https://github.com/hexaworld/hexaworld-schema"
},
"author": "Andrew Osheroff <[email protected]> (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",
"lodash": "^3.10.1"
}
}
Loading