Esempio n. 1
0
    public void StartWorld()
    {
        Input.SetMouseMode(Input.MouseMode.Visible);
        PackedScene main = (PackedScene)ResourceLoader.Load("res://Maps/lastresort_b5.tscn");
        Spatial     inst = (Spatial)main.Instance();
        Initial     of   = GetNode("/root/Initial") as Initial;

        of.AddChild(inst);

        Spatial entitySpawns = GetNode("/root/Initial/Map/QodotMap/Entity Spawns") as Spatial;

        Godot.Collections.Array ents = entitySpawns.GetChildren();

        foreach (Spatial ent in ents)
        {
            Godot.Collections.Dictionary fields = ent.Get("properties") as Godot.Collections.Dictionary;

            if (fields != null)
            {
                foreach (DictionaryEntry kvp in fields)
                {
                    if (kvp.Key.ToString().ToLower().Contains("classname"))
                    {
                        switch (kvp.Value.ToString().ToLower())
                        {
                        case "info_player_start":
                            foreach (DictionaryEntry kvp2 in fields)
                            {
                                switch (kvp2.Key.ToString().ToLower())
                                {
                                case "allowteams":
                                    string team = kvp2.Value.ToString().ToLower();
                                    if (team.Contains("blue"))
                                    {
                                        spawnsTeam1.Add(ent);
                                    }
                                    if (team.Contains("red"))
                                    {
                                        spawnsTeam2.Add(ent);
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }

        Spatial triggers = GetNode("/root/Initial/Map/QodotMap/Triggers") as Spatial;

        Godot.Collections.Array triggerents = triggers.GetChildren();
        List <Trigger_Door>     doors       = new List <Trigger_Door>();

        foreach (Area ent in triggerents)
        {
            Godot.Collections.Dictionary fields = ent.Get("properties") as Godot.Collections.Dictionary;

            foreach (DictionaryEntry kvp in fields)
            {
                if (kvp.Key.ToString().ToLower() == "classname")
                {
                    if (kvp.Value.ToString().ToLower() == "trigger_door")
                    {
                        // https://github.com/godotengine/godot/issues/31994#issuecomment-570073343
                        ulong objId = Convert.ToUInt64(ent.GetInstanceId());
                        ent.SetScript(ResourceLoader.Load("Scripts/Trigger_Door.cs"));

                        Trigger_Door newEnt = GD.InstanceFromId(objId) as Trigger_Door;
                        newEnt.SetProcess(true);
                        newEnt.Notification(NotificationReady);
                        newEnt.Init(fields);

                        doors.Add(newEnt);
                    }
                }
            }
        }

        this.LinkDoors(doors);
    }