static void Main(string[] args) { mArray <int> mas = new mArray <int>(5); Console.WriteLine(mas.Size); Console.WriteLine(mas.RealSize); Console.WriteLine(mas.Mas); mas.Add(10000); Console.WriteLine(mas.Size); Console.WriteLine(mas.RealSize); Console.WriteLine(mas.Mas); mas.Remove(10000); Console.WriteLine(mas.Size); Console.WriteLine(mas.RealSize); Console.WriteLine(mas.Mas); Console.WriteLine(mas.IndexOf(10000)); Console.ReadLine(); }
public override void Read(MTextIO io) { string token = null; string token2 = null; if (IsRoot) { token = io.GetToken(); token2 = io.GetToken(); if (token2 == MTextIO.SCOPE_START.ToString()) { // We only have the type TypeName = token; } else { Name = token; TypeName = token2; string token3 = io.GetToken(); if (token3 != MTextIO.SCOPE_START.ToString()) { throw new Exception($"Expected '{MTextIO.SCOPE_START}' character for node definition."); } } } mTypeBase field = null; while (true) { // Loop through all fields, now token = io.GetToken(); if (token == MTextIO.SCOPE_END.ToString()) { break; } token2 = io.GetToken(); if (token2 == MTextIO.SCOPE_START.ToString()) { // We only have the type field = new mNode(); ((mNode)field).TypeName = token; } else if (token2.StartsWith(MTextIO.ARRAY_START)) // Array def { int arrLen = int.Parse(token2.AsSpan(1, token2.Length - 2)); if (arrLen > byte.MaxValue) { throw new UISyntaxError($"Array length can only be {byte.MaxValue} elements maximum. Got {arrLen}."); } field = new mArray(); ((mArray)field).Length = (byte)arrLen; if (io.GetToken() != MTextIO.SCOPE_START.ToString()) { throw new Exception($"Expected '{MTextIO.SCOPE_START}' character for node array field definition."); } field.Name = token; } else { string fieldName = token; string fieldType = token2; string token3 = io.GetToken(); if (token3 != MTextIO.SCOPE_START.ToString()) { throw new Exception($"Expected '{MTextIO.SCOPE_START}' character for node field definition."); } if (fieldType == "digit") { // Search potentially colliding field names with different types UIDefType digitType; var potentialOverride = WidgetDefinitions.TypeOverrides.FirstOrDefault(e => e.WidgetName == TypeName && e.FieldName == fieldName); if (potentialOverride != null) { digitType = potentialOverride.ValueType; } else { WidgetDefinitions.Types.TryGetValue(fieldName, out digitType); // No collision, just try to find it by name } /* No real easier way, the component types i.e 'DialogParts::DialogFrame::Pane::Head::Close::Cross' do not expose their actual type */ if (digitType != UIDefType.Unknown) { field = 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 '{fieldName}', assuming Int"); field = new mInt(); } } else { field = fieldType 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 (field is mNode) { ((mNode)field).TypeName = token2; } field.Name = token; } field.Read(io); Child.Add(field); } }