|
|
|
import { Vector3 } from "@babylonjs/core";
|
|
|
|
import { Type } from "class-transformer";
|
|
|
|
import { BuildingData_ChemicalPlant, BuildingData_Environment, BuildingData_Normal, BuildingType } from "./building/building-data";
|
|
|
|
|
|
|
|
//单位信息
|
|
|
|
export class InstitutionData {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 版本号
|
|
|
|
*/
|
|
|
|
version: string = "1.0";
|
|
|
|
|
|
|
|
@Type(() => NormalData)
|
|
|
|
normalData: NormalData = null;//常规信息
|
|
|
|
|
|
|
|
@Type(() => BuildingData_Normal)
|
|
|
|
normalBuildingDatas: BuildingData_Normal[] = [];//普通建筑列表
|
|
|
|
|
|
|
|
@Type(() => BuildingData_Environment)
|
|
|
|
environmentDatas: BuildingData_Environment[] = [];//环境信息
|
|
|
|
|
|
|
|
@Type(() => BuildingData_ChemicalPlant)
|
|
|
|
chemicalPlantData: BuildingData_ChemicalPlant[] = [];//化工厂信息
|
|
|
|
|
|
|
|
@Type(() => Vector3)
|
|
|
|
pos: Vector3 = new Vector3(0, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
//获取一个最新的key(根据前一个同类建筑key,加一)
|
|
|
|
public getNewKey(buildingType: BuildingType): string {
|
|
|
|
let result = "";
|
|
|
|
|
|
|
|
let lastNormalData: NormalData = null;
|
|
|
|
let length = 0;
|
|
|
|
switch (buildingType) {
|
|
|
|
case BuildingType.Normal:
|
|
|
|
if (this.normalBuildingDatas != null && this.normalBuildingDatas.length > 0) {
|
|
|
|
length = this.normalBuildingDatas.length;
|
|
|
|
lastNormalData = this.normalBuildingDatas[length - 1].normalData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BuildingType.Environment:
|
|
|
|
if (this.environmentDatas != null && this.environmentDatas.length > 0) {
|
|
|
|
length = this.environmentDatas.length;
|
|
|
|
lastNormalData = this.environmentDatas[length - 1].normalData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BuildingType.ChemicalPlant:
|
|
|
|
if (this.chemicalPlantData != null && this.chemicalPlantData.length > 0) {
|
|
|
|
length = this.chemicalPlantData.length;
|
|
|
|
lastNormalData = this.chemicalPlantData[length - 1].normalData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let lastKey = 0;
|
|
|
|
if (lastNormalData != null) {
|
|
|
|
lastKey = Number.parseInt(lastNormalData.key);
|
|
|
|
lastKey++;
|
|
|
|
}
|
|
|
|
|
|
|
|
result += lastKey;
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//常规、必有的信息
|
|
|
|
export class NormalData {
|
|
|
|
|
|
|
|
key: string;//唯一key
|
|
|
|
|
|
|
|
name: string;//给用户编辑、查看用的名称
|
|
|
|
constructor(key: string = "", name: string = "") {
|
|
|
|
|
|
|
|
this.key = key;
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
clone(): NormalData {
|
|
|
|
let result = new NormalData(this.key, this.name);
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getName() {
|
|
|
|
//console.log("getName==" + this.name);
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
}
|