-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d049075
commit 6e7bd08
Showing
19 changed files
with
622 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Chonks { | ||
public class ChunkDataSegment { | ||
private readonly Dictionary<string, object> _container = new Dictionary<string, object>(); | ||
public ChunkDataSegment() { } | ||
public ChunkDataSegment(string json) { | ||
_container = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); | ||
} | ||
|
||
public string ToJson() { | ||
return JsonConvert.SerializeObject(_container); | ||
} | ||
|
||
public Type CheckType(string key) => ContainsKey(key) ? _container[key].GetType() : null; | ||
|
||
public bool ContainsKey(string key) => _container.ContainsKey(key); | ||
|
||
public bool TryAdd(string key, object value) => _container.TryAdd(key, value); | ||
|
||
public bool TryGetInt(string key, out int integer) { | ||
integer = -1; | ||
if (_container.TryGetValue(key, out var value)) { | ||
integer = Convert.ToInt32(value); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public T Get<T>(string key) { | ||
if (!ContainsKey(key)) { | ||
throw new KeyNotFoundException($"The key {key} was not found in the collection."); | ||
} | ||
|
||
object box; | ||
T check = default; | ||
|
||
// int is a difficult conversion since the default | ||
// for newtonsoft.json is Int64 | ||
if (check is int) { | ||
box = Convert.ToInt32(_container[key]); | ||
return (T)box; | ||
} | ||
|
||
return (T)_container[key]; | ||
} | ||
|
||
public bool TryGetBool(string key, out bool boolean) { | ||
boolean = false; | ||
if (_container.TryGetValue(key, out var value)) { | ||
boolean = (bool)value; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public bool TryGetString(string key, out string stringValue) { | ||
stringValue = null; | ||
if (_container.TryGetValue(key, out var value)) { | ||
stringValue = value.ToString(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
namespace Chonks { | ||
using System; | ||
|
||
namespace Chonks { | ||
public interface ISaveDepot { | ||
SaveContainer[] ListSaves(); | ||
bool TryLoadSave(string name, out SaveChunk[] chunks); | ||
bool TryWriteSave(string name, SaveChunk[] chunks); | ||
bool TryLoadSave(string name, out SaveChunk[] chunks, out Exception ex); | ||
bool TryWriteSave(string name, SaveChunk[] chunks, out Exception ex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.