mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
use URL-style string escaping
This commit is contained in:
parent
e82b02b0e5
commit
a6e2edc475
Binary file not shown.
@ -91,7 +91,6 @@
|
|||||||
<Compile Include="Text/TextRenderer.cs" />
|
<Compile Include="Text/TextRenderer.cs" />
|
||||||
<Compile Include="Text/DecalText.cs" />
|
<Compile Include="Text/DecalText.cs" />
|
||||||
<Compile Include="Text\DecalTextStyle.cs" />
|
<Compile Include="Text\DecalTextStyle.cs" />
|
||||||
<Compile Include="Text\TextEncoder.cs" />
|
|
||||||
<Compile Include="Text\TextRenderOutput.cs" />
|
<Compile Include="Text\TextRenderOutput.cs" />
|
||||||
<Compile Include="Text\TextRenderJob.cs" />
|
<Compile Include="Text\TextRenderJob.cs" />
|
||||||
<Compile Include="UI/ColorPickerController.cs" />
|
<Compile Include="UI/ColorPickerController.cs" />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Net;
|
||||||
using ConformalDecals.MaterialProperties;
|
using ConformalDecals.MaterialProperties;
|
||||||
using ConformalDecals.Text;
|
using ConformalDecals.Text;
|
||||||
using ConformalDecals.UI;
|
using ConformalDecals.UI;
|
||||||
@ -27,7 +28,7 @@ namespace ConformalDecals {
|
|||||||
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-text", guiActive = false, guiActiveEditor = true)]
|
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-text", guiActive = false, guiActiveEditor = true)]
|
||||||
public void SetText() {
|
public void SetText() {
|
||||||
if (_textEntryController == null) {
|
if (_textEntryController == null) {
|
||||||
_textEntryController = TextEntryController.Create(text, _font, _style, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
_textEntryController = TextEntryController.Create(_text, _font, _style, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_textEntryController.Close();
|
_textEntryController.Close();
|
||||||
@ -75,6 +76,7 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string _text;
|
||||||
private DecalTextStyle _style;
|
private DecalTextStyle _style;
|
||||||
private DecalFont _font;
|
private DecalFont _font;
|
||||||
private Color32 _fillColor;
|
private Color32 _fillColor;
|
||||||
@ -99,7 +101,6 @@ namespace ConformalDecals {
|
|||||||
public override void OnLoad(ConfigNode node) {
|
public override void OnLoad(ConfigNode node) {
|
||||||
base.OnLoad(node);
|
base.OnLoad(node);
|
||||||
OnAfterDeserialize();
|
OnAfterDeserialize();
|
||||||
text = TextEncoder.Decode(text);
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
// For some reason, rendering doesnt work right on the first frame a scene is loaded
|
// For some reason, rendering doesnt work right on the first frame a scene is loaded
|
||||||
@ -113,7 +114,6 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSave(ConfigNode node) {
|
public override void OnSave(ConfigNode node) {
|
||||||
text = TextEncoder.Encode(text);
|
|
||||||
OnBeforeSerialize();
|
OnBeforeSerialize();
|
||||||
base.OnSave(node);
|
base.OnSave(node);
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) {
|
public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) {
|
||||||
text = newText;
|
_text = newText;
|
||||||
_font = newFont;
|
_font = newFont;
|
||||||
_style = newStyle;
|
_style = newStyle;
|
||||||
UpdateTextRecursive();
|
UpdateTextRecursive();
|
||||||
@ -203,6 +203,7 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnBeforeSerialize() {
|
public void OnBeforeSerialize() {
|
||||||
|
text = WebUtility.UrlEncode(_text);
|
||||||
fontName = _font.Name;
|
fontName = _font.Name;
|
||||||
style = (int) _style.FontStyle;
|
style = (int) _style.FontStyle;
|
||||||
vertical = _style.Vertical;
|
vertical = _style.Vertical;
|
||||||
@ -213,6 +214,7 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnAfterDeserialize() {
|
public void OnAfterDeserialize() {
|
||||||
|
_text = WebUtility.UrlDecode(text);
|
||||||
_font = DecalConfig.GetFont(fontName);
|
_font = DecalConfig.GetFont(fontName);
|
||||||
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
|
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
|
||||||
|
|
||||||
@ -247,7 +249,7 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
var decal = counterpart.GetComponent<ModuleConformalText>();
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
||||||
decal.text = text;
|
decal._text = _text;
|
||||||
decal._font = _font;
|
decal._font = _font;
|
||||||
decal._style = _style;
|
decal._style = _style;
|
||||||
|
|
||||||
@ -264,7 +266,7 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
private void UpdateText() {
|
private void UpdateText() {
|
||||||
// Render text
|
// Render text
|
||||||
var newText = new DecalText(text, _font, _style);
|
var newText = new DecalText(_text, _font, _style);
|
||||||
var output = TextRenderer.UpdateTextNow(_currentText, newText);
|
var output = TextRenderer.UpdateTextNow(_currentText, newText);
|
||||||
_currentText = newText;
|
_currentText = newText;
|
||||||
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user