mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Fix overlapping text and add text escaping
This commit is contained in:
31
Source/ConformalDecals/Text/TextEncoder.cs
Normal file
31
Source/ConformalDecals/Text/TextEncoder.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ConformalDecals.Text {
|
||||
public static class TextEncoder {
|
||||
private static readonly Dictionary<string, string> _escapeSequences = new Dictionary<string, string>() {
|
||||
{"\n", "\\n"},
|
||||
{"\\", "\\\\"},
|
||||
{"/", "\\/"},
|
||||
{"=", "\\="}
|
||||
};
|
||||
|
||||
public static string Encode(string input) {
|
||||
var builder = new StringBuilder(input);
|
||||
foreach (var escapePair in _escapeSequences) {
|
||||
builder.Replace(escapePair.Key, escapePair.Value);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string Decode(string input) {
|
||||
var builder = new StringBuilder(input);
|
||||
foreach (var escapePair in _escapeSequences) {
|
||||
builder.Replace(escapePair.Value, escapePair.Key);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -280,25 +280,13 @@ namespace ConformalDecals.Text {
|
||||
RenderTexture.ReleaseTemporary(renderTex);
|
||||
|
||||
// CLEAR SUBMESHES
|
||||
_tmp.text = "";
|
||||
|
||||
for (int i = 0; i < transform.childCount; i++) {
|
||||
var child = transform.GetChild(i);
|
||||
var renderer = child.GetComponent<MeshRenderer>();
|
||||
var filter = child.GetComponent<MeshFilter>();
|
||||
if (filter == null || renderer == null) {
|
||||
Logging.Log("TMP Sub object has no filter or renderer, destroying");
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
if (filter.mesh.vertexCount < 3) {
|
||||
Logging.Log("TMP Sub object has no mesh, destroying");
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
renderer.enabled = false;
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
_tmp.ClearMesh(true);
|
||||
|
||||
return new TextRenderOutput(texture, window);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user