(f0d812055) v0.9.9.0
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public class RichTextData
|
||||
{
|
||||
public int StartIndex, EndIndex;
|
||||
public Color? Color;
|
||||
public string Metadata;
|
||||
|
||||
private const char definitionIndicator = '‖';
|
||||
private const char attributeSeparator = ';';
|
||||
private const char keyValueSeparator = ':';
|
||||
//private const char lineChangeIndicator = '\n';
|
||||
|
||||
private const string colorDefinition = "color";
|
||||
private const string metadataDefinition = "metadata";
|
||||
private const string endDefinition = "end";
|
||||
|
||||
public static List<RichTextData> GetRichTextData(string text, out string sanitizedText)
|
||||
{
|
||||
List<RichTextData> textColors = null;
|
||||
sanitizedText = text;
|
||||
if (!string.IsNullOrEmpty(text) && text.Contains(definitionIndicator))
|
||||
{
|
||||
string[] segments = text.Split(definitionIndicator);
|
||||
|
||||
sanitizedText = string.Empty;
|
||||
|
||||
textColors = new List<RichTextData>();
|
||||
RichTextData tempData = null;
|
||||
|
||||
int prevIndex = 0;
|
||||
int currIndex = 0;
|
||||
for (int i=0;i<segments.Length;i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
sanitizedText += segments[i];
|
||||
prevIndex = currIndex;
|
||||
currIndex += segments[i].Replace("\n", "").Replace("\r", "").Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] attributes = segments[i].Split(attributeSeparator);
|
||||
for (int j=0;j<attributes.Length;j++)
|
||||
{
|
||||
if (attributes[j].Contains(endDefinition))
|
||||
{
|
||||
if (tempData != null)
|
||||
{
|
||||
tempData.StartIndex = prevIndex;
|
||||
tempData.EndIndex = currIndex - 1;
|
||||
textColors.Add(tempData);
|
||||
}
|
||||
tempData = null;
|
||||
}
|
||||
else if (attributes[j].StartsWith(colorDefinition))
|
||||
{
|
||||
if (tempData == null) { tempData = new RichTextData(); }
|
||||
string valueStr = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
|
||||
if (valueStr.Equals("null", System.StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
tempData.Color = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempData.Color = XMLExtensions.ParseColor(valueStr);
|
||||
}
|
||||
}
|
||||
else if (attributes[j].StartsWith(metadataDefinition))
|
||||
{
|
||||
if (tempData == null) { tempData = new RichTextData(); }
|
||||
tempData.Metadata = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return textColors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace Barotrauma
|
||||
Directory.CreateDirectory(TempPath);
|
||||
try
|
||||
{
|
||||
ClearFolder(TempPath, new string[] { GameMain.GameSession.Submarine.FilePath });
|
||||
ClearFolder(TempPath, new string[] { GameMain.GameSession.SubmarineInfo.FilePath });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -69,23 +69,10 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
if (Submarine.MainSub != null)
|
||||
if (GameMain.GameSession.SubmarineInfo != null)
|
||||
{
|
||||
string subPath = Path.Combine(TempPath, Submarine.MainSub.Name + ".sub");
|
||||
if (Submarine.Loaded.Contains(Submarine.MainSub))
|
||||
{
|
||||
Submarine.MainSub.FilePath = subPath;
|
||||
Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath);
|
||||
}
|
||||
else if (Submarine.MainSub.FilePath != subPath)
|
||||
{
|
||||
if (File.Exists(subPath))
|
||||
{
|
||||
File.Delete(subPath);
|
||||
}
|
||||
File.Copy(Submarine.MainSub.FilePath, subPath);
|
||||
Submarine.MainSub.FilePath = subPath;
|
||||
}
|
||||
string subPath = Path.Combine(TempPath, GameMain.GameSession.SubmarineInfo.Name + ".sub");
|
||||
GameMain.GameSession.SubmarineInfo.SaveAs(subPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -123,7 +110,7 @@ namespace Barotrauma
|
||||
if (doc == null) { return; }
|
||||
|
||||
string subPath = Path.Combine(TempPath, doc.Root.GetAttributeString("submarine", "")) + ".sub";
|
||||
Submarine selectedSub = new Submarine(subPath, "");
|
||||
SubmarineInfo selectedSub = new SubmarineInfo(subPath, "");
|
||||
GameMain.GameSession = new GameSession(selectedSub, filePath, doc);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,22 +26,22 @@ namespace Barotrauma
|
||||
|
||||
public static void Add(Task task, Action<Task> onCompletion)
|
||||
{
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion(t); }, null);
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion?.Invoke(t); }, null);
|
||||
}
|
||||
|
||||
public static void Add<U>(Task task, U userdata, Action<Task, U> onCompletion) where U : class
|
||||
{
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion(t, (U)obj); }, userdata);
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion?.Invoke(t, (U)obj); }, userdata);
|
||||
}
|
||||
|
||||
public static void Add<T>(Task<T> task, Action<Task<T>> onCompletion)
|
||||
{
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion((Task<T>)t); }, null);
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion?.Invoke((Task<T>)t); }, null);
|
||||
}
|
||||
|
||||
public static void Add<T,U>(Task<T> task, U userdata, Action<Task<T>, U> onCompletion) where U : class
|
||||
{
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion((Task<T>)t, (U)obj); }, userdata);
|
||||
AddInternal(task, (Task t, object obj) => { onCompletion?.Invoke((Task<T>)t, (U)obj); }, userdata);
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using System;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Barotrauma.Networking;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -151,7 +152,7 @@ namespace Barotrauma
|
||||
|
||||
public static string RemoveInvalidFileNameChars(string fileName)
|
||||
{
|
||||
var invalidChars = Path.GetInvalidFileNameChars();
|
||||
var invalidChars = Path.GetInvalidFileNameChars().Concat(new char[] {':', ';'});
|
||||
foreach (char invalidChar in invalidChars)
|
||||
{
|
||||
fileName = fileName.Replace(invalidChar.ToString(), "");
|
||||
@@ -589,5 +590,12 @@ namespace Barotrauma
|
||||
_ => t,
|
||||
};
|
||||
}
|
||||
|
||||
public static Rectangle GetWorldBounds(Point center, Point size)
|
||||
{
|
||||
Point halfSize = size.Divide(2);
|
||||
Point topLeft = new Point(center.X - halfSize.X, center.Y + halfSize.Y);
|
||||
return new Rectangle(topLeft, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user