Exemplo n.º 1
0
    private Array <Dictionary <string, Color> > ParseFile()
    {
        var output = new Array <Dictionary <string, Color> >();

        var file = new File();

        file.Open(FileName, File.ModeFlags.Read);

        while (!file.EofReached())
        {
            var line      = file.GetLine();
            var colorName = line.Split(" ")[0];
            var regex     = new RegEx();
            regex.Compile("\\( .* \\)");
            var result          = regex.Search(line);
            var colorStr        = result.Strings[0] as string;
            var cleanedColorStr = colorStr.Replace("(", "").Replace(")", "").Replace(" ", "");
            var splitted        = cleanedColorStr.Split(",");

            var dic = new Dictionary <string, Color>
            {
                [colorName] = new Color(
                    float.Parse(splitted[0]),
                    float.Parse(splitted[1]),
                    float.Parse(splitted[2]),
                    float.Parse(splitted[3])
                    )
            };

            output.Add(dic);
        }

        return(output);
    }
Exemplo n.º 2
0
    // ConfigFile config;
    // const string configPath = "user://settings.cfg";
    // public override void _Ready() {
    //  config = new ConfigFile();
    //  config.Load(configPath);
    //  GD.Print(config.GetValue(section, key, ""));
    //  EmitSignal(nameof(DataPathSet), config.GetValue(section, key, ""));
    // }

    // private const string section = "", key = "GamePath";

    // [Signal]
    // public delegate void DataPathSet(string path);

    // public string dataPath {
    //  get => LR2Dir.Path;
    //  set {
    //      LR2Dir.Path = value;
    //  }
    // }

    // public void DataPathSelected(string path) {
    //  dataPath = path;
    //  EmitSignal(nameof(DataPathSet), path);
    // }

    // public string ResolvePath(string path) => LR2Dir.ResolvePath(path);

    //This function corrects the case sensitivity of filenames, not needed on windows but I couldn't be bothered to disable it
    // public static string ResolvePathStatic(string dataPath, string path) {
    //  Directory currentDir = new Directory();
    //  currentDir.Open(dataPath);

    //  string next = "";

    //  foreach (var pathDir in path.Split(new char[] { '/', '\\' })) {
    //      currentDir.ListDirBegin(true, true);
    //      do {
    //          next = currentDir.GetNext();
    //          if (next == "") {
    //              GD.PrintErr("Unable to resolve \"" + path + "\" with dataPath \"" + dataPath + "\"");
    //              return null;
    //          }
    //      } while (next.ToLower() != pathDir.ToLower());
    //      currentDir.ListDirEnd();
    //      currentDir.ChangeDir(next);
    //  }
    //  return currentDir.GetCurrentDir() + "/" + next;
    // }

    public void DeduceDataPath(string path)
    {
        if (LR2Dir.Path == "")
        {
            var regex = new RegEx();
            regex.Compile("^(.*[\\/\\\\]).*[\\/\\\\].*[\\/\\\\].*$");
            var result   = regex.Search(path);
            var gamePath = result.GetString(1);
            LR2Dir.Path = gamePath;
        }
    }
Exemplo n.º 3
0
        public CHECK recheck(RegEx regex, string value)
        {
            if (regex != null)
            {
                _rematch = regex.Search(value);

                if (_rematch != null)
                {
                    return(CHECK.OK);
                }
            }

            return(CHECK.FAILED);
        }
Exemplo n.º 4
0
        /**
         * Check if the given tile is a wall.
         * If it is, add it to the given graph reference.
         */
        private static void ComputeWall(String name, int x, int y, ref Graph.Graph graph)
        {
            // Prepare the regex matcher.
            RegEx rgx = new RegEx();

            rgx.Compile("^Wall([SOW])_([TLBR]{1})(Door)?.*$");

            // Get and check the result of the regex.
            RegExMatch result = rgx.Search(name);

            if (result != null)
            {
                // Get the type of wall.
                Tile.WallType type = Tile.WallType.WOOD;
                switch (result.GetString(1))
                {
                case "S": type = Tile.WallType.STONE;    break;

                case "O": type = Tile.WallType.OBSIDIAN; break;

                case "W": type = Tile.WallType.WOOD;     break;
                }

                Tile.Orientation dir = Tile.Orientation.OTHER;
                switch (result.GetString(2))
                {
                case "T": dir = Tile.Orientation.TOP; break;

                case "B": dir = Tile.Orientation.BOTTOM; break;

                case "L": dir = Tile.Orientation.LEFT; break;

                case "R": dir = Tile.Orientation.RIGHT; break;
                }



                // Check if the given wall is a door.
                bool bIsDoor = result.GetString(3).Equals("Door");

                // Create a new Wall instance.
                Tile.Wall wall = new Tile.Wall(type, bIsDoor, dir);
                wall.Position = new Vector2(x, y);

                // Add it to the graph object.
                graph.AddWall(wall, x, y);
            }
        }
Exemplo n.º 5
0
        /**
         * Check if the given tile is a vertex.
         * If it is, add it to the given graph reference.
         */
        private static void ComputeVertex(String name, int x, int y, ref Graph.Graph graph)
        {
            // Prepare the regex matcher.
            RegEx rgx = new RegEx();

            rgx.Compile("^Wall._[TBLR]{2}$|^(Tower)");

            // Get and check the result of the regex.
            RegExMatch result = rgx.Search(name);

            if (result != null)
            {
                // Check wether a tower was selected.
                bool bIsTower = result.GetString(1).Equals("Tower");

                // Create a new Vertex instance.
                Graph.Vertex vtx = new Graph.Vertex(x, y, graph.GetWallAt(new Vector2(x, y)));

                // Add the instance to the graph.
                graph.AddVertex(vtx);
            }
        }
