예제 #1
0
        public static void MProjectToBin(MProjectToBinVerbs verbs)
        {
            if (verbs.Version == 0)
            {
                Console.WriteLine("Version 0 is not currently supported.");
                return;
            }
            else if (verbs.Version > 1 || verbs.Version < 0)
            {
                Console.WriteLine("Version must be 0 or 1. (0 not current supported).");
                return;
            }

            var   mbin     = new MBinaryIO(verbs.InputPath);
            mNode rootNode = mbin.Read();

            if (rootNode is null)
            {
                var mtext = new MTextIO(verbs.InputPath);
                rootNode = mtext.Read();

                if (rootNode is null)
                {
                    Console.WriteLine("Could not read mproject.");
                    return;
                }
            }

            MBinaryWriter writer = new MBinaryWriter(verbs.OutputPath);

            writer.Version = verbs.Version;
            writer.WriteNode(rootNode);

            Console.WriteLine($"Done. Exported to '{verbs.OutputPath}'.");
        }
예제 #2
0
        public static void MProjectToText(MProjectToTextVerbs verbs)
        {
            var   mbin     = new MBinaryIO(verbs.InputPath);
            mNode rootNode = mbin.Read();

            if (rootNode is null)
            {
                var mtext = new MTextIO(verbs.InputPath);
                rootNode = mtext.Read();

                if (rootNode is null)
                {
                    Console.WriteLine("Could not read mproject.");
                    return;
                }
            }

            using MTextWriter writer = new MTextWriter(verbs.OutputPath);
            writer.Debug             = verbs.Debug;
            writer.WriteNode(rootNode);

            Console.WriteLine($"Done. Exported to '{verbs.OutputPath}'.");
        }
예제 #3
0
        public override void Read(MBinaryIO io)
        {
            Length   = io.Stream.Read1Byte();
            Elements = new List <mTypeBase>(Length);
            for (int i = 0; i < Length; i++)
            {
                if (io.Version == 0)
                {
                    int    endScope = io.Stream.ReadInt32();
                    byte[] typeName = io.Stream.Read7BitStringBytes();

                    mTypeBase element;
                    if (typeName.Length == 1)
                    {
                        element = (FieldTypeOld)typeName[0] switch
                        {
                            FieldTypeOld.String => new mString(),
                            FieldTypeOld.Array => new mArray(),
                            FieldTypeOld.Bool => new mBool(),
                            FieldTypeOld.Byte => new mUByte(),
                            FieldTypeOld.Double => new mDouble(),
                            FieldTypeOld.Float => new mFloat(),
                            FieldTypeOld.Long => new mLong(),
                            FieldTypeOld.SByte => new mSByte(),
                            FieldTypeOld.Short => new mShort(),
                            FieldTypeOld.UShort => new mUShort(),
                            FieldTypeOld.ULong => new mULong(),
                            FieldTypeOld.Int => new mInt(),
                            FieldTypeOld.UInt => new mUInt(),
                            _ => throw new NotSupportedException($"Received unsupported array element type {(FieldTypeOld)typeName[0]}"),
                        };
                    }
                    else
                    {
                        string customFieldType = Encoding.UTF8.GetString(typeName);

                        element = customFieldType switch
                        {
                            "rectangle" => new mRectangle(),
                            "RGBA" => new mColor(),
                            "color_name" => new mColorName(),
                            "vector" => new mVector(),
                            "vector3" => new mVector3(),
                            "region" => new mRegion(),
                            _ => null,
                        };

                        if (element is null)
                        {
                            element = new mNode();
                            ((mNode)element).EndScopeOffset = endScope;
                            ((mNode)element).TypeName       = customFieldType;
                        }
                    }

                    element.Read(io);
                    Elements.Add(element);
                }
                else
                {
                    mTypeBase field = null;
                    var       type  = (FieldType)io.Stream.ReadByte();
                    field = type switch
                    {
                        FieldType.UByte => new mUByte(),
                        FieldType.Bool => new mBool(),
                        FieldType.Short => new mShort(),
                        FieldType.UShort => new mUShort(),
                        FieldType.Float => new mFloat(),
                        FieldType.ULong => new mULong(),
                        FieldType.Long => new mLong(),
                        FieldType.Int => new mInt(),
                        FieldType.UInt => new mUInt(),
                        FieldType.String => new mString(),
                        FieldType.ArrayMaybe => new mArray(),
                        FieldType.ScopeStart => new mNode(),
                        FieldType.ScopeEnd => null,
                        FieldType.SByte => new mSByte(),
                        _ => throw new Exception($"Type: {type} not supported"),
                    };

                    if (type != FieldType.ScopeEnd)
                    {
                        field.Read(io);
                        if (field is mString str)
                        {
                            if (str.String == "RGBA")
                            {
                                // Array of colors
                                field = new mColor();
                                field.Read(io);
                            }
                            else if (str.String == "color_name")
                            {
                                field = new mColorName();
                                field.Read(io);
                            }
                            else if (str.String == "vector")
                            {
                                field = new mVector();
                                field.Read(io);
                            }
                            else if (str.String == "vector3")
                            {
                                field = new mVector3();
                                field.Read(io);
                            }
                            else if (str.String == "region")
                            {
                                field = new mRegion();
                                field.Read(io);
                            }
                        }

                        Elements.Add(field);
                    }
                }
            }
        }