Beispiel #1
0
        public ButtonTests()
        {
            _exchange = new EventExchange(new LogExchange());
            AssetMapping.GlobalIsThreadLocal = true;
            AssetMapping.Global.Clear()
            .RegisterAssetType(typeof(Base.Font), AssetType.Font)
            ;

            var jsonUtil   = new FormatJsonUtil();
            var font       = MockUniformFont.Font(AssetId.From(Base.Font.RegularFont));
            var modApplier = new MockModApplier()
                             .Add(new AssetId(AssetType.MetaFont, (ushort)new MetaFontId(false, FontColor.White)), font)
                             .AddInfo(AssetId.From(Base.Font.RegularFont), MockUniformFont.Info)
            ;

            var config = GameConfig.LoadLiteral(Encoding.UTF8.GetBytes(@"{ ""UI"": { ""ButtonDoubleClickIntervalSeconds"": 0.35 } }"), jsonUtil);

            _exchange
            .Register(config)
            .Attach(modApplier)
            .Attach(new AssetManager())
            .Attach(new SpriteManager())
            .Attach(new WindowManager {
                Resolution = (1920, 1080)
            })
Beispiel #2
0
        public void ParseNumericTest()
        {
            var m = AssetMapping.Global.Clear();

            m.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Portrait);
            m.RegisterAssetType(typeof(OneBasedByte), AssetType.Npc);

            Assert.Equal(new AssetId(AssetType.Unknown), m.Parse("somethinginvalid", null));
            Assert.Equal(new AssetId(AssetType.Unknown), m.Parse("Portrait.nonsense", null));
            Assert.Throws <FormatException>(() => m.Parse("0", null));
            Assert.Equal(AssetId.From(ZeroBasedByte.Zero), m.Parse("0", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("1", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(OneBasedByte.One), m.Parse("1", new[] { AssetType.Npc }));
            // Assert.Equal(AssetId.None, m.Parse("0", new[] { AssetType.Npc })); // TODO: Decide if this should be parse to None, an unmapped Npc.0 id, or throw.

            Assert.Equal(AssetId.From(ZeroBasedByte.Zero), m.Parse("Portrait.0", null));
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("Portrait.1", null));
            Assert.Equal(AssetId.From(OneBasedByte.One), m.Parse("Npc.1", null));
            Assert.Equal(AssetId.From(OneBasedByte.Two), m.Parse("Npc.2", null));

            m.RegisterAssetType(typeof(ZeroBasedShort), AssetType.Portrait);
            Assert.Equal(AssetId.From(ZeroBasedByte.Zero), m.Parse("0", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("1", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(ZeroBasedByte.Two), m.Parse("2", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(ZeroBasedShort.Zero), m.Parse("3", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(ZeroBasedShort.One), m.Parse("4", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(ZeroBasedShort.Two), m.Parse("5", new[] { AssetType.Portrait }));
        }
    static void ResolveItemProxies(AssetId id, Inventory inventory, IAssetManager assets)
    {
        if (inventory == null)
        {
            return;
        }

        // The first merchant has strange corrupt data, just zero it out
        if (id == AssetId.From(Base.Merchant.Unknown1))
        {
            foreach (var slot in inventory.Slots)
            {
                slot.Clear();
            }
            return;
        }

        foreach (var slot in inventory.EnumerateAll())
        {
            if (slot.Item is ItemProxy proxy)
            {
                slot.Item = assets.LoadItem(proxy.Id) ?? throw new InvalidOperationException($"Could not resolve item proxy for {slot.ItemId}");
            }
        }
    }
Beispiel #4
0
        static void StatsForEnum <T>(IAssetManager assets, Dictionary <AssetId, int> dict) where T : unmanaged, Enum
        {
            foreach (var enumValue in Enum.GetValues(typeof(T)).OfType <T>())
            {
                var id      = AssetId.From(enumValue);
                var info    = assets.GetAssetInfo(id);
                var texture = assets.LoadTexture(id) as IReadOnlyTexture <byte>;
                if (texture == null)
                {
                    continue;
                }

                var palleteId = new PaletteId(AssetType.Palette, info.Get(AssetProperty.PaletteId, 0));
                var palette   = assets.LoadPalette(palleteId);

                var frames        = texture.Regions.Count;
                var uniqueColours = new HashSet <byte>();
                foreach (var colour in texture.PixelData)
                {
                    uniqueColours.Add(colour);
                }

                var lcm = BlitUtil.CalculatePalettePeriod(uniqueColours, palette);
                dict[id] = (int)ApiUtil.Lcm(frames, lcm);
            }
        }
Beispiel #5
0
        public object LoadAsset(AssetId key, SerializationContext context, AssetInfo info)
        {
            var modApplier = Resolve <IModApplier>();
            var all        = (IDictionary <int, string>)modApplier.LoadAssetCached(AssetId.From(Base.Special.SystemStrings));

            return(all?[key.Id]);
        }
Beispiel #6
0
        public void Map2DTest()
        {
            var map = (MapData2D)Test(assets => assets.LoadMap(Map.TorontoBegin));

            Assert.Equal(MapType.TwoD, map.MapType);
            Assert.Equal(12, map.FrameRate);
            Assert.Equal(0, map.Sound);
            Assert.Equal(216, map.Width);
            Assert.Equal(81, map.Height);
            Assert.Equal(SpriteId.None, map.CombatBackgroundId);
            Assert.Equal(Song.Toronto, map.SongId);
            Assert.Equal(Tileset.Toronto, map.TilesetId);
            Assert.Equal(Palette.Toronto2D, map.PaletteId);
            Assert.Equal(FlatMapFlags.Unk2 | FlatMapFlags.Unk3 | FlatMapFlags.Unk4, map.Flags);
            Assert.Equal(map.Width * map.Height, map.Underlay.Length);
            Assert.Equal(871, map.Underlay[0]);
            Assert.Equal(349, map.Underlay[75]);
            Assert.Equal(map.Width * map.Height, map.Overlay.Length);
            Assert.Equal(0, map.Overlay[0]);
            Assert.Equal(2495, map.Overlay[719]);

            Assert.Equal(657, map.Events.Count);
            var en = map.Events[0];

            Assert.Equal(0, en.Id);
            Assert.Equal(1, en.Next.Id);
            Assert.IsType <ChangeIconEvent>(en.Event);
            var e = (ChangeIconEvent)en.Event;

            Assert.Equal(IconChangeType.BlockSoft, e.ChangeType);
            Assert.Equal(EventScopes.Rel, e.Scopes);
            Assert.Equal(-1, e.X);
            Assert.Equal(-3, e.Y);
            Assert.Equal(302, e.Value);

            Assert.Equal(250, map.Chains.Count);

            Assert.Equal(96, map.Npcs.Length);
            var n = map.Npcs[2];

            Assert.Equal(AssetId.From(Npc.Christine), n.Id);
            Assert.Equal(AssetId.From(LargeNpc.Christine), n.SpriteOrGroup);
            Assert.Equal(NpcFlags.Wander | NpcFlags.Unk3, n.Flags);
            Assert.Equal(0xffff, n.Chain);
            Assert.Equal(NpcMovementTypes.None, n.Movement);
            Assert.Equal(1, n.Unk8);
            Assert.Equal(0, n.Unk9);
            Assert.Equal(1152, n.Waypoints.Length);

            Assert.Equal(3768, map.Zones.Count);
            var z = map.Zones[0];

            Assert.Equal(24, z.Chain);
            Assert.True(z.Global);
            Assert.Equal(TriggerTypes.MapInit, z.Trigger);
            Assert.Equal(0, z.Unk1);
            Assert.Equal(255, z.X);
            Assert.Equal(0, z.Y);
        }
Beispiel #7
0
        public void PaletteTest()
        {
            var pal = Test(assets => assets.LoadPalette(Palette.Toronto2D));

            Assert.Equal(AssetId.From(Palette.Toronto2D), AssetId.FromUInt32(pal.Id));
            Assert.True(pal.IsAnimated);
            Assert.Equal(4, pal.Period);
            Assert.Equal("Palette.Toronto2D", pal.Name);
        }
Beispiel #8
0
        public void ChestTest()
        {
            var chest = Test(assets => assets.LoadInventory(AssetId.From(Chest.Unknown121)));

            Assert.Equal(25, chest.Gold.Amount);
            Assert.Equal(Gold.Instance, chest.Gold.Item);
            Assert.Equal(1, chest.Slots[0].Amount);
            Assert.Equal(Item.IskaiDagger, chest.Slots[0].ItemId);
        }
Beispiel #9
0
        public void ParseWithTypePrefixTest()
        {
            var m = AssetMapping.Global.Clear();

            m.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Portrait);
            m.RegisterAssetType(typeof(OneBasedByte), AssetType.Npc);
            _output.WriteLine(m.Serialize(JsonUtil));
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("Portrait.One", null));
            Assert.Equal(AssetId.From(OneBasedByte.One), m.Parse("Npc.One", null));
        }
Beispiel #10
0
        public void MerchantTest()
        {
            var i = Test(assets => assets.LoadInventory(AssetId.From(Merchant.Unknown109)));

            Assert.Equal(Item.Fireball, i.Slots[0].ItemId);
            Assert.Equal(25, i.Slots[0].Amount);
            Assert.Equal(1, i.Slots[0].Charges);
            Assert.Equal(Item.BanishDemons, i.Slots[1].ItemId);
            Assert.Equal(34, i.Slots[1].Amount);
            Assert.Equal(1, i.Slots[1].Charges);
        }
Beispiel #11
0
 static void AssetTest(AssetManager assets)
 {
     var item              = assets.LoadItem(Base.Item.LughsShield);
     var itemName          = assets.LoadString(item.Name);
     var fontTex           = assets.LoadTexture(Base.Font.RegularFont);
     var font              = assets.LoadFont(FontColor.White, false);
     var blocklist         = assets.LoadBlockList(Base.BlockList.Toronto);
     var chest             = assets.LoadInventory(AssetId.From(Base.Chest.Unknown121));
     var combatBackground  = assets.LoadTexture(Base.CombatBackground.Toronto);
     var combatGraphics    = assets.LoadTexture(Base.CombatGraphics.Unknown27);
     var coreSprite        = assets.LoadTexture(Base.CoreSprite.Cursor);
     var dungeonBackground = assets.LoadTexture(Base.DungeonBackground.EarlyGameL);
     var dungeonObject     = assets.LoadTexture(Base.DungeonObject.Barrel);
     var floor             = assets.LoadTexture(Base.Floor.Water);
     var fullBodyPicture   = assets.LoadTexture(Base.FullBodyPicture.Tom);
     var itemGraphics      = assets.LoadTexture(Base.ItemGraphics.ItemSprites);
     var labyrinthData     = assets.LoadLabyrinthData(Base.LabyrinthData.Unknown125);
     var largeNpc          = assets.LoadTexture(Base.LargeNpc.Christine);
     var largePartyMember  = assets.LoadTexture(Base.LargePartyMember.Tom);
     var mapText           = assets.LoadString(Base.MapText.TorontoBegin);
     var merchant          = assets.LoadInventory(AssetId.From(Base.Merchant.Unknown109));
     var monster           = assets.LoadSheet(Base.Monster.Krondir1);
     var monsterGraphics   = assets.LoadTexture(Base.MonsterGraphics.Krondir);
     var monsterGroup      = assets.LoadMonsterGroup(Base.MonsterGroup.TwoSkrinn1OneKrondir1);
     var npc              = assets.LoadSheet(Base.Npc.Christine);
     var paletteNull      = assets.LoadPalette(Base.Palette.CommonPalette);
     var palette          = assets.LoadPalette(Base.Palette.Toronto2D);
     var partyMember      = assets.LoadSheet(Base.PartyMember.Tom);
     var picture          = assets.LoadTexture(Base.Picture.OpenChestWithGold);
     var portrait         = assets.LoadTexture(Base.Portrait.Tom);
     var sample           = assets.LoadSample(Base.Sample.IllTemperedLlama);
     var script           = assets.LoadScript(Base.Script.Unknown1);
     var smallNpc         = assets.LoadTexture(Base.SmallNpc.Krondir);
     var smallPartyMember = assets.LoadTexture(Base.SmallPartyMember.Tom);
     var song             = assets.LoadSong(Base.Song.Toronto);
     var spell            = assets.LoadSpell(Base.Spell.FrostAvalanche);
     var systemText       = assets.LoadString(Base.SystemText.MainMenu_MainMenu);
     var tacticalGraphics = assets.LoadTexture(Base.TacticalGraphics.Unknown1);
     var tilesetData      = assets.LoadTileData(Base.TilesetData.Toronto);
     var tilesetGraphics  = assets.LoadTexture(Base.TilesetGraphics.Toronto);
     var uAlbionString    = assets.LoadString(Base.UAlbionString.TakeAll);
     var uiBackground     = assets.LoadTexture(Base.UiBackground.SLAB);
     var video            = assets.LoadVideo(Base.Video.MagicDemonstration);
     var wall             = assets.LoadTexture(Base.Wall.TorontoPanelling);
     var wallOverlay      = assets.LoadTexture(Base.WallOverlay.JiriWindow);
     var word             = assets.LoadString(Base.Word.Key);
     var map              = assets.LoadMap(Base.Map.TorontoBegin);
     var eventSet         = assets.LoadEventSet(Base.EventSet.Frill);
     var eventText        = assets.LoadString(Base.EventText.Frill);
     var waveLibrary      = assets.LoadWaveLib(Base.WaveLibrary.TorontoAmbient);
     var automapTiles     = assets.LoadTexture(Base.AutomapTiles.Set1);
     var automap          = assets.LoadAutomap(Base.Automap.Jirinaar);
 }
Beispiel #12
0
        public void TestFirstRegistrationOffsetPreserved()
        {
            var m = AssetMapping.Global.Clear();

            m.RegisterAssetType(typeof(OneBasedByte), AssetType.Map);
            m.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Map);
            Assert.Equal(new AssetId(AssetType.Map, 1), AssetId.From(OneBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Map, 2), AssetId.From(OneBasedByte.Two));
            Assert.Equal(new AssetId(AssetType.Map, 3), AssetId.From(OneBasedByte.Three));
            Assert.Equal(new AssetId(AssetType.Map, 4), AssetId.From(ZeroBasedByte.Zero));
            Assert.Equal(new AssetId(AssetType.Map, 5), AssetId.From(ZeroBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Map, 6), AssetId.From(ZeroBasedByte.Two));
        }
Beispiel #13
0
        public void AmbiguousParseTest()
        {
            var m = AssetMapping.Global.Clear();

            m.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Portrait);
            m.RegisterAssetType(typeof(OneBasedByte), AssetType.Npc);
            _output.WriteLine(m.Serialize(JsonUtil));
            Assert.Equal(AssetId.From(ZeroBasedByte.Zero), m.Parse("Zero", null));
            Assert.Throws <FormatException>(() => m.Parse("One", null)); // Ambiguous
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("One", new[] { AssetType.Portrait }));
            Assert.Equal(AssetId.From(OneBasedByte.One), m.Parse("One", new[] { AssetType.Npc }));
            Assert.Throws <FormatException>(() =>
                                            m.Parse("One", new[] { AssetType.Portrait, AssetType.Npc })); // Ambiguous
        }
Beispiel #14
0
        public AlbionPalette LoadPalette(PaletteId id)
        {
            var palette = (AlbionPalette)_modApplier.LoadAsset(id);

            if (palette == null)
            {
                return(null);
            }

            var commonPalette = (AlbionPalette)_modApplier.LoadAssetCached(AssetId.From(Base.Palette.Common));

            palette.SetCommonPalette(commonPalette);

            return(palette);
        }
Beispiel #15
0
        public void ParseTextualTest()
        {
            var m = AssetMapping.Global.Clear();

            Assert.Equal(AssetId.None, m.Parse("", null));
            m.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Portrait);

            Assert.Equal(AssetId.None, m.Parse("", null));
            Assert.Equal(AssetId.From(ZeroBasedByte.Zero), m.Parse("Zero", null));
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("One", null));
            Assert.Equal(AssetId.From(ZeroBasedByte.Zero), m.Parse("Portrait.Zero", null));
            Assert.Equal(AssetId.From(ZeroBasedByte.One), m.Parse("Portrait.One", null));
            Assert.Throws <FormatException>(() => m.Parse("Npc.Zero", null));
            Assert.Throws <FormatException>(() => m.Parse("Npc.One", null));
        }
