Skip to content

Commit 34a7b04

Browse files
committed
add bool param to scripts
1 parent 4c223cf commit 34a7b04

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

LuaDefinitionMaker/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static void Main()
6969
typeList.Add(new CustomTextType("enums", eventSb.ToString()));
7070

7171
// yes this is stupid but i don't want to figure out how to make it right
72-
typeList.Add(new CustomTextType("enums", "---@alias ParameterDefinitionType string\n---| \"string\"\n---| \"int\"\n---| \"float\""));
72+
typeList.Add(new CustomTextType("enums", "---@alias ParameterDefinitionType string\n---| \"string\"\n---| \"int\"\n---| \"float\"\n---| \"boolean\""));
7373
typeList.Add(new EnumType<StoryboardAnimationType>(false, "AnimationType", "storyboard"));
7474
typeList.Add(new EnumType<SkinSprite>(false, nameof(SkinSprite), "storyboard"));
7575
typeList.Add(new EnumType<StoryboardLayer>(true, "Layer", "storyboard"));
@@ -134,7 +134,7 @@ public static string GetLuaType(Type type, bool enumToNumber = true, Type? fallb
134134
name = (t.BaseType.IsEnum && enumToNumber) ? "number" : t.Name;
135135
}
136136

137-
if (name is not null)
137+
if (name is not null)
138138
return nullable ? $"{name}?" : name;
139139

140140
string fallbackType = getLuaTypeName(fallback) ?? fallback?.Name ?? type.Name;

fluXis/Screens/Edit/Tabs/Storyboarding/Settings/StoryboardElementSettings.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,19 @@ void showError(string text, [CanBeNull] Exception e)
484484
}
485485
});
486486
}
487+
else if (parameter.Type == typeof(bool))
488+
{
489+
drawables.Add(new PointSettingsToggle
490+
{
491+
Text = parameter.Title,
492+
CurrentValue = item.GetParameter(parameter.Key, parameter.GetDefaultFallback<bool>()),
493+
OnStateChanged = enabled =>
494+
{
495+
item.Parameters[parameter.Key] = enabled;
496+
map.Update(item);
497+
}
498+
});
499+
}
487500
}
488501

489502
break;

fluXis/Scripting/ScriptStorage.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public void AddParam(string name, string title, string type, object? fallback)
203203
"string" => typeof(string),
204204
"int" => typeof(int),
205205
"float" => typeof(float),
206+
"boolean" => typeof(bool),
206207
_ => throw new ArgumentOutOfRangeException(nameof(type))
207208
};
208209

@@ -222,10 +223,12 @@ private static object parseDefault(string type, string? defaultFallback = defaul
222223
return type switch
223224
{
224225
"string" => defaultFallback ?? string.Empty,
225-
"int" => isEmpty ? 0 :
226+
"int" => isEmpty ? 0 :
226227
int.TryParse(defaultFallback, out var intValue) ? intValue : 0,
227-
"float" => isEmpty ? 0f :
228+
"float" => isEmpty ? 0f :
228229
float.TryParse(defaultFallback, out var floatValue) ? floatValue : 0f,
230+
"boolean" => isEmpty ? false :
231+
bool.TryParse(defaultFallback, out var boolValue) ? boolValue : false,
229232
_ => throw new ArgumentOutOfRangeException(nameof(type))
230233
};
231234
}
@@ -237,9 +240,9 @@ public class ParameterDefinition
237240
public string Key { get; }
238241
public string Title { get; }
239242
public Type Type { get; }
240-
243+
241244
private readonly object defaultFallback;
242-
245+
243246
public T GetDefaultFallback<T>() => (T)defaultFallback ?? default;
244247

245248
public ParameterDefinition(string key, string title, Type type, object defaultFallback = default)

scripting/library/enums.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ function Anchor(input) end
8181
---@alias ParameterDefinitionType string
8282
---| "string"
8383
---| "int"
84-
---| "float"
84+
---| "float"
85+
---| "boolean"

0 commit comments

Comments
 (0)