示例#1
0
    public BrickGroup ToGroup(bool includeID = false)
    {
        BrickGroup g = new BrickGroup();

        g.Name = Name;
        if (includeID)
        {
            g.ID = ID;
        }
        return(g);
    }
示例#2
0
    private static Map Parse02BRK(string path)
    {
        Map    map   = new Map(); // map that will be outputted
        string name  = Path.GetFileNameWithoutExtension(path);
        string input = File.ReadAllText(path);

        string[] lines = input.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); // split all the lines of the input into separate strings, and remove empty lines

        map.Name = name;

        // the first 7 lines (including whitespace) should be the map info.
        //map.Version = lines[0]; // this is the line that says which version of workshop the map was created with
        map.AmbientColor   = Helper.StringToColor(lines[1], true); // for some reason, the ambient color is in BGR format. why?
        map.BaseplateColor = Helper.StringToColor(lines[2], true); // same as above
        map.SkyColor       = Helper.StringToColor(lines[3]);       // this however, is RGB. wack
        map.BaseplateSize  = int.Parse(lines[4], CultureInfo.InvariantCulture);
        map.SunIntensity   = int.Parse(lines[5], CultureInfo.InvariantCulture);

        int currentID = 0;                                         // this will be incremented when a brick or group is defined
        List <BrickGroup> startedGroups = new List <BrickGroup>(); // when groups are defined, they are added to this list, and removed when they are ended

        // iterate through lines
        for (int i = 6; i < lines.Length; i++)
        {
            string line = lines[i].Trim(); // get the line without any leading or trailing whitepsaces for easy parsing
            if (line[0] != '+')
            {
                // this line is either defining a new brick or something else that isn't a brick property
                if (line.StartsWith(">TEAM"))
                {
                    // this line is clearly defining a team
                    Team t = new Team();
                    t.Name = line.Substring(6);

                    if (lines.Length > i + 1)
                    {
                        string nextLine = lines[i + 1].Trim();
                        if (nextLine.StartsWith("+COLOR"))
                        {
                            t.TeamColor = Helper.StringToColor(nextLine.Substring(7));
                        }
                    }

                    map.Teams.Add(t);
                    i++; // increment i since we handled 2 lines
                }
                else if (line.StartsWith(">SLOT"))
                {
                    // this line is defining an item, but those are history so ignore them
                    continue;
                }
                else if (line.StartsWith(">CAMPOS"))
                {
                    // this line is defining the camera position/rotation. this is created by brickbuilder
                    // TODO
                }
                else if (line.StartsWith(">SUNROT"))
                {
                    // this line is defining the sun rotation. this is created by brickbuilder.
                    // TODO
                }
                else if (line.StartsWith(">GROUP"))
                {
                    // this line is defining a new group. this is created by brickbuilder.
                    BrickGroup newGroup = new BrickGroup();
                    newGroup.Name = line.Substring(7);
                    newGroup.ID   = currentID;

                    if (startedGroups.Count > 0)
                    {
                        startedGroups[startedGroups.Count - 1].Children.Add(currentID); // there is already an opened group, which means this group is a child of that group
                        newGroup.Parent = startedGroups[startedGroups.Count - 1];
                    }

                    startedGroups.Add(newGroup);
                    map.Groups.Add(newGroup);
                    map.MapElements.Add(currentID, newGroup);
                    map.lastID = currentID;
                    currentID++;
                }
                else if (line.StartsWith(">ENDGROUP"))
                {
                    // this line is ending the last group. this is created by brickbuilder.
                    // make sure there even is an opened group
                    if (startedGroups.Count > 0)
                    {
                        startedGroups.RemoveAt(startedGroups.Count - 1); // we have reached the end of that group
                    }
                    else
                    {
                        throw new Exception("Nonexistent group ended!");
                    }
                }
                else if (line[0] != '>')
                {
                    // this line is most likely defining a new brick
                    Brick   brick     = new Brick();
                    float[] brickInfo = Helper.StringToFloatArray(line);
                    brick.Position = new Vector3(brickInfo[0], brickInfo[1], brickInfo[2]);   // first 3 numbers are position
                    brick.Scale    = new Vector3(brickInfo[3], brickInfo[4], brickInfo[5]);   // next 3 numbers are scale
                    brick.ConvertTransformToUnity();
                    brick.BrickColor   = new Color(brickInfo[6], brickInfo[7], brickInfo[8]); // next 3 numbers are color
                    brick.Transparency = brickInfo[9];                                        // last number is transparency
                    brick.ID           = currentID;

                    if (startedGroups.Count > 0)
                    {
                        startedGroups[startedGroups.Count - 1].Children.Add(currentID); // there is already an opened group, which means this group is a child of that group
                        brick.Parent = startedGroups[startedGroups.Count - 1];
                    }

                    map.Bricks.Add(brick); // adds brick to map object
                    map.MapElements.Add(currentID, brick);
                    map.lastID = currentID;
                    currentID++;
                }
            }
            else
            {
                // this line is most likely defining a brick property
                Brick brick = map.Bricks[map.Bricks.Count - 1]; // get the last added brick
                if (line.StartsWith("+NAME"))
                {
                    // this line is defining the brick name
                    if (line.Length == 5)
                    {
                        // the brick doesn't have a name for some reason
                        brick.Name = "";
                    }
                    else
                    {
                        brick.Name = line.Substring(6);
                    }
                }
                else if (line.StartsWith("+ROT"))
                {
                    // this line is defining the brick rotation
                    brick.Rotation = (int.Parse(line.Substring(5), CultureInfo.InvariantCulture) * -1).Mod(360);
                    if (brick.Rotation != 0 && brick.Rotation != 180)
                    {
                        brick.Scale = brick.Scale.SwapXZ();                                               // assuming this is post transform conversion
                    }
                }
                else if (line.StartsWith("+SHAPE"))
                {
                    // this line is defining the brick shape
                    brick.Shape = BB.GetShape(line.Substring(7));
                }
                else if (line.StartsWith("+NOCOLLISION"))
                {
                    // this line is defining whether or not the brick has collision
                    brick.CollisionEnabled = false;
                }
                else if (line.StartsWith("+MODEL"))
                {
                    // this line is defining the custom asset the brick uses
                    brick.Model = line.Substring(7);
                }
                else if (line.StartsWith("+CLICKABLE"))
                {
                    // this line is defining whether or not the brick is clickable
                    // i dont even know if this property is used anymore but eh
                    brick.Clickable = true;
                    if (line.Length > 11)
                    {
                        string dist = lines[i].Substring(11);
                        brick.ClickDistance = float.Parse(dist, CultureInfo.InvariantCulture);
                    }
                }
            }
        }

        return(map);
    }
