rj-action-library/Runtime/XML/XMLReaderTest.cs

85 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Godot;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class XMLReaderTest:Node
{
[Export]
public string path;
[Export]
public bool loadFile;
public override void _Process( double delta )
{
if ( ! loadFile )
{
return;
}
Load();
}
void Load()
{
loadFile = false;
var text = FilesSync.LoadUTF8( path );
var reader = new XMLReader();
var doc = reader.Read( text );
var paths = doc.querySelectorAll( SVGElementName.path );
RJLog.Log( "paths:", paths.Count );
paths.ForEach(
( p ) =>
{
var pathData = SVGAttributeName.d.Get( p );
if ( pathData == null )
{
RJLog.Log( "No path data found:", p );
return;
}
RJLog.Log( "pathData:", pathData );
var commands = SVGPathParser.Parse( pathData );
if ( commands != null )
{
RJLog.Log( "Commands:", commands.Count, "\n" + Lists.Join( commands, "\n" ) );
var extractor = new SVGPathExtractor();
extractor.onInstruction.AddAction(
( si )=>
{
RJLog.Log( si );
}
);
extractor.Process( commands );
}
else
{
var messages = SVGPathParser.GetMessages( pathData );
RJLog.Log( "Commands failed parsing:", Lists.Join( messages, "\n" ) );
}
}
);
}
}
}