Esempio n. 1
0
        public override void Read(MTextIO io)
        {
            var x = io.GetNumberToken();

            if (float.TryParse(x, out float xVal))
            {
                X = xVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mVector X. Got {x}.");
            }

            var y = io.GetNumberToken();

            if (float.TryParse(y, out float yVal))
            {
                Y = yVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mVector Y. Got {x}.");
            }


            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected mVector scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 2
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}'.");
        }
Esempio n. 3
0
        public override void Read(MTextIO io)
        {
            String = io.GetString();

            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected string scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 4
0
        public override void Read(MTextIO io)
        {
            var r = io.GetNumberToken();

            if (byte.TryParse(r, out byte rVal))
            {
                R = rVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mColor R. Got {r}.");
            }

            var g = io.GetNumberToken();

            if (byte.TryParse(g, out byte gVal))
            {
                G = gVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mColor G. Got {g}.");
            }

            var b = io.GetNumberToken();

            if (byte.TryParse(b, out byte bVal))
            {
                B = bVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mColor B. Got {b}.");
            }

            var a = io.GetNumberToken();

            if (byte.TryParse(a, out byte aVal))
            {
                A = aVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mColor A. Got {a}.");
            }

            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected mColor scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 5
0
        public override void Read(MTextIO io)
        {
            var x1 = io.GetNumberToken();

            if (float.TryParse(x1, out float x1Val))
            {
                X1 = x1Val;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRegion X1. Got {x1}.");
            }

            var y1 = io.GetNumberToken();

            if (float.TryParse(y1, out float y1Val))
            {
                Y1 = y1Val;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRegion Y1. Got {y1}.");
            }

            var x2 = io.GetNumberToken();

            if (float.TryParse(x2, out float x2Val))
            {
                X2 = x2Val;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRegion X2. Got {x2}.");
            }

            var y2 = io.GetNumberToken();

            if (float.TryParse(y2, out float y2Val))
            {
                Y2 = y2Val;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRegion Y2. Got {y2}.");
            }

            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected mRectangle scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 6
0
        public override void Read(MTextIO io)
        {
            var x = io.GetNumberToken();

            if (float.TryParse(x, out float xVal))
            {
                X = xVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRectangle X. Got {x}.");
            }

            var y = io.GetNumberToken();

            if (float.TryParse(y, out float yVal))
            {
                Y = yVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRectangle Y. Got {x}.");
            }

            var w = io.GetNumberToken();

            if (float.TryParse(w, out float wVal))
            {
                Width = wVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRectangle Width. Got {w}.");
            }

            var h = io.GetNumberToken();

            if (float.TryParse(h, out float hVal))
            {
                Height = hVal;
            }
            else
            {
                throw new UISyntaxError($"Unexpected token for mRectangle Height. Got {h}.");
            }

            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected mRectangle scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 7
0
        public override void Read(MTextIO io)
        {
            var numbToken = io.GetNumberToken();

            if (short.TryParse(numbToken, out short val))
            {
                Value = val;
            }
            else
            {
                throw new UISyntaxError($"Unexpected short token for mShort. Got {numbToken}.");
            }

            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected mShort scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 8
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}'.");
        }
Esempio n. 9
0
        public override void Read(MTextIO io)
        {
            var numbToken = io.GetNumberToken();

            if (numbToken == "1")
            {
                Value = true;
            }
            else if (numbToken == "0")
            {
                Value = false;
            }
            else
            {
                throw new UISyntaxError($"Expected bool token (1/0) for mBool. Got {numbToken}.");
            }

            string end = io.GetToken();

            if (end != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected mBool scope end ({MTextIO.SCOPE_END}), got {end}");
            }
        }
Esempio n. 10
0
 public abstract void Read(MTextIO io);
Esempio n. 11
0
 public override void Read(MTextIO io)
 {
     throw new NotImplementedException();
 }
Esempio n. 12
0
        public override void Read(MTextIO io)
        {
            Elements = new List <mTypeBase>(Length);
            for (int i = 0; i < Length; i++)
            {
                string token  = io.GetToken();
                string token2 = io.GetToken();

                mTypeBase element = null;
                if (token2 != MTextIO.SCOPE_START.ToString())
                {
                    throw new UISyntaxError($"Expected array element scope start, got {token2}.");
                }

                // We only have the type
                if (token == "digit")
                {
                    if (WidgetDefinitions.Types.TryGetValue(Name, out UIDefType digitType) && digitType != UIDefType.Unknown)
                    {
                        element = digitType switch
                        {
                            UIDefType.Int => new mInt(),
                            UIDefType.UInt => new mUInt(),
                            UIDefType.Long => new mLong(),
                            UIDefType.ULong => new mULong(),
                            UIDefType.Short => new mShort(),
                            UIDefType.UShort => new mUShort(),
                            UIDefType.Byte => new mUByte(),
                            UIDefType.SByte => new mSByte(),
                            UIDefType.Float => new mFloat(),
                            UIDefType.Double => new mDouble(),
                            UIDefType.Bool => new mBool(),
                            _ => new mInt(),
                        };
                    }
                    else
                    {
                        Console.WriteLine($"Missing digit type for '{Name}', assuming Int");
                        element = new mInt();
                    }
                }
                else if (token.StartsWith(MTextIO.ARRAY_START)) // Array def
                {
                    int arrLen = int.Parse(token.AsSpan(1, token.Length - 2));
                    if (arrLen > byte.MaxValue)
                    {
                        throw new UISyntaxError($"Array length can only be {byte.MaxValue} elements maximum. Got {arrLen}.");
                    }

                    element = new mArray();
                    ((mArray)element).Length = (byte)arrLen;

                    if (token2 != MTextIO.SCOPE_START.ToString())
                    {
                        throw new Exception($"Expected '{MTextIO.SCOPE_START}' character for node array field definition.");
                    }
                }
                else
                {
                    element = token switch
                    {
                        "RGBA" => new mColor(),
                        "color_name" => new mColorName(),
                        "string" => new mString(),
                        "region" => new mRegion(),
                        "vector" => new mVector(),
                        "vector3" => new mVector3(),
                        "rectangle" => new mRectangle(),
                        _ => new mNode(),
                    };

                    if (element is mNode)
                    {
                        ((mNode)element).TypeName = token;
                    }
                }

                element.Read(io);
                Elements.Add(element);
            }

            string endToken = io.GetToken();

            if (endToken != MTextIO.SCOPE_END.ToString())
            {
                throw new UISyntaxError($"Expected array scope end, got {endToken}.");
            }
        }