public CursorProvider(ModData modData) { var sequenceFiles = modData.Manifest.Cursors; cursors = new Dictionary<string, CursorSequence>(); palettes = new Cache<string, PaletteReference>(CreatePaletteReference); var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); var shadowIndex = new int[] { }; var nodesDict = sequences.ToDictionary(); if (nodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref shadowIndex, shadowIndex.Length + 1); Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value, out shadowIndex[shadowIndex.Length - 1]); } palette = new HardwarePalette(); foreach (var p in nodesDict["Palettes"].Nodes) palette.AddPalette(p.Key, new ImmutablePalette(GlobalFileSystem.Open(p.Value.Value), shadowIndex), false); var spriteCache = new SpriteCache(modData.SpriteLoaders, new string[0], new SheetBuilder(SheetType.Indexed)); foreach (var s in nodesDict["Cursors"].Nodes) LoadSequencesForCursor(spriteCache, s.Key, s.Value); spriteCache.SheetBuilder.Current.ReleaseBuffer(); palette.Initialize(); }
public void Run(ModData modData, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; var failed = false; modData.SpriteSequenceLoader.OnMissingSpriteError = s => { Console.WriteLine("\t" + s); failed = true; }; foreach (var t in modData.Manifest.TileSets) { var ts = new TileSet(modData.DefaultFileSystem, t); Console.WriteLine("Tileset: " + ts.Name); var sc = new SpriteCache(modData.DefaultFileSystem, modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed)); var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(modData.DefaultFileSystem.Open(s)))); foreach (var n in nodes) modData.SpriteSequenceLoader.ParseSequences(modData, ts, sc, n); } if (failed) Environment.Exit(1); }
public void Run(ModData modData, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest); Game.ModData.SpriteSequenceLoader.OnMissingSpriteError = s => Console.WriteLine("\t" + s); foreach (var t in Game.ModData.Manifest.TileSets) { var ts = new TileSet(Game.ModData, t); Console.WriteLine("Tileset: " + ts.Name); var sc = new SpriteCache(modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed)); var sequenceFiles = modData.Manifest.Sequences; var nodes = sequenceFiles .Select(s => MiniYaml.FromFile(s)) .Aggregate(MiniYaml.MergeLiberal); foreach (var n in nodes) Game.ModData.SpriteSequenceLoader.ParseSequences(Game.ModData, ts, sc, n); } }
public SequenceProvider(SequenceCache cache, Map map) { this.sequences = Exts.Lazy(() => cache.LoadSequences(map)); this.SpriteCache = cache.SpriteCache; }
public Sequence(SpriteCache cache, string unit, string name, MiniYaml info) { var srcOverride = info.Value; Name = name; var d = info.ToDictionary(); var offset = float2.Zero; var blendMode = BlendMode.Alpha; try { if (d.ContainsKey("Start")) Start = Exts.ParseIntegerInvariant(d["Start"].Value); if (d.ContainsKey("Offset")) offset = FieldLoader.GetValue<float2>("Offset", d["Offset"].Value); if (d.ContainsKey("BlendMode")) blendMode = FieldLoader.GetValue<BlendMode>("BlendMode", d["BlendMode"].Value); // Apply offset to each sprite in the sequence // Different sequences may apply different offsets to the same frame sprites = cache[srcOverride ?? unit].Select( s => new Sprite(s.sheet, s.bounds, s.offset + offset, s.channel, blendMode)).ToArray(); if (!d.ContainsKey("Length")) Length = 1; else if (d["Length"].Value == "*") Length = sprites.Length - Start; else Length = Exts.ParseIntegerInvariant(d["Length"].Value); if (d.ContainsKey("Stride")) Stride = Exts.ParseIntegerInvariant(d["Stride"].Value); else Stride = Length; if (d.ContainsKey("Facings")) { var f = Exts.ParseIntegerInvariant(d["Facings"].Value); Facings = Math.Abs(f); reverseFacings = f < 0; } else Facings = 1; if (d.ContainsKey("Tick")) Tick = Exts.ParseIntegerInvariant(d["Tick"].Value); else Tick = 40; if (d.ContainsKey("Transpose")) transpose = bool.Parse(d["Transpose"].Value); if (d.ContainsKey("Frames")) Frames = Array.ConvertAll<string, int>(d["Frames"].Value.Split(','), Exts.ParseIntegerInvariant); if (d.ContainsKey("ShadowStart")) ShadowStart = Exts.ParseIntegerInvariant(d["ShadowStart"].Value); else ShadowStart = -1; if (d.ContainsKey("ShadowZOffset")) { WRange r; if (WRange.TryParse(d["ShadowZOffset"].Value, out r)) ShadowZOffset = r.Range; } else ShadowZOffset = -5; if (d.ContainsKey("ZOffset")) { WRange r; if (WRange.TryParse(d["ZOffset"].Value, out r)) ZOffset = r.Range; } if (Length > Stride) throw new InvalidOperationException( "{0}: Sequence {1}.{2}: Length must be <= stride" .F(info.Nodes[0].Location, unit, name)); if (Start < 0 || Start + Facings * Stride > sprites.Length || ShadowStart + Facings * Stride > sprites.Length) throw new InvalidOperationException( "{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist" .F(unit, name, Start, Start + Facings * Stride - 1, srcOverride ?? unit, sprites.Length - 1, info.Nodes[0].Location)); } catch (FormatException f) { throw new FormatException("Failed to parse sequences for {0}.{1} at {2}:\n{3}".F(unit, name, info.Nodes[0].Location, f)); } }
public TilesetSpecificSpriteSequence(ModData modData, TileSet tileSet, SpriteCache cache, ISpriteSequenceLoader loader, string sequence, string animation, MiniYaml info) : base(modData, tileSet, cache, loader, sequence, animation, info) { }
public override ISpriteSequence CreateSequence(ModData modData, TileSet tileSet, SpriteCache cache, string sequence, string animation, MiniYaml info) { return new TilesetSpecificSpriteSequence(modData, tileSet, cache, this, sequence, animation, info); }
void LoadSequencesForCursor(SpriteCache cache, string cursorSrc, MiniYaml cursor) { foreach (var sequence in cursor.Nodes) cursors.Add(sequence.Key, new CursorSequence(cache, cursorSrc, cursor.Value, sequence.Value)); }