public override void GenerateCopyIn(FileGeneration fg, ObjectGeneration objGen, TypeGeneration typeGen, Accessor nodeAccessor, Accessor itemAccessor, Accessor errorMaskAccessor, Accessor translationMaskAccessor) { GenderedType gendered = typeGen as GenderedType; var gen = this.XmlMod.GetTypeGeneration(gendered.SubTypeGeneration.GetType()); MaskGenerationUtility.WrapErrorFieldIndexPush( fg, () => { using (var args = new ArgsWrapper(fg, $"{itemAccessor} = new {typeGen.TypeName(getter: false)}")) { args.Add(subFg => { gen.GenerateCopyIn(subFg, objGen, gendered.SubTypeGeneration, nodeAccessor, Accessor.ConstructorParam($"male"), errorMaskAccessor, translationMaskAccessor: null); }); args.Add(subFg => { gen.GenerateCopyIn(subFg, objGen, gendered.SubTypeGeneration, nodeAccessor, Accessor.ConstructorParam($"female"), errorMaskAccessor, translationMaskAccessor: null); }); } }, errorMaskAccessor, typeGen.HasIndex ? typeGen.IndexEnumInt : default(Accessor)); }
public override string GetTranslationMaskTypeStr(TypeGeneration field) { GenderedType gendered = field as GenderedType; if (gendered.SubTypeGeneration is LoquiType loqui) { return($"GenderedItem<{loqui.Mask(MaskType.Translation)}>?"); } else { return($"GenderedItem<bool>?"); } }
public override void GenerateWrite(FileGeneration fg, ObjectGeneration objGen, TypeGeneration typeGen, Accessor writerAccessor, Accessor itemAccessor, Accessor errorMaskAccessor, Accessor nameAccessor, Accessor translationMaskAccessor) { GenderedType gendered = typeGen as GenderedType; var gen = this.XmlMod.GetTypeGeneration(gendered.SubTypeGeneration.GetType()); using (new BraceWrapper(fg)) { gen.GenerateWrite(fg, objGen, gendered.SubTypeGeneration, writerAccessor, $"{itemAccessor}.Male", errorMaskAccessor, nameAccessor, translationMaskAccessor); } using (new BraceWrapper(fg)) { gen.GenerateWrite(fg, objGen, gendered.SubTypeGeneration, writerAccessor, $"{itemAccessor}.Female", errorMaskAccessor, nameAccessor, translationMaskAccessor); } }
public override string GenerateForTranslationMaskCrystalization(TypeGeneration field) { GenderedType gendered = field as GenderedType; //ToDo //Implement crystal construction if (gendered.SubTypeGeneration is LoquiType loqui) { return($"({field.Name} != null || DefaultOn, null)"); } else { return($"({field.Name} != null || DefaultOn, null)"); } }
public override async Task <int?> ExpectedLength(ObjectGeneration objGen, TypeGeneration typeGen) { GenderedType gender = typeGen as GenderedType; if (!this.Module.TryGetTypeGeneration(gender.SubTypeGeneration.GetType(), out var subTransl)) { throw new ArgumentException("Unsupported type generator: " + gender.SubTypeGeneration); } var expected = await subTransl.ExpectedLength(objGen, gender.SubTypeGeneration); if (expected == null) { return(null); } return(expected.Value * 2); }
public override void GenerateForField(FileGeneration fg, TypeGeneration field, string typeStr) { if (!field.IntegrateField) { return; } GenderedType gendered = field as GenderedType; string maskStr; if (field.Nullable || gendered.SubTypeGeneration is LoquiType) { maskStr = $"MaskItem<{typeStr}, GenderedItem<{SubMaskString(field, typeStr)}>?>?"; } else { maskStr = $"GenderedItem<{SubMaskString(field, typeStr)}>"; } fg.AppendLine($"public {maskStr} {field.Name};"); }
public string SubMaskString(TypeGeneration field, string typeStr) { GenderedType gendered = field as GenderedType; if (gendered.SubTypeGeneration is LoquiType loqui) { if (gendered.ItemNullable) { return($"MaskItem<{typeStr}, {loqui.GetMaskString(typeStr)}?>?"); } else { return($"{loqui.GetMaskString(typeStr)}?"); } } else { return(typeStr); } }
public override void GenerateForAny(FileGeneration fg, TypeGeneration field, Accessor accessor, bool nullCheck, bool indexed) { if (!field.IntegrateField) { return; } GenderedType gendered = field as GenderedType; var isLoqui = gendered.SubTypeGeneration is LoquiType; if (field.Nullable || isLoqui) { using (var args = new ArgsWrapper(fg, $"if ({nameof(GenderedItem)}.{(isLoqui ? nameof(GenderedItem.AnyMask) : nameof(GenderedItem.Any))}", suffixLine: ") return true")) { args.Add($"{accessor}"); args.AddPassArg("eval"); } } else { fg.AppendLine($"if (eval({accessor}{(indexed ? ".Value" : null)}.Male) || eval({accessor}{(indexed ? ".Value" : null)}.Female)) return true;"); } }
public override async Task GenerateCopyIn( FileGeneration fg, ObjectGeneration objGen, TypeGeneration typeGen, Accessor readerAccessor, Accessor itemAccessor, Accessor errorMaskAccessor, Accessor translationAccessor) { GenderedType gender = typeGen as GenderedType; var data = typeGen.GetFieldData(); if (!this.Module.TryGetTypeGeneration(gender.SubTypeGeneration.GetType(), out var subTransl)) { throw new ArgumentException("Unsupported type generator: " + gender.SubTypeGeneration); } if (data.RecordType.HasValue) { fg.AppendLine($"{readerAccessor}.Position += {readerAccessor}.{nameof(MutagenBinaryReadStream.MetaData)}.{nameof(ParsingBundle.Constants)}.{nameof(GameConstants.SubConstants)}.{nameof(RecordHeaderConstants.HeaderLength)};"); } else if (data.MarkerType.HasValue && !gender.MarkerPerGender) { fg.AppendLine($"{readerAccessor}.Position += {readerAccessor}.{nameof(MutagenBinaryReadStream.MetaData)}.{nameof(ParsingBundle.Constants)}.{nameof(GameConstants.SubConstants)}.{nameof(RecordHeaderConstants.HeaderLength)} + contentLength; // Skip marker"); } bool notNull = gender.ItemHasBeenSet && !gender.SubTypeGeneration.IsNullable; using (var args = new ArgsWrapper(fg, $"{itemAccessor} = {this.Namespace}GenderedItemBinaryTranslation.Parse{(gender.MarkerPerGender ? "MarkerPerItem" : null)}<{gender.SubTypeGeneration.TypeName(getter: false, needsCovariance: true)}>")) { args.AddPassArg($"frame"); if (gender.MaleMarker.HasValue) { args.Add($"maleMarker: {objGen.RecordTypeHeaderName(gender.MaleMarker.Value)}"); args.Add($"femaleMarker: {objGen.RecordTypeHeaderName(gender.FemaleMarker.Value)}"); } if (data.MarkerType.HasValue && gender.MarkerPerGender) { args.Add($"marker: {objGen.RecordTypeHeaderName(data.MarkerType.Value)}"); } var subData = gender.SubTypeGeneration.GetFieldData(); if (subData.RecordType.HasValue && !(gender.SubTypeGeneration is LoquiType)) { args.Add($"contentMarker: {objGen.RecordTypeHeaderName(subData.RecordType.Value)}"); } LoquiType loqui = gender.SubTypeGeneration as LoquiType; if (loqui != null) { if (subData?.RecordTypeConverter != null && subData.RecordTypeConverter.FromConversions.Count > 0) { args.Add($"recordTypeConverter: {objGen.RegistrationName}.{typeGen.Name}Converter"); } } if (gender.FemaleConversions != null) { args.Add($"femaleRecordConverter: {objGen.RegistrationName}.{typeGen.Name}FemaleConverter"); } if (gender.MaleConversions != null) { args.Add($"maleRecordConverter: {objGen.RegistrationName}.{typeGen.Name}MaleConverter"); } if (loqui != null) { args.Add($"transl: {loqui.ObjectTypeName}{loqui.GenericTypes(getter: false)}.TryCreateFromBinary"); } else { args.Add($"transl: {subTransl.GetTranslatorInstance(gender.SubTypeGeneration, getter: false)}.Parse"); if (gender.ItemHasBeenSet) { args.Add($"skipMarker: false"); } } if (notNull) { args.Add($"fallback: {gender.SubTypeGeneration.GetDefault(getter: false)}"); } } }
public override void GenerateWrite( FileGeneration fg, ObjectGeneration objGen, TypeGeneration typeGen, Accessor writerAccessor, Accessor itemAccessor, Accessor errorMaskAccessor, Accessor translationAccessor, Accessor converterAccessor) { GenderedType gendered = typeGen as GenderedType; var gen = this.Module.GetTypeGeneration(gendered.SubTypeGeneration.GetType()); var data = typeGen.GetFieldData(); if (!this.Module.TryGetTypeGeneration(gendered.SubTypeGeneration.GetType(), out var subTransl)) { throw new ArgumentException("Unsupported type generator: " + gendered.SubTypeGeneration); } var allowDirectWrite = subTransl.AllowDirectWrite(objGen, gendered.SubTypeGeneration); bool needsMasters = gendered.SubTypeGeneration is FormLinkType || gendered.SubTypeGeneration is LoquiType; var typeName = gendered.SubTypeGeneration.TypeName(getter: true); var loqui = gendered.SubTypeGeneration as LoquiType; if (loqui != null) { typeName = loqui.TypeNameInternal(getter: true, internalInterface: true); } using (var args = new ArgsWrapper(fg, $"GenderedItemBinaryTranslation.Write{(gendered.MarkerPerGender ? "MarkerPerItem" : null)}")) { args.Add($"writer: {writerAccessor}"); args.Add($"item: {itemAccessor}"); if (data.RecordType.HasValue) { args.Add($"recordType: {objGen.RecordTypeHeaderName(data.RecordType.Value)}"); } else if (data.MarkerType.HasValue) { args.Add($"markerType: {objGen.RecordTypeHeaderName(data.MarkerType.Value)}"); } if (gendered.MaleMarker.HasValue) { args.Add($"maleMarker: {objGen.RecordTypeHeaderName(gendered.MaleMarker.Value)}"); } if (gendered.FemaleMarker.HasValue) { args.Add($"femaleMarker: {objGen.RecordTypeHeaderName(gendered.FemaleMarker.Value)}"); } if (gendered.MaleMarker.HasValue && loqui != null) { args.Add("markerWrap: false"); } if (gendered.FemaleConversions != null) { args.Add($"femaleRecordConverter: {objGen.RegistrationName}.{typeGen.Name}FemaleConverter"); } if (gendered.MaleConversions != null) { args.Add($"maleRecordConverter: {objGen.RegistrationName}.{typeGen.Name}MaleConverter"); } if (allowDirectWrite) { args.Add($"transl: {subTransl.GetTranslatorInstance(gendered.SubTypeGeneration, getter: true)}.Write{(gendered.SubTypeGeneration.HasBeenSet ? "Nullable" : string.Empty)}"); } else { args.Add((gen) => { var listTranslMask = this.MaskModule.GetMaskModule(gendered.SubTypeGeneration.GetType()).GetTranslationMaskTypeStr(gendered.SubTypeGeneration); gen.AppendLine($"transl: (MutagenWriter subWriter, {typeName}{gendered.SubTypeGeneration.NullChar} subItem{(needsMasters ? $", {nameof(RecordTypeConverter)}? conv" : null)}) =>"); using (new BraceWrapper(gen)) { subTransl.GenerateWrite( fg: gen, objGen: objGen, typeGen: gendered.SubTypeGeneration, writerAccessor: "subWriter", translationAccessor: "subTranslMask", itemAccessor: new Accessor($"subItem"), errorMaskAccessor: null, converterAccessor: needsMasters ? "conv" : null); } }); } } }