Exemplo n.º 1
0
        public static void WriteIfp(this AbideTagGroup tagGroup, TagDefinitionCollection collection, string path)
        {
            //Prepare
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true,
                NewLineOnAttributes = false,
                IndentChars         = "\t"
            };

            //Create stream
            using (FileStream fs = File.OpenWrite(path))
                using (XmlWriter writer = XmlWriter.Create(fs, settings))
                {
                    //Write start document
                    writer.WriteStartDocument();

                    //Write plugin element
                    writer.WriteStartElement("plugin");

                    //Write attributes
                    writer.WriteAttribute("class", tagGroup.GroupTag);
                    writer.WriteAttribute("author", "Abide");
                    writer.WriteAttribute("version", "0.1");

                    //Write end plugin element
                    writer.WriteEndElement();

                    //End document
                    writer.WriteEndDocument();
                    fs.Flush();
                }
        }
Exemplo n.º 2
0
        private static void SoundBlock_Preprocess(AbideTagBlock block, TagDefinitionCollection cache)
        {
            //Get sound tag group
            AbideTagGroup sound = cache.GetTagGroup("snd!");

            //Change definition to cache_file_sound_block
            sound.BlockName = "cache_file_sound_block";
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a pascal-cased member name of the tag group.
        /// </summary>
        /// <param name="tagGroup">The tag group.</param>
        /// <returns>A string.</returns>
        public static string GetMemberName(AbideTagGroup tagGroup)
        {
            //Check
            if (!tagGroupMemberLookup.ContainsKey(tagGroup))
            {
                tagGroupTagLookup.Add(tagGroup.GroupTag, tagGroup);
                tagGroupNameLookup.Add(tagGroup.Name, tagGroup);
                tagGroupMemberLookup.Add(tagGroup, GeneratePascalMemberName(tagGroup.Name));
            }

            //Return
            return(tagGroupMemberLookup[tagGroup]);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds an Abide tag group definition to the collection.
        /// </summary>
        /// <param name="tagGroup">The tag group definition.</param>
        public void Add(AbideTagGroup tagGroup)
        {
            //Check
            if (tagGroup == null)
            {
                return;
            }

            //Check
            if (!tagGroups.Contains(tagGroup) && !tagGroupLookup.ContainsKey(tagGroup.GroupTag))
            {
                tagGroupLookup.Add(tagGroup.GroupTag, tagGroups.Count);
                tagGroups.Add(tagGroup);
            }
        }
Exemplo n.º 5
0
        private void tagDefinitions_BuildCache(string directory)
        {
            //Clear
            collection.Clear();

            //Get files
            string[] abideTagGroupFiles = Directory.GetFiles(directory, "*.atg");
            string[] abideTagBlockfiles = Directory.GetFiles(directory, "*.atb");

            //Loop
            foreach (string abideTagGroup in abideTagGroupFiles)
            {
                //Load
                AbideTagGroup group = new AbideTagGroup();
                group.Load(abideTagGroup);

                //Add
                collection.Add(group);
            }
            foreach (string abideTagGroup in abideTagBlockfiles)
            {
                //Load
                AbideTagBlock block = new AbideTagBlock();
                block.Load(abideTagGroup);

                //Add
                collection.Add(block);
            }

            //Begin
            tagGroupTreeView.BeginUpdate();

            //Clear
            tagGroupTreeView.Nodes.Clear();

            //Recursive block node creation
            Func <AbideTagBlock, TreeNode> createTagBlockNode = null;

            createTagBlockNode = new Func <AbideTagBlock, TreeNode>((tagBlock) =>
            {
                //Create Node
                TreeNode blockNode = new TreeNode(tagBlock.DisplayName)
                {
                    Tag = tagBlock
                };

                //Loop
                AbideTagBlock block = null;
                foreach (AbideTagField field in tagBlock.FieldSet)
                {
                    //Check
                    switch (field.FieldType)
                    {
                    case FieldType.FieldBlock:
                        block = collection.GetTagBlock(field.BlockName);
                        blockNode.Nodes.Add(createTagBlockNode(block));
                        field.ReferencedBlock = block;
                        break;

                    case FieldType.FieldStruct:
                        block = collection.GetTagBlock(field.StructName);
                        blockNode.Nodes.Add(createTagBlockNode(block));
                        field.ReferencedBlock = block;
                        break;
                    }
                }

                //Return
                return(blockNode);
            });

            //Recursive group node creation
            Action <AbideTagGroup, TreeNode> createTagGroupNode = null;

            createTagGroupNode = new Action <AbideTagGroup, TreeNode>((tagGroup, node) =>
            {
                //Check
                if (tagGroup.ParentGroupTag.Dword != 0)
                {
                    createTagGroupNode(collection.GetTagGroup(tagGroup.ParentGroupTag), node);
                }

                //Add blocks
                node.Nodes.Add(createTagBlockNode(collection.GetTagBlock(tagGroup.BlockName)));
            });

            //Loop
            foreach (AbideTagGroup group in collection.GetTagGroups())
            {
                //Create Node
                TreeNode groupNode = new TreeNode($"[{group.GroupTag}] - {group.Name}")
                {
                    Tag = group
                };

                //Add parent blocks
                createTagGroupNode(group, groupNode);

                //Add
                tagGroupTreeView.Nodes.Add(groupNode);
            }

            //End
            tagGroupTreeView.EndUpdate();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Preprocesses a tag group, preparing a valid member name.
 /// </summary>
 /// <param name="tagGroup">The tag group.</param>
 public static void Preprocess(AbideTagGroup tagGroup)
 {
     memberNames.Add(GetMemberName(tagGroup));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AbideTagGroupCodeCompileUnit"/> class.
        /// </summary>
        /// <param name="tagGroup">The tag group definition.</param>
        /// <param name="namespaceString">The optional namespace string. This defaults to "Cache".</param>
        /// <param name="tagNamespace"></param>
        public AbideTagGroupCodeCompileUnit(AbideTagGroup tagGroup, string namespaceString = "Cache", string tagNamespace = "Abide.Tag", TypeAttributes typeAttributes = TypeAttributes.Public)
        {
            //Prepare
            string blockTypeName = AbideCodeDomGlobals.GetMemberName(AbideCodeDomGlobals.GetTagBlock(tagGroup.BlockName));
            string groupTypeName = AbideCodeDomGlobals.GetMemberName(tagGroup);

            //Create namespace
            CodeNamespace generatedCodeNamespace = new CodeNamespace($"{namespaceString}.Generated");

            //Add imports
            generatedCodeNamespace.Imports.Add(new CodeNamespaceImport(AbideCodeDomGlobals.SystemNamespace));
            generatedCodeNamespace.Imports.Add(new CodeNamespaceImport(AbideCodeDomGlobals.HaloLibraryNamespace));
            generatedCodeNamespace.Imports.Add(new CodeNamespaceImport(tagNamespace));

            //Create type
            tagGroupCodeTypeDeclaration = new CodeTypeDeclaration(groupTypeName)
            {
                TypeAttributes = typeAttributes,
                IsClass        = true
            };
            tagGroupCodeTypeDeclaration.BaseTypes.Add(nameof(Group));
            tagGroupCodeTypeDeclaration.Comments.Add(new CodeCommentStatement("<summary>", true));
            tagGroupCodeTypeDeclaration.Comments.Add(new CodeCommentStatement($"Represents the generated {tagGroup.Name} " +
                                                                              $"({tagGroup.GroupTag.FourCc.Replace("<", "&lt;").Replace(">", "&gt;")}) tag group.", true));
            tagGroupCodeTypeDeclaration.Comments.Add(new CodeCommentStatement("</summary>", true));

            //Name property
            CodeMemberProperty nameMemberProperty = new CodeMemberProperty()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Override,
                Name       = nameof(Group.Name),
                Type       = new CodeTypeReference(typeof(string))
            };

            nameMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(tagGroup.Name)));
            nameMemberProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
            nameMemberProperty.Comments.Add(new CodeCommentStatement($"Gets and returns the name of the {tagGroup.Name} tag group.", true));
            nameMemberProperty.Comments.Add(new CodeCommentStatement("</summary>", true));
            tagGroupCodeTypeDeclaration.Members.Add(nameMemberProperty);

            //GroupTag property
            CodeMemberProperty groupTagMemberProperty = new CodeMemberProperty()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Override,
                Name       = nameof(Group.Tag),
                Type       = new CodeTypeReference(nameof(TagFourCc))
            };

            groupTagMemberProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(tagGroup.GroupTag.FourCc)));
            groupTagMemberProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
            groupTagMemberProperty.Comments.Add(new CodeCommentStatement($"Gets and returns the group tag of the {tagGroup.Name} tag group.", true));
            groupTagMemberProperty.Comments.Add(new CodeCommentStatement("</summary>", true));
            tagGroupCodeTypeDeclaration.Members.Add(groupTagMemberProperty);

            //Constructor
            CodeConstructor constructor = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public,
            };

            constructor.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor.Comments.Add(new CodeCommentStatement($"Initializes a new instance of the <see cref=\"{groupTypeName}\"/> class.", true));
            constructor.Comments.Add(new CodeCommentStatement("</summary>", true));
            tagGroupCodeTypeDeclaration.Members.Add(constructor);

            //Initialize Blocks
            int       index  = 0;
            TagFourCc parent = tagGroup.ParentGroupTag;

            while (parent.Dword != 0)
            {
                //Get Parent
                var parentGroup = AbideCodeDomGlobals.GetTagGroup(parent);

                //Add Block
                constructor.Statements.Insert(0, new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodePropertyReferenceExpression(
                                                                                                                                                  new CodeThisReferenceExpression(), nameof(Group.TagBlocks)), nameof(List <Block> .Add)), new CodeObjectCreateExpression(
                                                                                                                new CodeTypeReference(AbideCodeDomGlobals.GetMemberName(AbideCodeDomGlobals.GetTagBlock(parentGroup.BlockName)))))));
                constructor.Statements.Insert(0, new CodeCommentStatement($"Add parent {parentGroup.Name} tag block to list."));

                CreateBlockProperty(index++, AbideCodeDomGlobals.GetTagBlock(parentGroup.BlockName));

                //Get parent's parent group
                parent = parentGroup.ParentGroupTag;
            }

            //Add Block
            constructor.Statements.Add(new CodeCommentStatement($"Add tag block to list."));
            constructor.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodePropertyReferenceExpression(
                                                                                                            new CodeThisReferenceExpression(), nameof(Group.TagBlocks)), nameof(List <ITagBlock> .Add)), new CodeObjectCreateExpression(
                                                                          new CodeTypeReference(AbideCodeDomGlobals.GetMemberName(AbideCodeDomGlobals.GetTagBlock(tagGroup.BlockName))))));


            //Add type to namespace
            generatedCodeNamespace.Types.Add(tagGroupCodeTypeDeclaration);

            //Add namespace
            Namespaces.Add(generatedCodeNamespace);
        }