public void GivenTypedKeyAndValueAbsent_WhenSetValue_ThenValueStored() { SaveKey <bool> key0 = new SaveKey <bool>("key0"); persister.ReadData().Returns(new Dictionary <string, object>()); store.Load(); store.SetValue(key0, true); Assert.That(store.GetValue(key0), Is.True); }
public void GivenTypedSaveKeyAndValueAbsent_WhenGetValueTyped_ThenDefaultForTypeReturned() { SaveKey <int> key0 = new SaveKey <int>("key0"); persister.ReadData().Returns(new Dictionary <string, object>()); store.Load(); int actual = store.GetValue(key0); Assert.That(actual, Is.EqualTo(default(int))); }
public void GivenTypedKeyAndValueAbsent_WhenHasValue_ThenFalse() { SaveKey <long> key0 = new SaveKey <long>("key0"); persister.ReadData().Returns(new Dictionary <string, object>()); store.Load(); bool actual = store.HasValue(key0); Assert.That(actual, Is.False); }
public void WhenGetAccessor_ThenAccessorForSpecifiedKeyProvided() { SaveKey <int> key = new SaveKey <int>("someKey"); store.Load(); store.SetValue(key, 100); SaveValueAccessor <int> accessor = store.GetAccessor(key); Assert.That(accessor.Get(), Is.EqualTo(100)); }
public void WhenSetSave_ThenValueChangedEventFired() { float retrievedValue = -1f; SaveKey <float> key = new SaveKey <float>("someKey"); SaveValueAccessor <float> accessor = store.GetAccessor(key); accessor.ValueChanged += (saveValue) => retrievedValue = saveValue; accessor.SetSave(100f); Assert.That(retrievedValue, Is.EqualTo(100f)); }
public void GivenTypedKeyAndValuePresent_WhenHasValue_ThenTrue() { SaveKey <long> key0 = new SaveKey <long>("key0"); Dictionary <string, object> expected = new Dictionary <string, object>(); expected[key0.Name] = 200L; persister.ReadData().Returns(expected); store.Load(); bool actual = store.HasValue(key0); Assert.That(actual, Is.True); }
public void GivenTypedKeyAndValuePresent_WhenSetValue_ThenValueOverwritten() { SaveKey <bool> key0 = new SaveKey <bool>("key0"); Dictionary <string, object> expected = new Dictionary <string, object>(); expected[key0.Name] = true; persister.ReadData().Returns(expected); store.Load(); store.SetValue(key0, false); Assert.That(store.GetValue(key0), Is.False); }
public SaveKey LoadSaveKey() { SaveKey save = null; if (File.Exists(Application.persistentDataPath + "/gamesave.save")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open); save = (SaveKey)bf.Deserialize(file); file.Close(); } return(save); }
public static bool GetBool(SaveKey key) { if (mCache.ContainsKey(key.ToString())) { return((bool)mCache[key.ToString()]); } else { bool value = ObscuredPrefs.GetBool(key.ToString(), (bool)Default(key)); mCache[key.ToString()] = value; return(value); } }
private void ToggleKey(SaveKey key, bool defaultIsZero = false) { if (defaultIsZero) { SetKey(key, GetKey(key) == 1 ? 0 : 1); } else { SetKey(key, GetKey(key) == 0 ? 1 : 0); } RpgManager.ZoneDisplayName("Cheat\n" + key.ToString() + " set to " + GetKey(key)); dataDebug.SetData(RpgManager.Data); }
public void GivenTypedSaveKeyAndValuePresent_WhenGetValueTyped_ThenStoredValueReturned() { SaveKey <int> key0 = new SaveKey <int>("key0"); Dictionary <string, object> expected = new Dictionary <string, object>(); expected[key0.Name] = 100; persister.ReadData().Returns(expected); store.Load(); int actual = store.GetValue(key0); Assert.That(actual, Is.EqualTo(100)); }
public static string GetString(SaveKey key) { if (mCache.ContainsKey(key.ToString())) { return((string)mCache[key.ToString()]); } else { string value = ObscuredPrefs.GetString(key.ToString(), (string)Default(key)); mCache[key.ToString()] = value; return(value); } }
public static float GetFloat(SaveKey key) { if (mCache.ContainsKey(key.ToString())) { return((float)mCache[key.ToString()]); } else { float value = ObscuredPrefs.GetFloat(key.ToString(), (float)Default(key)); mCache[key.ToString()] = value; return(value); } }
//--------------------------------------------------------------------------/ /// <summary> /// キーに対応するクラスを取得する /// </summary> /// <typeparam name="T">任意の型</typeparam> /// <param name="key">キー</param> /// <param name="defaultValue">初期値</param> /// <param name="subKey">サブキー</param> /// <returns></returns> //--------------------------------------------------------------------------/ public T GetClass <T>(SaveKey key, T defaultValue, string subKey = "") { // キーがないならデフォルト値を返す if (!HasKey(key, subKey)) { Debug.Log("defaultきちゃったー"); return(defaultValue); } // Json形式のstringを取り出し、T型に変換して返す string json = PlayerPrefs.GetString(key.ToString() + subKey); Debug.Log(json); return(JsonUtility.FromJson <T>(json)); }
SaveKey CreateSaveKey() { SaveKey save = new SaveKey(); foreach (GameObject i in ButtonCodeList) { save.keyCodeStr.Add(i.transform.Find("Button").transform.GetChild(0).GetComponent <Text>().text); int[] NewarrayInt = new int[8]; for (int o = 0; o < i.transform.Find("Text").GetComponent <Text>().text.Length; o++) { NewarrayInt[o] = i.transform.Find("Text").GetComponent <Text>().text[o]; } save.keyCodeArrayStr.Add(NewarrayInt); } return(save); }
public void GivenDefaultProviderWithTypedSaveKeyAndValueAbsent_WhenGetValueTyped_ThenDefaultReturned() { DefaultValueProvider provider = Substitute.For <DefaultValueProvider>(); store = new SerialSaveStore(persister, provider); SaveKey <int> key0 = new SaveKey <int>("key0"); persister.ReadData().Returns(new Dictionary <string, object>()); store.Load(); int expectedDefault = 5005; provider.GetDefaultValue(key0.Name).Returns(expectedDefault); int actual = store.GetValue <int>(key0); Assert.That(actual, Is.EqualTo(expectedDefault)); }
void Start() { keyCodeList = LoadSaveKey(); foreach (int[] i in keyCodeList.keyCodeArrayStr) { string NewStr = ""; foreach (int o in i) { NewStr += (char)o; } keyList.Add(NewStr); } SelectedChar = '\0'; foreach (GameObject i in TextLine) { i.GetComponent <RectTransform>().sizeDelta = new Vector2(500, 30); } }
public static void SetKey(SaveKey key, int value) { Data.SetKey(key, value); RpgManager.Instance.dataDebug.SetData(Data); }
public bool GetBool(SaveKey key) { return(GetKey(key) == 1); }
public void SetBool(SaveKey key, bool value) { data[key] = value ? 1 : 0; }
public static bool HasKey(SaveKey key) { return(PlayerPrefs.HasKey(keyNames[key])); }
private static void AddToDicts(SaveKey key, ValueType type, string name) { keyTypes.Add(key, type); keyNames.Add(key, name); }
/// <summary> /// Create an accessor to the specified save store for the provided save key. /// </summary> /// <param name="saveKey">The key to read and write the value for.</param> /// <param name="saveStore">The save store to use.</param> public SaveValueAccessor(SaveKey <T> saveKey, SerialSaveStore saveStore) { this.saveKey = saveKey; this.saveStore = saveStore; }
public static int GetKey(SaveKey key) { return(Data.GetKey(key)); }
private static void AddToDicts(SaveKey key, ValueType type) { AddToDicts(key, type, key.ToString()); }
public GameDataKey(SaveKey k, int v) { key = k; value = v; }
public static string GetPrefSaveName(SaveKey key) { return(keyNames[key]); }
public GameDataKey(KeyValuePair <SaveKey, int> pair) { key = pair.Key; value = pair.Value; }
public static void DeleteKey(SaveKey key) { PlayerPrefs.DeleteKey(keyNames[key]); }
public void SetKey(SaveKey key, int value) { data[key] = value; }