Removed a no-longer needed file.
Working on the builder. Made a dark-mode-friendly hightlight file for Browser .
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jint" />
|
||||
<PackageReference Include="Newtonsoft.Json" />
|
||||
<PackageReference Include="SkiaSharp" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
58
Progrart.Core/ProjectSystem/Builder.cs
Normal file
58
Progrart.Core/ProjectSystem/Builder.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Newtonsoft.Json;
|
||||
using Progrart.Core.JSExecution;
|
||||
|
||||
namespace Progrart.Core.ProjectSystem
|
||||
{
|
||||
public class Builder
|
||||
{
|
||||
public Project project;
|
||||
public string basePath;
|
||||
public Action<int, int>? OnProgressUpdate;
|
||||
public Action? OnCompleted;
|
||||
public Builder(StreamReader reader, string basePath)
|
||||
{
|
||||
var project = JsonConvert.DeserializeObject<Project>(reader.ReadToEnd());
|
||||
if (project is null) throw new JsonSerializationException();
|
||||
this.project = project;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
public Builder(Project project, string basePath)
|
||||
{
|
||||
this.project = project;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
public void Execute(BuildConfiguration config, BuildItem item)
|
||||
{
|
||||
FileInfo src = new FileInfo(Path.Combine(basePath, item.Source));
|
||||
FileInfo tgt = new FileInfo(Path.Combine(basePath, project.OutputDir, item.Target ?? item.Source + ".png"));
|
||||
var args = project.Arguments.Clone();
|
||||
args.MergeFrom(config.Arguments);
|
||||
args.MergeFrom(item.Arguments);
|
||||
ProgrartExecutor executor = new ProgrartExecutor();
|
||||
using var stream = src.OpenRead();
|
||||
using var reader = new StreamReader(stream);
|
||||
var img = executor.RenderImage(item.Size, reader.ReadToEnd(), args);
|
||||
using var img_stream = tgt.OpenWrite();
|
||||
img.DrawingCore.ToData().SaveTo(img_stream);
|
||||
img_stream.Flush();
|
||||
}
|
||||
public void Build(string targetConfig)
|
||||
{
|
||||
foreach (var config in project.Configurations)
|
||||
{
|
||||
if (config.Name == targetConfig)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var item in config.Items)
|
||||
{
|
||||
Execute(config, item);
|
||||
index++;
|
||||
OnProgressUpdate?.Invoke(config.Items.Count, index);
|
||||
}
|
||||
OnCompleted?.Invoke();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,18 +7,24 @@ namespace Progrart.Core.ProjectSystem
|
||||
[Serializable]
|
||||
public class Project
|
||||
{
|
||||
public string OutputDir = "output";
|
||||
public List<BuildConfiguration> Configurations = new List<BuildConfiguration>();
|
||||
public ExecuteArguments Arguments = new ExecuteArguments();
|
||||
}
|
||||
[Serializable]
|
||||
public class BuildConfiguration
|
||||
{
|
||||
public string? Name;
|
||||
public string? OutputDir;
|
||||
public List<BuildItem> Items = new List<BuildItem>();
|
||||
public ExecuteArguments Arguments = new ExecuteArguments();
|
||||
}
|
||||
[Serializable]
|
||||
public class BuildItem
|
||||
{
|
||||
public string? Source;
|
||||
public string Source = "";
|
||||
public string? Target;
|
||||
public int Size;
|
||||
public ExecuteArguments Arguments = new ExecuteArguments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Progrart.Core
|
||||
}
|
||||
public float TranslateSize(float s)
|
||||
{
|
||||
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height)/ Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
|
||||
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height) / Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
|
||||
}
|
||||
public RenderContext(int W, int H)
|
||||
{
|
||||
@@ -61,10 +61,27 @@ namespace Progrart.Core
|
||||
surface.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ExecuteArguments
|
||||
{
|
||||
public Dictionary<string, string> data = new Dictionary<string, string>();
|
||||
public ExecuteArguments Clone()
|
||||
{
|
||||
ExecuteArguments args = new ExecuteArguments();
|
||||
foreach (var item in data)
|
||||
{
|
||||
args.data.Add(item.Key, item.Value);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
public void MergeFrom(ExecuteArguments args)
|
||||
{
|
||||
|
||||
foreach (var item in args.data)
|
||||
{
|
||||
args.data.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class RenderConfig
|
||||
|
||||
Reference in New Issue
Block a user