diff --git a/Assets/Scripts/Game Loop/StorageSystem.cs b/Assets/Scripts/Game Loop/StorageSystem.cs index a71d90653..4e9ccfdac 100644 --- a/Assets/Scripts/Game Loop/StorageSystem.cs +++ b/Assets/Scripts/Game Loop/StorageSystem.cs @@ -146,10 +146,45 @@ namespace AibisDream } } + if (TryGetInitialValue(variableName, out result)) + { + return true; + } + result = default; return false; } + private bool TryGetInitialValue(string variableName, out T result) + { + result = default; + + if (Program == null || !Program.InitialValues.TryGetValue(variableName, out var initialValue)) + { + return false; + } + + if (!InitialValueMatchesType(initialValue.ValueCase)) + { + return false; + } + + return Program.TryGetInitialValue(variableName, out result); + } + + private static bool InitialValueMatchesType(Yarn.Operand.ValueOneofCase valueCase) + { + var targetType = typeof(T); + + return valueCase switch + { + Yarn.Operand.ValueOneofCase.BoolValue => targetType == typeof(bool), + Yarn.Operand.ValueOneofCase.StringValue => targetType == typeof(string), + Yarn.Operand.ValueOneofCase.FloatValue => targetType == typeof(float), + _ => false + }; + } + #endregion #region εΊεˆ—εŒ– @@ -365,4 +400,4 @@ namespace AibisDream public string variableName; public object value; } -} \ No newline at end of file +}