Beispiel #16
0
        public void CommonPaletteTest()
        {
            var pal = Test(assets => assets.LoadPalette(Palette.Common));

            Assert.Equal(AssetId.From(Palette.Common), AssetId.FromUInt32(pal.Id));
            Assert.False(pal.IsAnimated);
            Assert.Equal(1, pal.Period);
            Assert.Equal("Palette.Common", pal.Name);
            var at0 = pal.GetPaletteAtTime(0);

            for (int i = 0; i < 192; i++)
            {
                Assert.Equal(0u, at0[i]);
            }
        }
Beispiel #17
0
        public void IdToEnumStringTest()
        {
            var m = AssetMapping.Global.Clear();

            m.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Portrait);
            m.RegisterAssetType(typeof(OneBasedByte), AssetType.Npc);

            var zbb = "UAlbion.Config.Tests.AssetMappingTests+ZeroBasedByte, UAlbion.Config.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
            var obb = "UAlbion.Config.Tests.AssetMappingTests+OneBasedByte, UAlbion.Config.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";

            Assert.Equal((zbb, 0), m.IdToEnumString(AssetId.From(ZeroBasedByte.Zero)));
            Assert.Equal((zbb, 1), m.IdToEnumString(AssetId.From(ZeroBasedByte.One)));
            Assert.Equal((zbb, 2), m.IdToEnumString(AssetId.From(ZeroBasedByte.Two)));
            Assert.Equal((obb, 1), m.IdToEnumString(AssetId.From(OneBasedByte.One)));
            Assert.Equal((obb, 2), m.IdToEnumString(AssetId.From(OneBasedByte.Two)));
            Assert.Equal((obb, 3), m.IdToEnumString(AssetId.From(OneBasedByte.Three)));
        }
