Exemplo n.º 1
0
        public override Task PostFieldLoad(ObjectGeneration obj, TypeGeneration field, XElement node)
        {
            var data = field.CustomData.TryCreateValue(Constants.DataKey, () => new MutagenFieldData(field)) as MutagenFieldData;

            if (node.TryGetAttribute("recordType", out string recordAttr))
            {
                data.RecordType = new RecordType(recordAttr);
            }
            else if (node.TryGetAttribute("recordTypeHex", out string recordAttrInt))
            {
                data.RecordType = new RecordType(Convert.ToInt32(recordAttrInt, 16));
            }
            if (node.TryGetAttribute("overflowRecordType", out var overflow))
            {
                data.OverflowRecordType = new RecordType(overflow.Value);
            }
            var markerAttr = node.GetAttribute("markerType");

            if (markerAttr != null)
            {
                data.MarkerType = new RecordType(markerAttr);
            }
            if (obj.IsTopLevelGroup() && (field.Name?.Equals("Items") ?? false))
            {
                DictType  dict  = field as DictType;
                LoquiType loqui = dict.ValueTypeGen as LoquiType;
                data.TriggeringRecordAccessors.Add($"Group<T>.T_RecordType");
            }
            return(base.PostFieldLoad(obj, field, node));
        }
Exemplo n.º 2
0
        private async Task LoquiTypeHandler(
            FileGeneration fg,
            ObjectGeneration obj,
            Accessor loquiAccessor,
            LoquiType loquiType,
            Action <ArgsWrapper> addGetOrAddArg,
            string generic,
            bool checkType,
            bool includeSelf = true)
        {
            // ToDo
            // Quick hack.  Real solution should use reflection to investigate the interface
            if (loquiType.RefType == LoquiType.LoquiRefType.Interface)
            {
                if (checkType)
                {
                    fg.AppendLine($"if (type.IsAssignableFrom({loquiAccessor}.GetType()))");
                }
                using (new BraceWrapper(fg, doIt: checkType))
                {
                    using (var args = new ArgsWrapper(fg,
                                                      $"yield return new ModContext<{obj.GetObjectData().GameCategory.Value.ModInterface(getter: false)}, IMajorRecordCommon, IMajorRecordCommonGetter>"))
                    {
                        args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}");
                        args.Add($"record: {loquiAccessor}");
                        args.Add($"parent: curContext");
                        addGetOrAddArg(args);
                    }
                }
                return;
            }

            if (includeSelf &&
                loquiType.TargetObjectGeneration != null &&
                await loquiType.TargetObjectGeneration.IsMajorRecord())
            {
                if (checkType)
                {
                    fg.AppendLine($"if (type.IsAssignableFrom({loquiAccessor}.GetType()))");
                }
                using (new BraceWrapper(fg, doIt: checkType))
                {
                    using (var args = new ArgsWrapper(fg,
                                                      $"yield return new ModContext<{obj.GetObjectData().GameCategory.Value.ModInterface(getter: false)}, IMajorRecordCommon, IMajorRecordCommonGetter>"))
                    {
                        args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}");
                        args.Add($"record: {loquiAccessor}");
                        args.Add($"parent: curContext");
                        addGetOrAddArg(args);
                    }
                }
            }
            if (await MajorRecordModule.HasMajorRecords(loquiType, includeBaseClass: true, includeSelf: false) == Case.No)
            {
                return;
            }
            if (obj.IsListGroup())
            {
                return;
            }

            if (obj.IsTopLevelGroup())
            {
                fg.AppendLine($"foreach (var item in {loquiAccessor}.EnumerateMajorRecords({(generic == null ? null : "type, throwIfUnknown: false")}))");
                using (new BraceWrapper(fg))
                {
                    using (var args = new ArgsWrapper(fg,
                                                      $"yield return new ModContext<{obj.GetObjectData().GameCategory.Value.ModInterface(getter: false)}, IMajorRecordCommon, IMajorRecordCommonGetter>"))
                    {
                        args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}");
                        args.Add("record: item");
                        args.Add($"getOrAddAsOverride: (m, r) => m.{loquiType.Name}.GetOrAddAsOverride(({loquiType.GetGroupTarget().Interface(getter: true, internalInterface: true)})r)");
                    }
                }
            }
            else
            {
                using (var args = new ArgsWrapper(fg,
                                                  $"foreach (var item in {loquiType.TargetObjectGeneration.CommonClassInstance(loquiAccessor, LoquiInterfaceType.IGetter, CommonGenerics.Class)}.EnumerateMajorRecordContexts",
                                                  suffixLine: ")")
                {
                    SemiColon = false
                })
                {
                    args.Add($"obj: {loquiAccessor}");
                    args.AddPassArg("linkCache");
                    args.AddPassArg("type");
                    args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}");
                    args.Add($"parent: {(obj.GetObjectType() == ObjectType.Mod ? "null" : "curContext")}");
                    args.Add("throwIfUnknown: false");
                    addGetOrAddArg(args);
                }
                using (new BraceWrapper(fg))
                {
                    fg.AppendLine("yield return item;");
                }
            }
        }