Inheritance: FileComponent
Esempio n. 1
0
 internal Dungeon(Project p, int i)
     : base(p, i)
 {
     FileParser dungeonDataFile = Project.GetFileWithLabel("dungeonDataTable");
     Data pointerData = dungeonDataFile.GetData("dungeonDataTable", Index*2);
     string label = pointerData.GetValue(0);
     dataStart = dungeonDataFile.GetData(label);
 }
Esempio n. 2
0
        internal Area(Project p, int i)
            : base(p, i)
        {
            areaFile = Project.GetFileWithLabel("areaData");

            areaData = areaFile.GetData("areaData", Index * 8);

            // Initialize graphics state
            graphicsState = new GraphicsState();
            // Global palettes
            PaletteHeaderGroup globalPaletteHeaderGroup =
                Project.GetIndexedDataType<PaletteHeaderGroup>(0xf);
            graphicsState.AddPaletteHeaderGroup(globalPaletteHeaderGroup, PaletteGroupType.Common);

            Data data = areaData;
            flags1 = p.EvalToInt(data.GetValue(0));

            data = data.NextData;
            flags2 = p.EvalToInt(data.GetValue(0));

            data = data.NextData;
            SetUniqueGfx(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            SetMainGfx(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            SetPaletteHeader(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            SetTileset(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            layoutGroup = Project.EvalToInt(data.GetValue(0));

            data = data.NextData;
            SetAnimation((byte)Project.EvalToInt(data.GetValue(0)));
        }
Esempio n. 3
0
 public ValueReferenceEditor(Project p, Data data, string frameText=null)
     : this(p, data.GetValueReferenceGroup(), frameText)
 {
 }
Esempio n. 4
0
 public void InsertIntoParserBefore(Data reference)
 {
     parser.InsertComponentBefore(reference, this);
 }
Esempio n. 5
0
 public void InsertIntoParserAfter(Data reference)
 {
     parser.InsertComponentAfter(reference, this);
 }
Esempio n. 6
0
 public void SetData(Data d)
 {
     data = d;
     if (data != null && constantsMappingString != null) {
         constantsMapping = (ConstantsMapping)typeof(Project).GetField(constantsMappingString).GetValue(data.Project);
     }
 }
Esempio n. 7
0
        public static void InitializeDataValues(Data data, IList<ValueReference> refs)
        {
            int numValues = 0;
            foreach (ValueReference r in refs) {
                if (r.valueIndex+1 > numValues)
                    numValues = r.valueIndex+1;
            }

            data.SetNumValues(numValues);

            foreach (ValueReference r in refs) {
                data.SetValue(r.valueIndex, defaultDataValues[(int)r.ValueType]);
            }
        }
Esempio n. 8
0
 public ValueReference(ValueReference r)
 {
     data = r.data;
     valueIndex = r.valueIndex;
     ValueType = r.ValueType;
     Name = r.Name;
     startBit = r.startBit;
     endBit = r.endBit;
     Editable = r.Editable;
     constantsMappingString = r.constantsMappingString;
     constantsMapping = r.constantsMapping;
 }
Esempio n. 9
0
        public static void AddChestData(int room)
        {
            int group = room>>8;
            room &= 0xff;

            FileParser chestFileParser = Project.GetFileWithLabel("chestDataGroupTable");
            Data chestPointer = chestFileParser.GetData("chestDataGroupTable", group*2);
            string pointerString = chestPointer.GetValue(0);
            Data chestGroupData = Project.GetData(pointerString);

            Data newData = new Data(Project, ".db", new string[] {"$00"}, -1, null, new List<int>{-1});
            newData.EndsLine = false;
            chestFileParser.InsertComponentBefore(chestGroupData, newData);

            newData = new Data(Project, ".db", new string[] {Wla.ToByte((byte)room)}, -1, null, null);
            newData.PrintCommand = false;
            newData.EndsLine = false;
            chestFileParser.InsertComponentBefore(chestGroupData, newData);

            newData = new Data(Project, ".db", new string[] {"$00"}, -1, null, null);
            newData.PrintCommand = false;
            newData.EndsLine = false;
            chestFileParser.InsertComponentBefore(chestGroupData, newData);

            newData = new Data(Project, ".db", new string[] {"$00"}, -1, null, null);
            newData.PrintCommand = false;
            chestFileParser.InsertComponentBefore(chestGroupData, newData);
        }
Esempio n. 10
0
        void ParseLine(string pureLine, int i, List<FileComponent> fileStructure, List<string> fileStructureComments)
        {
            string[] split = pureLine.Split(';');
            string line = split[0];
            string comment = pureLine.Substring(split[0].Length);
            string warningString = "WARNING while parsing \"" + Filename + "\": Line " + (i+1) + ": ";

            // Helper functions

            Action<FileComponent,string> AddComponent = (component, c) => {
                fileStructure.Add(component);
                fileStructureComments.Add(c);
                if (component is Label)
                    AddLabelToDictionaries(component as Label);
            };
            Action<Label> AddLabelAndPopFileStructure = (label) => {
                fileStructure.RemoveAt(fileStructure.Count-1);
                string c = fileStructureComments[fileStructureComments.Count-1];
                fileStructureComments.RemoveAt(fileStructureComments.Count-1);
                AddComponent(label, c);
            };
            Action<Data> AddDataAndPopFileStructure = (data) => {
                fileStructure.RemoveAt(fileStructure.Count-1);
                string c = fileStructureComments[fileStructureComments.Count-1];
                fileStructureComments.RemoveAt(fileStructureComments.Count-1);
                AddComponent(data, c);
            };
            Action PopFileStructure = () => {
                fileStructure.RemoveAt(fileStructure.Count-1);
                fileStructureComments.RemoveAt(fileStructureComments.Count-1);
            };

            // Sub-function: returns true if a meaning for the token was found.
            Func<string[],IList<int>,bool> ParseData = (fTokens,fSpacing) =>
            {
                List<string> standardValues = new List<string>();

                // Variables used for some of the goto's
                int size=-1;

                for (int j = 1; j < fTokens.Length; j++)
                    standardValues.Add(fTokens[j]);

                switch (fTokens[0].ToLower()) {
                    case ".incbin":
                        {
                            Data d = new Data(Project, fTokens[0], standardValues, -1,
                                    this, fSpacing);
                            AddDataAndPopFileStructure(d);
                        }
                        break;
                    case ".dw":
                        if (context == "RAMSECTION")
                            break;
                        if (fTokens.Length < 2) {
                            log.Warn(warningString + "Expected .DW to have a value.");
                            break;
                        }
                        size = 2;
                        goto arbitraryLengthData;
                    case ".db":
                        if (context == "RAMSECTION")
                            break;
                        if (fTokens.Length < 2) {
                            log.Warn(warningString + "Expected .DB to have a value.");
                            break;
                        }
                        size = 1;
                        goto arbitraryLengthData;
                    case "dwbe":
                        if (fTokens.Length < 2) {
                            log.Warn(warningString + "Expected dwbe to have a value.");
                            break;
                        }
                        size = 2;
                        goto arbitraryLengthData;
                    case "dbrev":
                        if (fTokens.Length < 2) {
                            log.Warn(warningString + "Expected dbrev to have a value.");
                            break;
                        }
                        size = 1;
                        goto arbitraryLengthData;
            arbitraryLengthData:
                        PopFileStructure();
                        for (int j=1; j<fTokens.Length; j++) { // Each value is added as individual data
                            string[] values = { fTokens[j] };
                            List<int> newfSpacing = new List<int> {fSpacing[0],fSpacing[j],0};
                            if (j == fTokens.Length-1)
                                newfSpacing[2] = fSpacing[j+1];

                            Data d = new Data(Project, fTokens[0], values, size,
                                    this, newfSpacing);
                            if (j != fTokens.Length-1)
                                d.EndsLine = false;
                            if (j != 1)
                                d.PrintCommand = false;
                            AddComponent(d, "");
                        }
                        break;
                    case "db":
                        if (context != "RAMSECTION")
                            goto default;
                        address++;
                        break;
                    case "dw":
                        if (context != "RAMSECTION")
                            goto default;
                        address+=2;
                        break;
                    case "dsb":
                        if (context != "RAMSECTION")
                            goto default;
                        address += Project.EvalToInt(fTokens[1]);
                        break;
                    case "dsw":
                        if (context != "RAMSECTION")
                            goto default;
                        address += Project.EvalToInt(fTokens[1])*2;
                        break;

                    case "m_animationloop":
                        {
                            Data d = new Data(Project, fTokens[0], standardValues, 2,
                                this, fSpacing);
                            AddDataAndPopFileStructure(d);
                            break;
                        }
                    case "m_rgb16":
                        if (fTokens.Length != 4) {
                            log.Warn(warningString + "Expected " + fTokens[0] + " to take 3 parameters");
                            break;
                        }
                        {
                            Data d = new RgbData(Project, fTokens[0], standardValues,
                                    this, fSpacing);
                            AddDataAndPopFileStructure(d);
                            break;
                        }
                    case "m_gfxheader":
                    case "m_gfxheaderforcemode":
                        if (fTokens.Length < 4 || fTokens.Length > 5) {
                            log.Warn(warningString + "Expected " + fTokens[0] + " to take 3-4 parameters");
                            break;
                        }
                        {
                            Data d = new GfxHeaderData(Project, fTokens[0], standardValues,
                                    this, fSpacing);
                            AddDataAndPopFileStructure(d);
                            break;
                        }
                    case "m_paletteheaderbg":
                    case "m_paletteheaderspr":
                        if (fTokens.Length != 5) {
                            log.Warn(warningString + "Expected " + fTokens[0] + " to take 4 parameters");
                            break;
                        }
                        {
                            Data d = new PaletteHeaderData(Project, fTokens[0], standardValues,
                                    this, fSpacing);
                            AddDataAndPopFileStructure(d);
                            break;
                        }
                    case "m_tilesetheader":
                        if (fTokens.Length != 6) {
                            log.Warn(warningString + "Expected " + fTokens[0] + " to take 5 parameters");
                            break;
                        }
                        {
                            Data d = new TilesetHeaderData(Project, fTokens[0], standardValues,
                                    this, fSpacing);
                            AddDataAndPopFileStructure(d);
                            break;
                        }
                    case "m_tilesetdata":
                        if (fTokens.Length != 2) {
                            log.Warn(warningString + "Expected " + fTokens[0] + " to take 1 parameter");
                            break;
                        }
                        {
                            Stream file = Project.GetBinaryFile("tilesets/" + fTokens[1] + ".bin");
                            Data d = new Data(Project, fTokens[0], standardValues,
                                    (Int32)file.Length, this, fSpacing);
                            AddDataAndPopFileStructure(d);
                            break;
                        }
                    case "m_roomlayoutdata":
                        if (fTokens.Length != 2) {
                            log.Warn(warningString + "Expected " + fTokens[0] + " to take 1 parameter");
                            break;
                        }
                        {
                            Label l = new Label(this, fTokens[1]);
                            l.Fake = true;
                            AddLabelAndPopFileStructure(l);
                            Data d = new Data(Project, fTokens[0], standardValues, -1,
                                    this, fSpacing);
                            AddComponent(d, "");
                            break;
                        }

                    default:
                        {
                            Data d = null;
                            // Try object commands
                            for (int j=0; j<ObjectGroup.ObjectCommands.Length; j++) {
                                string s = ObjectGroup.ObjectCommands[j];

                                if (s.ToLower() == fTokens[0].ToLower()) {
                                    int minParams = ObjectGroup.ObjectCommandMinParams[j];
                                    int maxParams = ObjectGroup.ObjectCommandMaxParams[j];

                                    if (minParams == -1) minParams = maxParams;
                                    if (maxParams == -1) maxParams = minParams;
                                    if (fTokens.Length-1 < minParams || fTokens.Length-1 > maxParams) {
                                      log.Warn(warningString + "Expected " + fTokens[0] + " to take " +
                                          minParams + "-" + maxParams + "parameter(s)");
                                      break;
                                    }

                                    var objectType = (ObjectType)j;

                                    d = new ObjectData(Project, fTokens[0], standardValues,
                                        this, fSpacing, objectType);
                                    break;
                                }
                            }
                            // Try warp sources
                            foreach (string s in WarpSourceData.WarpCommands) {
                                if (s.ToLower() == fTokens[0].ToLower()) {
                                    d = new WarpSourceData(Project, fTokens[0], standardValues,
                                            this, fSpacing);
                                }
                            }
                            // Try warp dest
                            if (WarpDestData.WarpCommand.ToLower() == fTokens[0].ToLower()) {
                                d = new WarpDestData(Project, fTokens[0], standardValues,
                                        this, fSpacing);
                            }

                            if (d != null) {
                                AddDataAndPopFileStructure(d);
                                break;
                            }
                            return false;
                        }
                }
                return true;
            };

            // Add raw string to file structure, it'll be removed if
            // a better representation is found
            fileStructure.Add(new StringFileComponent(this, line, null));
            fileStructureComments.Add(comment);

            if (line.Trim().Length == 0)
                return;

            // TODO: split tokens more intelligently, ie: recognize this as one token: $8000 | $03
            //string[] tokens = line.Split(new char[] { ' ', '\t'} );
            string[] tokens = Regex.Split(line.Trim(), @"\s+");

            List<int> spacing = new List<int>();
            int[] tokenStartIndices = new int[tokens.Length];
            {
                // Generate "spacing" list, keeps track of whitespace
                // between arguments (+'ve = spaces, -'ve = tabs)
                int index = 0;

                for (int j=0; j<tokens.Length+1; j++) {
                    int spaces=0;
                    while (index < line.Length && (line[index] == ' ' || line[index] == '\t')) {
                        if (line[index] == ' ' && spaces >= 0) spaces++;
                        else if (line[index] == '\t' && spaces <= 0) spaces--;
                        index++;
                    }
                    if (j<tokens.Length)
                        tokenStartIndices[j] = index;
                    spacing.Add(spaces);
                    while (index < line.Length && line[index] != ' ' && line[index] != '\t')
                        index++;
                }
            }

            string value;

            if (tokens.Length > 0) {
                switch (tokens[0].ToLower()) {
                    // Built-in directives
                    case ".ramsection":
                        {
                            context = "RAMSECTION";
                            // Find the last token which specifies the name
                            int tokenIndex = 1;
                            while (tokens[tokenIndex][tokens[tokenIndex].Length-1] != '"')
                                tokenIndex++;
                            tokenIndex++;

                            while (tokenIndex < tokens.Length) {
                                if (tokens[tokenIndex] == "BANK") {
                                    tokenIndex++;
                                    bank = Project.EvalToInt(tokens[tokenIndex++]);
                                }
                                else if (tokens[tokenIndex] == "SLOT") {
                                    tokenIndex++;
                                    string slotString = tokens[tokenIndex++];
                                    int slot = Project.EvalToInt(slotString);
                                    if (slot == 2)
                                        address = 0xc000;
                                    else { // Assuming slot >= 3
                                        address = 0xd000;
                                    }
                                }
                            }
                            break;
                        }
                    case ".ends":
                        if (context == "RAMSECTION")
                            context = "";
                        break;

                    case ".define":
                        if (tokens.Length < 3) {
                            log.Debug(warningString + "Expected .DEFINE to have a string and a value.");
                            break;
                        }
                        value = "";
                        for (int j = 2; j < tokens.Length; j++) {
                            value += tokens[j];
                            value += " ";
                        }
                        value = value.Trim();
                        AddDefinition(tokens[1], value);
                        break;

                    default:
                        if (tokens[0][tokens[0].Length - 1] == ':') {
                            // Label
                            string s = tokens[0].Substring(0, tokens[0].Length - 1);
                            FileComponent addedComponent;
                            if (context == "RAMSECTION") {
                                AddDefinition(s, address.ToString());
                                AddDefinition(":"+s, bank.ToString());
                                PopFileStructure();
                                StringFileComponent sc = new StringFileComponent(this, tokens[0], spacing);
                                fileStructure.Add(sc);
                                fileStructureComments.Add(comment);
                                addedComponent = sc;
                            }
                            else {
                                Label label = new Label(this,s,spacing);
                                AddLabelAndPopFileStructure(label);
                                addedComponent = label;
                            }
                            if (tokens.Length > 1) { // There may be data directly after the label
                                string[] tokens2 = new string[tokens.Length-1];
                                List<int> spacing2 = new List<int>();

                                addedComponent.EndsLine = false;

                                // Add raw string to file structure, it'll
                                // be removed if a better representation is
                                // found
                                fileStructure.Add(new StringFileComponent(
                                            this, line.Substring(tokenStartIndices[1]), spacing2));
                                fileStructureComments.Add(comment);

                                for (int j=1; j<tokens.Length; j++)
                                    tokens2[j-1] = tokens[j];
                                for (int j=1; j<spacing.Count; j++)
                                    spacing2.Add(spacing[j]);
                                if (!ParseData(tokens2, spacing2)) {
                                    log.Debug(warningString + "Error parsing line.");
                                }
                            }
                        } else {
                            if (!ParseData(tokens, spacing)) {
                                // Unknown data
                                log.Debug(warningString + "Did not understand \"" + tokens[0] + "\".");
                            }
                        }
                        break;
                }
            }
        }
Esempio n. 11
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;
        }
Esempio n. 12
0
            public MyMinimap(Data d)
                : base(1.0/4)
            {
                bitData = d;

                Action<int,int> OnDragged = (x, y) => {
                    x /= TileWidth;
                    y /= TileHeight;
                    SetSelected(x, y, dragSet);
                };

                this.ButtonPressEvent += delegate(object o, ButtonPressEventArgs args) {
                    int x,y;
                    Gdk.ModifierType state;
                    args.Event.Window.GetPointer(out x, out y, out state);
                    if (IsInBounds(x, y)) {
                        if (state.HasFlag(Gdk.ModifierType.Button1Mask)) {
                            dragSet = true;
                            OnDragged(x,y);
                        }
                        else if (state.HasFlag(Gdk.ModifierType.Button3Mask)) {
                            dragSet = false;
                            OnDragged(x,y);
                        }
                    }
                };
                this.MotionNotifyEvent += delegate(object o, MotionNotifyEventArgs args) {
                    int x,y;
                    Gdk.ModifierType state;
                    args.Event.Window.GetPointer(out x, out y, out state);
                    if (IsInBounds(x, y)) {
                        if (state.HasFlag(Gdk.ModifierType.Button1Mask) || state.HasFlag(Gdk.ModifierType.Button3Mask))
                            OnDragged(x, y);
                    }
                };
            }