예제 #1
0
        // Attempt to insert newComponent after refComponent, or at the end if
        // refComponent is null
        // Returns false if failed (refComponent doesn't exist or newComponent already
        // exists in this file).
        public bool InsertComponentAfter(FileComponent refComponent, FileComponent newComponent)
        {
            int i;

            if (refComponent == null)
            {
                i = fileStructure.Count - 1;
            }
            else
            {
                i = fileStructure.IndexOf(refComponent);
                if (i == -1)
                {
                    return(false);
                }
            }

            if (fileStructure.Contains(newComponent))
            {
                return(false);
            }

            if (newComponent is Label)
            {
                AddLabelToDictionaries(newComponent as Label);
            }

            fileStructure.Insert(i + 1, newComponent);
            newComponent.SetFileParser(this);

            Modified = true;

            return(true);
        }
예제 #2
0
        // Parse an array of text (each element is a line) and insert it after
        // refComponent (or at the end if refComponent is null);
        public bool InsertParseableTextAfter(FileComponent refComponent, string[] text)
        {
            int index;

            if (refComponent == null)
            {
                index = fileStructure.Count - 1;
            }
            else
            {
                index = fileStructure.IndexOf(refComponent);
                if (index == -1)
                {
                    return(false);
                }
            }

            context = "";
            List <FileComponent> structure = new List <FileComponent>();

            for (int i = 0; i < text.Length; i++)
            {
                currentLine = -1;
                ParseLine(text[i], structure);
            }

            fileStructure.InsertRange(index + 1, structure);

            return(true);
        }
예제 #3
0
        // If this is a WarpSourceData which is pointed to from another one,
        // return the next in the sequence, or null if the sequence is over.
        public WarpSourceData GetNextWarp()
        {
            if (WarpSourceType != WarpSourceType.PointedWarp)
            {
                return(null);
            }

            // A warp with opcode bit 7 set signals the end of the sequence
            if ((Opcode & 0x80) != 0)
            {
                return(null);
            }

            FileComponent next = Next;

            while (next != null)
            {
                // This condition is a bit weird, but the game doesn't always
                // end with a 0x80 opcode, so I need another way to discern the
                // endpoint
                if (next is Label)
                {
                    return(null);
                }

                if (next is Data)
                {
                    return(next as WarpSourceData);
                }

                next = next.Next;
            }

            return(null);
        }
예제 #4
0
        public bool InsertParseableTextBefore(FileComponent refComponent, string[] text)
        {
            int index;

            if (refComponent == null)
            {
                index = 0;
            }
            else
            {
                index = fileStructure.IndexOf(refComponent);
                if (index == -1)
                {
                    return(false);
                }
            }

            context = "";
            List <FileComponent> structure         = new List <FileComponent>();
            List <string>        structureComments = new List <string>();

            for (int i = 0; i < text.Length; i++)
            {
                ParseLine(text[i], i, structure, structureComments);
            }

            fileStructure.InsertRange(index, structure);
            fileStructureComments.InsertRange(index, structureComments);

            return(true);
        }
예제 #5
0
        // Insert at the beginning if refComponent is null.
        public bool InsertComponentBefore(FileComponent refComponent, FileComponent newComponent, string comment = "")
        {
            int i;

            if (refComponent == null)
            {
                i = 0;
            }
            else
            {
                i = fileStructure.IndexOf(refComponent);
                if (i == -1)
                {
                    return(false);
                }
            }

            if (newComponent is Label)
            {
                AddLabelToDictionaries(newComponent as Label);
            }

            fileStructure.Insert(i, newComponent);
            fileStructureComments.Insert(i, comment);
            newComponent.SetFileParser(this);

            Modified = true;

            return(true);
        }
예제 #6
0
        internal WarpDestGroup(Project p, int id) : base(p, id)
        {
            fileParser = Project.GetFileWithLabel("warpDestTable");
            Data tmp = fileParser.GetData("warpDestTable", id * 2);

            string label = tmp.GetValue(0);

            WarpDestData data = fileParser.GetData(label) as WarpDestData;

            warpDestDataList = new List <WarpDestData>();

            while (data != null)
            {
                data.DestGroup = this;
                data.DestIndex = warpDestDataList.Count;
                warpDestDataList.Add(data);

                FileComponent component = data.Next;
                data = null;
                while (component != null)
                {
                    if (component is Label)
                    {
                        data = null;
                        break;
                    }
                    else if (component is Data)
                    {
                        data = component as WarpDestData;
                        break;
                    }
                    component = component.Next;
                }
            }
        }
예제 #7
0
        public FileComponent GetNextFileComponent(FileComponent reference)
        {
            int i = fileStructure.IndexOf(reference);

            if (i == -1)
            {
                return(null);
            }
            if (i + 1 < fileStructure.Count)
            {
                return(fileStructure[i + 1]);
            }
            return(null);
        }
예제 #8
0
        public FileComponent GetPrevFileComponent(FileComponent reference)
        {
            int i = fileStructure.IndexOf(reference);

            if (i == -1)
            {
                return(null);
            }
            if (i - 1 >= 0)
            {
                return(fileStructure[i - 1]);
            }
            return(null);
        }
예제 #9
0
        public void Save()
        {
            if (!Modified)
            {
                return;
            }

            List <string> output        = new List <string>();
            FileComponent lastComponent = null;

            for (int i = 0; i < fileStructure.Count; i++)
            {
                string s = null;

                FileComponent d = fileStructure[i];
                if (d.Fake)
                {
                    s = null;
                }
                else
                {
                    s = "";
                    if (lastComponent != null && !lastComponent.EndsLine)
                    {
                        s = output[output.Count - 1];
                        output.RemoveAt(output.Count - 1);
                    }
                    s += d.GetString();
                    if (d.EndsLine)
                    {
                        s += fileStructureComments[i];
                    }
                }

                if (s != null)
                {
                    output.Add(s);
                }

                if (d is Data)
                {
                    (d as Data).Modified = false;
                }

                lastComponent = d;
            }
            File.WriteAllLines(FullFilename, output);

            Modified = false;
        }
