Esempio n. 1
0
        public virtual void LoadBrushWithBackAsset(EditorBrush brush, Editor parent, string name, string type)
        {
            string extension = EditorHelpers.GetExtensionFromBrushType(type);

            // Objects and NPCs must always be a front asset
            if (!brush.NeedsBackAsset || extension == null || type == "object" || type == "npc")
            {
                return;
            }

            StarboundAsset asset = null;

            // Load the background tile
            if (parent.AssetMap.ContainsKey(name + extension))
            {
                asset           = parent.AssetMap[name + extension];
                brush.BackAsset = asset;
            }
            else
            {
                // If this is an internal asset - liquids, etc
                // This is a hack to display liquids until liquid parsing has been implemented
                // (low priority)
                if (name == "lava")
                {
                    asset           = new StarboundTile();
                    asset.AssetName = name;
                    asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8, 207, 16, 32, 255);
                }
                else if (name == "acid")
                {
                    asset           = new StarboundTile();
                    asset.AssetName = name;
                    asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8, 107, 141, 63, 255);
                }
                else if (name == "water")
                {
                    asset           = new StarboundTile();
                    asset.AssetName = name;
                    asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8, 0, 78, 111, 255);
                }
                else if (name == "liquidtar" || name == "tentaclejuice")
                {
                    asset           = new StarboundTile();
                    asset.AssetName = name;
                    asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8, 200, 191, 231, 255);
                }
                // Else just load the asset
                else
                {
                    asset = parent.LoadAsset(name, type);
                }

                if (asset != null)
                {
                    parent.AssetMap[name + extension] = asset;
                    brush.BackAsset = asset;
                }
            }
        }
Esempio n. 2
0
        public virtual void LoadBrushWithFrontAsset(EditorBrush brush, Editor parent, string name, string type)
        {
            string extension = EditorHelpers.GetExtensionFromBrushType(type);

            if (!brush.NeedsFrontAsset || extension == null)
            {
                return;
            }

            StarboundAsset asset = null;

            // Load the foreground tile
            if (parent.AssetMap.ContainsKey(name + extension))
            {
                asset            = parent.AssetMap[name + extension];
                brush.FrontAsset = asset;
            }
            else
            {
                asset = parent.LoadAsset(name, type);

                if (asset != null)
                {
                    parent.AssetMap[name + extension] = asset;
                    brush.FrontAsset = asset;
                }
            }
        }
