mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Move RobustXaml to a shared package In a near-future change, I'll make it possible to optionally link to this from Robust.Client, which will allow JIT compiling XAML. Also upgrade it to a version of .NET that supports nullability annotations. * Re-namespace packages * Add a JIT compiler, plus hooks that call into it In Debug, after this change, all XAML will be hot reloaded once every time an assembly is reloaded. The new code is compiled with SRE and is _not_ sandboxed -- this is not suitable to run against prod. In Release, the hot reload path is totally skipped, using the same trick as SmugLeaf used in an earlier attempt to implement this functionality. * Hot reload: watcher This is a bit of a horror, but there's not in-engine support for identifying the source tree or the XAML files in it. * Put everything dangerous behind conditional comp * Code cleanup, docs * Fix a bad comment * Deal a little better with crashes in the watcher * Make reload failures Info, since they're expected They were previously causing the integration tests to flag, even though "a few types fail hot reloading because they're internal" is expected behavior. * Fix an unnecessary null check I removed the ability for CompileCore to return null. * injectors: null! strings, default primitives * Tidy documentation (thanks, PJB!) * Reinstate netstandard2.0, abolish Pidgin * Internal-ize all of Robust.Xaml * Add a cautionary note to Sandbox.yml * Shuffle around where conditional compilation occurs * Privatize fields in XamlImplementationStorage * Internalize XamlJitDelegate * Inline some remarks. No cond. comp in Robust.Xaml * Use file-scoped namespaces They aren't allowed at Language Level 8.0. (which I arbitrarily picked for Robust.Xaml because it's the oldest one that would work) * Bump language level for R.Xaml, file namespaces * Force hot reloading off for integration tests * Fix bizarre comment/behavior in XamlImplementationStorage * Consistently use interfaces, even in generated code * Update Robust.Client/ClientIoC.cs --------- Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
114 lines
3.4 KiB
C#
114 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Robust.Xaml;
|
|
|
|
internal static class MathParsing
|
|
{
|
|
private static float[]? ParseSingleArr(string input)
|
|
{
|
|
// Transliteration note: The original patterns in this file were Pidgin parsers
|
|
// All of them were variations on Real.Select(c => (float c)).Between(SkipWhiteSpaces).Repeat(n)
|
|
// They somehow handled commas too, but I don't know how
|
|
//
|
|
// SkipWhitespace splits based on char.IsWhitespace:
|
|
// https://github.com/benjamin-hodgson/Pidgin/blob/cc72abb/Pidgin/Parser.Whitespace.cs#L30
|
|
var items = SplitStringByFunction(input, (c) => c == ',' || char.IsWhiteSpace(c));
|
|
var outs = new float[items.Count];
|
|
|
|
for (var i = 0; i < outs.Length; i++)
|
|
{
|
|
// Parser.Real ultimately resorts to double.TryParse
|
|
// https://github.com/benjamin-hodgson/Pidgin/blob/cc72abb/Pidgin/Parser.Number.cs#L222
|
|
var parsed = double.TryParse(
|
|
items[i],
|
|
NumberStyles.Float | NumberStyles.AllowExponent | NumberStyles.AllowLeadingSign,
|
|
CultureInfo.InvariantCulture,
|
|
out var d
|
|
);
|
|
if (!parsed)
|
|
{
|
|
return null;
|
|
}
|
|
outs[i] = (float)d;
|
|
}
|
|
|
|
return outs;
|
|
}
|
|
|
|
private static List<string> SplitStringByFunction(string s, Func<char, bool> isSeparator)
|
|
{
|
|
// we want to split by commas _or_ char.IsWhitespace
|
|
// C#'s Split() can do one but not both
|
|
var splitItems = new List<string>();
|
|
var itemInProgress = new StringBuilder();
|
|
foreach (var c in s)
|
|
{
|
|
if (isSeparator(c))
|
|
{
|
|
if (itemInProgress.Length > 0)
|
|
{
|
|
splitItems.Add(itemInProgress.ToString());
|
|
itemInProgress.Clear();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
itemInProgress.Append(c);
|
|
}
|
|
}
|
|
|
|
if (itemInProgress.Length > 0)
|
|
{
|
|
splitItems.Add(itemInProgress.ToString());
|
|
}
|
|
|
|
return splitItems;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse a vector of two floats separated by commas or spaces, such as
|
|
/// "1,2" or "1.5 2.5"
|
|
/// </summary>
|
|
/// <param name="s">the string representation of the vector</param>
|
|
/// <returns>the parsed floats, or null if parsing failed</returns>
|
|
public static (float, float)? ParseVector2(string s)
|
|
{
|
|
var arr = ParseSingleArr(s);
|
|
if (arr == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (arr.Length == 2)
|
|
{
|
|
return (arr[0], arr[1]);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse a vector of one, two, or four floats separated by commas or
|
|
/// spaces, such as "1", "1e2,2e3" or ".1,.2,.3,.4"
|
|
/// </summary>
|
|
/// <param name="s">the string representation of the vector</param>
|
|
/// <returns>the parsed floats, or null if parsing failed</returns>
|
|
public static float[]? ParseThickness(string s)
|
|
{
|
|
var arr = ParseSingleArr(s);
|
|
if (arr == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (arr.Length == 1 || arr.Length == 2 || arr.Length == 4)
|
|
{
|
|
return arr;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|