|
- using System;
- using System.Collections.Generic;
- using SUISS.Storage;
-
- namespace SUISSEngine
- {
- public abstract class DailyAbstractState<T> : AbstractState<T> where T : DailyAbstractState<T>
- {
- protected override void Awake()
- {
- base.Awake();
- Daily.Day value = this.GetValue<Daily.Day>("Daily_SavedDay", null);
- if (!object.Equals(value, Singleton<Daily>.Instance.CurrentDay))
- {
- this.SaveDailyState();
- }
- Singleton<Daily>.Instance.CurrentDayChanged += this.OnCurrentDayChanged;
- }
-
- protected override void Start()
- {
- base.Start();
- }
-
- protected override void OnDestroy()
- {
- base.OnDestroy();
- if (Singleton<Daily>.IsAvailable)
- {
- Singleton<Daily>.Instance.CurrentDayChanged -= this.OnCurrentDayChanged;
- }
- }
-
- public virtual object GetStartOfDayValue(string key)
- {
- return this.GetStartOfDayValue(key, null);
- }
-
- public virtual object GetStartOfDayValue(string key, object defaultValue)
- {
- object result;
- if (!base.Persistent.TryGetValue("Daily_" + key, out result))
- {
- result = defaultValue;
- }
- return result;
- }
-
- private void OnCurrentDayChanged(Daily.Day previousDay, Daily.Day newDay)
- {
- this.SaveDailyState();
- }
-
- private void SaveDailyState()
- {
- Dictionary<string, object> persistent = base.Persistent;
- List<string> list = new List<string>(persistent.Keys);
- int i = 0;
- while (i < list.Count)
- {
- string text = list[i];
- if (text.StartsWith("Daily_"))
- {
- persistent.Remove(text);
- list.RemoveAt(i);
- }
- else
- {
- i++;
- }
- }
- foreach (string text2 in list)
- {
- object obj = persistent[text2];
- object value = Storage.CloneObject(obj);
- persistent["Daily_" + text2] = value;
- base.FireValueChangedHandler(text2, obj, obj);
- }
- persistent["Daily_SavedDay"] = Singleton<Daily>.Instance.CurrentDay;
- }
-
- public const string DailyKeyPrefix = "Daily_";
-
- public const string SavedDayKey = "Daily_SavedDay";
- }
- }
|