kiriri / gd2cs.py

Regex based Python script that converts arbitrary gdscript code to C#
GNU General Public License v3.0
87 stars 12 forks source link

Function brackets put in the wrong spot #2

Closed cgbeutler closed 3 years ago

cgbeutler commented 3 years ago

In my result file I am getting every function formatted with brackets in the wrong place. Example of output issue:

using System;
using Godot;
using Dictionary = Godot.Collections.Dictionary;
using Array = Godot.Collections.Array;

[Tool]
public class array : Godot.Object
{

    class_name array_ext

    static public Dictionary create_lookup( Array src, String field_name )
     {   
     }

        var result := new Dictionary(){}
        foreach(var item in src)
        {
            var key = item.get(field_name);
            if(!result.has(key))
                  result[key] = item;
        }
        return result;

}

Not sure what is causing the issue. The file has tabs, which I think is the Godot default:

tool
class_name array_ext

static func create_lookup( src :Array, field_name :String ) -> Dictionary:
    var result := {}
    for item in src:
        var key = item.get(field_name)
        if not result.has(key):  result[key] = item
    return result

As a side note, the file doesn't have a extends type. The one added is Godot.Object, but Godot technically has a default of Reference for all non-explicit types.

kiriri commented 3 years ago

New output is

using System;
using Godot;
using Dictionary = Godot.Collections.Dictionary;
using Array = Godot.Collections.Array;

[Tool]
public class GameDataTest2 : Godot.Object
{

    public Dictionary create_lookup( Array src, String field_name )
    {  
        Dictionary result  = new Dictionary(){};
        foreach(var item in src)
        {
            var key = item.get(field_name);
            if(!result.has(key))
                  result[key] = item;
        }
        return result;
    }

}