Exemple #1
0
        public override bool Convert(ConvertOperation convert)
        {
            bool finishConvertOp = false;
            List<Pixmap> availData = convert.Perform<Pixmap>().ToList();

            // Generate objects
            foreach (Pixmap baseRes in availData)
            {
                if (convert.IsObjectHandled(baseRes)) continue;

                // Find target Resource matching the source - or create one.
                Tileset targetRes =
                    this.FindMatchingResources<Pixmap,Tileset>(baseRes, IsMatch)
                    .FirstOrDefault();
                if (targetRes == null && convert.AllowedOperations.HasFlag(ConvertOperation.Operation.CreateRes))
                {
                    string texPath = PathHelper.GetFreePath(baseRes.FullName, Resource.GetFileExtByType<Tileset>());
                    targetRes = new Tileset();
                    targetRes.RenderConfig.Add(new TilesetRenderInput
                    {
                        SourceData = baseRes
                    });
                    targetRes.Compile();
                    targetRes.Save(texPath);
                }

                if (targetRes == null) continue;
                convert.AddResult(targetRes);
                finishConvertOp = true;
                convert.MarkObjectHandled(baseRes);
            }

            return finishConvertOp;
        }
Exemple #2
0
        public override void Perform(Pixmap obj)
        {
            string  targetPath = PathHelper.GetFreePath(obj.FullName, Resource.GetFileExtByType <Tileset>());
            Tileset targetRes  = new Tileset();

            targetRes.RenderConfig.Add(new TilesetRenderInput
            {
                SourceData = obj
            });
            targetRes.Compile();
            targetRes.Save(targetPath);
        }
Exemple #3
0
        private void PropagateDependentResourceChanges(ContentRef <Resource> resRef, List <object> modifiedObjects)
        {
            // If a pixmap has been modified, rebuild the tilesets that are based on it.
            if (resRef.Is <Pixmap>())
            {
                ContentRef <Pixmap> pixRef            = resRef.As <Pixmap>();
                List <Tileset>      recompileTilesets = this.GetRecompileTilesets(pixRef);
                foreach (Tileset tileset in recompileTilesets)
                {
                    // Recompile the tileset
                    tileset.Compile();
                    modifiedObjects.Add(tileset);
                }
            }
            // If a Tileset has been modified, we'll need to give local Components a chance to update.
            else if (resRef.Is <Tileset>())
            {
                ContentRef <Tileset> tilesetRef = resRef.As <Tileset>();
                Tileset tileset = tilesetRef.Res;

                if (tileset != null)
                {
                    // A Tileset was modified for which we scheduled an auto-apply / recompile
                    if (tileset.HasChangedSinceCompile && this.recompileOnChange.Remove(tilesetRef))
                    {
                        tileset.Compile();
                    }

                    // Since we're able to edit tilesets without applying changes yet,
                    // we'll check whether there are new compiled changes. Don't update
                    // stuff unnecessarily if the changes aren't compiled yet anyway.
                    bool appliedTilesetChanges = tileset.Compiled && !tileset.HasChangedSinceCompile;
                    if (appliedTilesetChanges)
                    {
                        foreach (Tilemap tilemap in Scene.Current.FindComponents <Tilemap>())
                        {
                            // Early-out for unaffected tilemaps
                            if (tilemap.Tileset != tilesetRef)
                            {
                                continue;
                            }

                            // Notify every Component that is interested about changes using
                            // a trick: Since they will almost certainly be subscribed to
                            // tilemap changes anyway, pretend to change the entire tilemap.
                            tilemap.BeginUpdateTiles();
                            tilemap.EndUpdateTiles();
                        }
                    }
                }
            }
        }
Exemple #4
0
        public override bool Convert(ConvertOperation convert)
        {
            bool          finishConvertOp = false;
            List <Pixmap> availData       = convert.Perform <Pixmap>().ToList();

            // Generate objects
            foreach (Pixmap baseRes in availData)
            {
                if (convert.IsObjectHandled(baseRes))
                {
                    continue;
                }

                // Find target Resource matching the source - or create one.
                Tileset targetRes =
                    this.FindMatchingResources <Pixmap, Tileset>(baseRes, IsMatch)
                    .FirstOrDefault();
                if (targetRes == null && convert.AllowedOperations.HasFlag(ConvertOperation.Operation.CreateRes))
                {
                    string texPath = PathHelper.GetFreePath(baseRes.FullName, Resource.GetFileExtByType <Tileset>());
                    targetRes = new Tileset();
                    targetRes.RenderConfig.Add(new TilesetRenderInput
                    {
                        SourceData = baseRes
                    });
                    targetRes.Compile();
                    targetRes.Save(texPath);
                }

                if (targetRes == null)
                {
                    continue;
                }
                convert.AddResult(targetRes);
                finishConvertOp = true;
                convert.MarkObjectHandled(baseRes);
            }

            return(finishConvertOp);
        }
