初始化工程

This commit is contained in:
2025-07-15 15:33:35 +08:00
parent ead49da3e8
commit bbd78128d0
301 changed files with 23953 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
using System.Collections.Generic;
using SimpleJSON;
using Luban;
{{namespace_with_grace_begin __namespace_with_top_module}}
{{~if __this.comment != '' ~}}
/// <summary>
/// {{escape_comment __this.comment}}
/// </summary>
{{~end~}}
public {{class_modifier __bean}} class {{__name}} : {{if __parent_def_type}} {{__this.parent}} {{else}} Luban.EditorBeanBase {{end}}
{
public {{__name}}()
{
{{~ for field in __fields ~}}
{{~if (need_init field.ctype) && !field.ctype.is_nullable ~}}
{{format_field_name __code_style field.name}} = {{init_value field.ctype}};
{{~end~}}
{{~end~}}
}
{{~if !__this.is_abstract_type~}}
public override void LoadJson(SimpleJSON.JSONObject _json)
{
{{~ for field in __hierarchy_fields ~}}
{
var _fieldJson = _json["{{field.name}}"];
if (_fieldJson != null)
{
{{deserialize '_fieldJson' (format_field_name __code_style field.name) field.ctype}}
}
}
{{~end~}}
}
public override void SaveJson(SimpleJSON.JSONObject _json)
{
{{~if parent~}}
_json["$type"] = "{{__this.full_name}}";
{{~end~}}
{{~ for field in __hierarchy_fields ~}}
{{~if field.ctype.is_nullable}}
if ({{format_field_name __code_style field.name}} != null)
{
{{serialize '_json' field.name (format_field_name __code_style field.name) field.ctype}}
}
{{~else~}}
{
{{~if (is_raw_nullable field.ctype)}}
if ({{format_field_name __code_style field.name}} == null) { throw new System.ArgumentNullException(); }
{{~end~}}
{{serialize '_json' field.name (format_field_name __code_style field.name) field.ctype}}
}
{{~end~}}
{{~end~}}
}
{{~end~}}
public static {{__name}} LoadJson{{__name}}(SimpleJSON.JSONNode _json)
{
{{~if __this.is_abstract_type~}}
string type = _json["$type"];
{{__name}} obj;
switch (type)
{
{{~for child in __this.hierarchy_not_abstract_children~}}
{{~if child.namespace == __this.namespace && __this.namespace != '' ~}}
case "{{child.full_name}}":
{{~end~}}
case "{{impl_data_type child __this}}":obj = new {{child.full_name}}(); break;
{{~end~}}
default: throw new SerializationException();
}
{{~else~}}
{{__name}} obj = new {{__this.full_name}}();
{{~end~}}
obj.LoadJson((SimpleJSON.JSONObject)_json);
return obj;
}
public static void SaveJson{{__name}}({{__name}} _obj, SimpleJSON.JSONNode _json)
{
{{~if __this.is_abstract_type~}}
_json["$type"] = _obj.GetType().Name;
{{~end~}}
_obj.SaveJson((SimpleJSON.JSONObject)_json);
}
{{~ for field in __fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{escape_comment field.comment}}
/// </summary>
{{~end~}}
public {{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}};
{{~end~}}
}
{{namespace_with_grace_end __namespace_with_top_module}}

View File

@@ -0,0 +1,59 @@
{{~
comment = __enum.comment
items = __enum.items
itemType = 'Luban.EditorEnumItemInfo'
~}}
{{namespace_with_grace_begin __namespace_with_top_module}}
{{~if comment != '' ~}}
/// <summary>
/// {{escape_comment comment}}
/// </summary>
{{~end~}}
{{~if __enum.is_flags~}}
[System.Flags]
{{~end~}}
public enum {{__name}}
{
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
/// <summary>
/// {{escape_comment item.comment_or_alias}}
/// </summary>
{{~end~}}
{{format_enum_item_name __code_style item.name}} = {{item.value}},
{{~end~}}
}
public static class {{__name}}_Metadata
{
{{~ for item in items ~}}
public static readonly {{itemType}} {{item.name}} = new {{itemType}}("{{item.name}}", "{{item.alias}}", {{item.int_value}}, "{{item.comment}}");
{{~end~}}
private static readonly System.Collections.Generic.List<{{itemType}}> __items = new System.Collections.Generic.List<{{itemType}}>
{
{{~ for item in items ~}}
{{item.name}},
{{~end~}}
};
public static System.Collections.Generic.List<{{itemType}}> GetItems() => __items;
public static {{itemType}} GetByName(string name)
{
return __items.Find(c => c.Name == name);
}
public static {{itemType}} GetByNameOrAlias(string name)
{
return __items.Find(c => c.Name == name || c.Alias == name);
}
public static {{itemType}} GetByValue(int value)
{
return __items.Find(c => c.Value == value);
}
}
{{namespace_with_grace_end __namespace_with_top_module}}