IsaacMulcahy / RPG-AI-SYSTEM-WIKI

A wiki which covers how the RPG-AI-SYSTEM works and how to customize it
5 stars 0 forks source link

Can't open sample jobs in the workflow editor #11

Open Sanglyon opened 7 months ago

Sanglyon commented 7 months ago

Unity 2021.3.32f1 Packages: Civil-AI, Synthy PolygonFarm

In the workflow editor, when trying to load or import one of the samples, (Demo, Demo0.3.0, Weighting, Woodcutter), there's nothing loaded, and there's an exception raised in ImportNodesV2.LoadLayout(string file)) at the line:

candidate.position.x = float.Parse(columns[1]);

so I replaced

candidate.position.x = float.Parse(columns[1]); candidate.position.y = float.Parse(columns[2]);

with

candidate.position.x = 0.0f; float.TryParse(columns[1],out candidate.position.x); candidate.position.y = 0.00f; float.TryParse(columns[2], out candidate.position.y);

so that the nodes get at least loaded at the position 0,0 even if it fails to get the positions from the file.

Sanglyon commented 7 months ago

This is in fact a localisation issue. float.Parse is culture aware, so on my system that uses a decimal comma, it can't parse values that where saved on a system that uses a decimal dot.

This isn't an issue in half of the world (US, UK, Canada, Japan, Korea, India, etc...), which is quite a lot of people, sure, but it will be for the other half (the rest of Europe, South America, Indonesia,...)

You can use CultureInfo.InvariantCulture to ensure it works everywhere:

when saving : node.GetPosition().x.ToString(**CultureInfo.InvariantCulture**)

when loading : candidate.position.x = float.Parse(columns[1], **CultureInfo.InvariantCulture**);

And since the decimal separator for InvariantCulture is the dot, it works with the existing samples.