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[] { }; if (sequences.NodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref shadowIndex, shadowIndex.Length + 1); Exts.TryParseIntegerInvariant(sequences.NodesDict["ShadowIndex"].Value, out shadowIndex[shadowIndex.Length - 1]); } palette = new HardwarePalette(); foreach (var p in sequences.NodesDict["Palettes"].Nodes) palette.AddPalette(p.Key, new Palette(GlobalFileSystem.Open(p.Value.Value), shadowIndex), false); var spriteLoader = new SpriteLoader(new string[0], new SheetBuilder(SheetType.Indexed)); foreach (var s in sequences.NodesDict["Cursors"].Nodes) LoadSequencesForCursor(spriteLoader, s.Key, s.Value); palette.Initialize(); }
Sprite[] LoadSprite(string filename, List <Sprite[]> cache) { var sprite = SpriteLoader.GetSprites(fileSystem, filename, loaders, SheetBuilder); cache.Add(sprite); return(sprite); }
void LoadSequencesForCursor(SpriteLoader loader, string cursorSrc, MiniYaml cursor) { foreach (var sequence in cursor.Nodes) { cursors.Add(sequence.Key, new CursorSequence(loader, cursorSrc, cursor.Value, sequence.Value)); } }
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 spriteLoader = new SpriteLoader(new string[0], new SheetBuilder(SheetType.Indexed)); foreach (var s in nodesDict["Cursors"].Nodes) { LoadSequencesForCursor(spriteLoader, s.Key, s.Value); } spriteLoader.SheetBuilder.Current.ReleaseBuffer(); palette.Initialize(); }
public CursorSequence(SpriteLoader loader, string cursorSrc, string palette, MiniYaml info) { sprites = loader.LoadAllSprites(cursorSrc); var d = info.NodesDict; start = Exts.ParseIntegerInvariant(d["start"].Value); this.palette = palette; if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*")) { length = sprites.Length - start; } else if (d.ContainsKey("length")) { length = Exts.ParseIntegerInvariant(d["length"].Value); } else if (d.ContainsKey("end")) { length = Exts.ParseIntegerInvariant(d["end"].Value) - start; } else { length = 1; } if (d.ContainsKey("x")) { Exts.TryParseIntegerInvariant(d["x"].Value, out Hotspot.X); } if (d.ContainsKey("y")) { Exts.TryParseIntegerInvariant(d["y"].Value, out Hotspot.Y); } }
public SpriteCache(ISpriteLoader[] loaders, string[] exts, SheetBuilder sheetBuilder) { SheetBuilder = sheetBuilder; // Include extension-less version exts = exts.Append("").ToArray(); sprites = new Cache <string, Sprite[]>(filename => SpriteLoader.GetSprites(filename, exts, loaders, sheetBuilder)); }
public CursorSequence(SpriteLoader loader, string cursorSrc, string palette, MiniYaml info) { sprites = loader.LoadAllSprites(cursorSrc); var d = info.NodesDict; start = Exts.ParseIntegerInvariant(d["start"].Value); this.palette = palette; if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*")) length = sprites.Length - start; else if (d.ContainsKey("length")) length = Exts.ParseIntegerInvariant(d["length"].Value); else if (d.ContainsKey("end")) length = Exts.ParseIntegerInvariant(d["end"].Value) - start; else length = 1; if (d.ContainsKey("x")) Exts.TryParseIntegerInvariant(d["x"].Value, out Hotspot.X); if (d.ContainsKey("y")) Exts.TryParseIntegerInvariant(d["y"].Value, out Hotspot.Y); }
public Map PrepareMap(string uid) { LoadScreen.Display(); if (!AvailableMaps.ContainsKey(uid)) throw new InvalidDataException("Invalid map uid: {0}".F(uid)); var map = new Map(AvailableMaps[uid].Path); // Reinit all our assets LoadInitialAssets(); foreach (var pkg in Manifest.Packages) FileSystem.Mount(pkg); // Mount map package so custom assets can be used. TODO: check priority. FileSystem.Mount(FileSystem.OpenPackage(map.Path, int.MaxValue)); Rules.LoadRules(Manifest, map); SpriteLoader = new SpriteLoader( Rules.TileSets[map.Tileset].Extensions, SheetBuilder ); SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); return map; }
public FrameCache(IReadOnlyFileSystem fileSystem, ISpriteLoader[] loaders) { frames = new Cache <string, ISpriteFrame[]>(filename => SpriteLoader.GetFrames(fileSystem, filename, loaders)); }
public Map PrepareMap(string uid) { LoadScreen.Display(); if (!AvailableMaps.ContainsKey(uid)) throw new InvalidDataException("Invalid map uid: {0}".F(uid)); var map = new Map(AvailableMaps[uid].Path); // Reinit all our assets InitializeLoaders(); FileSystem.LoadFromManifest(Manifest); // Mount map package so custom assets can be used. TODO: check priority. FileSystem.Mount(FileSystem.OpenPackage(map.Path, null, int.MaxValue)); Rules.LoadRules(Manifest, map); SpriteLoader = new SpriteLoader(Rules.TileSets[map.Tileset].Extensions, SheetBuilder); // TODO: Don't load the sequences for assets that are not used in this tileset. Maybe use the existing EditorTilesetFilters. SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequences); return map; }
public Sequence(SpriteLoader loader, string unit, string name, MiniYaml info) { var srcOverride = info.Value; Name = name; var d = info.NodesDict; 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 = loader.LoadAllSprites(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 SpriteCache(ISpriteLoader[] loaders, SheetBuilder sheetBuilder) { SheetBuilder = sheetBuilder; sprites = new Cache <string, Sprite[]>(filename => SpriteLoader.GetSprites(filename, loaders, sheetBuilder)); }
void LoadSequencesForCursor(SpriteLoader loader, string cursorSrc, MiniYaml cursor) { foreach (var sequence in cursor.Nodes) cursors.Add(sequence.Key, new CursorSequence(loader, cursorSrc, cursor.Value, sequence.Value)); }
public Sequence(SpriteLoader loader, 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 = loader.LoadAllSprites(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 Map PrepareMap(string uid) { LoadScreen.Display(); if (!AvailableMaps.ContainsKey(uid)) throw new InvalidDataException("Invalid map uid: {0}".F(uid)); var map = new Map(AvailableMaps[uid].Path); // Maps may contain custom assets // TODO: why are they lowest priority? they should be highest. if (previousMapMount != null) FileSystem.Unmount(previousMapMount); previousMapMount = FileSystem.OpenPackage(map.Path, int.MaxValue); FileSystem.Mount(previousMapMount); // Reinit all our assets LoadInitialAssets(); foreach (var pkg in Manifest.Packages) FileSystem.Mount(pkg); Rules.LoadRules(Manifest, map); SpriteLoader = new SpriteLoader( Rules.TileSets[map.Tileset].Extensions, SheetBuilder ); SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); return map; }
public void LoadInitialAssets() { // all this manipulation of static crap here is nasty and breaks // horribly when you use ModData in unexpected ways. FileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) FileSystem.Mount(dir); AvailableMaps = FindMaps(Manifest.Mods); ChromeMetrics.Initialize(Manifest.ChromeMetrics); ChromeProvider.Initialize(Manifest.Chrome); SheetBuilder = new SheetBuilder(TextureChannel.Red); SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder); CursorProvider.Initialize(Manifest.Cursors); }
public SequenceProvider(SequenceCache cache, Map map) { this.sequences = Exts.Lazy(() => cache.LoadSequences(map)); this.SpriteLoader = cache.SpriteLoader; }
public FrameCache(ISpriteLoader[] loaders) { frames = new Cache <string, ISpriteFrame[]>(filename => SpriteLoader.GetFrames(filename, loaders)); }
public void InitializeLoaders() { // all this manipulation of static crap here is nasty and breaks // horribly when you use ModData in unexpected ways. ChromeMetrics.Initialize(Manifest.ChromeMetrics); ChromeProvider.Initialize(Manifest.Chrome); SheetBuilder = new SheetBuilder(SheetType.Indexed); SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder); VoxelLoader = new VoxelLoader(); CursorProvider.Initialize(Manifest.Cursors); }