LynnaLab.FileParser.InsertComponentBefore C# (CSharp) Method

InsertComponentBefore() public method

public InsertComponentBefore ( FileComponent refComponent, FileComponent newComponent, string comment = "" ) : bool
refComponent FileComponent
newComponent FileComponent
comment string
return bool
        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;
        }

Usage Example

コード例 #1
0
        // Adds the given data to the end of the group and inserts the data
        // into the FileParser.
        public void AddWarpSourceData(WarpSourceData data)
        {
            if (warpSourceDataList.Contains(data))
            {
                return;
            }

            // Assumes the last element of warpSourceDataList is always the
            // m_WarpSourcesEnd command
            fileParser.InsertComponentBefore(EndData, data);
            warpSourceDataList.Insert(warpSourceDataList.Count - 1, data);

            if (data.WarpSourceType == WarpSourceType.PointerWarp && data.PointerString == ".")
            {
                // Create a unique pointer after m_WarpSourcesEnd
                int    nameIndex = 0;
                string name;
                do
                {
                    name = "customWarpSource" + nameIndex.ToString("d2");
                    nameIndex++;
                }while (Project.HasLabel(name));

                data.PointerString = name;

                Label newLabel = new Label(FileParser, name);
                // Insert label after m_WarpSourcesEnd
                FileParser.InsertComponentAfter(EndData, newLabel);

                // Create a blank PointedData to go after this label
                WarpSourceData pointedData = new WarpSourceData(Project,
                                                                WarpSourceData.WarpCommands[(int)WarpSourceType.PointedWarp],
                                                                WarpSourceData.DefaultValues[(int)WarpSourceType.PointedWarp],
                                                                FileParser,
                                                                new List <int> {
                    -1
                });
                pointedData.Opcode     = 0x80;
                pointedData.Transition = 4;
                FileParser.InsertComponentAfter(newLabel, pointedData);
            }
        }