コード例 #1
0
ファイル: ScriptManager.cs プロジェクト: vsafonkin/ualbion
        bool Run(DoScriptEvent doScriptEvent, Action continuation)
        {
            var assets     = Resolve <IAssetManager>();
            var mapManager = Resolve <IMapManager>();

            var events = assets.LoadScript(doScriptEvent.ScriptId);

            if (events == null)
            {
                CoreUtil.LogError($"Could not load script {doScriptEvent.ScriptId}");
                return(false);
            }

            var nodes = new EventNode[events.Count];
            var chain = new EventChain(0);

            // Create, link and add all the nodes.
            for (ushort i = 0; i < events.Count; i++)
            {
                nodes[i] = new EventNode(i, events[i]);
            }
            for (ushort i = 0; i < events.Count - 1; i++)
            {
                nodes[i].Next = nodes[i + 1];
            }
            for (ushort i = 0; i < events.Count; i++)
            {
                chain.Events.Add(nodes[i]);
            }

            var source  = new EventSource(mapManager.Current.MapId, mapManager.Current.MapId.ToMapText(), TriggerTypes.Default); // TODO: Is there a better trigger type for this?
            var trigger = new TriggerChainEvent(chain, chain.FirstEvent, source);

            return(RaiseAsync(trigger, continuation) > 0);
        }
コード例 #2
0
ファイル: LogicalMap2D.cs プロジェクト: IllidanS4/ualbion
        void ChangeOverlay(byte x, byte y, ushort value)
        {
            var index = Index(x, y);

            if (index < 0 || index >= _mapData.Overlay.Length)
            {
                CoreUtil.LogError($"Tried to update invalid overlay index {index} (max {_mapData.Overlay.Length}");
            }
            else
            {
                _mapData.Overlay[Index(x, y)] = value;
                Dirty?.Invoke(this, new DirtyTileEventArgs(x, y, IconChangeType.Overlay));
            }
        }
コード例 #3
0
ファイル: DumpGraphics.cs プロジェクト: vsafonkin/ualbion
        public static IList <ExportedImageInfo> ExportImage(AssetId assetId, IAssetManager assets, string directory, DumpFormats formats, Func <int, int, bool> frameFilter = null)
        {
            var filenames = new List <ExportedImageInfo>();
            var config    = assets.GetAssetInfo(assetId);
            var palette   = assets.LoadPalette((Base.Palette)(config?.Get <int?>("PaletteHint", null) ?? (int)Base.Palette.Inventory));
            var texture   = assets.LoadTexture(assetId);

            if (texture == null)
            {
                return(filenames);
            }

            if (texture is TrueColorTexture trueColor)
            {
                var path  = Path.Combine(directory, $"{assetId.Id}_{assetId}");
                var image = trueColor.ToImage();
                Save(image, path, formats, filenames);
            }
            else if (texture is VeldridEightBitTexture tilemap && (
                         assetId.Type == AssetType.Font ||
                         assetId.Type == AssetType.TilesetGraphics ||
                         assetId.Type == AssetType.AutomapGraphics))
            {
                if (palette == null)
                {
                    CoreUtil.LogError($"Could not load palette for {assetId}");
                    return(filenames);
                }

                var colors        = tilemap.DistinctColors(null);
                int palettePeriod = palette.CalculatePeriod(colors);

                for (int palFrame = 0; palFrame < palettePeriod; palFrame++)
                {
                    if (frameFilter != null && !frameFilter(0, palFrame))
                    {
                        continue;
                    }
                    var path  = Path.Combine(directory, $"{assetId.Id}_{palFrame}_{assetId}");
                    var image = tilemap.ToImage(palette.GetPaletteAtTime(palFrame));
                    Save(image, path, formats, filenames);
                }
            }
コード例 #4
0
ファイル: LogicalMap2D.cs プロジェクト: IllidanS4/ualbion
        public void PlaceBlock(byte x, byte y, ushort blockId, bool overwrite)
        {
            if (blockId >= _blockList.Count)
            {
                CoreUtil.LogError($"Tried to set out-of-range block {blockId} (max id {_blockList.Count-1})");
                return;
            }

            var block = _blockList[blockId];

            for (int j = 0; j < block.Height; j++)
            {
                for (int i = 0; i < block.Width; i++)
                {
                    var targetIndex      = Index(x + i, y + j);
                    var targetBlockIndex = j * block.Width + i;

                    if (targetIndex < 0 || targetIndex > _mapData.Underlay.Length)
                    {
                        CoreUtil.LogError($"Tried to set out-of-range index {targetIndex}, @ ({x},{y}) + ({i},{j}) for block {blockId}");
                        return;
                    }

                    int underlay    = _mapData.Underlay[targetIndex];
                    int newUnderlay = block.Underlay[targetBlockIndex];
                    if (newUnderlay > 1 && (overwrite || underlay <= 1))
                    {
                        _mapData.Underlay[targetIndex] = newUnderlay;
                        Dirty?.Invoke(this, new DirtyTileEventArgs(x + i, y + j, IconChangeType.Underlay));
                    }

                    int overlay    = _mapData.Overlay[targetIndex];
                    int newOverlay = block.Overlay[targetBlockIndex];
                    if (overwrite || overlay > 1)
                    {
                        _mapData.Overlay[targetIndex] = newOverlay;
                        Dirty?.Invoke(this, new DirtyTileEventArgs(x + i, y + j, IconChangeType.Overlay));
                    }
                }
            }
        }