Esempio n. 3
0
        public void SetSelectedBrush(EditorBrush brush)
        {
            StarboundAsset asset = null;

            if (brush != null && brush.NeedsFrontAsset && brush.FrontAsset != null)
            {
                asset = brush.FrontAsset;
            }
            else if (brush != null && brush.NeedsBackAsset && brush.BackAsset != null)
            {
                asset = brush.BackAsset;
            }
            else
            {
                asset           = new StarboundTile();
                asset.AssetName = "gridAsset.INTERNAL";
                asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8, 255, 255, 255, 128);
            }

            m_selectedBrush = brush;
            m_selectedAsset = asset;

            Invalidate();
        }
        // This function is one big wall of useless repeated code
        // Fix it at some point
        private void LoadSpecialBrushes(Editor.Editor parent)
        {
            // Get all collision blocks
            foreach (DungeonBrush brush in BlockMap)
            {
                // If this brush is a connector
                if (brush.Connector != null && (bool) brush.Connector)
                {
                    string assetName = brush.Comment + ".INTERNAL";

                    StarboundAsset asset = parent.LoadAsset(assetName, "brush");
                    if (asset == null )
                    {
                        asset = new StarboundAsset();
                        //asset.AssetName = assetName;
                        asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8,
                            brush.Colour.R,
                            brush.Colour.G,
                            brush.Colour.B,
                            brush.Colour.A);
                        //parent.RegisterAsset(assetName, "brush", asset);
                    }

                    brush.NeedsFrontAsset = true;
                    brush.FrontAsset = asset;
                    brush.IsSpecial = true;
                }

                // If this brush is surface foreground
                else if (brush.BrushTypes.Contains("surface"))
                {
                    string assetName = Editor.Editor.Settings.SurfaceForegroundTile;

                    StarboundAsset asset = parent.LoadAsset(assetName, "surface");
                    if (asset == null && assetName.Contains("INTERNAL"))
                    {
                        asset = new StarboundAsset();
                        //asset.AssetName = assetName;
                        asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8,
                            87, 59, 12, 255);
                        //parent.RegisterAsset(assetName, "surface", asset);
                    }

                    brush.FrontAsset = asset;
                    brush.BrushTypes.Add("front");
                    brush.NeedsFrontAsset = true;
                }

                // If this brush is surface background
                else if (brush.BrushTypes.Contains("surfacebackground"))
                {
                    string assetName = Editor.Editor.Settings.SurfaceBackgroundTile;

                    StarboundAsset asset = parent.LoadAsset(assetName, "surfacebackground");
                    if (asset == null && assetName.Contains("INTERNAL"))
                    {
                        asset = new StarboundAsset();
                        //asset.AssetName = assetName;
                        asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8,
                            87, 59, 12, 255);
                        //parent.RegisterAsset(assetName, "surfacebackground", asset);
                    }
                    brush.BackAsset = asset;
                    brush.BrushTypes.Add("back");
                    brush.NeedsBackAsset = true;
                }
            }
        }
        // This function is one big wall of useless repeated code
        // Fix it at some point
        private void LoadSpecialBrushes(Editor parent)
        {
            // Get all collision blocks
            foreach (DungeonBrush brush in BlockMap)
            {
                // If this brush is a connector
                if (brush.Connector != null && (bool)brush.Connector)
                {
                    string         assetName = brush.Comment + ".INTERNAL";
                    StarboundAsset asset     = null;

                    if (parent.AssetMap.ContainsKey(assetName))
                    {
                        asset = parent.AssetMap[assetName];
                    }
                    else
                    {
                        asset           = new StarboundAsset();
                        asset.AssetName = assetName;
                        asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8,
                                                                              brush.Colour[0],
                                                                              brush.Colour[1],
                                                                              brush.Colour[2],
                                                                              brush.Colour[3]);

                        parent.AssetMap[asset.AssetName] = asset;
                    }

                    brush.NeedsFrontAsset = true;
                    brush.FrontAsset      = asset;
                    brush.IsSpecial       = true;
                }

                // If this brush is surface foreground
                else if (brush.BrushTypes.Contains("surface"))
                {
                    string         assetName = Editor.Settings.SurfaceForegroundTile;
                    StarboundAsset asset     = null;

                    if (parent.AssetMap.ContainsKey(assetName))
                    {
                        asset = parent.AssetMap[assetName];
                    }
                    else
                    {
                        if (assetName.Contains("INTERNAL"))
                        {
                            asset           = new StarboundAsset();
                            asset.AssetName = assetName;
                            asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8,
                                                                                  87, 59, 12, 255);
                        }
                        else
                        {
                            asset = parent.LoadAsset(assetName, "surface");
                        }

                        parent.AssetMap[assetName] = asset;
                    }

                    brush.FrontAsset = asset;
                    brush.BrushTypes.Add("front");
                    brush.NeedsFrontAsset = true;
                }

                // If this brush is surface background
                else if (brush.BrushTypes.Contains("surfacebackground"))
                {
                    string         assetName = Editor.Settings.SurfaceBackgroundTile;
                    StarboundAsset asset     = null;

                    if (parent.AssetMap.ContainsKey(assetName))
                    {
                        asset = parent.AssetMap[assetName];
                    }
                    else
                    {
                        if (assetName.Contains("INTERNAL"))
                        {
                            asset           = new StarboundAsset();
                            asset.AssetName = assetName;
                            asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8,
                                                                                  87, 59, 12, 255);
                        }
                        else
                        {
                            asset = parent.LoadAsset(assetName, "surfacebackground");
                        }

                        parent.AssetMap[assetName] = asset;
                    }

                    brush.BackAsset = asset;
                    brush.BrushTypes.Add("back");
                    brush.NeedsBackAsset = true;
                }
            }
        }
