aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Objects/Save.cs
diff options
context:
space:
mode:
authorAShifter <[email protected]>2017-06-05 09:49:46 -0600
committerAShifter <[email protected]>2017-06-05 09:49:46 -0600
commit61c906e596145bbedd60725c6dcee68c34a27907 (patch)
treecd7a00d501affe96028bfb21a8dec90c2ee63f2c /ShiftOS.Objects/Save.cs
parent66ea2cf2fdeeaa025bd22961a0400423233c505d (diff)
parent3e11eca70481841b6e2f2253d667944779cfd5fb (diff)
downloadshiftos_thereturn-61c906e596145bbedd60725c6dcee68c34a27907.tar.gz
shiftos_thereturn-61c906e596145bbedd60725c6dcee68c34a27907.tar.bz2
shiftos_thereturn-61c906e596145bbedd60725c6dcee68c34a27907.zip
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
Diffstat (limited to 'ShiftOS.Objects/Save.cs')
-rw-r--r--ShiftOS.Objects/Save.cs85
1 files changed, 82 insertions, 3 deletions
diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs
index 2a02bbc..7891a22 100644
--- a/ShiftOS.Objects/Save.cs
+++ b/ShiftOS.Objects/Save.cs
@@ -26,20 +26,94 @@ using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Threading;
namespace ShiftOS.Objects
{
//Better to store this stuff server-side so we can do some neat stuff with hacking...
public class Save
{
+ public bool MusicEnabled = true;
+ public bool SoundEnabled = true;
+ public int MusicVolume = 100;
[Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")]
public string Username { get; set; }
+ private List<Action> _setCpCallbacks = new List<Action>(); // everything in this list is called by Codepoints.set() and syncCp().
+ private ulong _cp = 0; // locally cached codepoints counter
+ private Object _cpLock = new Object(); // locked when modifying or reading the codepoints counter
+ private Object _webLock = new Object(); // locked when communicating with the server
+ private Timer _updTimer; // timer to start a new sync thread every 5 minutes
+
+ // Sync local Codepoints count with the server.
+ public void syncCp()
+ {
+ new Thread(() =>
+ {
+ lock (_cpLock)
+ {
+ lock (_webLock)
+ {
+ var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken);
+ _cp = uc.GetCodepoints();
+ }
+ }
+ foreach (Action a in _setCpCallbacks)
+ a();
+ }).Start();
+ }
+
+ // we have to write these wrapper functions so we can keep _setCpCallbacks private,
+ // so that it doesn't get serialised
+ public void addSetCpCallback(Action callback)
+ {
+ _setCpCallbacks.Add(callback);
+ }
+
+ public void removeSetCpCallback(Action callback)
+ {
+ _setCpCallbacks.Remove(callback);
+ }
+
+ public ulong Codepoints
+ {
+ get
+ {
+ if (_updTimer == null)
+ _updTimer = new Timer((o) => syncCp(), null, 0, 300000);
+ lock (_cpLock)
+ {
+ return _cp;
+ }
+ }
+ set
+ {
+ lock (_cpLock)
+ {
+ _cp = value;
+ new Thread(() =>
+ {
+ lock (_webLock)
+ {
+ try
+ {
+ var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken);
+ uc.SetCodepoints(value);
+ }
+ catch
+ { }
+ }
+ })
+ {
+ IsBackground = false
+ }.Start();
+ }
+ foreach (Action a in _setCpCallbacks)
+ a();
+ }
+ }
- public long Codepoints { get; set; }
public Dictionary<string, bool> Upgrades { get; set; }
public int StoryPosition { get; set; }
public string Language { get; set; }
@@ -99,6 +173,11 @@ namespace ShiftOS.Objects
}
public List<ClientSave> Users { get; set; }
+
+ /// <summary>
+ /// DO NOT MODIFY THIS. EVER. YOU WILL BREAK THE STORYLINE. Let the engine do it's job.
+ /// </summary>
+ public string PickupPoint { get; set; }
}
public class SettingsObject : DynamicObject