先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace Coffee.UISoftMaskInternal.AssetModification
|
|
{
|
|
internal class TextAssetModifier : Modifier
|
|
{
|
|
public ITextModifier[] textModifiers;
|
|
protected override string id => "Text";
|
|
protected virtual string savePath => path;
|
|
|
|
protected override bool RunModify(bool dryRun)
|
|
{
|
|
using (var scope = new EditScope(path, savePath))
|
|
{
|
|
foreach (var line in scope.lines)
|
|
{
|
|
if (!ModifyLine(scope.sb, line))
|
|
{
|
|
scope.sb.AppendLine(line);
|
|
}
|
|
}
|
|
|
|
var changed = File.ReadAllText(path) != scope.sb.ToString();
|
|
if (!dryRun && changed)
|
|
{
|
|
scope.Save();
|
|
}
|
|
|
|
return changed;
|
|
}
|
|
}
|
|
|
|
private bool ModifyLine(StringBuilder sb, string line)
|
|
{
|
|
foreach (var modifier in textModifiers)
|
|
{
|
|
if (modifier.ModifyText(sb, line))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private readonly struct EditScope : IDisposable
|
|
{
|
|
private static readonly StringBuilder s_File = new StringBuilder();
|
|
private readonly string _path;
|
|
private readonly string _savePath;
|
|
public IEnumerable<string> lines => File.ReadLines(_path);
|
|
public StringBuilder sb => s_File;
|
|
|
|
public EditScope(string path, string savePath)
|
|
{
|
|
s_File.Length = 0;
|
|
_path = path;
|
|
_savePath = savePath;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
File.WriteAllText(_savePath, sb.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|