示例#3
0
    private static Map ParseBB(string path)
    {
        Map    map  = new Map();
        string name = Path.GetFileNameWithoutExtension(path);

        map.Name = name;
        // first we must decompress the file
        byte[] bytes        = CLZF2.Decompress(File.ReadAllBytes(path));
        string decompressed = Encoding.UTF8.GetString(bytes);

        // then split into lines
        string[] lines = decompressed.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
        // then parse
        // first environment data
        string[] envData = lines[0].Split(' '); // line 0 is environment data
        ColorUtility.TryParseHtmlString("#" + envData[0], out Color ambientColor);
        ColorUtility.TryParseHtmlString("#" + envData[1], out Color baseplateColor);
        ColorUtility.TryParseHtmlString("#" + envData[2], out Color skyColor);
        map.AmbientColor   = ambientColor;
        map.BaseplateColor = baseplateColor;
        map.SkyColor       = skyColor;
        map.BaseplateSize  = int.Parse(envData[3], CultureInfo.InvariantCulture);
        map.SunIntensity   = int.Parse(envData[4], CultureInfo.InvariantCulture);
        // then everything else
        int currentID = 0;
        List <BrickGroup> startedGroups = new List <BrickGroup>();

        for (int i = 1; i < lines.Length; i++)
        {
            if (lines[i][0] == '!')   // Brick
            {
                Brick    b    = new Brick();
                string[] data = lines[i].Substring(1).Split(' ');
                float[]  fd   = Helper.StringArrayToFloatArray(data, 6);
                b.Position = new Vector3(fd[0], fd[1], fd[2]);
                b.Scale    = new Vector3(fd[3], fd[4], fd[5]);
                b.Rotation = int.Parse(data[6], CultureInfo.InvariantCulture);
                //b.ConvertTransformToUnity();
                ColorUtility.TryParseHtmlString("#" + data[7], out Color brickColor);
                b.BrickColor   = brickColor;
                b.Transparency = brickColor.a;
                b.Shape        = (Brick.ShapeType) int.Parse(data[8], NumberStyles.HexNumber);
                b.Name         = data.JoinSection(9);
                b.ID           = currentID;

                if (startedGroups.Count > 0)
                {
                    startedGroups[startedGroups.Count - 1].Children.Add(currentID);
                    b.Parent = startedGroups[startedGroups.Count - 1];
                }

                map.Bricks.Add(b);
                map.MapElements.Add(currentID, b);
                map.lastID = currentID;
                currentID++;
            }
            else if (lines[i][0] == '#')  // Group
            {
                if (lines[i][1] == 'S')   // group start
                {
                    BrickGroup g = new BrickGroup();
                    g.Name = lines[i].Substring(3);
                    g.ID   = currentID;
                    if (startedGroups.Count > 0)
                    {
                        startedGroups[startedGroups.Count - 1].Children.Add(currentID); // there is already an opened group, which means this group is a child of that group
                        g.Parent = startedGroups[startedGroups.Count - 1];
                    }
                    startedGroups.Add(g);
                    map.Groups.Add(g);
                    map.MapElements.Add(currentID, g);
                    map.lastID = currentID;
                    currentID++;
                }
                else if (lines[i][1] == 'E')     // group end
                {
                    if (startedGroups.Count > 0)
                    {
                        startedGroups.RemoveAt(startedGroups.Count - 1);
                    }
                }
            }
            else if (lines[i][0] == '@')     // Team
            {
                Team t = new Team();
                ColorUtility.TryParseHtmlString("#" + lines[i].Substring(1, 6), out Color tc);
                t.TeamColor = tc;
                t.Name      = lines[i].Substring(8);
                map.Teams.Add(t);
            }
            else if (lines[i][0] == '%')  // BB Info
            {
                if (lines[i][1] == 'C')   // camera transform
                //TODO
                {
                }
                else if (lines[i][1] == 'S')     // sun transform
                //TODO
                {
                }
            }
            else                                            // Probably extra brick data
            {
                Brick b = map.Bricks[map.Bricks.Count - 1]; // get last brick
                if (lines[i].StartsWith("NOCOLLISION"))
                {
                    b.CollisionEnabled = false;
                }
                else if (lines[i].StartsWith("MODEL"))
                {
                    b.Model = lines[i].Substring(6);
                }
                else if (lines[i].StartsWith("CLICKABLE"))
                {
                    b.Clickable = true;
                    if (lines[i].Length > 10)
                    {
                        string dist = lines[i].Substring(10);
                        b.ClickDistance = float.Parse(dist, CultureInfo.InvariantCulture);
                    }
                }
            }
        }

        return(map);
    }
示例#4
0
 public GroupData(BrickGroup group)
 {
     Name = group.Name;
     ID   = group.ID;
 }
示例#5
0
    public void SetGroupProperties(GroupData g, int ID)
    {
        BrickGroup gr = LoadedMap.MapElements[ID] as BrickGroup; // unsafe, what if this element isn't a brickgroup?

        gr.Name = g.Name;
    }