Beispiel #18
0
        public AlbionPalette LoadPalette(PaletteId id)
        {
            var palette = (AlbionPalette)_modApplier.LoadAssetCached(id);

            if (palette == null)
            {
                return(null);
            }

            var commonId = AssetId.From(Base.Palette.CommonPalette);

            if (palette.Id != commonId.ToUInt32())
            {
                var commonPalette = (AlbionPalette)_modApplier.LoadAssetCached(commonId);
                palette.SetCommonPalette(commonPalette);
            }

            return(palette);
        }
Beispiel #19
0
    public void YesNoPromptTest()
    {
        AssetMapping.GlobalIsThreadLocal = true;
        AssetMapping.Global.Clear()
        .RegisterAssetType(typeof(Base.SystemText), AssetType.Text)
        .RegisterAssetType(typeof(Base.Font), AssetType.Font)
        ;

        var systemText = new Dictionary <TextId, string>
        {
            { Base.SystemText.MainMenu_DoYouReallyWantToQuit, "Do you really want to quit?" },
            { Base.SystemText.MsgBox_Yes, "Yes" },
            { Base.SystemText.MsgBox_No, "No" }
        };

        var ex  = new EventExchange(new LogExchange());
        var dm  = new DialogManager();
        var lm  = new LayoutManager();
        var mma = new MockModApplier()
                  .Add(new AssetId(AssetType.MetaFont, (ushort)new MetaFontId(false, FontColor.White)), MockUniformFont.Font(AssetId.From(Base.Font.RegularFont)))
                  .AddInfo(AssetId.From(Base.Font.RegularFont), MockUniformFont.Info)
        ;

        foreach (var kvp in systemText)
        {
            mma.Add(kvp.Key, kvp.Value);
        }

        ex
        .Attach(mma)
        .Attach(new AssetManager())
        .Attach(new SpriteManager())
        .Attach(new MockGameFactory())
        .Attach(new WordLookup())
        .Attach(new TextFormatter())
        .Attach(new TextManager())
        .Attach(new WindowManager {
            Resolution = (1920, 1080)
        })
Beispiel #20
0
        public void Map3DTest()
        {
            var map = (MapData3D)Test(assets => assets.LoadMap(Map.OldFormerBuilding));

            Assert.Equal(MapType.ThreeD, map.MapType);
            Assert.Equal(100, map.Width);
            Assert.Equal(50, map.Height);
            Assert.Equal(SpriteId.None, map.CombatBackgroundId);
            Assert.Equal(Song.Ethereal, map.SongId);
            Assert.Equal(Palette.GlowyPlantDungeon, map.PaletteId);
            Assert.Equal(Labyrinth.Argim, map.LabDataId);
            Assert.Equal(64, map.AutomapGraphics.Length);
            Assert.Equal(Song.DungeonAmbient, map.AmbientSongId);
            Assert.Equal(Map3DFlags.Unk0 | Map3DFlags.Unk2, map.Flags);
            Assert.Equal(map.Width * map.Height, map.Ceilings.Length);
            Assert.Equal(2, map.Ceilings[101]);
            Assert.Equal(map.Width * map.Height, map.Floors.Length);
            Assert.Equal(1, map.Floors[101]);
            Assert.Equal(map.Width * map.Height, map.Contents.Length);
            Assert.Equal(117, map.Contents[212]);

            Assert.Equal(0, map.Automap.Count);

            Assert.Equal(452, map.Events.Count);
            var en = map.Events[0];

            Assert.Equal(0, en.Id);
            Assert.Equal(1, en.Next.Id);
            Assert.IsType <SoundEvent>(en.Event);
            var e = (SoundEvent)en.Event;

            Assert.Equal(0, e.FrequencyOverride);
            Assert.Equal(SoundMode.LocalLoop, e.Mode);
            Assert.Equal(0, e.RestartProbability);
            Assert.Equal(0, e.Unk3);
            Assert.Equal(0, e.Unk3);
            Assert.Equal(SampleId.None, e.SoundId);

            Assert.Equal(64, map.Chains.Count);

            Assert.Equal(96, map.Npcs.Length);
            var n = map.Npcs[2];

            Assert.Equal(AssetId.From(MonsterGroup.Unknown1), n.Id);
            Assert.Equal(new AssetId(AssetType.ObjectGroup, 68), n.SpriteOrGroup);
            Assert.Equal(NpcFlags.Wander
                         | NpcFlags.IsMonster
                         | NpcFlags.Unk4
                         | NpcFlags.Unk5, n.Flags);
            Assert.Equal(23, n.Chain);
            Assert.Equal(NpcMovementTypes.Random1, n.Movement);
            Assert.Equal(3, n.Unk8);
            Assert.Equal(0, n.Unk9);
            Assert.Collection(n.Waypoints,
                              x =>
            {
                Assert.Equal(86, x.X);
                Assert.Equal(12, x.Y);
            });

            Assert.Equal(355, map.Zones.Count);
            var z = map.Zones[6];

            Assert.Equal(15, z.Chain);
            Assert.False(z.Global);
            Assert.Equal(TriggerTypes.Normal | TriggerTypes.Examine | TriggerTypes.UseItem, z.Trigger);
            Assert.Equal(0, z.Unk1);
            Assert.Equal(72, z.X);
            Assert.Equal(3, z.Y);
        }
Beispiel #21
0
 static AssetId Id <T>(T enumValue) where T : unmanaged, Enum => AssetId.From(enumValue);
Beispiel #22
0
        public void Dump(string baseDir, ISet <AssetType> types, DumpFormats formats, AssetId[] dumpIds)
        {
            void Export <TEnum>(string name) where TEnum : unmanaged, Enum
            {
                var directory = Path.Combine(baseDir, "data", "exported", "gfx", name);

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                var ids = Enum.GetValues(typeof(TEnum)).OfType <TEnum>().ToArray();

                Console.WriteLine($"Dumping {ids.Length} assets to {directory}...");
                var assets = Resolve <IAssetManager>();

                foreach (var id in ids)
                {
                    var assetId = AssetId.From(id);
                    if (dumpIds != null && !dumpIds.Contains(assetId))
                    {
                        continue;
                    }

                    ExportImage(assetId, assets, directory, formats, (frame, palFrame) => palFrame < 10); // Limit to 10, some of the tile sets can get a bit silly.
                }
            }

            foreach (var type in types)
            {
                switch (type)
                {
                // case AssetType.Slab:                Export<Base.Slab>             ("SLAB");                 break;
                case AssetType.AutomapGraphics:     Export <Base.AutomapTiles>     ("Automap");              break;

                case AssetType.CombatBackground:    Export <Base.CombatBackground> ("CombatBackgrounds");    break;

                case AssetType.CombatGraphics:      Export <Base.CombatGraphics>   ("Combat");               break;

                case AssetType.CoreGraphics:        Export <Base.CoreSprite>       ("Core");                 break;

                case AssetType.BackgroundGraphics:  Export <Base.DungeonBackground>("Backgrounds");          break;

                case AssetType.Floor:               Export <Base.Floor>            ("Floors");               break;

                case AssetType.Object3D:            Export <Base.DungeonObject>    ("Objects");              break;

                case AssetType.WallOverlay:         Export <Base.WallOverlay>      ("Overlays");             break;

                case AssetType.Wall:                Export <Base.Wall>             ("Walls");                break;

                case AssetType.Font:                Export <Base.Font>             ("Fonts");                break;

                case AssetType.FullBodyPicture:     Export <Base.FullBodyPicture>  ("InventoryBackgrounds"); break;

                case AssetType.TilesetGraphics:     Export <Base.TilesetGraphics>  ("Tiles");                break;

                case AssetType.ItemGraphics:        Export <Base.ItemGraphics>     ("Item");                 break;

                case AssetType.LargeNpcGraphics:    Export <Base.LargeNpc>         ("NpcLarge");             break;

                case AssetType.LargePartyGraphics:  Export <Base.LargePartyMember> ("PartyLarge");           break;

                case AssetType.MonsterGraphics:     Export <Base.MonsterGraphics>  ("Monster");              break;

                case AssetType.Picture:             Export <Base.Picture>          ("Picture");              break;

                case AssetType.SmallNpcGraphics:    Export <Base.SmallNpc>         ("NpcSmall");             break;

                case AssetType.SmallPartyGraphics:  Export <Base.SmallPartyMember> ("PartySmall");           break;

                case AssetType.Portrait:            Export <Base.Portrait>         ("Portrait");             break;

                case AssetType.TacticalIcon:        Export <Base.TacticalGraphics> ("TacticalIcon");         break;
                }
            }
        }
Beispiel #23
0
        static void MapData(IAssetManager assets, ITextFormatter tf, string baseDir, AssetId[] dumpIds)
        {
            using var sw = Open(baseDir, MapInfoPath);
            for (int i = 100; i < 400; i++)
            {
                AssetId id = AssetId.From((Base.Map)i);
                if (dumpIds != null && !dumpIds.Contains(id))
                {
                    continue;
                }

                IMapData map = assets.LoadMap(id);
                if (map == null)
                {
                    continue;
                }

                sw.Write($"{i} {(Base.Map)i} {map.MapType} ");
                sw.Write($"{map.Width}x{map.Height} ");
                sw.Write($"Palette:{map.PaletteId} ({map.PaletteId.Id}) ");
                if (map is MapData2D map2d)
                {
                    sw.Write($"FrameRate:{map2d.FrameRate} ");
                    sw.Write($"TileSet:{map2d.TilesetId} ");
                    sw.Write($"Flags:{map2d.Flags} ");
                    sw.Write($"Sound?:{map2d.Sound} ");
                }

                LabyrinthData lab = null;
                if (map is MapData3D map3d)
                {
                    sw.Write($"Flags: {map3d.Flags} ");
                    sw.Write($"Labyrinth: {map3d.LabDataId} ");
                    sw.Write($"Sound?:{map3d.AmbientSongId} ");
                    lab = assets.LoadLabyrinthData(map3d.LabDataId);
                }

                sw.Write($"Song:{map.SongId} ({map.SongId.Id}) ");
                sw.WriteLine($"CombatBackground:{map.CombatBackgroundId} ({map.CombatBackgroundId.Id})");

                for (int j = 0; j < map.Npcs.Count; j++)
                {
                    if (!map.Npcs.TryGetValue(j, out var npc))
                    {
                        continue;
                    }

                    var wp     = npc.Waypoints.FirstOrDefault();
                    var idText = npc.Id.ToString().PadLeft(15);

                    sw.Write($"    Npc{j:D3}: {idText} ({npc.Id.Id:D3}) ");
                    sw.Write($"X:{wp.X:D3} Y:{wp.Y:D3} ");
                    sw.Write($"U8:{npc.Unk8} ");
                    sw.Write($"U9:{npc.Unk9} ");
                    sw.Write($"F{(int)npc.Flags:X2}:({npc.Flags}) ");
                    sw.Write($"M:{npc.Movement} ");
                    sw.Write($"S:{npc.Sound} ({(int?)npc.Sound}) ");
                    switch (map.MapType)
                    {
                    case MapType.TwoD: sw.Write($"GR:{npc.SpriteOrGroup} "); break;

                    case MapType.TwoDOutdoors: sw.Write($"KL:{npc.SpriteOrGroup} "); break;

                    case MapType.ThreeD:
                        if (lab != null)
                        {
                            if (npc.SpriteOrGroup.Id >= lab.ObjectGroups.Count)
                            {
                                sw.Write($"InvalidObjGroup:{npc.SpriteOrGroup.Id}");
                            }
                            else
                            {
                                var objectData = lab.ObjectGroups[npc.SpriteOrGroup.Id];
                                sw.Write($"3D:{npc.SpriteOrGroup.Id}=(");
                                bool first = true;
                                foreach (var subObject in objectData.SubObjects)
                                {
                                    if (!first)
                                    {
                                        sw.Write(", ");
                                    }
                                    first = false;
                                    var def = lab.Objects[subObject.ObjectInfoNumber];
                                    sw.Write(def.SpriteId);
                                }

                                sw.Write(")");
                            }
                        }

                        break;
                    }

                    sw.WriteLine();

                    if (npc.Chain != null)
                    {
                        // var context = new EventContext(new EventSource.Map((MapDataId)i, TriggerType.Default, 0, 0));
                        sw.WriteLine($"        EventChain: {npc.Chain?.Id}");
                        foreach (var e in npc.Chain.Events)
                        {
                            if (e.Event is TextEvent textEvent)
                            {
                                var textSource = tf.Format(textEvent.ToId());
                                var text       = string.Join(", ", textSource.GetBlocks().Select(x => x.Text));
                                sw.WriteLine($"        {e} = {text}");
                            }
                            else
                            {
                                sw.Write("        ");
                                sw.WriteLine(e.ToString());
                            }
                        }
                    }
                }
            }
        }