Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected override void Update(GameTime gameTime)
- {
- var watch = new Stopwatch();
- if (!_written)
- {
- watch.Start();
- Console.Write("Writing json files...items...");
- DumpItems(ItemID.Count, _dumpPath);
- Console.Write("buffs...");
- DumpBuffs(BuffID.Count, _dumpPath);
- Console.Write("prefixes...");
- DumpPrefixes(PrefixID.Count, _dumpPath);
- Console.WriteLine("Done!");
- _written = true;
- watch.Stop();
- Console.WriteLine("Completed in {0} Seconds", watch.Elapsed.TotalSeconds);
- }
- else
- {
- Console.WriteLine("Press any key to exit");
- Process.Start(_dumpPath);
- Environment.Exit(0);
- }
- base.Update(gameTime);
- }
- public void DumpItems(int count, string path)
- {
- var items = new Dictionary<int, Item>();
- var itm = new Item
- {
- ItemID = 0,
- ItemName = "(none)",
- Nick = "(none)"
- };
- items.Add(0, itm);
- for (var i = 0; i < count; i++)
- {
- itm = GetItem(i);
- if (itm.ItemID != 0)
- items.Add(i, itm);
- }
- File.WriteAllText(path + @"\items.json",
- JsonConvert.SerializeObject(items, format,
- new JsonSerializerSettings
- {
- DefaultValueHandling = DefaultValueHandling.Ignore
- }));
- }
- public void DumpBuffs(int count, string path)
- {
- var buffs = new Dictionary<int, Buff>();
- var buff = new Buff
- {
- BuffID = 0,
- BuffName = "(none)",
- BuffDescription = "(none)"
- };
- buffs.Add(0, buff);
- for (var i = 0; i < count; i++)
- {
- buff = GetBuff(i);
- if (buff.BuffID != 0)
- buffs.Add(i, buff);
- }
- File.WriteAllText(path + @"\buffs.json",
- JsonConvert.SerializeObject(buffs, format,
- new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }));
- }
- public void DumpPrefixes(int count, string path)
- {
- var prefixes = new Dictionary<int, Prefix>();
- var prfx = new Prefix
- {
- ID = 0,
- Name = "(none)"
- };
- prefixes.Add(0, prfx);
- for (var i = 0; i < count; i++)
- {
- prfx.ID = (byte)i;
- prfx.Name = Language.GetTextValue(Lang.prefix[i].Value);
- if (prfx.ID != 0)
- prefixes.Add(i, prfx);
- }
- File.WriteAllText(path + @"\prefixes.json",
- JsonConvert.SerializeObject(prefixes, format,
- new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }));
- }
- private static Buff GetBuff(int type)
- {
- var buff = new Buff
- {
- BuffID = type,
- BuffName = Language.GetTextValue(Lang.GetBuffName(type)),
- BuffDescription = Language.GetTextValue(Lang.GetBuffDescription(type))
- };
- return buff;
- }
- private static Item GetItem(int type)
- {
- var terraItem = new Terraria.Item();
- terraItem.netDefaults(type);
- return new Item
- {
- ItemID = terraItem.netID,
- Nick = string.Empty,
- MaxStack = terraItem.maxStack,
- ItemName = Lang.GetItemName(terraItem.netID).ToNetworkText().ToString(),
- BackSlot = terraItem.backSlot,
- BalloonSlot = terraItem.balloonSlot,
- BodySlot = terraItem.bodySlot,
- FaceSlot = terraItem.faceSlot,
- FrontSlot = terraItem.frontSlot,
- HandOffSlot = terraItem.handOffSlot,
- HandOnSlot = terraItem.handOnSlot,
- HeadSlot = terraItem.headSlot,
- LegSlot = terraItem.legSlot,
- NeckSlot = terraItem.neckSlot,
- ShieldSlot = terraItem.shieldSlot,
- ShoeSlot = terraItem.shoeSlot,
- WaistSlot = terraItem.waistSlot,
- WingSlot = terraItem.wingSlot,
- Color = terraItem.color.PackedValue == 0
- ? null
- : new int[] { terraItem.color.A, terraItem.color.R, terraItem.color.G, terraItem.color.B }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement