Exemplo n.º 1
0
        public void SetPacked(int offset, byte[] packed, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            _set.Clear();
            if (packed == null)
            {
                return;
            }

            for (int i = 0; i < packed.Length; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    bool     flagValue = (packed[i] & (1 << j)) != 0;
                    int      diskId    = i * 8 + j + offset;
                    SwitchId id        = AssetMapping.Global.EnumToId(mapping.IdToEnum(new SwitchId(AssetType.Switch, diskId)));
                    if (flagValue)
                    {
                        _set.Add(id);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static DoorId FromDisk(int disk, AssetMapping mapping)
        {
            if (mapping == null) throw new ArgumentNullException(nameof(mapping));
            

            var (enumType, enumValue) = mapping.IdToEnum(new DoorId(AssetType.Door, disk));
            return (DoorId)AssetMapping.Global.EnumToId(enumType, enumValue);
        }
Exemplo n.º 3
0
 public static AssetId FromDisk(AssetType type, int disk, AssetMapping mapping)
 {
     if (mapping == null)
     {
         throw new ArgumentNullException(nameof(mapping));
     }
     var(enumType, enumValue) = mapping.IdToEnum(new AssetId(type, disk));
     return(AssetMapping.Global.EnumToId(enumType, enumValue));
 }
Exemplo n.º 4
0
        public void MergeTest()
        {
            var m1 = new AssetMapping();
            var m2 = new AssetMapping();

            m1.RegisterAssetType(typeof(ZeroBasedByte), AssetType.Portrait);
            m2.RegisterAssetType(typeof(OneBasedByte), AssetType.Portrait);

            Assert.Equal(new AssetId(AssetType.Portrait, 1), m1.EnumToId(ZeroBasedByte.One));
            Assert.Throws <ArgumentOutOfRangeException>(() => m1.EnumToId(OneBasedByte.One));
            Assert.Throws <ArgumentOutOfRangeException>(() => m2.EnumToId(ZeroBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Portrait, 1), m2.EnumToId(OneBasedByte.One));

            Assert.Throws <ArgumentNullException>(() => m2.MergeFrom(null));
            m2.MergeFrom(m1);
            Assert.Equal(new AssetId(AssetType.Portrait, 1), m1.EnumToId(ZeroBasedByte.One));
            Assert.Throws <ArgumentOutOfRangeException>(() => m1.EnumToId(OneBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Portrait, 5), m2.EnumToId(ZeroBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Portrait, 1), m2.EnumToId(OneBasedByte.One));

            m2.RegisterAssetType(typeof(ZeroBasedShort), AssetType.Portrait);
            Assert.Throws <ArgumentOutOfRangeException>(() => m1.EnumToId(ZeroBasedShort.Zero));
            Assert.Equal(new AssetId(AssetType.Portrait, 7), m2.EnumToId(ZeroBasedShort.Zero));

            m1.MergeFrom(m2);
            Assert.Equal(new AssetId(AssetType.Portrait, 1), m1.EnumToId(ZeroBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Portrait, 3), m1.EnumToId(OneBasedByte.One));
            Assert.Equal(new AssetId(AssetType.Portrait, 6), m1.EnumToId(ZeroBasedShort.Zero));

            Assert.Collection(
                new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }.Select(x => m1.IdToEnum(new AssetId(AssetType.Portrait, x))),
                x => { Assert.Equal(typeof(ZeroBasedByte), x.Item1); Assert.Equal(0, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedByte), x.Item1); Assert.Equal(1, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedByte), x.Item1); Assert.Equal(2, x.Item2); },
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(1, x.Item2); },
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(2, x.Item2); },
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(3, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedShort), x.Item1); Assert.Equal(0, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedShort), x.Item1); Assert.Equal(1, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedShort), x.Item1); Assert.Equal(2, x.Item2); }
                );

            Assert.Collection(
                new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.Select(x => m2.IdToEnum(new AssetId(AssetType.Portrait, x))),
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(0, x.Item2); },
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(1, x.Item2); },
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(2, x.Item2); },
                x => { Assert.Equal(typeof(OneBasedByte), x.Item1); Assert.Equal(3, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedByte), x.Item1); Assert.Equal(0, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedByte), x.Item1); Assert.Equal(1, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedByte), x.Item1); Assert.Equal(2, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedShort), x.Item1); Assert.Equal(0, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedShort), x.Item1); Assert.Equal(1, x.Item2); },
                x => { Assert.Equal(typeof(ZeroBasedShort), x.Item1); Assert.Equal(2, x.Item2); }
                );
        }
