mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-04-10 14:26:44 +00:00
Basic support for variable World size
This commit is contained in:
parent
a06e49c0dd
commit
9903631a93
@ -125,7 +125,10 @@ var TerrainListener = (function () {
|
||||
mar.world.removeBigMessage();
|
||||
}
|
||||
if (message.ok) {
|
||||
//todo handle vault worlds here
|
||||
var worldSize = message.size;
|
||||
if (worldSize == undefined) {
|
||||
worldSize = config.defaultWorldSize;
|
||||
}
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] World is available");
|
||||
}
|
||||
@ -133,13 +136,13 @@ var TerrainListener = (function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Updating World terrain");
|
||||
}
|
||||
mar.world.updateTerrain(message.terrain);
|
||||
mar.world.updateTerrain(message.terrain, worldSize);
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating new World");
|
||||
}
|
||||
mar.world = new World(message.terrain);
|
||||
mar.world = new World(message.terrain, worldSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -150,13 +153,13 @@ var TerrainListener = (function () {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Updating World terrain");
|
||||
}
|
||||
mar.world.updateTerrain([]);
|
||||
mar.world.updateTerrain([], config.defaultWorldSize);
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating new World");
|
||||
}
|
||||
mar.world = new World([]);
|
||||
mar.world = new World([], config.defaultWorldSize);
|
||||
}
|
||||
if (mar.world) {
|
||||
mar.world.setBigMessage("[Uncharted World]");
|
||||
|
@ -143,7 +143,10 @@ class TerrainListener implements MessageListener {
|
||||
|
||||
if (message.ok) {
|
||||
|
||||
//todo handle vault worlds here
|
||||
let worldSize = message.size;
|
||||
if (worldSize == undefined) {
|
||||
worldSize = config.defaultWorldSize;
|
||||
}
|
||||
|
||||
|
||||
if (DEBUG) {
|
||||
@ -156,7 +159,7 @@ class TerrainListener implements MessageListener {
|
||||
console.log("[MAR] Updating World terrain");
|
||||
}
|
||||
|
||||
mar.world.updateTerrain(message.terrain);
|
||||
mar.world.updateTerrain(message.terrain, worldSize);
|
||||
|
||||
} else {
|
||||
|
||||
@ -164,7 +167,7 @@ class TerrainListener implements MessageListener {
|
||||
console.log("[MAR] Creating new World");
|
||||
}
|
||||
|
||||
mar.world = new World(message.terrain);
|
||||
mar.world = new World(message.terrain, worldSize);
|
||||
|
||||
}
|
||||
} else {
|
||||
@ -180,7 +183,7 @@ class TerrainListener implements MessageListener {
|
||||
console.log("[MAR] Updating World terrain");
|
||||
}
|
||||
|
||||
mar.world.updateTerrain([]);
|
||||
mar.world.updateTerrain([], config.defaultWorldSize);
|
||||
|
||||
} else {
|
||||
|
||||
@ -188,7 +191,7 @@ class TerrainListener implements MessageListener {
|
||||
console.log("[MAR] Creating new World");
|
||||
}
|
||||
|
||||
mar.world = new World([]);
|
||||
mar.world = new World([], config.defaultWorldSize);
|
||||
|
||||
}
|
||||
if (mar.world) {
|
||||
|
@ -119,32 +119,45 @@ var CopperTile = (function (_super) {
|
||||
return CopperTile;
|
||||
}(Tile));
|
||||
var World = (function () {
|
||||
function World(terrain) {
|
||||
function World(terrain, size) {
|
||||
this.tiles = [];
|
||||
this.objects = [];
|
||||
//Create tilemap
|
||||
this.setTerrain(terrain);
|
||||
//Setup World Arrows
|
||||
mar.isoGroup.add(new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH));
|
||||
mar.isoGroup.add(new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST));
|
||||
mar.isoGroup.add(new WorldArrow(528, 1170, "ui/arrow_south", Direction.SOUTH));
|
||||
mar.isoGroup.add(new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST));
|
||||
this.northArrow = new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH);
|
||||
mar.isoGroup.add(this.northArrow);
|
||||
this.eastArrow = new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST);
|
||||
mar.isoGroup.add(this.eastArrow);
|
||||
this.southArrow = new WorldArrow(0, 0, "ui/arrow_south", Direction.SOUTH);
|
||||
mar.isoGroup.add(this.southArrow);
|
||||
this.westArrow = new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST);
|
||||
mar.isoGroup.add(this.westArrow);
|
||||
//Create tilemap
|
||||
this.setTerrain(terrain, size);
|
||||
}
|
||||
/**
|
||||
* Load terrain data from array and create Tiles
|
||||
* @param terrain
|
||||
* @param size Size of a side of the World
|
||||
*/
|
||||
World.prototype.setTerrain = function (terrain) {
|
||||
World.prototype.setTerrain = function (terrain, size) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating tilemap");
|
||||
console.log("[MAR] Creating tilemap of size " + size);
|
||||
}
|
||||
for (var x = 0; x < config.worldSize; x++) {
|
||||
for (var y = 0; y < config.worldSize; y++) {
|
||||
var tile = Tile.createTile(terrain[y * config.worldSize + x], x, y);
|
||||
for (var x = 0; x < size; x++) {
|
||||
for (var y = 0; y < size; y++) {
|
||||
var tile = Tile.createTile(terrain[y * size + x], x, y);
|
||||
this.tiles.push(tile);
|
||||
mar.isoGroup.add(tile);
|
||||
}
|
||||
}
|
||||
//Update World arrows location
|
||||
this.eastArrow.isoY = 32 * (size + 2);
|
||||
this.eastArrow.isoX = 72.5 * (size) - 20;
|
||||
this.southArrow.isoX = 32 * (size + 1);
|
||||
this.southArrow.isoY = 72.5 * (size) + 20;
|
||||
//Update Phaser World size
|
||||
mar.game.world.width = (size + 2) * 128;
|
||||
mar.game.world.height = (size + 2) * 64;
|
||||
};
|
||||
World.prototype.setBigMessage = function (msg) {
|
||||
this.bigMessage = mar.game.add.text(908, 450, msg, {
|
||||
@ -226,8 +239,9 @@ var World = (function () {
|
||||
/**
|
||||
* Delete current ojects and tiles and replace them with provided terrain
|
||||
* @param terrain
|
||||
* @param size
|
||||
*/
|
||||
World.prototype.updateTerrain = function (terrain) {
|
||||
World.prototype.updateTerrain = function (terrain, size) {
|
||||
for (var i = 0; i < this.objects.length; i++) {
|
||||
this.objects[i].destroy();
|
||||
}
|
||||
@ -236,7 +250,7 @@ var World = (function () {
|
||||
}
|
||||
this.objects = [];
|
||||
this.tiles = [];
|
||||
this.setTerrain(terrain);
|
||||
this.setTerrain(terrain, size);
|
||||
mar.game.iso.topologicalSort(mar.isoGroup);
|
||||
};
|
||||
return World;
|
||||
|
@ -152,42 +152,64 @@ class World {
|
||||
private tiles: Tile[] = [];
|
||||
private objects: GameObject[] = [];
|
||||
|
||||
private northArrow: WorldArrow;
|
||||
private eastArrow: WorldArrow;
|
||||
private southArrow: WorldArrow;
|
||||
private westArrow: WorldArrow;
|
||||
|
||||
|
||||
/**
|
||||
* Message displayed in the middle of the World
|
||||
*/
|
||||
private bigMessage: Phaser.Text;
|
||||
|
||||
constructor(terrain) {
|
||||
|
||||
//Create tilemap
|
||||
this.setTerrain(terrain);
|
||||
constructor(terrain, size) {
|
||||
|
||||
//Setup World Arrows
|
||||
mar.isoGroup.add(new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH));
|
||||
mar.isoGroup.add(new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST));
|
||||
mar.isoGroup.add(new WorldArrow(528, 1170, "ui/arrow_south", Direction.SOUTH));
|
||||
mar.isoGroup.add(new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST));
|
||||
this.northArrow = new WorldArrow(528, -10, "ui/arrow_north", Direction.NORTH);
|
||||
mar.isoGroup.add(this.northArrow);
|
||||
this.eastArrow = new WorldArrow(1115, 587, "ui/arrow_east", Direction.EAST);
|
||||
mar.isoGroup.add(this.eastArrow);
|
||||
this.southArrow = new WorldArrow(0, 0, "ui/arrow_south", Direction.SOUTH);
|
||||
mar.isoGroup.add(this.southArrow);
|
||||
this.westArrow = new WorldArrow(-60, 587, "ui/arrow_west", Direction.WEST);
|
||||
mar.isoGroup.add(this.westArrow);
|
||||
|
||||
//Create tilemap
|
||||
this.setTerrain(terrain, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load terrain data from array and create Tiles
|
||||
* @param terrain
|
||||
* @param size Size of a side of the World
|
||||
*/
|
||||
private setTerrain(terrain: number[]) {
|
||||
private setTerrain(terrain: number[], size: number) {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Creating tilemap");
|
||||
console.log("[MAR] Creating tilemap of size " + size);
|
||||
}
|
||||
|
||||
for (let x = 0; x < config.worldSize; x++) {
|
||||
for (let y = 0; y < config.worldSize; y++) {
|
||||
for (let x = 0; x < size; x++) {
|
||||
for (let y = 0; y < size; y++) {
|
||||
|
||||
let tile: Tile = Tile.createTile(terrain[y * config.worldSize + x], x, y);
|
||||
let tile: Tile = Tile.createTile(terrain[y * size + x], x, y);
|
||||
|
||||
this.tiles.push(tile);
|
||||
mar.isoGroup.add(tile);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Update World arrows location
|
||||
this.eastArrow.isoY = 32 * (size + 2);
|
||||
this.eastArrow.isoX = 72.5 * (size) - 20;
|
||||
|
||||
this.southArrow.isoX = 32 * (size + 1);
|
||||
this.southArrow.isoY = 72.5 * (size) + 20;
|
||||
|
||||
//Update Phaser World size
|
||||
mar.game.world.width = (size + 2) * 128;
|
||||
mar.game.world.height = (size + 2) * 64;
|
||||
}
|
||||
|
||||
public setBigMessage(msg: string) {
|
||||
@ -287,8 +309,9 @@ class World {
|
||||
/**
|
||||
* Delete current ojects and tiles and replace them with provided terrain
|
||||
* @param terrain
|
||||
* @param size
|
||||
*/
|
||||
public updateTerrain(terrain: number[]) {
|
||||
public updateTerrain(terrain: number[], size: number) {
|
||||
|
||||
for (let i = 0; i < this.objects.length; i++) {
|
||||
this.objects[i].destroy();
|
||||
@ -300,7 +323,7 @@ class World {
|
||||
this.objects = [];
|
||||
this.tiles = [];
|
||||
|
||||
this.setTerrain(terrain);
|
||||
this.setTerrain(terrain, size);
|
||||
mar.game.iso.topologicalSort(mar.isoGroup);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,8 @@ var config = {
|
||||
arrowTint: 0xFFFFFF,
|
||||
arrowHoverTint: 0x00FF00,
|
||||
selfUsernameColor: 0xFB4D0A,
|
||||
otherCubotAlpha: 0.6
|
||||
otherCubotAlpha: 0.6,
|
||||
defaultWorldSize: 16
|
||||
};
|
||||
var TileType;
|
||||
(function (TileType) {
|
||||
|
4
mar/phaser/mar.min.js
vendored
4
mar/phaser/mar.min.js
vendored
@ -1,4 +1,4 @@
|
||||
var RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio,DEBUG=!0,config={tileTint:16777215,wallTint:14540253,oreTint:15987699,worldSize:16,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,textIron:"#434341",itemCopper:13139256,textCopper:"#C87D38",hologramFill:"#0aced6",hologramStroke:"#12FFB0",
|
||||
copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(a){return{fontSize:32,fill:a?a:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6},TileType;
|
||||
(function(a){a[a.PLAIN=0]="PLAIN";a[a.WALL=1]="WALL";a[a.IRON=2]="IRON";a[a.COPPER=3]="COPPER"})(TileType||(TileType={}));
|
||||
copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(a){return{fontSize:32,fill:a?a:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6,defaultWorldSize:16},
|
||||
TileType;(function(a){a[a.PLAIN=0]="PLAIN";a[a.WALL=1]="WALL";a[a.IRON=2]="IRON";a[a.COPPER=3]="COPPER"})(TileType||(TileType={}));
|
||||
var Util=function(){function a(){}a.getIsoY=function(b){return a.getIsoX(b)};a.getIsoX=function(a){return 71.5*a};a.getDeltaX=function(a){switch(a){case Direction.NORTH:case Direction.SOUTH:return 0;case Direction.EAST:return 1;case Direction.WEST:return-1}};a.getDeltaY=function(a){switch(a){case Direction.EAST:case Direction.WEST:return 0;case Direction.NORTH:return 1;case Direction.SOUTH:return-1}};return a}(),mar=new MarGame;
|
||||
|
@ -53,7 +53,8 @@ let config = {
|
||||
arrowTint: 0xFFFFFF,
|
||||
arrowHoverTint: 0x00FF00,
|
||||
selfUsernameColor: 0xFB4D0A,
|
||||
otherCubotAlpha: 0.6
|
||||
otherCubotAlpha: 0.6,
|
||||
defaultWorldSize: 16
|
||||
|
||||
};
|
||||
|
||||
|
115
mar/phaser/phaser-plugin-isometric.min.js
vendored
115
mar/phaser/phaser-plugin-isometric.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user