public static EnumerableModKeySettingsVM Factory(SettingsParameters param, FieldMeta fieldMeta, object?defaultVal) { return(new EnumerableModKeySettingsVM( param.DetectedLoadOrder.Transform(x => x.Listing.ModKey), fieldMeta, defaultVal as IEnumerable <ModKey> ?? Enumerable.Empty <ModKey>())); }
public static EnumerableStringSettingsVM Factory(FieldMeta fieldMeta, object?defaultVal) { Func <JsonElement, TryGet <IBasicSettingsNodeVM> > import = new((elem) => { return(TryGet <IBasicSettingsNodeVM> .Succeed( new ListElementWrapperVM <string, StringSettingsVM>( new StringSettingsVM() { Value = elem.GetString() ?? string.Empty }))); }); return(new EnumerableStringSettingsVM( fieldMeta, import, (list) => { list.Add(new ListElementWrapperVM <string, StringSettingsVM>(new StringSettingsVM() { Value = string.Empty }) { IsSelected = true }); }, defaultVal as IEnumerable <string> ?? Enumerable.Empty <string>())); }
public EnumerableSettingsVM( FieldMeta fieldMeta, Func <JsonElement, TryGet <IBasicSettingsNodeVM> > get, Action <ObservableCollection <IBasicSettingsNodeVM> > add) : base(fieldMeta) { _import = get; _add = add; DeleteCommand = ReactiveCommand.Create( execute: () => { if (SelectedValues == null) { return; } IBasicSettingsNodeVM[] vms = new IBasicSettingsNodeVM[SelectedValues.Count]; for (int i = 0; i < vms.Length; i++) { vms[i] = (IBasicSettingsNodeVM)SelectedValues[i] !; } Values.Remove(vms); }, canExecute: this.WhenAnyValue(x => x.SelectedValues !.Count) .Select(x => x > 0)); AddCommand = ReactiveCommand.Create( execute: () => { _add(Values); }); }
public void InspectEntity(Entity entity) { Layout.Label("Fields:"); foreach (var key in entity.Fields.OwnValues.Keys.ToList()) { var type = FieldMeta.Get(key).FieldType; if (type == typeof(int)) { var value = entity.Fields.GetValue <int>(key, entity); if (Layout.IntField(key.GetName(), ref value)) { entity.Fields.SetValue(key, value); } } else if (type == typeof(string)) { var value = entity.Fields.GetValue <string>(key, entity); if (Layout.TextField(key.GetName(), ref value)) { entity.Fields.SetValue(key, value); } } else if (type == typeof(Entity)) { var link = entity.Fields.GetValue <Entity>(key, entity); Layout.Button("Link: " + Utils.ToString(link), () => DataExplorer.Instance.Select(link)); } } }
public object AddOwnValue(FieldKey key, Type type = null) { if (type == null) { type = FieldMeta.Get(key).FieldType; } object value = null; if (type.IsArray) { value = Activator.CreateInstance(type, 0); } else { if (type == typeof(String) || type == typeof(string)) { value = String.Empty; } else { value = Activator.CreateInstance(type); } } SetValue(key, value); return(value); }
public ModKeySettingsVM( IObservable <IChangeSet <ModKey> > detectedLoadOrder, FieldMeta fieldMeta, object?defaultVal) : base(fieldMeta, TryStripOrigin(defaultVal)) { DetectedLoadOrder = detectedLoadOrder; }
public ActionResult DeleteConfirmed(int id) { FieldMeta fieldMeta = db.FieldMetas.Find(id); db.FieldMetas.Remove(fieldMeta); db.SaveChanges(); return(RedirectToAction("Index")); }
private EnumerableObjectSettingsVM(FieldMeta fieldMeta, ObjectSettingsVM prototype, ObjectSettingsVM[] defaultValues) : base(fieldMeta) { _prototype = prototype; _defaultValues = defaultValues; _prototype.Meta = _prototype.Meta with { Parent = this, MainVM = this.Meta.MainVM, }; DeleteCommand = ReactiveCommand.Create( execute: () => { if (SelectedValues == null) { return; } SelectionWrapper[] vms = new SelectionWrapper[SelectedValues.Count]; for (int i = 0; i < vms.Length; i++) { vms[i] = (SelectionWrapper)SelectedValues[i] !; } Values.Remove(vms); }, canExecute: this.WhenAnyValue(x => x.SelectedValues !.Count) .Select(x => x > 0)); AddCommand = ReactiveCommand.Create( execute: () => { var vm = (ObjectSettingsVM)_prototype.Duplicate(); vm.Meta = vm.Meta with { Parent = this, MainVM = this.Meta.MainVM, }; vm.WrapUp(); Values.Add(new SelectionWrapper() { IsSelected = true, Value = vm }); }); Values.SetTo(defaultValues.Select(o => { var dup = (ObjectSettingsVM)o.Duplicate(); dup.Meta = dup.Meta with { Parent = this, MainVM = this.Meta.MainVM, }; dup.WrapUp(); return(new SelectionWrapper() { Value = dup }); })); }
/// <summary> /// Set the Revision directly against a Type /// </summary> /// <typeparam name="T">the tpye which to set the Revision against</typeparam> /// <param name="fieldName">name of the Revision field</param> public static void SetUpRevision <T>(this IRevisionAccessor revisionAccessor, string fieldName) { if (fieldName == null) { throw new ArgumentNullException(nameof(fieldName)); } FieldMeta fieldInfo = typeof(T).GetTypeMeta().Fields.FirstOrDefault(x => x.Name == fieldName); revisionAccessor.SetUpRevision(typeof(T), fieldInfo?.FieldInfo); }
public ActionResult Edit([Bind(Include = "Id,TableName,Field,Required")] FieldMeta fieldMeta) { if (ModelState.IsValid) { db.Entry(fieldMeta).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(fieldMeta)); }
public EnumerableModKeySettingsVM( IObservable <IChangeSet <ModKey> > detectedLoadOrder, FieldMeta fieldMeta, IEnumerable <ModKey> defaultVal) : base(fieldMeta) { _defaultVal = defaultVal.ToArray(); DetectedLoadOrder = detectedLoadOrder; Values.SetTo(defaultVal.Select(i => new ModKeyItemViewModel(i))); }
public EnumSettingsVM(FieldMeta fieldMeta, string?defaultVal, IEnumerable <string> enumNames) : base(fieldMeta) { EnumNames = enumNames; _defaultVal = defaultVal; Value = defaultVal ?? string.Empty; _DisplayName = this.WhenAnyValue(x => x.Value) .Select(x => x.ToString()) .ToGuiProperty(this, nameof(DisplayName), string.Empty, deferSubscription: true); }
public static EnumerableObjectSettingsVM Factory(SettingsParameters param, FieldMeta fieldMeta) { var proto = new ObjectSettingsVM(param with { DefaultVal = null }, FieldMeta.Empty with { Parent = fieldMeta.Parent, MainVM = fieldMeta.MainVM, IsPassthrough = true, });
public static FormLinkSettingsVM Factory(IObservable <ILinkCache> linkCache, FieldMeta fieldMeta, Type targetType, object?defaultVal) { FormKey formKey = FormKey.Null; if (defaultVal != null) { formKey = FormKey.Factory( defaultVal.GetType().GetProperty("FormKey") !.GetValue(defaultVal) !.ToString()); } return(new FormLinkSettingsVM(linkCache, fieldMeta, targetType, formKey)); }
public EnumerableNumericSettingsVM( FieldMeta fieldMeta, Func <JsonElement, TryGet <IBasicSettingsNodeVM> > get, Action <ObservableCollection <IBasicSettingsNodeVM> > add, Action <ObservableCollection <IBasicSettingsNodeVM>, object?> setToDefault, object?defaultVal) : base(fieldMeta, get, add) { _setToDefault = setToDefault; _defaultVal = defaultVal; }
//<inheritdoc /> public void SetId(object instance, object id) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } Type type = instance.GetType(); FieldMeta idField = GetIdField(type); idField.SetFieldValueOf(instance, id); }
// <inheritdoc /> public object GetId(object instance) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } Type type = instance.GetType(); FieldMeta idField = GetIdField(type); return(idField.GetFieldValueFor(instance)); }
public ActionResult Create([Bind(Include = "Id,TableName,Field,Required")] FieldMeta fieldMeta) { if (ModelState.IsValid) { db.FieldMetas.Add(fieldMeta); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(fieldMeta)); }
public ObjectSettingsVM(FieldMeta fieldMeta, Dictionary <string, SettingsNodeVM> nodes, string[] names) : base(fieldMeta) { _nodes = nodes; _names = names; Nodes = new ObservableCollection <SettingsNodeVM>(_nodes.Values); Nodes.ForEach(n => n.Meta = n.Meta with { Parent = this, MainVM = this.Meta.MainVM });
public BasicSettingsVM(FieldMeta fieldMeta, object?defaultVal) : base(fieldMeta) { if (defaultVal is T item) { Value = item; DefaultValue = item; } else { Value = default !;
public EnumerableFormLinkSettingsVM( IObservable <ILinkCache> linkCache, FieldMeta fieldMeta, string typeName, IEnumerable <FormKey> defaultVal) : base(fieldMeta) { _defaultVal = defaultVal.ToArray(); _linkCacheObs = linkCache; _typeName = typeName; _LinkCache = linkCache .ToGuiProperty(this, nameof(LinkCache), default(ILinkCache?)); }
/* * public static void SetUpId<T>(FieldMeta field) * { * if (field == null) throw new ArgumentNullException(nameof(field)); * _typeIdFields.Add(typeof(T), field); * } */ /// <summary> /// Set the Id directly against a Type /// </summary> /// <typeparam name="T">the tpye which to set the Id against</typeparam> /// <param name="idAccessor">the idaccessor instance</param> /// <param name="fieldName">name of the Id field</param> public static void SetUpId <T>(this IIdAccessor idAccessor, string fieldName) { if (idAccessor == null) { throw new ArgumentNullException(nameof(idAccessor)); } if (fieldName == null) { throw new ArgumentNullException(nameof(fieldName)); } FieldMeta fieldInfo = typeof(T).GetTypeMeta().Fields.FirstOrDefault(x => x.Name == fieldName); SetUpId <T>(idAccessor, fieldInfo?.FieldInfo); }
// GET: FieldMeta/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FieldMeta fieldMeta = db.FieldMetas.Find(id); if (fieldMeta == null) { return(HttpNotFound()); } return(View(fieldMeta)); }
public static EnumerableFormKeySettingsVM Factory(FieldMeta fieldMeta, object?defaultVal) { var defaultKeys = new List <FormKey>(); if (defaultVal is IEnumerable e) { foreach (var item in e) { defaultKeys.Add(FormKey.Factory(item.ToString())); } } return(new EnumerableFormKeySettingsVM( fieldMeta, defaultVal as IEnumerable <FormKey> ?? Enumerable.Empty <FormKey>())); }
public static FormLinkSettingsVM Factory(IObservable <ILinkCache> linkCache, FieldMeta fieldMeta, Type targetType, object?defaultVal) { FormKey formKey = FormKey.Null; if (defaultVal != null) { formKey = FormKey.Factory( defaultVal.GetType().GetPublicProperties().FirstOrDefault(m => m.Name == "FormKey") !.GetValue(defaultVal) !.ToString()); } if (!LoquiRegistration.TryGetRegisterByFullName(targetType.GenericTypeArguments[0].FullName !, out var regis)) { throw new ArgumentException($"Can't create a formlink control for type: {targetType}"); } return(new FormLinkSettingsVM(linkCache, fieldMeta, regis.GetterType, formKey)); }
public EntityCopyToTarget(FieldMeta field) { _field = field; _action = _field.IsReadOnly ? (Action <object, object>)((s, d) => { var dest = field.GetFieldValueFor(d); Copier.Copy(s, dest); }) : (Action <object, object>)((s, d) => { var copy = Copier.Copy(s); _field.SetFieldValueOf(d, copy); }); }
public EnumerableStringSettingsVM( FieldMeta fieldMeta, Func <JsonElement, TryGet <IBasicSettingsNodeVM> > get, Action <ObservableCollection <IBasicSettingsNodeVM> > add, IEnumerable <string> defaultVal) : base(fieldMeta, get, add) { _defaultVal = defaultVal; Values.SetTo(_defaultVal.Select(x => { return(new ListElementWrapperVM <string, StringSettingsVM>(new StringSettingsVM() { Value = x })); })); }
public SettingsNodeVM(FieldMeta fieldMeta) { Meta = fieldMeta; Parents = new Lazy <IEnumerable <SettingsNodeVM> >(() => GetParents().Reverse()); FocusSettingCommand = ReactiveCommand.Create(() => { var oldSetting = Meta.MainVM.SelectedSettings; Meta.MainVM.SelectedSettings = this; Meta.MainVM.ScrolledToSettings = oldSetting; }); if (this.Meta.MainVM != null && !this.Meta.IsPassthrough) { _IsFocused = this.Meta.MainVM.WhenAnyValue(x => x.SelectedSettings) .Select(x => IsFocusedCheck(x)) .ToGuiProperty(this, nameof(IsFocused), deferSubscription: true); } }
public object AddOwnValue(FieldKey key, FieldBytes fieldBytes, bool sort = false) { var slice = fieldBytes.ByteSlice; Serializer.Instance.State = GameState.Instance.OriginalState; Serializer.Instance.State.StartLocalGroup(); var resolver = MessagePack.MessagePackSerializer.DefaultResolver; var value = FieldMeta.Get(key).Deserialize(slice.GetBytes(), slice.Offset, resolver, out int readSize); Serializer.Instance.State = null; SetValue(key, value); OwnValues.AddFieldBytes(fieldBytes); if (sort) { OwnValues.OriginalBytes.Sort(); } return(value); }
public static SettingsNodeVM Factory(SettingsParameters param, FieldMeta fieldMeta, string typeName, object?defaultVal) { var defaultKeys = new List <FormKey>(); if (defaultVal is IEnumerable e) { var targetType = e.GetType().GenericTypeArguments[0]; var getter = targetType.GetProperty("FormKey") !; foreach (var item in e) { defaultKeys.Add(FormKey.Factory(getter.GetValue(item) !.ToString())); } } return(new EnumerableFormLinkSettingsVM( param.LinkCache, fieldMeta: fieldMeta, typeName: typeName, defaultKeys)); }
public InstructionField(InstructionKindEnum aKind, int aIndex, FieldMeta aField) : base(aKind, aIndex) { Field = aField; }