LoGaCulture / LUTE

LUTE stands for LoGaCulture Unity Toolkit/Engine. A Unity based tool to create narrative rich location-based games for the purposes of heritage preservation.
MIT License
0 stars 0 forks source link

Saving as Blueprint has wrong coordinates in the node #28

Closed IoIoToTM closed 1 month ago

IoIoToTM commented 1 month ago

Trying to save a simple choice convergence as a Blueprint, when I try to add it back to a new empty project, it puts it at a very large distance from the centre. I am not sure if this is either because this specific example the coordinates are so far from the centre, or if there is something else happening. This is the collection of nodes I am trying to save, in the "FindTheStonesAR" scene in the Cookbook folder:

image

When I go into the Flow Engine and look into the actual Node Scripts, I can see their coordinates are very large:

image

I looked into the code when creating the Blueprint, maybe we want something that sets the nodes to a closer point to zero with an offset, like this (In GraphWindow.cs:3461):

 float xOffset = 0;
 float yOffset = 0;

 bool firstNode = false;

 //copy any relevant variables and set the values to the new engine
 foreach (var node in BPNodes)
 {

     if (firstNode == false)
     {
         xOffset = node._NodeRect.x;
         yOffset = node._NodeRect.y;
         firstNode = true;
     }

     //subtract the offset from the node position
     Rect nodeRect = node._NodeRect;
     nodeRect.x -= xOffset;
     nodeRect.y -= yOffset;
     node._NodeRect = nodeRect;

This currently actually resets the originals node position, so probably we would want to change the copy's position.

IoIoToTM commented 1 month ago

After further testing, it turned out that the problem was that the BasicGame Prefab starts your nodes at a very large coordinate, like 25000, while if you are creating an empty engine, it starts at 250. The blueprints I had created were made in the prefab, while to test them I was using an empty instance and created a new LUTE engine, so it put the blueprints at their original coordinates and there was a mismatch.

A potential solution would probably get the central position of the graph window (or a random visible point on the graph window), and then put the blueprint there, and then the user can drag it wherever they want.

IoIoToTM commented 1 month ago

I had a go at trying to implement a quick and dirty possible solution, it probably breaks other things, but basically, in the "AddBlueprint" function in "GraphWindow.cs:3461", I get the centreOffset through another function, and then use that to put the nodes in the middle of the graph, no matter where their original coordinates were:

public void AddBlueprint(List<Node> BPNodes, List<Group> BPGroups, BasicFlowEngine engine, BasicFlowEngine originalEngine = null)
    {

        float xOffset = 0;
        float yOffset = 0;

        bool firstNode = false;

        //get centre of original engine
        Vector2 centreOffset = GetNodeCentre(engine.GetComponents<Node>());

        //copy any relevant variables and set the values to the new engine
        foreach (var node in BPNodes)
        {
            if (node.NodeLocation != null)
            {
                var newLocVar = engine.AddVariable(node.NodeLocation.GetType(), node.NodeLocation.Key);
                newLocVar.Apply(SetOperator.Assign, node.NodeLocation);
                newLocVar.Scope = VariableScope.Global;
            }

            if (firstNode == false)
            {
                xOffset = node._NodeRect.x - centreOffset.x;
                yOffset = node._NodeRect.y - centreOffset.y;
                firstNode = true;
            }

            //subtract the offset from the node position
            Rect nodeRect = node._NodeRect;
            nodeRect.x -= xOffset;
            nodeRect.y -= yOffset;
            node._NodeRect = nodeRect;

I tested it and it spawns the 25000 nodes exactly in the middle where it should.

Jacki3 commented 1 month ago

The fix @IoIoToTM has provided was a viable solution and has worked well. Blueprints will now be placed at the central point of any nodes that are in the window with a small offset to avoid too much covering of exisiting nodes.

Closing this issue as resolved based on this fix.