public Background(string file) : base(Kafe.Me) { Console.WriteLine("Instantiating a Background using definition \"{0}\"...", file); json = Mix.GetJson(file) as JsonObj; Sheet = Mix.GetTexture("locales\\" + json.Path <string>("/base")); Layers = new List <BackgroundLayer>(); Kafe.Ground = json.ContainsKey("ground") ? json.Path <int>("/ground") : 240; Kafe.LeftStart = Kafe.RightStart = 100; if (json.ContainsKey("start")) { Kafe.LeftStart = json.Path <int>("/start/0"); Kafe.RightStart = json.Path <int>("/start/1"); } LeftExtent = 0; RightExtent = 512; if (json.ContainsKey("extent")) { LeftExtent = json.Path <int>("/extent/0"); RightExtent = json.Path <int>("/extent/1"); } foreach (var layer in ((List <object>)json["layers"])) { Layers.Add(new BackgroundLayer((JsonObj)layer, this)); } }
private static void LoadFonts() { var data = Mix.GetJson("fonts") as List <object>; fonts = new Font[data.Count]; var i = 0; foreach (var entry in data) { var font = (JsonObj)entry; var sheet = Mix.GetTexture(font["sheet"] as string); var width = (int)(double)font["width"]; var height = (int)(double)font["height"]; var lineHeight = (int)(double)font["line"]; var widths = (font["widths"] as List <object>); var newWidths = new int[widths.Count]; for (var j = 0; j < newWidths.Length; j++) { newWidths[j] = (int)(double)widths[j]; } fonts[i] = new Font(sheet, width, height, lineHeight, newWidths); i++; } }
public void Reload(string jsonFile, int palIndex, bool refresh) { Console.WriteLine("Loading Character from \"{0}\"...", jsonFile); json = Mix.GetJson("fighters\\" + jsonFile, false) as JsonObj; Name = json.Path <string>("/name"); var baseName = json.Path <string>("/base"); var keys = new string[json.Keys.Count]; json.Keys.CopyTo(keys, 0); foreach (var key in keys) { if (json[key] is string && ((string)json[key]).StartsWith("import://")) { json[key] = Mix.GetJson("fighters\\" + ((string)json[key]).Substring(9)); } } atlas = Atlas.FromJson(json["sprites"]); json.Remove("sprites"); if (sheets.ContainsKey(baseName) && !refresh) { Console.WriteLine("Reusing spritesheet \"{0}\"...", baseName); sheet = sheets[baseName]; if (palettes.ContainsKey(baseName)) { palette = palettes[baseName]; } if (icons.ContainsKey(baseName)) { icon = icons[baseName]; } } else { Console.WriteLine("Loading spritesheet \"{0}\"...", baseName); sheet = Mix.GetTexture("fighters\\" + baseName); sheets[baseName] = sheet; if (Mix.FileExists("fighters\\" + baseName + "-pal.png")) { palette = Mix.GetTexture("fighters\\" + baseName + "-pal.png"); palettes[baseName] = palette; var timer1 = DateTime.Now; Console.WriteLine("Palette start at {0}", timer1.ToLongTimeString()); var numPals = palette.Height; var paletteData = new int[palette.Width * palette.Height]; palette.GetData(paletteData); var spriteData = new int[sheet.Width * sheet.Height]; sheet.GetData(spriteData); for (var j = 0; j < spriteData.Length; j++) { for (var p = 0; p < palette.Width; p++) { if (spriteData[j] == paletteData[p]) { spriteData[j] = 0x10000000 + p; } } } sheet.SetData(spriteData); ColorSwaps = numPals; if (palIndex >= numPals) { palIndex %= numPals; } if (palIndex == 0) { palIndex++; } var timer2 = DateTime.Now; Console.WriteLine("Palette end at {0}", timer2.ToLongTimeString()); var timer3 = timer2 - timer1; Console.WriteLine("Palette remapping took {0}", timer3); } if (Mix.FileExists("fighters\\" + baseName + "-icon.png")) { icon = Mix.GetTexture("fighters\\" + baseName + "-icon.png"); icons[baseName] = icon; } } ColorSwap = palIndex; animations = json.Path <List <JsonObj> >("/animations"); if (!refresh) { animation = animations[0]; } else { animation = animations[(int)currentAnim]; } Position = new Vector2(160, 160); SetupFrames(); if (!refresh || currentFrame >= totalFrames) { currentFrame = 0; } SetupImage(); MultiplyColor = new Vector4(1); AddColor = new Vector4(0); inputSequence = string.Empty; Console.WriteLine("Finished loading {0}.", Name); }