Exemple #5
0
        private void OnResourceModified(ContentRef <Resource> resRef)
        {
            List <object> changedObj = null;

            // If a pixmap has been modified, rebuild the tilesets that are based on it.
            if (resRef.Is <Pixmap>())
            {
                ContentRef <Pixmap> pixRef            = resRef.As <Pixmap>();
                List <Tileset>      recompileTilesets = this.GetRecompileTilesets(pixRef);
                foreach (Tileset tileset in recompileTilesets)
                {
                    // Recompile the tileset
                    tileset.Compile();

                    if (changedObj == null)
                    {
                        changedObj = new List <object>();
                    }
                    changedObj.Add(tileset);
                }
            }
            // If a Tileset has been modified, we'll need to give local Components a chance to update.
            else if (resRef.Is <Tileset>())
            {
                ContentRef <Tileset> tilesetRef = resRef.As <Tileset>();
                Tileset tileset = tilesetRef.Res;

                // A Tileset was modified for which we scheduled an auto-apply / recompile
                if (tileset.HasChangedSinceCompile && this.recompileOnChange.Remove(tilesetRef))
                {
                    tileset.Compile();
                }

                // Since we're able to edit tilesets without applying changes yet,
                // we'll check whether there are new compiled changes. Don't update
                // stuff unnecessarily if the changes aren't compiled yet anyway.
                bool appliedTilesetChanges =
                    tileset != null &&
                    tileset.Compiled &&
                    !tileset.HasChangedSinceCompile;

                if (appliedTilesetChanges)
                {
                    foreach (Tilemap tilemap in Scene.Current.FindComponents <Tilemap>())
                    {
                        // Early-out for unaffected tilemaps
                        if (tilemap.Tileset != tilesetRef)
                        {
                            continue;
                        }

                        // Notify every Component that is interested about changes using
                        // a trick: Since they will almost certainly be subscribed to
                        // tilemap changes anyway, pretend to change the entire tilemap.
                        tilemap.BeginUpdateTiles();
                        tilemap.EndUpdateTiles();
                    }
                }
            }

            // Notify a change that isn't critical regarding persistence (don't flag stuff unsaved)
            if (changedObj != null)
            {
                DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(changedObj as IEnumerable <object>), false);
            }
        }
        private void OnResourceModified(ContentRef <Resource> resRef)
        {
            List <object> changedObj = null;

            // If a pixmap has been modified, rebuild the tilesets that are based on it.
            if (resRef.Is <Pixmap>())
            {
                ContentRef <Pixmap> pixRef = resRef.As <Pixmap>();
                foreach (ContentRef <Tileset> tilesetRef in ContentProvider.GetLoadedContent <Tileset>())
                {
                    Tileset tileset = tilesetRef.Res;

                    // Early-out, if the tileset is unavailable, or we didn't compile it yet anyway
                    if (tileset == null)
                    {
                        continue;
                    }
                    if (!tileset.Compiled)
                    {
                        continue;
                    }

                    // Determine whether this tileset uses the modified pixmap
                    bool usesModifiedPixmap = false;
                    foreach (TilesetRenderInput input in tileset.RenderConfig)
                    {
                        if (input.SourceData == pixRef)
                        {
                            usesModifiedPixmap = true;
                            break;
                        }
                    }
                    if (!usesModifiedPixmap)
                    {
                        continue;
                    }

                    // Recompile the tileset
                    tileset.Compile();

                    if (changedObj == null)
                    {
                        changedObj = new List <object>();
                    }
                    changedObj.Add(tilesetRef.Res);
                }
            }
            // If a Tileset has been modified, we'll need to give local Components a chance to update.
            else if (resRef.Is <Tileset>())
            {
                ContentRef <Tileset> tilesetRef = resRef.As <Tileset>();
                Tileset tileset = tilesetRef.Res;

                // Since we're able to edit tilesets without applying changes yet,
                // we'll check whether there are new compiled changes. Don't update
                // stuff unnecessarily if the changes aren't compiled yet anyway.
                bool appliedTilesetChanges =
                    tileset != null &&
                    tileset.Compiled &&
                    !tileset.HasChangedSinceCompile;

                if (appliedTilesetChanges)
                {
                    foreach (Tilemap tilemap in Scene.Current.FindComponents <Tilemap>())
                    {
                        // Early-out for unaffected tilemaps
                        if (tilemap.Tileset != tilesetRef)
                        {
                            continue;
                        }

                        // Notify every Component that is interested about changes using
                        // a trick: Since they will almost certainly be subscribed to
                        // tilemap changes anyway, pretend to change the entire tilemap.
                        tilemap.BeginUpdateTiles();
                        tilemap.EndUpdateTiles();
                    }
                }
            }

            // Notify a change that isn't critical regarding persistence (don't flag stuff unsaved)
            if (changedObj != null)
            {
                DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(changedObj as IEnumerable <object>), false);
            }
        }