Exemplo n.º 6
0
        /**
         * Computes the cost of a given tile.
         */
        private static void ComputeCost(int x, int y, TileMap map)
        {
            // Get the tile id.
            int tileID = map.GetCell(x, y);

            if (tileID > -1)
            {
                // Get the name of the tile.
                String tileName = map.TileSet.TileGetName(tileID);

                // Prepare the weight counter.
                float weight = 1;

                // Check the name of the tile.
                RegEx rgx = new RegEx();
                rgx.Compile("(Road|Wall|Tower|House|Well|Tree|Objective|Barrier)");
                RegExMatch result = rgx.Search(tileName);
                if (result != null)
                {
                    switch (result.GetString(1))
                    {
                    case "Wall":
                    case "Tower":
                    case "Well":
                    case "Tree":
                    case "House":
                    case "Barrier":
                    case "Objective":
                        weight = float.PositiveInfinity;
                        break;
                    }
                }

                // Add the weight.
                Pathfinder.AStar.AddCost(x, y, weight);
            }
        }
Exemplo n.º 7
0
        /**
         * Computes the resource on the given tile.
         */
        private static void ComputeResource(int x, int y, TileMap map, ref Graph.Graph graph)
        {
            // Get the face of the given resource.
            Graph.Face face = graph.GetFaceFromPoint(new Vector2(x, y));
            if (face != null)
            {
                // Prepare the regex of the tile name.
                RegEx rgx = new RegEx();
                rgx.Compile(".*(House|Well|Grass|Cow|Start|Objective).*");

                // Check the result.
                String     tileName = map.TileSet.TileGetName(map.GetCell(x, y));
                RegExMatch result   = rgx.Search(tileName);
                if (result != null)
                {
                    switch (result.GetString(1))
                    {
                    case "House":
                        face.zone.addHouse();
                        break;

                    case "Well":
                        face.zone.AddWell();
                        break;

                    case "Grass":
                        // Check the value of the grass.
                        rgx.Compile("([0-9])");
                        result = rgx.Search(tileName);
                        if (result != null)
                        {
                            face.zone.AddGrass(new Vector2(x, y), result.GetString(1).ToInt());
                        }
                        break;

                    case "Objective":
                        face.zone.IsObjective = true;
                        break;

                    case "Cow":
                        // Add a cow to the zone.
                        Tile.Cow cow = Tile.Cow.Instance();
                        cow.Position = new Vector2(x, y);
                        World.Instance.AddChild(cow);
                        face.zone.AddCow(cow);

                        // Remove the cow.
                        map.SetCell(x, y, -1);
                        break;

                    case "Start":
                        // Take the zone.
                        face.zone.TakeOver();

                        // Remove the start point.
                        map.SetCell(x, y, -1);
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
    public override void _Process(float delta)
    {
        Offset += speed * delta;
        if (UnitOffset == 1 && GetParent().Name == "MainPath")
        {
            EmitSignal(nameof(endMainPath), this);
        }
        else if (UnitOffset == 1 && GetParent().Name == "MainPathLeft")
        {
            EmitSignal(nameof(endMainPathLeft), this);
        }
        else if (UnitOffset == 1 && GetParent().Name == "MainPathRight")
        {
            EmitSignal(nameof(endMainPathRight), this);
        }

        if (global.setCount == 2)
        {
            speed = 180f;
        }
        else if (global.setCount >= 3)
        {
            speed = 200f;
        }

        if (global.mode == "Easy")
        {
            regex.Compile("@?Easy@?\\d*");
            resPath = regex.Search(GetPath());
            newPath = resPath.GetString();
            if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/EndPosition_y").GlobalPosition.y&& GetParent().Name == "LeftPath")
            {
                EmitSignal(nameof(reachEnd), "Left", colors, this, newPath);
            }
            else if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/EndPosition_y").GlobalPosition.y&& GetParent().Name == "RightPath")
            {
                EmitSignal(nameof(reachEnd), "Right", colors, this, newPath);
            }
        }
        else if (global.mode == "Hard")
        {
            regex.Compile("@?Hard@?\\d*");
            resPath = regex.Search(GetPath());
            newPath = resPath.GetString();
            if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/LeftEndPosition").GlobalPosition.y&& GetParent().Name == "LeftPath")
            {
                EmitSignal(nameof(reachEnd), "Left", colors, this, newPath);
            }
            else if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/MidEndPosition").GlobalPosition.y&& (GetParent().Name == "MiddlePath1" || GetParent().Name == "MiddlePath2"))
            {
                EmitSignal(nameof(reachEnd), "Middle", colors, this, newPath);
            }
            else if (Position.y >= GetNode <Position2D>("/root/HUD/" + newPath + "/RightEndPosition").GlobalPosition.y&& GetParent().Name == "RightPath")
            {
                EmitSignal(nameof(reachEnd), "Right", colors, this, newPath);
            }
        }

        if (Modulate.a < 0.3f)
        {
            QueueFree();
        }
    }