diff --git a/Jakefile b/Jakefile new file mode 100644 index 0000000..d5c4f39 --- /dev/null +++ b/Jakefile @@ -0,0 +1,31 @@ +var interleave = require('interleave'); + + +desc('build the client files'); +task('dev', function() { + interleave(['mobileservices.dev.js'], { + multi: 'pass', + path: 'app/js', + aliases: aliases + }); +}); + +task('dev.deps', function() { + interleave(['mobileservices.deps.js'], { + multi: 'pass', + path: 'app/js', + aliases: aliases + }); +}); + +task('build', function() { + interleave(['mobileservices.js'], { + after: ['uglify'], + multi: 'pass', + path: 'app/js', + aliases: aliases + }); +}); + + +task('default', ['dev']); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..a337f52 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "gamebase-types", + "description": "Gamebase Common Types for both browser and server usage", + "version": "0.1.0", + "dependencies": { + "underscore": "*" + }, + "devDependencies": { + "interleave": "*", + "uglify-js": "*" + } +} \ No newline at end of file diff --git a/pkg/amd/GamebaseTypes.js b/pkg/amd/GamebaseTypes.js new file mode 100644 index 0000000..8cbb5b4 --- /dev/null +++ b/pkg/amd/GamebaseTypes.js @@ -0,0 +1,90 @@ +define('GamebaseTypes', ['underscore'], function(underscore) { + + /** + The 2dMap contains all the information related to a 2d map + **/ + function Map2D(opts) { + + opts = opts || {}; + this.size = opts.size || {width: 300, height: 300}; + + this.initialise(); + } + + Map2D.prototype.initialise = function() { + + this.tiles = new Array(this.size.width); + for (var i = 0; i < this.size.width; i++) { + this.tiles[i] = new Array(this.size.height); + } + } + + /** + Gets the tile at the given coordinates + **/ + Map2D.prototype.getTile = function(x, y) { + return this.tiles[x][y] = tile; + } + + /** + Sets the tile at the given coordinates + **/ + Map2D.prototype.setTile = function(x, y, tile) { + this.tiles[x][y] = tile; + } + + Map2D.prototype.toJSON = function() { + var results = {world: {size: this.size}, tiles: []}; + + for (var i = 0; i < this.tiles.length; i++) { + var column = this.tiles[i]; + for (var j = 0; j < column.length; j++) { + results.tiles.push(column[j]); + } + } + return results; + } + + function Tile(opts) { + + opts = opts || {}; + this.update(opts); + } + + Tile.prototype.update = function(opts) { + if (!opts) return; + if (opts.elevation) this.el = opts.elevation; + if (opts.terrain) this.tn = opts.terrain; + } + + /** + Sets the height of the tile + **/ + Tile.prototype.setElevation = function(elevation) { + this.el = elevation; + } + + /** + Sets the terrain of the tile + **/ + Tile.prototype.setTerrain = function(terrain) { + this.tn = terrain; + } + + function randomInRange(min, max) { + return Math.round(min+ (Math.random() * (max - min))); + } + + + + + function GamebaseTypes() { + + } + + GamebaseTypes.Map2D = Map2D; + GamebaseTypes.Tile = Tile; + GamebaseTypes.randomInRange = randomInRange; + + return GamebaseTypes; +}); \ No newline at end of file diff --git a/pkg/cjs/GamebaseTypes.js b/pkg/cjs/GamebaseTypes.js new file mode 100644 index 0000000..2043346 --- /dev/null +++ b/pkg/cjs/GamebaseTypes.js @@ -0,0 +1,90 @@ +var underscore = require('underscore'); + + +/** + The 2dMap contains all the information related to a 2d map + **/ +function Map2D(opts) { + + opts = opts || {}; + this.size = opts.size || {width: 300, height: 300}; + + this.initialise(); +} + +Map2D.prototype.initialise = function() { + + this.tiles = new Array(this.size.width); + for (var i = 0; i < this.size.width; i++) { + this.tiles[i] = new Array(this.size.height); + } +} + +/** + Gets the tile at the given coordinates + **/ +Map2D.prototype.getTile = function(x, y) { + return this.tiles[x][y] = tile; +} + +/** + Sets the tile at the given coordinates + **/ +Map2D.prototype.setTile = function(x, y, tile) { + this.tiles[x][y] = tile; +} + +Map2D.prototype.toJSON = function() { + var results = {world: {size: this.size}, tiles: []}; + + for (var i = 0; i < this.tiles.length; i++) { + var column = this.tiles[i]; + for (var j = 0; j < column.length; j++) { + results.tiles.push(column[j]); + } + } + return results; +} + +function Tile(opts) { + + opts = opts || {}; + this.update(opts); +} + +Tile.prototype.update = function(opts) { + if (!opts) return; + if (opts.elevation) this.el = opts.elevation; + if (opts.terrain) this.tn = opts.terrain; +} + +/** + Sets the height of the tile + **/ +Tile.prototype.setElevation = function(elevation) { + this.el = elevation; +} + +/** + Sets the terrain of the tile + **/ +Tile.prototype.setTerrain = function(terrain) { + this.tn = terrain; +} + +function randomInRange(min, max) { + return Math.round(min+ (Math.random() * (max - min))); +} + + + + +function GamebaseTypes() { + +} + +GamebaseTypes.Map2D = Map2D; +GamebaseTypes.Tile = Tile; +GamebaseTypes.randomInRange = randomInRange; + +module.exports = GamebaseTypes; \ No newline at end of file diff --git a/pkg/oldschool/GamebaseTypes.js b/pkg/oldschool/GamebaseTypes.js new file mode 100644 index 0000000..f1e99e0 --- /dev/null +++ b/pkg/oldschool/GamebaseTypes.js @@ -0,0 +1,93 @@ +// dep: underscore + +(function (glob) { + + /** + The 2dMap contains all the information related to a 2d map + **/ + function Map2D(opts) { + + opts = opts || {}; + this.size = opts.size || {width: 300, height: 300}; + + this.initialise(); + } + + Map2D.prototype.initialise = function() { + + this.tiles = new Array(this.size.width); + for (var i = 0; i < this.size.width; i++) { + this.tiles[i] = new Array(this.size.height); + } + } + + /** + Gets the tile at the given coordinates + **/ + Map2D.prototype.getTile = function(x, y) { + return this.tiles[x][y] = tile; + } + + /** + Sets the tile at the given coordinates + **/ + Map2D.prototype.setTile = function(x, y, tile) { + this.tiles[x][y] = tile; + } + + Map2D.prototype.toJSON = function() { + var results = {world: {size: this.size}, tiles: []}; + + for (var i = 0; i < this.tiles.length; i++) { + var column = this.tiles[i]; + for (var j = 0; j < column.length; j++) { + results.tiles.push(column[j]); + } + } + return results; + } + + function Tile(opts) { + + opts = opts || {}; + this.update(opts); + } + + Tile.prototype.update = function(opts) { + if (!opts) return; + if (opts.elevation) this.el = opts.elevation; + if (opts.terrain) this.tn = opts.terrain; + } + + /** + Sets the height of the tile + **/ + Tile.prototype.setElevation = function(elevation) { + this.el = elevation; + } + + /** + Sets the terrain of the tile + **/ + Tile.prototype.setTerrain = function(terrain) { + this.tn = terrain; + } + + function randomInRange(min, max) { + return Math.round(min+ (Math.random() * (max - min))); + } + + + + + function GamebaseTypes() { + + } + + GamebaseTypes.Map2D = Map2D; + GamebaseTypes.Tile = Tile; + GamebaseTypes.randomInRange = randomInRange; + + glob.GamebaseTypes = GamebaseTypes; + +})(this); \ No newline at end of file diff --git a/pkg/raw/GamebaseTypes.js b/pkg/raw/GamebaseTypes.js new file mode 100644 index 0000000..2850fff --- /dev/null +++ b/pkg/raw/GamebaseTypes.js @@ -0,0 +1,87 @@ +// dep: underscore + +/** + The 2dMap contains all the information related to a 2d map + **/ +function Map2D(opts) { + + opts = opts || {}; + this.size = opts.size || {width: 300, height: 300}; + + this.initialise(); +} + +Map2D.prototype.initialise = function() { + + this.tiles = new Array(this.size.width); + for (var i = 0; i < this.size.width; i++) { + this.tiles[i] = new Array(this.size.height); + } +} + +/** + Gets the tile at the given coordinates + **/ +Map2D.prototype.getTile = function(x, y) { + return this.tiles[x][y] = tile; +} + +/** + Sets the tile at the given coordinates + **/ +Map2D.prototype.setTile = function(x, y, tile) { + this.tiles[x][y] = tile; +} + +Map2D.prototype.toJSON = function() { + var results = {world: {size: this.size}, tiles: []}; + + for (var i = 0; i < this.tiles.length; i++) { + var column = this.tiles[i]; + for (var j = 0; j < column.length; j++) { + results.tiles.push(column[j]); + } + } + return results; +} + +function Tile(opts) { + + opts = opts || {}; + this.update(opts); +} + +Tile.prototype.update = function(opts) { + if (!opts) return; + if (opts.elevation) this.el = opts.elevation; + if (opts.terrain) this.tn = opts.terrain; +} + +/** + Sets the height of the tile + **/ +Tile.prototype.setElevation = function(elevation) { + this.el = elevation; +} + +/** + Sets the terrain of the tile + **/ +Tile.prototype.setTerrain = function(terrain) { + this.tn = terrain; +} + +function randomInRange(min, max) { + return Math.round(min+ (Math.random() * (max - min))); +} + + + + +function GamebaseTypes() { + +} + +GamebaseTypes.Map2D = Map2D; +GamebaseTypes.Tile = Tile; +GamebaseTypes.randomInRange = randomInRange; \ No newline at end of file diff --git a/src/GamebaseTypes.js b/src/GamebaseTypes.js new file mode 100644 index 0000000..709cb90 --- /dev/null +++ b/src/GamebaseTypes.js @@ -0,0 +1,14 @@ +// dep: underscore + +//= map/map.js +//= map/tile.js +//= utils/random.js +//= utils/sort.js + +function GamebaseTypes() { + +} + +GamebaseTypes.Map2D = Map2D; +GamebaseTypes.Tile = Tile; +GamebaseTypes.randomInRange = randomInRange; \ No newline at end of file diff --git a/src/map/map.js b/src/map/map.js index 4edb991..fe0f51e 100644 --- a/src/map/map.js +++ b/src/map/map.js @@ -1,6 +1,3 @@ -var _ = require('underscore'), - Tile = require('./tile'); - /** The 2dMap contains all the information related to a 2d map **/ @@ -44,6 +41,4 @@ Map2D.prototype.toJSON = function() { } } return results; -} - -module.exports = Map2D; \ No newline at end of file +} \ No newline at end of file diff --git a/src/map/tile.js b/src/map/tile.js index f6c28cc..408e16f 100644 --- a/src/map/tile.js +++ b/src/map/tile.js @@ -22,6 +22,4 @@ Tile.prototype.setElevation = function(elevation) { **/ Tile.prototype.setTerrain = function(terrain) { this.tn = terrain; -} - -module.exports = Tile; \ No newline at end of file +} \ No newline at end of file diff --git a/src/utils/random.js b/src/utils/random.js index 60f1060..5fe5a59 100644 --- a/src/utils/random.js +++ b/src/utils/random.js @@ -1,5 +1,3 @@ -module.exports = { - randomInRange: function(min, max) { - return Math.round(min+ (Math.random() * (max - min))); - } +function randomInRange(min, max) { + return Math.round(min+ (Math.random() * (max - min))); } \ No newline at end of file diff --git a/tests/test_node.js b/tests/test_node.js new file mode 100644 index 0000000..dec4bca --- /dev/null +++ b/tests/test_node.js @@ -0,0 +1,11 @@ +var gbtypes = require('../pkg/cjs/GamebaseTypes'); + +describe('Can use gamebase types', function() { + + it('create a map', function(done) { + + var map = new gbtypes.Map2D(); + done(); + }); + +}); \ No newline at end of file