Esempio n. 6
0
        public StarboundAsset LoadAsset(string name, string rawType)
        {
            m_log.Write("Loading asset " + name + " of type " + rawType);

            StarboundAsset newAsset = null;
            string         ext      = EditorHelpers.GetExtensionFromBrushType(rawType);
            string         path     = m_assetDirContents.Find(file => Path.GetFileName(file) == name + ext);

            if (path == null)
            {
                return(null);
            }

            if (ext == ".material")
            {
                StarboundTile tempAsset = new JsonParser(path).ParseJson <StarboundTile>();

                int    originX   = 0;
                int    originY   = 0;
                string imagePath = null;

                if (tempAsset.Platform)
                {
                    imagePath = Path.Combine(Path.GetDirectoryName(path), tempAsset.PlatformImage);
                    originX   = 24;
                }
                else
                {
                    imagePath = Path.Combine(Path.GetDirectoryName(path), tempAsset.Frames);
                    originX   = 4;
                    originY   = 12;
                }

                if (File.Exists(imagePath))
                {
                    Image tempImage  = EditorHelpers.LoadImageFromFile(imagePath);
                    var   imageAsBmp = new Bitmap(tempImage);

                    Bitmap croppedBmp =
                        imageAsBmp.Clone(new Rectangle(originX, originY, DEFAULT_GRID_FACTOR, DEFAULT_GRID_FACTOR),
                                         imageAsBmp.PixelFormat);

                    tempAsset.Image     = croppedBmp;
                    tempAsset.AssetName = name + ext;

                    m_log.Write("  Image loaded at " + imagePath);
                }
                else
                {
                    m_log.Write("Image for asset " + name + " at location " + imagePath + " not found!");
                }

                newAsset = tempAsset;
            }

            // four types of objects:
            //   1. With ImageName
            //   2. With DualImageName
            //   3. With LeftImage and RightImage
            //   4. With ImageLayers
            else if (ext == ".object")
            {
                StarboundObject sbObject = new JsonParser(path).ParseJson <StarboundObject>();
                sbObject.AssetName = name + ext;

                foreach (ObjectOrientation orientation in sbObject.Orientations)
                {
                    string imageName      = null;
                    string imageNameLeft  = null;
                    string imageNameRight = null;

                    if (orientation.ImageName != null)
                    {
                        imageName = orientation.ImageName;
                    }
                    else if (orientation.DualImageName != null)
                    {
                        imageName = orientation.DualImageName;
                    }
                    else if (orientation.LeftImageName != null || orientation.RightImageName != null)
                    {
                        if (orientation.LeftImageName != null)
                        {
                            imageNameLeft = orientation.LeftImageName;
                        }

                        if (orientation.RightImageName != null)
                        {
                            imageNameRight = orientation.RightImageName;
                        }
                    }
                    else if (orientation.ImageLayers != null)
                    {
                        // Potentially improve to use all image layers
                        imageName = orientation.ImageLayers.First().ImageName;
                    }

                    // Loading with separate right and left images
                    if (imageNameLeft != null && imageNameRight != null)
                    {
                        int leftIndex  = imageNameLeft.LastIndexOf(".png", StringComparison.Ordinal);
                        int rightIndex = imageNameRight.LastIndexOf(".png", StringComparison.Ordinal);

                        if (leftIndex > 0)
                        {
                            imageNameLeft = imageNameLeft.Substring(0, leftIndex + 4);
                        }

                        if (rightIndex > 0)
                        {
                            imageNameRight = imageNameRight.Substring(0, rightIndex + 4);
                        }

                        string leftFramesPath =
                            m_assetDirContents.Find(
                                file =>
                                Path.GetFileName(file) ==
                                Path.GetFileNameWithoutExtension(imageNameLeft) + ".frames");

                        string rightFramesPath =
                            m_assetDirContents.Find(
                                file =>
                                Path.GetFileName(file) ==
                                Path.GetFileNameWithoutExtension(imageNameLeft) + ".frames");

                        if (leftFramesPath != null)
                        {
                            orientation.LeftFrames = new JsonParser(leftFramesPath).ParseJson <ObjectFrames>();
                        }

                        if (rightFramesPath != null)
                        {
                            orientation.RightFrames = new JsonParser(rightFramesPath).ParseJson <ObjectFrames>();
                        }

                        string leftPath  = Path.Combine(Path.GetDirectoryName(path), imageNameLeft);
                        string rightPath = Path.Combine(Path.GetDirectoryName(path), imageNameRight);

                        // Load the left image
                        if (File.Exists(leftPath) && orientation.LeftFrames != null)
                        {
                            int leftWidth  = orientation.LeftFrames.FrameGrid.Size[0];
                            int leftHeight = orientation.LeftFrames.FrameGrid.Size[1];

                            // Load the image
                            Image tempImage  = EditorHelpers.LoadImageFromFile(leftPath);
                            var   imageAsBmp = new Bitmap(tempImage);

                            // Crop the image (remove any animation frames)
                            Bitmap croppedBmp = imageAsBmp.Clone(new Rectangle(0, 0, leftWidth, leftHeight),
                                                                 imageAsBmp.PixelFormat);

                            orientation.LeftImage = croppedBmp;

                            m_log.Write("  Left image loaded at " + leftPath);
                        }
                        else
                        {
                            m_log.Write("Left image for asset " + name + " at location " + leftPath + " not found!");
                        }

                        // Load the right image
                        if (File.Exists(rightPath) && orientation.RightFrames != null)
                        {
                            int rightWidth  = orientation.RightFrames.FrameGrid.Size[0];
                            int rightHeight = orientation.RightFrames.FrameGrid.Size[1];

                            // Load the image
                            Image tempImage  = EditorHelpers.LoadImageFromFile(rightPath);
                            var   imageAsBmp = new Bitmap(tempImage);

                            // Crop the image (remove any animation frames)
                            Bitmap croppedBmp = imageAsBmp.Clone(new Rectangle(0, 0, rightWidth, rightHeight),
                                                                 imageAsBmp.PixelFormat);

                            orientation.RightImage = croppedBmp;

                            m_log.Write("  Right image loaded at " + rightPath);
                        }
                        else
                        {
                            m_log.Write("Right image for asset " + name + " at location " + rightPath +
                                        " not found!");
                        }
                    }
                    // Loading with just one image
                    else if (imageName != null)
                    {
                        int index = imageName.LastIndexOf(".png", StringComparison.Ordinal);

                        if (index > 0)
                        {
                            imageName = imageName.Substring(0, index + 4);
                        }

                        // If the frames file is in our asset list
                        string framesPath =
                            m_assetDirContents.Find(
                                file =>
                                Path.GetFileName(file) ==
                                Path.GetFileNameWithoutExtension(imageName) + ".frames");

                        if (framesPath == null)
                        {
                            return(null);
                        }

                        // Find the frames associated with this object
                        orientation.RightFrames = new JsonParser(framesPath).ParseJson <ObjectFrames>();
                        orientation.LeftFrames  = orientation.RightFrames;

                        if (orientation.RightFrames == null)
                        {
                            return(null);
                        }

                        // Get the size of the asset
                        int width  = orientation.RightFrames.FrameGrid.Size[0];
                        int height = orientation.RightFrames.FrameGrid.Size[1];

                        string imagePath = Path.Combine(Path.GetDirectoryName(path), imageName);

                        if (File.Exists(imagePath) && orientation.RightFrames != null)
                        {
                            // Load the image
                            Image tempImage  = EditorHelpers.LoadImageFromFile(imagePath);
                            var   imageAsBmp = new Bitmap(tempImage);

                            // Crop the image (remove any animation frames)
                            Bitmap croppedBmp = imageAsBmp.Clone(new Rectangle(0, 0, width, height),
                                                                 imageAsBmp.PixelFormat);

                            // The right image (default) is the one we load
                            orientation.RightImage = croppedBmp;

                            // The left image is a flipped version of the right
                            orientation.LeftImage = (Bitmap)orientation.RightImage.Clone();
                            orientation.LeftImage.RotateFlip(RotateFlipType.Rotate180FlipY);

                            m_log.Write("  Image loaded at " + imagePath);
                        }
                        else
                        {
                            m_log.Write("Image for asset " + name + " at location " + imagePath + " not found!");
                        }
                    }
                    // No image has been found, this isn't a valid object, leave
                    else
                    {
                        return(null);
                    }
                }

                // The default image will just be the first orientation's default image
                sbObject.Image = sbObject.Orientations[0].RightImage;
                newAsset       = sbObject;
            }
            else if (ext == ".npctype")
            {
            }

            return(newAsset);
        }