Beispiel #1
0
        private static void WriteSpellLinesMethod()
        {
            writer.WriteLine("SpellLine[] lines;");
            writer.WriteLine();

            for (var i = 0; i < Maps.Length; i++)
            {
                var map  = Maps[i];
                var clss = (ClassId)i;

                if (map != null)
                {
                    var listCount = map.Count;
                    var s         = 0;

                    writer.WriteMap((clss != 0 ? clss.ToString() : "Other") + " (" + listCount + ")");
                    writer.WriteLine("lines = new SpellLine[]");
                    writer.OpenBracket();

                    foreach (var set in map.Values)
                    {
                        var spells   = set.ToList();
                        var lineName = GetSpellLineName(spells.First());

                        spells.Sort((a, b) => a.Id.CompareTo(b.Id));                                    // first sort by rank and then by id
                        spells.Sort((a, b) => a.Rank.CompareTo(b.Rank));

                        writer.WriteLine("new SpellLine(SpellLineId." + lineName + ", ");
                        writer.IndentLevel++;
                        var j = 0;
                        foreach (var spell in spells)
                        {
                            j++;
                            writer.WriteIndent("SpellHandler.Get(SpellId." + spell.SpellId + ")");
                            if (j < set.Count)
                            {
                                writer.WriteLine(",");
                            }
                        }
                        writer.IndentLevel--;
                        writer.Write(")");
                        if (s < listCount - 1)
                        {
                            writer.WriteLine(",");
                        }
                        ++s;
                    }
                    writer.CloseBracket(true);
                    writer.WriteLine("AddSpellLines(ClassId.{0}, lines);", clss);
                    writer.WriteEndMap();
                    writer.WriteLine();
                }
            }
        }
		public void Write(string fileName)
		{
			using (var writer = new CodeFileWriter(fileName,
			                                       "WCell.Constants.Updates", "UpdateFields",
			                                       CodeFileWriter.StaticTag + " " + CodeFileWriter.Class, 
												   "",
			                                       "System"))
			{
				writer.ExecuteSafely(() =>{
				                          	writer.WriteIndent("public static readonly ");
				                          	writer.Array(UpdateFieldTypeName, "AllFields", 2, ";", () =>{
				                          	                                                            	for (var i = 0;
				                          	                                                            	     i < m_fields.Length;
				                          	                                                            	     i++)
				                          	                                                            	{
				                          	                                                            		var fieldArr = m_fields[i];
				                          	                                                            		writer.WriteRegion(
				                          	                                                            			((ObjectTypeId) i).ToString());
				                          	                                                            		writer.NewArray("UpdateField", ",",
				                          	                                                            		                () =>{
				                          	                                                            		                     	foreach (
				                          	                                                            		                     		var field in
				                          	                                                            		                     			fieldArr)
				                          	                                                            		                     	{
				                          	                                                            		                     		if (field != null)
				                          	                                                            		                     		{
				                          	                                                            		                     			writer.
				                          	                                                            		                     				WriteCommentLine(
				                          	                                                            		                     				field.FullName);
				                          	                                                            		                     			var flags =
				                          	                                                            		                     				Utility.
				                          	                                                            		                     					GetSetIndicesEnum
				                          	                                                            		                     					(field.Flags);

				                          	                                                            		                     			var args = new[]
				                          	                                                            		                     			           	{
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Flags",
				                          	                                                            		                     			           			flags
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				TransformList
				                          	                                                            		                     			           				((
				                          	                                                            		                     			           					flag)
				                          	                                                            		                     			           				 =>
				                          	                                                            		                     			           				 "UpdateFieldFlags." +
				                          	                                                            		                     			           				 flag)
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				ToString
				                          	                                                            		                     			           				(" | "))
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Group",
				                          	                                                            		                     			           			"ObjectTypeId." +
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Group)
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Name",
				                          	                                                            		                     			           			"\"" +
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Name +
				                          	                                                            		                     			           			"\"")
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Offset",
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Offset)
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Size",
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Size)
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Type",
				                          	                                                            		                     			           			"UpdateFieldType." +
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Type)
				                          	                                                            		                     			           	};
				                          	                                                            		                     			writer.NewInit(
				                          	                                                            		                     				UpdateFieldTypeName,
				                          	                                                            		                     				args, ",");
				                          	                                                            		                     		}
				                          	                                                            		                     		else
				                          	                                                            		                     		{
				                          	                                                            		                     			writer.WriteLine(
				                          	                                                            		                     				"null,");
				                          	                                                            		                     		}
				                          	                                                            		                     	}
				                          	                                                            		                });
				                          	                                                            		writer.WriteEndRegion();
				                          	                                                            		writer.WriteLine();
				                          	                                                            	}
				                          	});
				                          	writer.WriteLine();

				                          	//writer.WriteStaticMethod("Init", () => {

				                          	//});

				                          	//writer.WriteStaticCTor(() => {
				                          	//    writer.Call("Init");
				                          	//});
				});
			}
		}
Beispiel #3
0
        public void Write(string fileName)
        {
            using (var writer = new CodeFileWriter(fileName,
                                                   "WCell.Constants.Updates", "UpdateFields",
                                                   CodeFileWriter.StaticTag + " " + CodeFileWriter.Class,
                                                   "",
                                                   "System"))
            {
                writer.ExecuteSafely(() =>
                {
                    writer.WriteIndent("public static readonly ");
                    writer.Array(UpdateFieldTypeName, "AllFields", 2, ";", () =>
                    {
                        for (var i = 0; i < m_fields.Length; i++)
                        {
                            var fieldArr = m_fields[i];
                            writer.WriteRegion(((ObjectTypeId)i).ToString());
                            writer.NewArray("UpdateField", ",", () =>
                            {
                                foreach (var field in fieldArr)
                                {
                                    if (field != null)
                                    {
                                        writer.WriteCommentLine(field.FullName);
                                        var flags = Utility.GetSetIndicesEnum(field.Flags);

                                        var args = new[]
                                        {
                                            new KeyValuePair <string, object> ("Flags", flags.TransformList((flag) =>
                                                                                                            "UpdateFieldFlags." +
                                                                                                            flag)
                                                                               .
                                                                               ToString
                                                                                   (" | "))
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Group",
                                                "ObjectTypeId." +
                                                field
                                                .
                                                Group)
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Name",
                                                "\"" +
                                                field
                                                .
                                                Name +
                                                "\"")
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Offset",
                                                field
                                                .
                                                Offset)
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Size",
                                                field
                                                .
                                                Size)
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Type",
                                                "UpdateFieldType." +
                                                field
                                                .
                                                Type)
                                        };
                                        writer.NewInit(
                                            UpdateFieldTypeName,
                                            args, ",");
                                    }
                                    else
                                    {
                                        writer.WriteLine(
                                            "null,");
                                    }
                                }
                            });
                            writer.WriteEndRegion();
                            writer.WriteLine();
                        }
                    });
                    writer.WriteLine();

                    //writer.WriteStaticMethod("Init", () => {

                    //});

                    //writer.WriteStaticCTor(() => {
                    //    writer.Call("Init");
                    //});
                });
            }
        }