Exemplo n.º 5
0
        public static FullBodyPictureId FromDisk(int disk, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }


            var(enumType, enumValue) = mapping.IdToEnum(new FullBodyPictureId(AssetType.FullBodyPicture, disk));
            return((FullBodyPictureId)AssetMapping.Global.EnumToId(enumType, enumValue));
        }
Exemplo n.º 6
0
        public static WaveLibraryId FromDisk(int disk, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }


            var(enumType, enumValue) = mapping.IdToEnum(new WaveLibraryId(AssetType.WaveLibrary, disk));
            return((WaveLibraryId)AssetMapping.Global.EnumToId(enumType, enumValue));
        }
Exemplo n.º 7
0
    public static TilesetGraphicsId FromDisk(int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }


        var(enumType, enumValue) = mapping.IdToEnum(new TilesetGraphicsId(AssetType.TilesetGraphics, disk));
        return((TilesetGraphicsId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 8
0
        public static MonsterGroupId FromDisk(int disk, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }


            var(enumType, enumValue) = mapping.IdToEnum(new MonsterGroupId(AssetType.MonsterGroup, disk));
            return((MonsterGroupId)AssetMapping.Global.EnumToId(enumType, enumValue));
        }
Exemplo n.º 9
0
        public static PartyMemberId FromDisk(int disk, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }


            var(enumType, enumValue) = mapping.IdToEnum(new PartyMemberId(AssetType.PartyMember, disk));
            return((PartyMemberId)AssetMapping.Global.EnumToId(enumType, enumValue));
        }
Exemplo n.º 10
0
    public static TextId FromDisk(AssetType type, int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }

        if (!(type == AssetType.None || type >= AssetType.EventText && type <= AssetType.Word || type == AssetType.Special))
        {
            throw new ArgumentOutOfRangeException($"Tried to construct a TextId with a type of {type}");
        }

        var(enumType, enumValue) = mapping.IdToEnum(new TextId(type, disk));
        return((TextId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 11
0
    public static CharacterId FromDisk(AssetType type, int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }

        if (!(type == AssetType.None || type >= AssetType.Monster && type <= AssetType.Party))
        {
            throw new ArgumentOutOfRangeException($"Tried to construct a CharacterId with a type of {type}");
        }

        var(enumType, enumValue) = mapping.IdToEnum(new CharacterId(type, disk));
        return((CharacterId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 12
0
    public static SpriteId FromDisk(AssetType type, int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }

        if (!(type >= AssetType.None && type <= AssetType.WallOverlay))
        {
            throw new ArgumentOutOfRangeException($"Tried to construct a SpriteId with a type of {type}");
        }

        var(enumType, enumValue) = mapping.IdToEnum(new SpriteId(type, disk));
        return((SpriteId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 13
0
        public byte[] GetPacked(int from, int to, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }
            var packed = new byte[PackedSize(from, to)];

            for (int i = 0; i < to - from; i++)
            {
                var diskId   = new SwitchId(AssetType.Switch, i + from);
                var globalId = AssetMapping.Global.EnumToId(mapping.IdToEnum(diskId));
                packed[i / 8] |= (byte)((_set.Contains(globalId) ? 1 : 0) << (i % 8));
            }

            return(packed);
        }
Exemplo n.º 14
0
    public static AssetId SerdesU16(string name, AssetId id, AssetType type, AssetMapping mapping, ISerializer s)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        var(enumType, enumValue) = AssetMapping.Global.IdToEnum(id);
        ushort diskValue = (ushort)mapping.EnumToId(enumType, enumValue).Id;

        diskValue = s.UInt16(name, diskValue);

        (enumType, enumValue) = mapping.IdToEnum(new AssetId(type, diskValue));
        return(AssetMapping.Global.EnumToId(enumType, enumValue));
    }