added some types in WorldGeneration.js and new map alias - Vault class
This commit is contained in:
parent
fe2299f864
commit
aab9708ba8
@ -145,6 +145,7 @@ function setupInGameSelector() {
|
|||||||
let terrainObject = getObjectFromTerrainLayer(t.x, t.y);
|
let terrainObject = getObjectFromTerrainLayer(t.x, t.y);
|
||||||
let vegetationObject = getObjectFromVegetationLayer(t.x, t.y);
|
let vegetationObject = getObjectFromVegetationLayer(t.x, t.y);
|
||||||
let buildingObject = getObjectFromBuildingsLayer(t.x, t.y);
|
let buildingObject = getObjectFromBuildingsLayer(t.x, t.y);
|
||||||
|
console.log(vegetationObject);
|
||||||
if(UIMainPipe.get().building && terrainObject.type !== "ter_water" && !vegetationObject && !buildingObject)
|
if(UIMainPipe.get().building && terrainObject.type !== "ter_water" && !vegetationObject && !buildingObject)
|
||||||
{
|
{
|
||||||
if(UIObtainedResourcesPipe.get().gold >= 50)
|
if(UIObtainedResourcesPipe.get().gold >= 50)
|
||||||
|
72
src/Game/Utils/DataTypes.utils.js
Normal file
72
src/Game/Utils/DataTypes.utils.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* map representation
|
||||||
|
*/
|
||||||
|
export class Vault {
|
||||||
|
constructor(name = "") {
|
||||||
|
this.name = name;
|
||||||
|
this.storage = {};
|
||||||
|
/**
|
||||||
|
* set key-value pair in storage
|
||||||
|
* @param {String} key
|
||||||
|
* @param {*} value
|
||||||
|
*/
|
||||||
|
this.set = (key, value) => {
|
||||||
|
this.storage[key] = value;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* return element from storage
|
||||||
|
* @param {String} key
|
||||||
|
* @returns element (ref) or undefined
|
||||||
|
*/
|
||||||
|
this.get = (key) => {
|
||||||
|
return this.storage[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {String} key
|
||||||
|
* @returns true/false
|
||||||
|
*/
|
||||||
|
this.existsKey = (key) => {
|
||||||
|
return Object.keys(this.storage).includes(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove key from storage
|
||||||
|
* @param {String} key
|
||||||
|
* @returns true/false
|
||||||
|
*/
|
||||||
|
this.del = (key) => {
|
||||||
|
return delete this.storage[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clears storage
|
||||||
|
*/
|
||||||
|
this.clear = () => {this.storage = {}}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} value
|
||||||
|
* @returns found value (ref) or false
|
||||||
|
*/
|
||||||
|
this.find = (value) => {
|
||||||
|
let t = Object.keys(this.storage);
|
||||||
|
for (const i of t) {
|
||||||
|
if (this.storage[i] === value) return this.storage[i];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run 'for' loop through all storage and call 'fn(storage_element)'
|
||||||
|
* @param {Function} fn
|
||||||
|
*/
|
||||||
|
this.forAll = (fn) => {
|
||||||
|
let keys = Object.keys(this.storage);
|
||||||
|
for (const i of keys) {
|
||||||
|
fn(this.storage[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import * as PIXI from "../../pixi/pixi.mjs";
|
import * as PIXI from "../../pixi/pixi.mjs";
|
||||||
|
import { Vault } from "../Utils/DataTypes.utils";
|
||||||
|
|
||||||
export function createWorldChunk() {
|
export function createWorldChunkContainer() {
|
||||||
let chunk = new PIXI.Container();
|
let chunk = new PIXI.Container();
|
||||||
let terrainLayer = new PIXI.Container();
|
let terrainLayer = new PIXI.Container();
|
||||||
let vegetationLayer = new PIXI.Container();
|
let vegetationLayer = new PIXI.Container();
|
||||||
@ -11,52 +12,18 @@ export function createWorldChunk() {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {String} type
|
|
||||||
*/
|
|
||||||
export function terrainObjectProps(type) {
|
|
||||||
this.type = type;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {String} type
|
|
||||||
*/
|
|
||||||
export function buildingObjectProps(type) {
|
|
||||||
this.type = type;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {String} type
|
|
||||||
* @param {Number} num
|
|
||||||
*/
|
|
||||||
export function vegetationObjectProps(type, num) {
|
|
||||||
this.type = type;
|
|
||||||
this.num = num;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {terrainObjectProps} obj
|
|
||||||
*/
|
|
||||||
export function terrainObjectsVaultType(obj)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {PIXI.Container} chunk
|
* @param {PIXI.Container} chunk
|
||||||
* @param {PIXI.Container} terrainLayer
|
* @param {PIXI.Container} terrainLayer
|
||||||
* @param {PIXI.Container} vegetationLayer
|
* @param {PIXI.Container} vegetationLayer
|
||||||
* @param {PIXI.Container} buildingsLayer
|
* @param {PIXI.Container} buildingsLayer
|
||||||
* @param {terrainObjectsVaultType} terrainObjectsVault
|
* @param {Vault} terrainObjectsVault
|
||||||
* @param {vegetationObjectProps} vegetationObjectsVault
|
* @param {Vault} vegetationObjectsVault
|
||||||
* @param {buildingObjectProps} buildingsObjectsVault
|
* @param {Vault} buildingsObjectsVault
|
||||||
*/
|
*/
|
||||||
export function WorldChunk(chunk, terrainLayer, vegetationLayer, buildingsLayer, terrainObjectsVault, vegetationObjectsVault, buildingsObjectsVault) {
|
export class WorldChunk {
|
||||||
|
constructor(chunk, terrainLayer, vegetationLayer, buildingsLayer, terrainObjectsVault, vegetationObjectsVault, buildingsObjectsVault) {
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
this.terrainLayer = terrainLayer;
|
this.terrainLayer = terrainLayer;
|
||||||
this.vegetationLayer = vegetationLayer;
|
this.vegetationLayer = vegetationLayer;
|
||||||
@ -65,3 +32,4 @@ export function WorldChunk(chunk, terrainLayer, vegetationLayer, buildingsLayer,
|
|||||||
this.vegetationObjectsVault = vegetationObjectsVault;
|
this.vegetationObjectsVault = vegetationObjectsVault;
|
||||||
this.buildingsObjectsVault = buildingsObjectsVault;
|
this.buildingsObjectsVault = buildingsObjectsVault;
|
||||||
}
|
}
|
||||||
|
}
|
45
src/Game/WorldGeneration/ObjectsPropsSchemes.js
Normal file
45
src/Game/WorldGeneration/ObjectsPropsSchemes.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { WorldChunk } from "../WorldChunk/WorldChunk";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {PIXI.Container} objectRef
|
||||||
|
* @param {String} type
|
||||||
|
*/
|
||||||
|
export function TerrainObjectProps(objectRef, {type}) {
|
||||||
|
this.obj = objectRef;
|
||||||
|
this.type = type;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {PIXI.Container} objectRef
|
||||||
|
* @param {String} type
|
||||||
|
* @param {Number} num
|
||||||
|
*/
|
||||||
|
export function VegetationObjectProps(objectRef, {type, num}) {
|
||||||
|
this.obj = objectRef;
|
||||||
|
this.type = type;
|
||||||
|
this.num = num;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {PIXI.Container} objectRef
|
||||||
|
* @param {String} type
|
||||||
|
* @param {Number} goldSec
|
||||||
|
*/
|
||||||
|
export function BuildingsObjectProps(objectRef, {type, goldSec}) {
|
||||||
|
this.obj = objectRef;
|
||||||
|
this.type = type;
|
||||||
|
this.goldSec = goldSec;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {WorldChunk} chunkRef
|
||||||
|
* @param {Boolean} central
|
||||||
|
*/
|
||||||
|
export function VisibleChunkProps(chunkRef, central) {
|
||||||
|
this.chunkRef = chunkRef;
|
||||||
|
this.central = central;
|
||||||
|
}
|
@ -2,9 +2,11 @@ import { Noise } from "noisejs";
|
|||||||
import { BC_CAMERA, BC_CHUNKS_SETTINGS, BC_SPRITES_SETTINGS, BC_TERRAIN_SETTINGS, PRNG } from "../GlobalVariables/GlobalVariables";
|
import { BC_CAMERA, BC_CHUNKS_SETTINGS, BC_SPRITES_SETTINGS, BC_TERRAIN_SETTINGS, PRNG } from "../GlobalVariables/GlobalVariables";
|
||||||
import { integerDivision } from "../Utils/Math.utils";
|
import { integerDivision } from "../Utils/Math.utils";
|
||||||
import { addToViewport } from "../Utils/World.utils";
|
import { addToViewport } from "../Utils/World.utils";
|
||||||
import { WorldChunk, createWorldChunk } from "../WorldChunk/WorldChunk";
|
import { WorldChunk, createWorldChunkContainer } from "../WorldChunk/WorldChunk";
|
||||||
import { getSpriteFromAtlas } from "../Utils/Sprites.utils";
|
import { getSpriteFromAtlas } from "../Utils/Sprites.utils";
|
||||||
import * as PIXI from "../../pixi/pixi.mjs";
|
import * as PIXI from "../../pixi/pixi.mjs";
|
||||||
|
import { BuildingsObjectProps, TerrainObjectProps, VegetationObjectProps, VisibleChunkProps } from "./ObjectsPropsSchemes";
|
||||||
|
import { Vault } from "../Utils/DataTypes.utils";
|
||||||
// import {WorldChunk} from "../Types/WorldGenerationTypes";
|
// import {WorldChunk} from "../Types/WorldGenerationTypes";
|
||||||
|
|
||||||
const terrainSpriteList = {
|
const terrainSpriteList = {
|
||||||
@ -88,17 +90,8 @@ const stoneVegResourcesList = {
|
|||||||
2: { type: "stone", num: 5 / 5 },
|
2: { type: "stone", num: 5 / 5 },
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
const WORLD_CHUNKS = new Vault();
|
||||||
* {
|
let VISIBLE_CHUNKS = new Vault();
|
||||||
* chunk: PIXI.Container - chunk,
|
|
||||||
terrainLayer: PIXI.Container - 0 index child,
|
|
||||||
vegetationLayer: PIXI.Container - 1st child,
|
|
||||||
terrainObjectsVault: {},
|
|
||||||
vegetationObjectsVault: {}
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
const WORLD_CHUNKS = {};
|
|
||||||
let VISIBLE_CHUNKS = {};
|
|
||||||
|
|
||||||
export function worldCoordinatesToChunkIndex(x, y) {
|
export function worldCoordinatesToChunkIndex(x, y) {
|
||||||
let w = BC_CHUNKS_SETTINGS.width * BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
let w = BC_CHUNKS_SETTINGS.width * BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
||||||
@ -142,7 +135,7 @@ export function worldCoordinatesToChunkLocalCoordinates(x, y) {
|
|||||||
*/
|
*/
|
||||||
export function getChunk(x, y) {
|
export function getChunk(x, y) {
|
||||||
let t = worldCoordinatesToChunkIndex(x, y);
|
let t = worldCoordinatesToChunkIndex(x, y);
|
||||||
if (WORLD_CHUNKS[t.x + "_" + t.y]) return WORLD_CHUNKS[t.x + "_" + t.y];
|
if (WORLD_CHUNKS.existsKey(t.x + "_" + t.y)) return WORLD_CHUNKS.get(t.x + "_" + t.y);
|
||||||
else return undefined;
|
else return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,29 +147,37 @@ export function updateChunksVisibility() {
|
|||||||
let cx = Math.floor(BC_CAMERA.position.x / w);
|
let cx = Math.floor(BC_CAMERA.position.x / w);
|
||||||
let cy = Math.floor(BC_CAMERA.position.y / h);
|
let cy = Math.floor(BC_CAMERA.position.y / h);
|
||||||
let chunkId = cx + "_" + cy;
|
let chunkId = cx + "_" + cy;
|
||||||
if ((VISIBLE_CHUNKS[chunkId] && !VISIBLE_CHUNKS[chunkId].central) || !VISIBLE_CHUNKS[chunkId]) {
|
if ((VISIBLE_CHUNKS.existsKey(chunkId) && !VISIBLE_CHUNKS.get(chunkId).central) || !VISIBLE_CHUNKS.existsKey(chunkId)) {
|
||||||
for (const key in VISIBLE_CHUNKS) {
|
VISIBLE_CHUNKS.forAll((vis_chunk) => {
|
||||||
VISIBLE_CHUNKS[key].chunkRef.chunk.visible = false;
|
vis_chunk.chunkRef.chunk.visible = false;
|
||||||
}
|
});
|
||||||
VISIBLE_CHUNKS = {};
|
VISIBLE_CHUNKS.clear();
|
||||||
for (let i = -1; i < 2; i++) {
|
for (let i = -1; i < 2; i++) {
|
||||||
for (let j = -1; j < 2; j++) {
|
for (let j = -1; j < 2; j++) {
|
||||||
let t_chunkId = cx + i + "_" + (cy + j);
|
let t_chunkId = cx + i + "_" + (cy + j);
|
||||||
if (WORLD_CHUNKS[t_chunkId]) {
|
if (WORLD_CHUNKS.existsKey(t_chunkId)) {
|
||||||
VISIBLE_CHUNKS[t_chunkId] = { chunkRef: WORLD_CHUNKS[t_chunkId], central: i === 0 && j === 0 };
|
VISIBLE_CHUNKS.set(t_chunkId, new VisibleChunkProps(WORLD_CHUNKS.get(t_chunkId), i === 0 && j === 0));
|
||||||
VISIBLE_CHUNKS[t_chunkId].chunkRef.chunk.visible = true;
|
VISIBLE_CHUNKS.get(t_chunkId).chunkRef.chunk.visible = true;
|
||||||
} else if (enableAutoGeneration) {
|
} else if (enableAutoGeneration) {
|
||||||
console.log(t_chunkId);
|
// console.log(t_chunkId);
|
||||||
let newChunk = createWorldChunk();
|
let newChunk = createWorldChunkContainer();
|
||||||
// chunkRef.isRenderGroup = true;
|
// chunkRef.isRenderGroup = true;
|
||||||
newChunk.position.set(w * (cx + i), h * (cy + j));
|
newChunk.position.set(w * (cx + i), h * (cy + j));
|
||||||
// console.log(w * chunkXCeiled, h * chunkYCeiled);
|
// console.log(w * chunkXCeiled, h * chunkYCeiled);
|
||||||
let chunk0 = new WorldChunk(newChunk, newChunk.getChildAt(0), newChunk.getChildAt(1), newChunk.getChildAt(2), {}, {}, {});
|
let chunk0 = new WorldChunk(
|
||||||
|
newChunk,
|
||||||
|
newChunk.getChildAt(0),
|
||||||
|
newChunk.getChildAt(1),
|
||||||
|
newChunk.getChildAt(2),
|
||||||
|
new Vault("terrain"),
|
||||||
|
new Vault("vegetation"),
|
||||||
|
new Vault("buildings")
|
||||||
|
);
|
||||||
fillChunk(chunk0, cx + i, cy + j);
|
fillChunk(chunk0, cx + i, cy + j);
|
||||||
WORLD_CHUNKS[t_chunkId] = chunk0;
|
WORLD_CHUNKS.set(t_chunkId, chunk0);
|
||||||
addToViewport(newChunk);
|
addToViewport(newChunk);
|
||||||
VISIBLE_CHUNKS[t_chunkId] = { chunkRef: WORLD_CHUNKS[t_chunkId], central: i === 0 && j === 0 };
|
VISIBLE_CHUNKS.set(t_chunkId, new VisibleChunkProps(WORLD_CHUNKS.get(t_chunkId), i === 0 && j === 0));
|
||||||
VISIBLE_CHUNKS[t_chunkId].chunkRef.chunk.visible = true;
|
VISIBLE_CHUNKS.get(t_chunkId).chunkRef.chunk.visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,41 +186,41 @@ export function updateChunksVisibility() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {*} chunk from WORLD_CHUNKS
|
* @param {WorldChunk} chunk from WORLD_CHUNKS
|
||||||
* @param {PIXI.Container} object
|
* @param {PIXI.Container} object
|
||||||
* @param {*} props any props
|
* @param {TerrainObjectProps} props
|
||||||
* @param {Number} ceiledX
|
* @param {Number} ceiledX
|
||||||
* @param {Number} ceiledY
|
* @param {Number} ceiledY
|
||||||
*/
|
*/
|
||||||
export function addToTerrain(chunk, object, props = {}, ceiledX, ceiledY) {
|
export function addToTerrain(chunk, object, props, ceiledX, ceiledY) {
|
||||||
chunk.terrainLayer.addChild(object);
|
chunk.terrainLayer.addChild(object);
|
||||||
chunk.terrainObjectsVault[ceiledX + "_" + ceiledY] = { obj: object, ...props };
|
chunk.terrainObjectsVault.set(ceiledX + "_" + ceiledY, new TerrainObjectProps(object, { ...props }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {*} chunk from WORLD_CHUNKS
|
* @param {WorldChunk} chunk from WORLD_CHUNKS
|
||||||
* @param {PIXI.Container} object
|
* @param {PIXI.Container} object
|
||||||
* @param {*} props any props
|
* @param {VegetationObjectProps} props
|
||||||
* @param {Number} ceiledX
|
* @param {Number} ceiledX
|
||||||
* @param {Number} ceiledY
|
* @param {Number} ceiledY
|
||||||
*/
|
*/
|
||||||
export function addToVegetation(chunk, object, props = {}, ceiledX, ceiledY) {
|
export function addToVegetation(chunk, object, props, ceiledX, ceiledY) {
|
||||||
chunk.vegetationLayer.addChild(object);
|
chunk.vegetationLayer.addChild(object);
|
||||||
chunk.vegetationObjectsVault[ceiledX + "_" + ceiledY] = { obj: object, ...props };
|
chunk.vegetationObjectsVault.set(ceiledX + "_" + ceiledY, new VegetationObjectProps(object, { ...props }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {*} chunk from WORLD_CHUNKS
|
* @param {WorldChunk} chunk from WORLD_CHUNKS
|
||||||
* @param {PIXI.Container} object
|
* @param {PIXI.Container} object
|
||||||
* @param {*} props any props
|
* @param {BuildingsObjectProps} props
|
||||||
* @param {Number} ceiledX
|
* @param {Number} ceiledX
|
||||||
* @param {Number} ceiledY
|
* @param {Number} ceiledY
|
||||||
*/
|
*/
|
||||||
export function addToBuildings(chunk, object, props = {}, ceiledX, ceiledY) {
|
export function addToBuildings(chunk, object, props = {}, ceiledX, ceiledY) {
|
||||||
chunk.buildingsLayer.addChild(object);
|
chunk.buildingsLayer.addChild(object);
|
||||||
chunk.buildingsObjectsVault[ceiledX + "_" + ceiledY] = { obj: object, ...props };
|
chunk.buildingsObjectsVault.set(ceiledX + "_" + ceiledY, new BuildingsObjectProps(object, { ...props }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,11 +232,11 @@ export function addToBuildings(chunk, object, props = {}, ceiledX, ceiledY) {
|
|||||||
export function removeFromTerrain(x, y, object) {
|
export function removeFromTerrain(x, y, object) {
|
||||||
let chunkIndex = worldCoordinatesToChunkIndex(x, y);
|
let chunkIndex = worldCoordinatesToChunkIndex(x, y);
|
||||||
let chunkId = chunkIndex.x + "_" + chunkIndex.y;
|
let chunkId = chunkIndex.x + "_" + chunkIndex.y;
|
||||||
if (WORLD_CHUNKS[chunkId]) {
|
if (WORLD_CHUNKS.existsKey(chunkId)) {
|
||||||
let objLocalPos = worldCoordinatesToChunkIndexesCoordinates(x, y);
|
let objLocalPos = worldCoordinatesToChunkIndexesCoordinates(x, y);
|
||||||
let objId = objLocalPos.x + "_" + objLocalPos.y;
|
let objId = objLocalPos.x + "_" + objLocalPos.y;
|
||||||
WORLD_CHUNKS[chunkId].terrainLayer.removeChild(object);
|
WORLD_CHUNKS.get(chunkId).terrainLayer.removeChild(object);
|
||||||
WORLD_CHUNKS[chunkId].terrainObjectsVault[objId] = undefined;
|
WORLD_CHUNKS.get(chunkId).terrainObjectsVault.del(objId);
|
||||||
object.destroy();
|
object.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,11 +249,29 @@ export function removeFromTerrain(x, y, object) {
|
|||||||
export function removeFromVegetation(x, y, object) {
|
export function removeFromVegetation(x, y, object) {
|
||||||
let chunkIndex = worldCoordinatesToChunkIndex(x, y);
|
let chunkIndex = worldCoordinatesToChunkIndex(x, y);
|
||||||
let chunkId = chunkIndex.x + "_" + chunkIndex.y;
|
let chunkId = chunkIndex.x + "_" + chunkIndex.y;
|
||||||
if (WORLD_CHUNKS[chunkId]) {
|
if (WORLD_CHUNKS.existsKey(chunkId)) {
|
||||||
let objLocalPos = worldCoordinatesToChunkIndexesCoordinates(x, y);
|
let objLocalPos = worldCoordinatesToChunkIndexesCoordinates(x, y);
|
||||||
let objId = objLocalPos.x + "_" + objLocalPos.y;
|
let objId = objLocalPos.x + "_" + objLocalPos.y;
|
||||||
WORLD_CHUNKS[chunkId].vegetationLayer.removeChild(object);
|
WORLD_CHUNKS.get(chunkId).vegetationLayer.removeChild(object);
|
||||||
WORLD_CHUNKS[chunkId].vegetationObjectsVault[objId] = undefined;
|
WORLD_CHUNKS.get(chunkId).vegetationObjectsVault.del(objId);
|
||||||
|
object.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Number} x world coordinates
|
||||||
|
* @param {Number} y world coordinates
|
||||||
|
* @param {PIXI.Container} object object to remove
|
||||||
|
*/
|
||||||
|
export function removeFromBuildings(x, y, object) {
|
||||||
|
let chunkIndex = worldCoordinatesToChunkIndex(x, y);
|
||||||
|
let chunkId = chunkIndex.x + "_" + chunkIndex.y;
|
||||||
|
if (WORLD_CHUNKS.existsKey(chunkId)) {
|
||||||
|
let objLocalPos = worldCoordinatesToChunkIndexesCoordinates(x, y);
|
||||||
|
let objId = objLocalPos.x + "_" + objLocalPos.y;
|
||||||
|
WORLD_CHUNKS.get(chunkId).buildingsLayer.removeChild(object);
|
||||||
|
WORLD_CHUNKS.get(chunkId).buildingsObjectsVault.del(objId);
|
||||||
object.destroy();
|
object.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +289,7 @@ export function getObjectFromTerrainLayer(x, y) {
|
|||||||
let hs = BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
let hs = BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
||||||
let chunkId = Math.floor(x / w) + "_" + Math.floor(y / h);
|
let chunkId = Math.floor(x / w) + "_" + Math.floor(y / h);
|
||||||
let objectId = Math.floor(x / ws) + "_" + Math.floor(y / hs);
|
let objectId = Math.floor(x / ws) + "_" + Math.floor(y / hs);
|
||||||
if (WORLD_CHUNKS[chunkId]) return WORLD_CHUNKS[chunkId].terrainObjectsVault[objectId];
|
if (WORLD_CHUNKS.existsKey(chunkId)) return WORLD_CHUNKS.get(chunkId).terrainObjectsVault.get(objectId);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -285,7 +304,7 @@ export function getObjectFromVegetationLayer(x, y) {
|
|||||||
let hs = BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
let hs = BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
||||||
let chunkId = Math.floor(x / w) + "_" + Math.floor(y / h);
|
let chunkId = Math.floor(x / w) + "_" + Math.floor(y / h);
|
||||||
let objectId = Math.floor(x / ws) + "_" + Math.floor(y / hs);
|
let objectId = Math.floor(x / ws) + "_" + Math.floor(y / hs);
|
||||||
if (WORLD_CHUNKS[chunkId]) return WORLD_CHUNKS[chunkId].vegetationObjectsVault[objectId];
|
if (WORLD_CHUNKS.existsKey(chunkId)) return WORLD_CHUNKS.get(chunkId).vegetationObjectsVault.get(objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,7 +320,7 @@ export function getObjectFromBuildingsLayer(x, y) {
|
|||||||
let hs = BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
let hs = BC_TERRAIN_SETTINGS.tileSize * BC_TERRAIN_SETTINGS.scale;
|
||||||
let chunkId = Math.floor(x / w) + "_" + Math.floor(y / h);
|
let chunkId = Math.floor(x / w) + "_" + Math.floor(y / h);
|
||||||
let objectId = Math.floor(x / ws) + "_" + Math.floor(y / hs);
|
let objectId = Math.floor(x / ws) + "_" + Math.floor(y / hs);
|
||||||
if (WORLD_CHUNKS[chunkId]) return WORLD_CHUNKS[chunkId].buildingsObjectsVault[objectId];
|
if (WORLD_CHUNKS.existsKey(chunkId)) return WORLD_CHUNKS.get(chunkId).buildingsObjectsVault.get(objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFirstWorldChunks() {
|
export function createFirstWorldChunks() {
|
||||||
@ -312,25 +331,26 @@ export function createFirstWorldChunks() {
|
|||||||
let chunkXCeiled = Math.floor((BC_CAMERA.position.x + w * i) / w);
|
let chunkXCeiled = Math.floor((BC_CAMERA.position.x + w * i) / w);
|
||||||
let chunkYCeiled = Math.floor((BC_CAMERA.position.y + h * j) / h);
|
let chunkYCeiled = Math.floor((BC_CAMERA.position.y + h * j) / h);
|
||||||
let chunkId = chunkXCeiled + "_" + chunkYCeiled;
|
let chunkId = chunkXCeiled + "_" + chunkYCeiled;
|
||||||
console.log(chunkId);
|
// console.log(chunkId);
|
||||||
let chunkRef = createWorldChunk();
|
let chunkRef = createWorldChunkContainer();
|
||||||
// chunkRef.isRenderGroup = true;
|
// chunkRef.isRenderGroup = true;
|
||||||
chunkRef.position.set(w * chunkXCeiled, h * chunkYCeiled);
|
chunkRef.position.set(w * chunkXCeiled, h * chunkYCeiled);
|
||||||
// console.log(w * chunkXCeiled, h * chunkYCeiled);
|
// console.log(w * chunkXCeiled, h * chunkYCeiled);
|
||||||
let chunk0 = {
|
let chunk0 = new WorldChunk(
|
||||||
chunk: chunkRef,
|
chunkRef,
|
||||||
terrainLayer: chunkRef.getChildAt(0),
|
chunkRef.getChildAt(0),
|
||||||
vegetationLayer: chunkRef.getChildAt(1),
|
chunkRef.getChildAt(1),
|
||||||
buildingsLayer: chunkRef.getChildAt(2),
|
chunkRef.getChildAt(2),
|
||||||
terrainObjectsVault: {},
|
new Vault("terrain"),
|
||||||
vegetationObjectsVault: {},
|
new Vault("vegetation"),
|
||||||
buildingsObjectsVault: {},
|
new Vault("buildings")
|
||||||
};
|
);
|
||||||
|
|
||||||
fillChunk(chunk0, chunkXCeiled, chunkYCeiled);
|
fillChunk(chunk0, chunkXCeiled, chunkYCeiled);
|
||||||
WORLD_CHUNKS[chunkId] = chunk0;
|
WORLD_CHUNKS.set(chunkId, chunk0);
|
||||||
chunkRef.visible = false;
|
chunkRef.visible = false;
|
||||||
addToViewport(chunkRef);
|
addToViewport(chunkRef);
|
||||||
|
// console.log(WORLD_CHUNKS)
|
||||||
// console.log(chunkXCeiled, chunkYCeiled);
|
// console.log(chunkXCeiled, chunkYCeiled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user