public override void _Ready() { int i = 0; this.Multimesh.InstanceCount = 0; if (Global.IsLoaded) { this.Multimesh.InstanceCount = Global.LoadedMeat.Count; foreach (Godot.Collections.Dictionary m in Global.LoadedMeat) { Meat newMeat = new Meat(); newMeat.meatSpatial = (Spatial) new Spatial(); newMeat.meatSpatial.Translation = new Vector3((float)m["MeatTranslationX"], (float)m["MeatTranslationY"], (float)m["MeatTranslationZ"]); newMeat.meatSpatial.Scale = new Vector3((float)m["MeatScaleX"], (float)m["MeatScaleY"], (float)m["MeatScaleZ"]); newMeat.timeOnGround = (float)m["TimeOnGround"]; newMeat.EatersCount = (int)((float)m["EatersCount"]); newMeat.Collider = (CreatureCollider) new CreatureCollider(); newMeat.Collider.Translation = new Vector3((float)m["ColliderTranslationX"], (float)m["ColliderTranslationY"], (float)m["ColliderTranslationZ"]); newMeat.Collider.MyMeat = newMeat; newMeat.Collider.MyCreatureAlive = false; AddChild(newMeat.Collider); newMeat.decay = (int)((float)m["Decay"]); newMeat.meatGone = (bool)m["MeatGone"]; MeatArray.Add(newMeat); Multimesh.SetInstanceTransform(i, newMeat.meatSpatial.Transform); i++; } MeatBiomassArray = DataCollector.ConvertToFloatArray(Global.LoadedMeatBiomass); } else { MeatBiomassArray.Add(0.0f); } }
public void ConvertToFloatArrayNotEmptyArrayTest() { const int X = 5; const int Y = 5; bool allFloat = true; Godot.Collections.Array inputArray = new Godot.Collections.Array(); for (int i = 0; i < X; i++) { inputArray.Add((float)i / 10.0f); } Godot.Collections.Array parsed = new Godot.Collections.Array((Godot.Collections.Array)JSON.Parse(JSON.Print(inputArray)).Result); Godot.Collections.Array arrayOfFloats = DataCollector.ConvertToFloatArray(parsed); for (int i = 0; i < arrayOfFloats.Count; i++) { if (arrayOfFloats[i].GetType() != typeof(float)) { allFloat = false; break; } } Assert.IsEqual(Y, arrayOfFloats.Count, "Then it passes"); Assert.IsTrue(allFloat, "Then it passes"); }
public override void _Ready() { GlobalGrowthRate = Global.biomeGrowthRate; if (!Global.IsLoaded) { switch (Global.biomeType) { case 0: InitialBiome = 4; break; case 1: InitialBiome = 0; break; case 2: InitialBiome = 1; break; case 3: InitialBiome = 2; break; case 4: InitialBiome = 3; break; } TileSelectInst = TileSelector.Instance(); AddChild(TileSelectInst); } else { InitialBiome = 4; } WorldSize = Global.worldSize; Vector3 position = (Vector3) new Vector3(0, 0, 0); position.x = -WorldSize / 2; position.z = -WorldSize / 2; for (int i = 0; i < WorldSize; i++) { for (int j = 0; j < WorldSize; j++) { SetCellItem((int)position.x, (int)position.y, (int)position.z, InitialBiome); position.z += 1; } position.x += 1; position.z = -WorldSize / 2; } position = (Vector3) new Vector3(0, 1, 0); position.x = -(WorldSize * 2 - 2); position.z = -(WorldSize * 2 - 2); for (int i = 0; i < WorldSize; i++) { for (int j = 0; j < WorldSize; j++) { Spatial tileCollInst = (Spatial)TileCollider.Instance(); tileCollInst.Translation = position; tileCollInst.Scale = (Vector3) new Vector3(2, 0.7f, 2); AddChild(tileCollInst); position.z += 4; } position.x += 4; position.z = -(WorldSize * 2 - 2); } MultiMeshPlants = GetParent().GetNode <MultiMeshInstance>("MultiMeshPlants"); MultiMeshPlants.Multimesh.InstanceCount = 0; if (Global.IsLoaded) { int i = 0; CurrentWaitingTime = Global.LoadedBiomesWaitingTime; GD.Print(CurrentWaitingTime); GD.Print("type of tile: " + Global.LoadedTiles[0].GetType()); MultiMeshPlants.Multimesh.InstanceCount = Global.LoadedTiles.Count; foreach (Godot.Collections.Dictionary t in Global.LoadedTiles) { GroundTile newTile = new GroundTile(); newTile.type = (BiomeType)((int)((float)t["BiomeType"])); newTile.plantSpatial = (Spatial) new Spatial(); newTile.plantSpatial.Translation = new Vector3((float)t["PlantTranslationX"], (float)t["PlantTranslationY"], (float)t["PlantTranslationZ"]); newTile.plantSpatial.Scale = new Vector3((float)t["PlantScaleX"], (float)t["PlantScaleY"], (float)t["PlantScaleZ"]); newTile.plantGrowthTime = (float)t["PlantGrowthTime"]; newTile.EatersCount = (int)((float)t["EatersCount"]); newTile.isPlantGrowing = (bool)t["IsPlantGrowing"]; newTile.hasPlant = (bool)t["HasPlant"]; newTile.gridIndex = new Vector3((float)t["GridIndexX"], (float)t["GridIndexY"], (float)t["GridIndexZ"]); if (newTile.plantSpatial.Scale.x > 0.0f || newTile.hasPlant || newTile.isPlantGrowing) { SetPlantColor(i, newTile.type); MultiMeshPlants.Multimesh.SetInstanceTransform(i, newTile.plantSpatial.Transform); } GroundTiles.Add(newTile.gridIndex, newTile); switch (newTile.type) { case BiomeType.desert: SetCellItem((int)newTile.gridIndex.x, (int)newTile.gridIndex.y, (int)newTile.gridIndex.z, 1); break; case BiomeType.forest: SetCellItem((int)newTile.gridIndex.x, (int)newTile.gridIndex.y, (int)newTile.gridIndex.z, 0); break; case BiomeType.grassland: SetCellItem((int)newTile.gridIndex.x, (int)newTile.gridIndex.y, (int)newTile.gridIndex.z, 2); break; case BiomeType.tundra: SetCellItem((int)newTile.gridIndex.x, (int)newTile.gridIndex.y, (int)newTile.gridIndex.z, 3); break; } i++; } isWorldBuilding = false; PlantBiomassArray = DataCollector.ConvertToFloatArray(Global.LoadedPlantBiomass); } }
public void ConvertToFloatArrayEmptyArrayTest() { Assert.IsEqual(0, DataCollector.ConvertToFloatArray(new Godot.Collections.Array()).Count, "Then it passes"); }