Skip to content

Commit

Permalink
v1.1 Update
Browse files Browse the repository at this point in the history
Changed the following:
- Fixed typos in errors
- Added remove functions
- Made it so you can't name multiple variables of the same type the same name
    - Returns an error if you try
  • Loading branch information
Persomatey committed Sep 17, 2022
1 parent 9d2d3e7 commit f074d94
Showing 1 changed file with 107 additions and 12 deletions.
119 changes: 107 additions & 12 deletions JSONSerializerPackage/Assets/Code/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public bool GetBool(string variableName)
}
else
{
Debug.LogError($"ERROR: No variable names {variableName} found! returning 'false' instead");
Debug.LogError($"ERROR: No variable named {variableName} found! returning 'false' instead");
return false;
}
}
Expand All @@ -199,7 +199,7 @@ public int GetInt(string variableName)
}
else
{
Debug.LogError($"ERROR: No variable names {variableName} found! returning '0' instead");
Debug.LogError($"ERROR: No variable named {variableName} found! returning '0' instead");
return 0;
}
}
Expand All @@ -224,7 +224,7 @@ public float GetFloat(string variableName)
}
else
{
Debug.LogError($"ERROR: No variable names '{variableName}' found! returning '0.0f' instead");
Debug.LogError($"ERROR: No variable named '{variableName}' found! returning '0.0f' instead");
return 0.0f;
}
}
Expand All @@ -249,7 +249,7 @@ public string GetString(string variableName)
}
else
{
Debug.LogError($"ERROR: No variable names '{variableName}' found! returning NULL instead");
Debug.LogError($"ERROR: No variable named '{variableName}' found! returning NULL instead");
return null;
}
}
Expand All @@ -273,7 +273,7 @@ public void SetBool(string variableName, bool newBool)

if (!found)
{
Debug.LogError($"ERROR: No variable names {variableName} found!");
Debug.LogError($"ERROR: No variable named {variableName} found!");
}
}

Expand All @@ -292,7 +292,7 @@ public void SetInt(string variableName, int newInt)

if (!found)
{
Debug.LogError($"ERROR: No variable names {variableName} found!");
Debug.LogError($"ERROR: No variable named {variableName} found!");
}
}

Expand All @@ -311,7 +311,7 @@ public void SetFloat(string variableName, float newFloat)

if (!found)
{
Debug.LogError($"ERROR: No variable names {variableName} found!");
Debug.LogError($"ERROR: No variable named {variableName} found!");
}
}

Expand All @@ -330,7 +330,7 @@ public void SetString(string variableName, string newString)

if (!found)
{
Debug.LogError($"ERROR: No variable names {variableName} found!");
Debug.LogError($"ERROR: No variable named {variableName} found!");
}
}

Expand All @@ -340,31 +340,126 @@ public void SetString(string variableName, string newString)

public void AddBool(string newItemName, bool newItemValue)
{
for (int i = 0; i < boolList.Count; i++)
{
if (boolList[i].name == newItemName)
{
Debug.LogError($"ERROR: There is already a boolean named {newItemValue} in {jsonFile.name}.json!");
return;
}
}

boolList.Add(new JSONBoolean(newItemName, newItemValue));
}

public void AddInt(string newItemName, int newItemValue)
{
for (int i = 0; i < intList.Count; i++)
{
if (intList[i].name == newItemName)
{
Debug.LogError($"ERROR: There is already a integer named {newItemValue} in {jsonFile.name}.json!");
return;
}
}

intList.Add(new JSONInteger(newItemName, newItemValue));
}

public void AddFloat(string newItemName, float newItemValue)
{
for (int i = 0; i < floatList.Count; i++)
{
if (floatList[i].name == newItemName)
{
Debug.LogError($"ERROR: There is already a float named {newItemValue} in {jsonFile.name}.json!");
return;
}
}

floatList.Add(new JSONFloat(newItemName, newItemValue));
}

public void AddString(string newItemName, string newItemValue)
{
for (int i = 0; i < stringList.Count; i++)
{
if (stringList[i].name == newItemName)
{
Debug.LogError($"ERROR: There is already a string named {newItemValue} in {jsonFile.name}.json!");
return;
}
}

stringList.Add(new JSONString(newItemName, newItemValue));
}

#endregion Add Functions

#region Remove Functions

public void RemoveBool(string variableName)
{
for (int i = 0; i < boolList.Count; i++)
{
if (boolList[i].name == variableName)
{
boolList.Remove(boolList[i]);
return;
}
}

Debug.LogError($"ERROR: No variable named {variableName} found!");
}

public void RemoveInt(string variableName)
{
for (int i = 0; i < intList.Count; i++)
{
if (intList[i].name == variableName)
{
intList.Remove(intList[i]);
return;
}
}

Debug.LogError($"ERROR: No variable named {variableName} found!");
}

public void RemoveFloat(string variableName)
{
for (int i = 0; i < floatList.Count; i++)
{
if (floatList[i].name == variableName)
{
floatList.Remove(floatList[i]);
return;
}
}

Debug.LogError($"ERROR: No variable named {variableName} found!");
}

public void RemoveString(string variableName)
{
for (int i = 0; i < stringList.Count; i++)
{
if (stringList[i].name == variableName)
{
stringList.Remove(stringList[i]);
return;
}
}

Debug.LogError($"ERROR: No variable named {variableName} found!");
}

#endregion Remove Functions
}

#region JSON Variables

[System.Serializable]
[Serializable]
public class JSONBoolean
{
public string name;
Expand All @@ -377,7 +472,7 @@ public JSONBoolean(string name, bool value)
}
}

[System.Serializable]
[Serializable]
public class JSONInteger
{
public string name;
Expand All @@ -390,7 +485,7 @@ public JSONInteger(string name, int value)
}
}

[System.Serializable]
[Serializable]
public class JSONFloat
{
public string name;
Expand All @@ -403,7 +498,7 @@ public JSONFloat(string name, float value)
}
}

[System.Serializable]
[Serializable]
public class JSONString
{
public string name;
Expand Down

0 comments on commit f074d94

Please sign in to comment.