Exemple #1
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();
        });
    }