public override void ConvertProject(ProjectFile pf)
        {
            var dataAssets = pf.DataHandle.GetChunk <GMChunkFONT>().List;

            // Assemble dictionary of group names to actual Group classes
            Dictionary <string, Textures.Group> groupNames = new Dictionary <string, Textures.Group>();

            foreach (var g in pf.Textures.TextureGroups)
            {
                groupNames[g.Name] = g;
            }

            List <GMFont> newList = new List <GMFont>();

            for (int i = 0; i < pf.Fonts.Count; i++)
            {
                AssetFont projectAsset = pf.Fonts[i].Asset;
                if (projectAsset == null)
                {
                    // This asset was never converted
                    newList.Add((GMFont)pf.Fonts[i].DataAsset);
                    continue;
                }

                // Add texture item to proper texture group
                if (projectAsset.TextureGroup != null &&
                    groupNames.TryGetValue(projectAsset.TextureGroup, out var group))
                {
                    group.AddNewEntry(pf.Textures, projectAsset.TextureItem);
                }
                else
                {
                    // Make a new texture group for this
                    var g = new Textures.Group()
                    {
                        Dirty     = true,
                        Border    = 0,
                        AllowCrop = false,
                        Name      = $"__DS_AUTO_GEN_{projectAsset.Name}__{pf.Textures.TextureGroups.Count}"
                    };
                    g.AddNewEntry(pf.Textures, projectAsset.TextureItem);
                    pf.Textures.TextureGroups.Add(g);
                }

                GMFont dataAsset = new GMFont()
                {
                    Name        = pf.DataHandle.DefineString(projectAsset.Name),
                    DisplayName = pf.DataHandle.DefineString(projectAsset.DisplayName),
                    Bold        = projectAsset.Bold,
                    Italic      = projectAsset.Italic,
                    Charset     = projectAsset.Charset,
                    AntiAlias   = projectAsset.AntiAlias,
                    ScaleX      = projectAsset.ScaleX,
                    ScaleY      = projectAsset.ScaleY,
                    TextureItem = projectAsset.TextureItem,

                    Glyphs = new Core.GMUniquePointerList <GMGlyph>()
                };

                if (projectAsset.Size != null)
                {
                    dataAsset.Size = (int)projectAsset.Size;
                }
                else
                {
                    dataAsset.SizeFloat = (float)projectAsset.SizeFloat;
                }

                foreach (var g in projectAsset.Glyphs.OrderBy(g => g.Character))
                {
                    dataAsset.Glyphs.Add(g);
                }
                if (dataAsset.Glyphs.Count != 0)
                {
                    dataAsset.RangeStart = dataAsset.Glyphs[0].Character;
                    dataAsset.RangeEnd   = dataAsset.Glyphs[^ 1].Character;
Beispiel #2
0
        public override void ConvertProject(ProjectFile pf)
        {
            var dataAssets = pf.DataHandle.GetChunk <GMChunkBGND>().List;

            // Assemble dictionary of group names to actual Group classes
            Dictionary <string, Textures.Group> groupNames = new Dictionary <string, Textures.Group>();

            foreach (var g in pf.Textures.TextureGroups)
            {
                groupNames[g.Name] = g;
            }

            List <GMBackground> newList = new List <GMBackground>();

            for (int i = 0; i < pf.Backgrounds.Count; i++)
            {
                AssetBackground projectAsset = pf.Backgrounds[i].Asset;
                if (projectAsset == null)
                {
                    // This asset was never converted
                    newList.Add((GMBackground)pf.Backgrounds[i].DataAsset);
                    continue;
                }

                // Add texture item to proper texture group
                if (projectAsset.TextureGroup != null &&
                    groupNames.TryGetValue(projectAsset.TextureGroup, out var group))
                {
                    group.AddNewEntry(pf.Textures, projectAsset.TextureItem);
                }
                else
                {
                    // Make a new texture group for this
                    var g = new Textures.Group()
                    {
                        Dirty     = true,
                        Border    = 0,
                        AllowCrop = false,
                        Name      = $"__DS_AUTO_GEN_{projectAsset.Name}__{pf.Textures.TextureGroups.Count}"
                    };
                    g.AddNewEntry(pf.Textures, projectAsset.TextureItem);
                    pf.Textures.TextureGroups.Add(g);
                }

                GMBackground dataAsset = new GMBackground()
                {
                    Name        = pf.DataHandle.DefineString(projectAsset.Name),
                    Transparent = projectAsset.Transparent,
                    Smooth      = projectAsset.Smooth,
                    Preload     = projectAsset.Preload,
                    TextureItem = projectAsset.TextureItem
                };

                if (pf.DataHandle.VersionInfo.IsNumberAtLeast(2))
                {
                    dataAsset.TileWidth         = projectAsset.GMS2Tiles.Width;
                    dataAsset.TileHeight        = projectAsset.GMS2Tiles.Height;
                    dataAsset.TileOutputBorderX = projectAsset.GMS2Tiles.BorderX;
                    dataAsset.TileOutputBorderY = projectAsset.GMS2Tiles.BorderY;
                    dataAsset.TileColumns       = projectAsset.GMS2Tiles.Columns;
                    dataAsset.TileFrameLength   = projectAsset.GMS2Tiles.FrameLength;
                    dataAsset.Tiles             = projectAsset.GMS2Tiles.Tiles;
                }

                newList.Add(dataAsset);
            }

            dataAssets.Clear();
            foreach (var obj in newList)
            {
                dataAssets.Add(obj);
            }
        }
Beispiel #3
0
        public override void ConvertProject(ProjectFile pf)
        {
            var dataAssets = pf.DataHandle.GetChunk <GMChunkSPRT>().List;

            // Assemble dictionary of group names to actual Group classes
            Dictionary <string, Textures.Group> groupNames = new Dictionary <string, Textures.Group>();

            foreach (var g in pf.Textures.TextureGroups)
            {
                groupNames[g.Name] = g;
            }

            List <GMSprite> newList = new List <GMSprite>();

            for (int i = 0; i < pf.Sprites.Count; i++)
            {
                AssetSprite projectAsset = pf.Sprites[i].Asset;
                if (projectAsset == null)
                {
                    // This asset was never converted
                    newList.Add((GMSprite)pf.Sprites[i].DataAsset);
                    continue;
                }

                // Add texture items to group
                if (!projectAsset.SeparateTextureGroup &&
                    projectAsset.TextureGroup != null &&
                    groupNames.TryGetValue(projectAsset.TextureGroup, out var group))
                {
                    foreach (var item in projectAsset.TextureItems)
                    {
                        if (item != null)
                        {
                            group.AddNewEntry(pf.Textures, item);
                        }
                    }
                }
                else
                {
                    if (projectAsset.SeparateTextureGroup)
                    {
                        // Export each frame to a separate texture page
                        foreach (var item in projectAsset.TextureItems)
                        {
                            if (item == null)
                            {
                                continue;
                            }

                            var g = new Textures.Group()
                            {
                                Dirty     = true,
                                Border    = 0,
                                AllowCrop = false,
                                Name      = $"__DS_AUTO_GEN_{projectAsset.Name}__{pf.Textures.TextureGroups.Count}",
                                FillTGIN  = false // Apparently
                            };
                            g.AddNewEntry(pf.Textures, item);
                            pf.Textures.TextureGroups.Add(g);
                        }
                    }
                    else
                    {
                        // Make a new texture group for this
                        var g = new Textures.Group()
                        {
                            Dirty     = true,
                            Border    = 0,
                            AllowCrop = false,
                            Name      = $"__DS_AUTO_GEN_{projectAsset.Name}__{pf.Textures.TextureGroups.Count}",
                            FillTGIN  = false // Apparently
                        };
                        foreach (var item in projectAsset.TextureItems)
                        {
                            if (item != null)
                            {
                                g.AddNewEntry(pf.Textures, item);
                            }
                        }
                        pf.Textures.TextureGroups.Add(g);
                    }
                }

                CollisionMasks.Rect outbbox;

                GMSprite dataAsset = new GMSprite()
                {
                    Name           = pf.DataHandle.DefineString(projectAsset.Name),
                    Transparent    = projectAsset.Transparent,
                    Smooth         = projectAsset.Smooth,
                    Preload        = projectAsset.Preload,
                    Width          = projectAsset.Width,
                    Height         = projectAsset.Height,
                    OriginX        = projectAsset.OriginX,
                    OriginY        = projectAsset.OriginY,
                    TextureItems   = new GMRemotePointerList <GMTextureItem>(),
                    CollisionMasks = CollisionMasks.GetMasksForSprite(pf, projectAsset, out outbbox)
                };

                // Get collision mask info
                var colInfo = projectAsset.CollisionMask;
                if (colInfo.Left == null || colInfo.Top == null || colInfo.Right == null || colInfo.Bottom == null)
                {
                    dataAsset.MarginLeft   = outbbox.Left;
                    dataAsset.MarginTop    = outbbox.Top;
                    dataAsset.MarginRight  = outbbox.Right;
                    dataAsset.MarginBottom = outbbox.Bottom;
                }
                else
                {
                    dataAsset.MarginLeft   = (int)colInfo.Left;
                    dataAsset.MarginTop    = (int)colInfo.Top;
                    dataAsset.MarginRight  = (int)colInfo.Right;
                    dataAsset.MarginBottom = (int)colInfo.Bottom;
                }

                if ((int)colInfo.Mode < 0)
                {
                    dataAsset.BBoxMode = (uint)(-(1 + (int)colInfo.Mode));
                    dataAsset.SepMasks = GMSprite.SepMaskType.Precise;
                }
                else
                {
                    dataAsset.BBoxMode = (uint)colInfo.Mode;
                    switch (colInfo.Type)
                    {
                    case AssetSprite.CollisionMaskInfo.MaskType.Rectangle:
                        dataAsset.SepMasks = GMSprite.SepMaskType.AxisAlignedRect;
                        break;

                    case AssetSprite.CollisionMaskInfo.MaskType.RectangleWithRotation:
                        dataAsset.SepMasks = GMSprite.SepMaskType.RotatedRect;
                        break;

                    case AssetSprite.CollisionMaskInfo.MaskType.Precise:
                    case AssetSprite.CollisionMaskInfo.MaskType.Diamond:
                    case AssetSprite.CollisionMaskInfo.MaskType.Ellipse:
                    case AssetSprite.CollisionMaskInfo.MaskType.PrecisePerFrame:
                        dataAsset.SepMasks = GMSprite.SepMaskType.Precise;
                        break;
                    }
                }

                // Actually add the texture items
                foreach (var item in projectAsset.TextureItems)
                {
                    dataAsset.TextureItems.Add(item);
                }

                if (projectAsset.SpecialInfo != null)
                {
                    var info = projectAsset.SpecialInfo;

                    dataAsset.SpecialOrGMS2 = true;
                    dataAsset.S_SpriteType  = info.SpriteType;
                    if (info.SpriteType != GMSprite.SpriteType.Normal)
                    {
                        dataAsset.S_Buffer = info.InternalBuffer;
                    }

                    if (info.GMS2PlaybackSpeed != null)
                    {
                        dataAsset.GMS2_PlaybackSpeed     = (float)info.GMS2PlaybackSpeed;
                        dataAsset.GMS2_PlaybackSpeedType = (GMSprite.AnimSpeedType)info.GMS2PlaybackSpeedType;
                    }

                    if (projectAsset.SpecialInfo.Sequence != null)
                    {
                        var seq    = projectAsset.SpecialInfo.Sequence;
                        var newSeq = new GMSequence()
                        {
                            Name              = pf.DataHandle.DefineString(seq.Name),
                            PlaybackType      = GMSequence.PlaybackTypeEnum.Loop,
                            PlaybackSpeed     = dataAsset.GMS2_PlaybackSpeed,
                            PlaybackSpeedType = dataAsset.GMS2_PlaybackSpeedType,
                            Length            = seq.Frames.Max(f => f.Position + f.Length),
                            OriginX           = dataAsset.OriginX,
                            OriginY           = dataAsset.OriginY,
                            Volume            = 1,
                            BroadcastMessages = new(),
                            Tracks            = new()
                            {
                                new()
                                {
                                    BuiltinName     = 0,
                                    IsCreationTrack = false,
                                    Keyframes       = new GMSequence.Track.ValueKeyframes()
                                    {
                                        List = new()
                                    },
                                    ModelName          = pf.DataHandle.DefineString("GMSpriteFramesTrack"),
                                    Name               = pf.DataHandle.DefineString("frames"),
                                    OwnedResources     = new(),
                                    OwnedResourceTypes = new(),
                                    Tags               = new(),
                                    Tracks             = new(),
                                    Traits             = GMSequence.Track.TraitsEnum.Unknown1
                                }
                            },