コード例 #1
0
ファイル: IsometricBuilder.cs プロジェクト: lucorp/ualbion
        public List <int>[] Build(LabyrinthData labyrinth, AssetInfo info, IsometricMode mode, IAssetManager assets)
        {
            if (labyrinth == null)
            {
                throw new ArgumentNullException(nameof(labyrinth));
            }
            _labId = labyrinth.Id;
            _mode  = mode;

            _layout.Load(labyrinth, info, _mode, BuildProperties(), _paletteId, assets);
            int rows = (_layout.TileCount + _tilesPerRow - 1) / _tilesPerRow;

            if (Framebuffer != null)
            {
                Framebuffer.Width  = (uint)(_width * _tilesPerRow);
                Framebuffer.Height = (uint)(_height * rows);
            }

            Update();

            return(mode switch
            {
                IsometricMode.Floors => _layout.FloorFrames,
                IsometricMode.Ceilings => _layout.CeilingFrames,
                IsometricMode.Walls => _layout.WallFrames,
                IsometricMode.Contents => _layout.ContentsFrames,
                _ => null
            });
コード例 #2
0
ファイル: IsometricLayout.cs プロジェクト: lucorp/ualbion
        public void Load(LabyrinthId labyrinthId, IsometricMode mode, TilemapRequest request, int?paletteId)
        {
            var assets        = Resolve <IAssetManager>();
            var labyrinthData = assets.LoadLabyrinthData(labyrinthId);
            var info          = assets.GetAssetInfo(labyrinthId);

            if (labyrinthData == null || info == null)
            {
                return;
            }

            Load(labyrinthData, info, mode, request, paletteId, assets);
        }
コード例 #3
0
    public List <int>[] Build(LabyrinthData labyrinth, AssetInfo info, IsometricMode mode, IAssetManager assets)
    {
        if (labyrinth == null)
        {
            throw new ArgumentNullException(nameof(labyrinth));
        }
        _labId = labyrinth.Id;
        _mode  = mode;

        _layout.Load(labyrinth, info, _mode, BuildProperties(), _paletteId, assets);
        ResizeFramebuffer();
        Update();

        return(mode switch
        {
            IsometricMode.Floors => _layout.FloorFrames,
            IsometricMode.Ceilings => _layout.CeilingFrames,
            IsometricMode.Walls => _layout.WallFrames,
            IsometricMode.Contents => _layout.ContentsFrames,
            _ => null
        });
コード例 #4
0
    public IsometricBuilder(IFramebufferHolder framebuffer, int width, int height, int diamondHeight, int tilesPerRow)
    {
        Framebuffer  = framebuffer ?? throw new ArgumentNullException(nameof(framebuffer));
        _labId       = Base.Labyrinth.Test1;
        _layout      = AttachChild(new IsometricLayout());
        _width       = width;
        _height      = height;
        _pitch       = ApiUtil.RadToDeg(MathF.Asin((float)diamondHeight / _width));
        _tilesPerRow = tilesPerRow;

        On <IsoLabEvent>(e => { _labId = e.Id; RecreateLayout(); });
        On <IsoModeEvent>(e => { _mode = e.Mode; RecreateLayout(); });
        On <IsoYawEvent>(e => { _yaw += e.Delta; Update(); });
        On <IsoPitchEvent>(e => { _pitch += e.Delta; Update(); });
        On <IsoRowWidthEvent>(e =>
        {
            _tilesPerRow += e.Delta;
            if (_tilesPerRow < 1)
            {
                _tilesPerRow = 1;
            }
            Update();
        });
        On <IsoWidthEvent>(e =>
        {
            _width += e.Delta;
            if (_width < 1)
            {
                _width = 1;
            }
            Update();
        });
        On <IsoHeightEvent>(e =>
        {
            _height += e.Delta;
            if (_height < 1)
            {
                _height = 1;
            }
            Update();
        });
        On <IsoPaletteEvent>(e =>
        {
            _paletteId = (_paletteId ?? 0) + e.Delta;
            if (_paletteId <= 0)
            {
                _paletteId = null;
            }
            Info($"PalId: {_paletteId}");
            RecreateLayout();
        });
        On <IsoLabDeltaEvent>(e =>
        {
            var newId = _labId.Id + e.Delta;
            if (newId < 0)
            {
                return;
            }

            _labId = new LabyrinthId(AssetType.Labyrinth, newId);
            Info($"LabId: {_labId} ({_labId.Id})");
            RecreateLayout();
        });
    }
コード例 #5
0
ファイル: RawAssetManager.cs プロジェクト: lucorp/ualbion
 public LabyrinthData LoadLabyrinthData(LabyrinthId id) => (LabyrinthData)_modApplier.LoadAsset(id);
コード例 #6
0
ファイル: MapData3D.cs プロジェクト: lucorp/ualbion
        public static MapData3D Serdes(AssetInfo info, MapData3D existing, AssetMapping mapping, ISerializer s)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            var map = existing ?? new MapData3D {
                Id = info.AssetId
            };

            map.Flags            = s.EnumU8(nameof(Flags), map.Flags);                                                                              // 0
            map.OriginalNpcCount = s.UInt8(nameof(OriginalNpcCount), map.OriginalNpcCount);                                                         // 1
            int npcCount = NpcCountTransform.Instance.FromNumeric(map.OriginalNpcCount);
            var _        = s.UInt8("MapType", (byte)map.MapType);                                                                                   // 2

            map.SongId             = SongId.SerdesU8(nameof(SongId), map.SongId, mapping, s);                                                       // 3
            map.Width              = s.UInt8(nameof(Width), map.Width);                                                                             // 4
            map.Height             = s.UInt8(nameof(Height), map.Height);                                                                           // 5
            map.LabDataId          = LabyrinthId.SerdesU8(nameof(LabDataId), map.LabDataId, mapping, s);                                            // 6
            map.CombatBackgroundId = SpriteId.SerdesU8(nameof(CombatBackgroundId), map.CombatBackgroundId, AssetType.CombatBackground, mapping, s); // 7 TODO: Verify this is combat background
            map.PaletteId          = PaletteId.SerdesU8(nameof(PaletteId), map.PaletteId, mapping, s);
            map.AmbientSongId      = SongId.SerdesU8(nameof(AmbientSongId), map.AmbientSongId, mapping, s);
            map.Npcs = s.List(
                nameof(Npcs),
                map.Npcs,
                npcCount,
                (n, x, s2) => MapNpc.Serdes(n, x, map.MapType, mapping, s2)).ToArray();

            map.Contents ??= new byte[map.Width * map.Height];
            map.Floors ??= new byte[map.Width * map.Height];
            map.Ceilings ??= new byte[map.Width * map.Height];

            for (int i = 0; i < map.Width * map.Height; i++)
            {
                map.Contents[i] = s.UInt8(null, map.Contents[i]);
                map.Floors[i]   = s.UInt8(null, map.Floors[i]);
                map.Ceilings[i] = s.UInt8(null, map.Ceilings[i]);
            }
            s.Check();

            map.SerdesZones(s);

            if (s.IsReading() && s.IsComplete() || s.IsWriting() && map.AutomapGraphics == null)
            {
                ApiUtil.Assert(map.Zones.Count == 0);
                foreach (var npc in map.Npcs)
                {
                    npc.Waypoints = new NpcWaypoint[1];
                }
                return(map);
            }

            map.SerdesEvents(mapping, s);
            map.SerdesNpcWaypoints(s);
            map.SerdesAutomap(s);
            map.SerdesChains(s, 64);

            if (s.IsReading())
            {
                map.Unswizzle();
            }

            return(map);
        }
コード例 #7
0
ファイル: IsoLabEvent.cs プロジェクト: csinkers/ualbion
 public IsoLabEvent(LabyrinthId id) => Id = id;
コード例 #8
0
        public static MapData3D Serdes(AssetInfo info, MapData3D existing, AssetMapping mapping, ISerializer s)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            var map = existing ?? new MapData3D(info.AssetId);

            map.Flags = s.EnumU8(nameof(Flags), map.Flags);                                                                                         // 0
            int npcCount = s.Transform("NpcCount", map.Npcs.Count, S.UInt8, NpcCountTransform.Instance);                                            // 1
            var _        = s.UInt8("MapType", (byte)map.MapType);                                                                                   // 2

            map.SongId             = SongId.SerdesU8(nameof(SongId), map.SongId, mapping, s);                                                       // 3
            map.Width              = s.UInt8(nameof(Width), map.Width);                                                                             // 4
            map.Height             = s.UInt8(nameof(Height), map.Height);                                                                           // 5
            map.LabDataId          = LabyrinthId.SerdesU8(nameof(LabDataId), map.LabDataId, mapping, s);                                            // 6
            map.CombatBackgroundId = SpriteId.SerdesU8(nameof(CombatBackgroundId), map.CombatBackgroundId, AssetType.CombatBackground, mapping, s); // 7 TODO: Verify this is combat background
            map.PaletteId          = PaletteId.SerdesU8(nameof(PaletteId), map.PaletteId, mapping, s);
            map.AmbientSongId      = SongId.SerdesU8(nameof(AmbientSongId), map.AmbientSongId, mapping, s);

            for (int i = 0; i < npcCount; i++)
            {
                map.Npcs.TryGetValue(i, out var npc);
                npc = MapNpc.Serdes(i, npc, MapType.ThreeD, mapping, s);
                if (!npc.Id.IsNone)
                {
                    map.Npcs[i] = npc;
                }
            }
            s.Check();

            map.Contents ??= new byte[map.Width * map.Height];
            map.Floors ??= new byte[map.Width * map.Height];
            map.Ceilings ??= new byte[map.Width * map.Height];

            for (int i = 0; i < map.Width * map.Height; i++)
            {
                map.Contents[i] = s.UInt8(null, map.Contents[i]);
                map.Floors[i]   = s.UInt8(null, map.Floors[i]);
                map.Ceilings[i] = s.UInt8(null, map.Ceilings[i]);
            }
            s.Check();

            map.SerdesZones(s);

            if (s.Mode == SerializerMode.Reading && s.IsComplete() || s.Mode != SerializerMode.Reading && map.AutomapGraphics == null)
            {
                ApiUtil.Assert(map.Zones.Count == 0);
                return(map);
            }

            map.SerdesEvents(mapping, s);
            map.SerdesNpcWaypoints(s);
            map.SerdesAutomap(s);
            map.SerdesChains(s, 64);

            if (s.Mode == SerializerMode.Reading)
            {
                map.Unswizzle();
            }

            return(map);
        }
コード例 #9
0
ファイル: AssetManager.cs プロジェクト: vsafonkin/ualbion
 LabyrinthData IAssetManager.LoadLabyrinthData(LabyrinthId id)
 {
     return(LoadLabyrinthData(id));
 }