Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions Assets/Scripts/Chip/HardDrive.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
using System.Collections.Generic;
using UnityEngine;

public class HardDrive : BuiltinChip
{
public static Dictionary<string, List<int>> contents = new Dictionary<string, List<int>>();
string binary;
public class HardDrive : BuiltinChip {
public static Dictionary<string, List<int>> contents;

protected override void Awake()
{
protected override void Awake() {
base.Awake();
contents = SaveSystem.LoadHDDContents();
}

protected override void ProcessOutput()
{
switch(inputPins[0].State)
{
protected override void ProcessOutput() {
switch(inputPins[0].State) {
case 0:
string binary = "";
for (int i = 1; i < 5; i++)
{
for (int i = 1; i < 5; i++) {
binary += inputPins[i].State.ToString();
}
if(contents.ContainsKey(binary))
{
if(contents.ContainsKey(binary)) {
for (int i = 0; i < outputPins.Length; i++)
{
outputPins[i].ReceiveSignal(contents[binary][i]);
}
} else
{
for (int i = 0; i < outputPins.Length; i++)
{
} else {
for (int i = 0; i < outputPins.Length; i++) {
outputPins[0].ReceiveSignal(0);
}
}
break;
case 1:
bool updateFile = false;
string address = "";
List<int> store = new List<int>();
for (int i = 5; i < 13; i++)
{
for (int i = 5; i < 13; i++) {
store.Add(inputPins[i].State);
}
for (int i = 1; i < 5; i++)
{
for (int i = 1; i < 5; i++) {
address += inputPins[i].State;
}
if(contents.ContainsKey(address))
{
if(contents.ContainsKey(address)) {
if (contents[address] != store) {
updateFile = true;
}
contents.Remove(address);
}
} else {
updateFile = true;
}
contents.Add(address, store);
if (updateFile) {
SaveSystem.SaveHDDContents(contents);
}
break;
default:
foreach(Pin i in outputPins)
{
foreach(Pin i in outputPins) {
i.ReceiveSignal(0);
}
break;
Expand Down
22 changes: 22 additions & 0 deletions Assets/Scripts/Save System/SaveSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;

public static class SaveSystem {

Expand Down Expand Up @@ -66,6 +68,26 @@ public static string[] GetSaveNames () {
return savedProjectPaths;
}


public static Dictionary<string, List<int>> LoadHDDContents () {
string hddSavePath = Path.Combine(CurrentSaveProfileDirectoryPath, "HDDContents.json");
if (System.IO.File.Exists(hddSavePath)){
//Load HDD contents from file
FileInfo saveFile = new FileInfo(hddSavePath);
string jsonString = saveFile.OpenText().ReadToEnd();
return JsonConvert.DeserializeObject<Dictionary<string, List<int>>>(jsonString);
}
return new Dictionary<string, List<int>> {};
}

public static void SaveHDDContents (Dictionary<string, List<int>> contents) {
string hddSavePath = Path.Combine(CurrentSaveProfileDirectoryPath, "HDDContents.json");
string jsonStr = JsonConvert.SerializeObject(contents);
//Format json string
jsonStr = jsonStr.Replace("{", "{\n\t").Replace("}", "\n}").Replace("],", "],\n\t");
System.IO.File.WriteAllText(hddSavePath, jsonStr);
}

public static string SaveDataDirectoryPath {
get {
const string saveFolderName = "SaveData";
Expand Down
1 change: 0 additions & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"com.unity.collab-proxy": "1.11.2",
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.11",
"com.unity.ide.vscode": "1.2.4",
Expand Down
7 changes: 0 additions & 7 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"dependencies": {
"com.unity.collab-proxy": {
"version": "1.11.2",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "1.0.6",
"depth": 1,
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2020.3.20f1
m_EditorVersionWithRevision: 2020.3.20f1 (41c4e627c95f)
m_EditorVersion: 2020.3.22f1
m_EditorVersionWithRevision: 2020.3.22f1 (e1a7f79fd887)