Skip to content

Commit

Permalink
Fixes save system and block selection dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSuckerberg committed Apr 19, 2021
1 parent 61854a9 commit 6b79002
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
24 changes: 12 additions & 12 deletions Blocktest/Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_Mode: 0
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
Expand Down Expand Up @@ -906,10 +906,10 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName: PlayerUI, Assembly-CSharp
- m_Target: {fileID: 1372863295}
m_TargetAssemblyTypeName: BlockManager, Assembly-CSharp
m_MethodName: PlayerSaveLevel
m_Mode: 3
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
Expand Down Expand Up @@ -1537,7 +1537,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_Mode: 0
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
Expand Down Expand Up @@ -1568,10 +1568,10 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName: PlayerUI, Assembly-CSharp
- m_Target: {fileID: 1372863295}
m_TargetAssemblyTypeName: BlockManager, Assembly-CSharp
m_MethodName: PlayerLoadLevel
m_Mode: 3
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
Expand Down Expand Up @@ -1749,7 +1749,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_Mode: 0
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
Expand Down Expand Up @@ -2336,7 +2336,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_Mode: 0
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
Expand Down Expand Up @@ -2375,8 +2375,8 @@ MonoBehaviour:
m_OnValueChanged:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName: PlayerUI, Assembly-CSharp
- m_Target: {fileID: 1372863295}
m_TargetAssemblyTypeName: BlockManager, Assembly-CSharp
m_MethodName: ChangeBlockSelection
m_Mode: 0
m_Arguments:
Expand Down
13 changes: 12 additions & 1 deletion Blocktest/Assets/Scripts/Block System/BlockManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class BlockManager : MonoBehaviour
[SerializeField] private Tilemap backgroundTilemap;
[SerializeField] public GameObject defaultPlayerPrefab;


private void Awake()
{
// Add this to the global variable
Expand Down Expand Up @@ -60,4 +59,16 @@ where assemblyType.IsSubclassOf(typeof(Block))
selectionDropdown.AddOptions(blockNames.ToList());
WorldGen.GenerateMainMap(); // TODO: Move this to some sort of global initialization method
}

// Code bandaid for saving
public void PlayerLoadLevel() {
SaveSystem.LoadGame(0);
}

public void PlayerSaveLevel() {
SaveSystem.SaveGame(0);
}

// disgusting
public void ChangeBlockSelection(int slot) => Globals.characterObject.GetComponent<PlayerUI>().ChangeBlockSelection(slot);
}
4 changes: 2 additions & 2 deletions Blocktest/Assets/Scripts/SaveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void SaveGame(int saveIndex) {
string path = Application.persistentDataPath + "/savegame-" + saveIndex + ".bt";

FileStream stream = new FileStream(path, FileMode.Create);
Vector3 playerPos3 = GameObject.Find("Player").transform.position;
Vector3 playerPos3 = Globals.characterObject.transform.position;
float[] playerPos = new float[3] {playerPos3.x, playerPos3.y, playerPos3.z};

SaveData save = new SaveData(playerPos, BuildSystem.currentWorld);
Expand Down Expand Up @@ -47,7 +47,7 @@ public static void LoadGame(int saveIndex) {

BuildSystem.PlaceIDsCells(blocksToPlaceFore, true, positions);
BuildSystem.PlaceIDsCells(blocksToPlaceBack, false, positions);
GameObject.Find("Player").transform.position = new Vector3(data.playerPosition[0], data.playerPosition[1], data.playerPosition[2]);
Globals.characterObject.transform.position = new Vector3(data.playerPosition[0], data.playerPosition[1], data.playerPosition[2]);
BuildSystem.currentWorld = data.worldData;

} else
Expand Down

0 comments on commit 6b79002

Please sign in to comment.