private static void Extract(string name, string[] ignore = null) { DisplayMessage("Generating files for " + name + "..."); #if !DEBUG try { #endif var xml = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement(name)); var lua = new LuaFile(name); foreach (var obj in model[name]) { if (!IsValidName(ignore ?? new string[] {}, obj)) { continue; } var xmlelement = new XElement("o"); foreach (var pair in obj) { //TODO: Level dictionaries are currently messed up on XML output if (pair.Key.StartsWith("_")) { continue; } if (!(pair.Value is string) && pair.Value is IEnumerable) { xmlelement.SetAttributeValue(pair.Key, LuaAttribute.MakeValue(pair.Value)); } else { xmlelement.SetAttributeValue(pair.Key, pair.Value); } } xml.Root.Add(xmlelement); lua.Add(obj); } xml.Root.ReplaceNodes(xml.Root.Elements().OrderBy(e => (uint)((int?)e.Attribute("id") ?? 0))); xml.Save(Path.Combine("resources", "xml", FormattableString.Invariant($"{name}.xml"))); lua.Save(); #if !DEBUG } catch { DisplayError(); throw; } #endif DisplaySuccess(); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (svc == null) { return(""); } // Set the initial text for the editor. var win = new StringEditor { Text = (string)value }; // Custom attributes we'll look for on strings. var lua = new LuaAttribute(); if (context.PropertyDescriptor != null && context.PropertyDescriptor.Attributes.Contains(lua)) { // Set the initial type for highlighting. win.EditorMode = StringEditor.EditorType.Lua; } else { win.EditorMode = StringEditor.EditorType.Text; } // Show what alias is being edited in the status bar of the string editor window. if (context.PropertyDescriptor != null) { win.StatusText = $"Property: {context.PropertyDescriptor.Name}"; } // Startup position of the dialog should be in the center of the parent window. The // owner has to be set for this to work. win.Owner = App.MainWindow; win.WindowStartupLocation = WindowStartupLocation.CenterOwner; // Show the Lua dialog. var result = win.ShowDialog(); // If the result if (result != null && result.Value) { return(win.Text); } // If cancel happened, return the original value. return(value); }
string GetAttributeName(MemberInfo memberInfo) { string attributeName = string.Empty; var attributes = memberInfo.GetCustomAttributes(true); LuaAttribute luaAttribute = null; foreach (var v in attributes) { luaAttribute = v as LuaAttribute; if (luaAttribute != null) { if (luaAttribute.useDefaultName) { attributeName = memberInfo.Name; } else { attributeName = luaAttribute.luaName; } break; } } return(attributeName); }