예제 #10
0
        // Returns true if no data is shared with another label
        bool IsIsolated()
        {
            FileComponent d = objectDataList[0];

            d = d.Prev;
            if (!(d is Label))
            {
                return(true); // This would be an odd case, there should be at least one label...
            }
            if (d.Prev is Label)
            {
                return(false);
            }
            return(true);
        }
예제 #11
0
        // Returns >0 if c2 comes after c1, <0 if c2 comes before c1, or 0 if c1
        // and c2 are the same.
        public int CompareComponentPositions(FileComponent c1, FileComponent c2)
        {
            if (c1 == c2)
            {
                return(0);
            }
            int p1 = fileStructure.IndexOf(c1);
            int p2 = fileStructure.IndexOf(c2);

            if (p1 == -1 || p2 == -1)
            {
                throw new NotFoundException();
            }
            return(p2.CompareTo(p1));
        }
예제 #12
0
        // Returns the label immediately before this data, or null if there is
        // no label or there is another Data between itself and the label.
        public Label GetDataLabel(Data data)
        {
            FileComponent cmp = data.Prev;

            while (cmp != null)
            {
                if (cmp is Data)
                {
                    return(null);
                }
                if (cmp is Label)
                {
                    return(cmp as Label);
                }
                cmp = cmp.Prev;
            }
            return(null);
        }
예제 #13
0
        // Remove a FileComponent (Data, Label) from the fileStructure.
        public void RemoveFileComponent(FileComponent component)
        {
            int index = fileStructure.IndexOf(component);

            if (index == -1)
            {
                return;
            }

            fileStructure.RemoveAt(index);

            Label l = component as Label;

            if (l != null)
            {
                labelDictionary.Remove(l.Name);
                Project.RemoveLabel(l.Name);
            }

            Modified = true;
        }
예제 #14
0
        public Data GetData(string labelStr, int offset = 0)
        {
            int origOffset = offset;

            Label label = labelDictionary[labelStr];

            if (label != null)
            {
                FileComponent component = label;
                while (component != null && !(component is Data))
                {
                    component = component.Next;
                }

                Data data = component as Data;
                while (data != null)
                {
                    if (offset == 0)
                    {
                        return(data);
                    }
                    if (data.Size == -1)
                    {
                        break;
                    }
                    offset -= data.Size;
                    if (offset < 0)
                    {
                        break;
                    }
                    data = data.NextData;
                }
            }
            throw new Exception("Provided offset (" + origOffset + ") relative to label \"" + labelStr +
                                "\" was invalid.");
        }
예제 #15
0
 public FileComponent GetNextFileComponent(FileComponent reference)
 {
     int i = fileStructure.IndexOf(reference);
     if (i == -1) return null;
     if (i+1 < fileStructure.Count)
         return fileStructure[i+1];
     return null;
 }
예제 #16
0
 public FileComponent GetPrevFileComponent(FileComponent reference)
 {
     int i = fileStructure.IndexOf(reference);
     if (i == -1) return null;
     if (i-1 >= 0)
         return fileStructure[i-1];
     return null;
 }
예제 #17
0
        // Insert at the beginning if refComponent is null.
        public bool InsertComponentBefore(FileComponent refComponent, FileComponent newComponent, string comment="")
        {
            int i;
            if (refComponent == null)
                i = 0;
            else {
                i = fileStructure.IndexOf(refComponent);
                if (i == -1)
                    return false;
            }

            if (newComponent is Label) {
                AddLabelToDictionaries(newComponent as Label);
            }

            fileStructure.Insert(i, newComponent);
            fileStructureComments.Insert(i, comment);
            newComponent.SetFileParser(this);

            Modified = true;

            return true;
        }
예제 #18
0
        public bool InsertParseableTextBefore(FileComponent refComponent, string[] text)
        {
            int index;
            if (refComponent == null)
                index = 0;
            else {
                index = fileStructure.IndexOf(refComponent);
                if (index == -1)
                    return false;
            }

            context = "";
            List<FileComponent> structure = new List<FileComponent>();
            List<string> structureComments = new List<string>();

            for (int i=0;i<text.Length;i++) {
                ParseLine(text[i], i, structure, structureComments);
            }

            fileStructure.InsertRange(index, structure);
            fileStructureComments.InsertRange(index, structureComments);

            return true;
        }
예제 #19
0
        // Remove a FileComponent (Data, Label) from the fileStructure.
        public void RemoveFileComponent(FileComponent component)
        {
            int index = fileStructure.IndexOf(component);
            if (index == -1) return;

            fileStructure.RemoveAt(index);
            fileStructureComments.RemoveAt(index);

            Label l = component as Label;
            if (l != null) {
                labelDictionary.Remove(l.Name);
                Project.RemoveLabel(l.Name);
            }

            Modified = true;
        }
예제 #20
0
 // Returns >0 if c2 comes after c1, <0 if c2 comes before c1, or 0 if c1
 // and c2 are the same.
 public int CompareComponentPositions(FileComponent c1, FileComponent c2)
 {
     if (c1 == c2)
         return 0;
     int p1 = fileStructure.IndexOf(c1);
     int p2 = fileStructure.IndexOf(c2);
     if (p1 == -1 || p2 == -1)
         throw new NotFoundException();
     return p2.CompareTo(p1);
 }