Skip to content

Commit

Permalink
fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSuckerberg committed Apr 4, 2021
1 parent 8ffe26e commit e7a3cd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Blocktest/Assets/Scripts/Block System/BlockManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BlockManager : MonoBehaviour
/// <summary> Array which stores all block instances for referencing as if they were globals. </summary>
[HideInInspector] public Block[] allBlocks;
/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary>
[HideInInspector] public List<string> blockNames;
[HideInInspector] public string[] blockNames;

/// <summary> Dropdown used for player item selection </summary>
[SerializeField] private Dropdown selectionDropdown;
Expand All @@ -38,6 +38,7 @@ where assemblyType.IsSubclassOf(typeof(Block))
select assemblyType).ToArray();

allBlocks = new Block[allBlockTypes.Length];
blockNames = new string[allBlockTypes.Length];

// For loops to populate main allBlocks array.
for (int i = 0; i < allBlockTypes.Length; i++) {
Expand All @@ -52,10 +53,10 @@ where assemblyType.IsSubclassOf(typeof(Block))
} else if (newBlock.blockID > allBlocks.Length || newBlock.blockID < 0) {
Debug.LogWarning("Block " + newBlock + " has invalid ID " + newBlock.blockID + "! (Max ID " + allBlocks.Length + ")");
}
blockNames.Add(newBlock.blockName);
blockNames[newBlock.blockID] = newBlock.blockName;
allBlocks[newBlock.blockID] = newBlock;
}
selectionDropdown.AddOptions(blockNames);
selectionDropdown.AddOptions(blockNames.ToList());
WorldGen.GenerateMainMap(); // TODO: Move this to some sort of global initialization method
}
}
8 changes: 2 additions & 6 deletions Blocktest/Assets/Scripts/SaveSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
Expand All @@ -15,7 +13,7 @@ public static void SaveGame(int saveIndex) {
Vector3 playerPos3 = GameObject.Find("Player").transform.position;
float[] playerPos = new float[3] {playerPos3.x, playerPos3.y, playerPos3.z};

SaveData save = new SaveData(Globals.blockManager.blockNames, playerPos, BuildSystem.currentWorld);
SaveData save = new SaveData(playerPos, BuildSystem.currentWorld);

formatter.Serialize(stream, save);
stream.Close();
Expand Down Expand Up @@ -62,14 +60,12 @@ public static void LoadGame(int saveIndex) {
[System.Serializable]
public class SaveData
{
public List<string> blockNames;
public DateTime createDate;
public DateTime saveDate;
public float[] playerPosition;
public int[,,] worldData;
public SaveData(List<string> blockNames, float[] playerPosition, int[,,] worldData)
public SaveData(float[] playerPosition, int[,,] worldData)
{
this.blockNames = blockNames;
this.playerPosition = playerPosition;
this.worldData = worldData;
this.saveDate = DateTime.Now;
Expand Down

0 comments on commit e7a3cd5

Please sign in to comment.