调整了模板

This commit is contained in:
CortexCore
2023-07-17 04:10:14 +08:00
parent 498b0617f8
commit e27cce2ac3
56 changed files with 2165 additions and 581 deletions

View File

@@ -0,0 +1,79 @@
using Godot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BITKit;
using BITKit.IO;
using Godot.Collections;
namespace BITFactory;
[GlobalClass]
public partial class IDIS_TemplateResource : TemplateResource
{
private static readonly List<FormResource> Templates=new();
private static InitializationState state = InitializationState.None;
private static string assetPath => PathHelper.GetPath("标识模板资源包.zip");
private static string entryPath => "Templates.json";
public override FormResource[] GetTemplates()
{
EnsureCreated();
return Templates.ToArray();
}
public override string[] GetTemplateNames()
{
EnsureCreated();
return Templates.Select(x => x.Name).ToArray();
}
public override FormResource GetTemplate(string name)
{
EnsureCreated();
return Templates.Single(x => x.Name == name);
}
public override bool IsSupportCreateTemplate => true;
public override void CreateTemplate()
{
Templates.Add(new IDIS_TemplateFormResource()
{
Name = "新的标识模板:"+Guid.NewGuid(),
Fields = new IFormField[]
{
new IDIS_TemplateForm()
}
});
}
private void EnsureCreated()
{
if (state != InitializationState.None) return;
if (File.Exists(assetPath))
{
foreach (var x in BITAssets.Read<KeyValuePair<string,IDIS_TemplateForm[]>[]>(assetPath, entryPath))
{
Templates.Add(new IDIS_TemplateFormResource()
{
Name = x.Key,
Fields = x.Value.Select(_=>_ as IFormField).ToArray()
});
}
}
state = InitializationState.Initialized;
}
public override void OnStop()
{
ManualSave();
}
public override void ManualSave()
{
// var values = new System.Collections.Generic.Dictionary<string, List<IFormField>>(
// Templates.Select(x=>new KeyValuePair<string, List<IFormField>>(
// x.Key,x.Value.Fields.ToList()
// ))
// );
var values = Templates.Select(x => new KeyValuePair<string, object>(
x.Name, x.Fields
));
BITAssets.Build(assetPath,new BITAsset(entryPath,JsonHelper.Get(values)));
}
}