-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeItem.cs
More file actions
46 lines (42 loc) · 1.68 KB
/
RuntimeItem.cs
File metadata and controls
46 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
namespace GameDialog.Lang
{
/// <summary>
/// Base type for all runtime items in the interpreter.
/// Provides a foundation for extensibility with future types like None, List, Index, etc.
/// </summary>
public abstract record RuntimeItem
{
/// <summary>
/// Gets the display name of the item type.
/// </summary>
public abstract string GetTypeName();
/// <summary>
/// The display name for runtime item types.
/// </summary>
public static string DisplayName => "item";
/// <summary>
/// Mapping of runtime item types to their display names.
/// </summary>
private static readonly Dictionary<Type, string> TypeDisplayNames = new()
{
{ typeof(RuntimeItem), RuntimeItem.DisplayName },
{ typeof(RuntimeValue), RuntimeValue.DisplayName },
{ typeof(RuntimeNumber), RuntimeNumber.DisplayName },
{ typeof(RuntimeInteger), RuntimeInteger.DisplayName },
{ typeof(RuntimeFloat), RuntimeFloat.DisplayName },
{ typeof(RuntimeString), RuntimeString.DisplayName },
{ typeof(RuntimeBoolean), RuntimeBoolean.DisplayName },
};
/// <summary>
/// Gets the display name for a specific runtime item type.
/// </summary>
public static string GetDisplayName<T>() where T : RuntimeItem
{
return TypeDisplayNames.TryGetValue(typeof(T), out var displayName)
? displayName
: throw new NotSupportedException($"Type {typeof(T).Name} is not a supported RuntimeItem type.");
}
}
}