Skip to content

Commit

Permalink
Merge pull request #336 from edbmods/bug-fixes-for-1.5.2
Browse files Browse the repository at this point in the history
Bug fixes for 1.5.2
  • Loading branch information
edbmods authored Apr 24, 2024
2 parents 6039a22 + 945e1f9 commit e6b0d41
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
[assembly: AssemblyVersion("1.1.1")]

// Increment for each new release
[assembly: AssemblyFileVersion("1.5.1")]
[assembly: AssemblyFileVersion("1.5.2")]
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

If you get a set of starting colonists that you like, save them as a preset so that you can start your game the same way next time.

[Version 1.5.1]
[Version 1.5.2]
</description>
<loadAfter>
<li>net.pardeike.rimworld.mod.harmony</li>
Expand Down
2 changes: 1 addition & 1 deletion Resources/About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>EdB.PrepareCarefully</identifier>
<version>1.5.1</version>
<version>1.5.2</version>
<showCrossPromotions>false</showCrossPromotions>
<manifestUri>https://github.com/edbmods/EdBPrepareCarefully/raw/master/Resources/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/edbmods/EdBPrepareCarefully/releases/latest</downloadUri>
Expand Down
14 changes: 14 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
_____________________________________________________________________________

Version 1.5.2
_____________________________________________________________________________

- Bug fixes:
- Fixed the randomize button in the name panel
- Bionics/implants are applied from save files again
- Custom xenotypes are loaded from save files again
- Fixed a problem where the color selector was not visible in the Apparel
dialog in some cases
- Fixed a problem where abilities were written to the save file twice
- Fixed the skill clear and reset buttons

_____________________________________________________________________________

Version 1.5.1
Expand Down
4 changes: 4 additions & 0 deletions Source/ControllerTabViewPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,9 @@ public void UpdatePawnLayerColor(PawnLayer pawnLayer, Color color) {
public void UpdateFavoriteColor(Color? color) {
PawnManager.UpdateFavoriteColor(ViewState?.CurrentPawn, color);
}

public void RandomizeName() {
PawnManager.RandomizeName(ViewState?.CurrentPawn);
}
}
}
2 changes: 2 additions & 0 deletions Source/CustomizationsPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class CustomizationsPawn {

public PawnKindDef PawnKind { get; set; }
public XenotypeDef XenotypeDef { get; set; }
public bool UniqueXenotype { get; set; }
public string XenotypeName { get; set; }
public CustomXenotype CustomXenotype { get; set; }
public AlienRace AlienRace { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions Source/DialogApparel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ void deleteAction() {
}

public void ScrollToSelectedApparel(Apparel apparel) {
EquipmentOption option = ProviderEquipment.EquipmentDatabase.FindOptionForThingDef(apparel.def);
if (option == null) {
return;
}
SelectApparelOption(option);
ScrollToThingDef = apparel.def;
SelectedStuff = apparel.Stuff;
if (apparel.TryGetQuality(out QualityCategory quality)) {
Expand Down
18 changes: 18 additions & 0 deletions Source/ManagerPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ public void ClearSkillLevels(CustomizedPawn pawn) {
foreach (var customizedSkill in pawn.Customizations.Skills) {
if (modifiers.TryGetValue(customizedSkill.SkillDef, out int minimumLevel)) {
customizedSkill.Level = minimumLevel;
var skillRecord = pawn.Pawn.skills.GetSkill(customizedSkill.SkillDef);
if (skillRecord != null) {
skillRecord.Level = minimumLevel;
}
}
}
CostAffected?.Invoke();
Expand All @@ -523,6 +527,10 @@ public void ResetSkillLevels(CustomizedPawn pawn) {
}
foreach (var customizedSkill in pawn.Customizations.Skills) {
customizedSkill.Level = customizedSkill.OriginalLevel;
var skillRecord = pawn.Pawn.skills.GetSkill(customizedSkill.SkillDef);
if (skillRecord != null) {
skillRecord.Level = customizedSkill.OriginalLevel;
}
}
CostAffected?.Invoke();
}
Expand Down Expand Up @@ -1155,5 +1163,15 @@ public void UpdateFavoriteColor(CustomizedPawn customizedPawn, Color? color) {
PawnToCustomizationsMapper.MapFavoriteColor(pawn, customizations);
}
}

public void RandomizeName(CustomizedPawn customizedPawn) {
Pawn pawn = customizedPawn?.Pawn;
CustomizationsPawn customizations = customizedPawn?.Customizations;
if (pawn == null || customizations == null) {
return;
}
pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, null, false, pawn.genes.Xenotype);
PawnToCustomizationsMapper.MapName(pawn, customizations);
}
}
}
2 changes: 2 additions & 0 deletions Source/MapperPawnToCustomizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void MapKindDef(Pawn pawn, CustomizationsPawn customizations) {
}
public void MapXenotype(Pawn pawn, CustomizationsPawn customizations) {
customizations.XenotypeDef = pawn.genes.Xenotype;
customizations.XenotypeName = pawn.genes.xenotypeName;
customizations.UniqueXenotype = pawn.genes.UniqueXenotype;
customizations.CustomXenotype = pawn.genes.CustomXenotype;
}
public void MapGender(Pawn pawn, CustomizationsPawn customizations) {
Expand Down
1 change: 1 addition & 0 deletions Source/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public void Start(Page_ConfigureStartingPawns configureStartingPawnsPage) {
namePanel.FirstNameUpdated += controllerPawns.UpdateFirstName;
namePanel.NickNameUpdated += controllerPawns.UpdateNickName;
namePanel.LastNameUpdated += controllerPawns.UpdateLastName;
namePanel.NameRandomized += controllerPawns.RandomizeName;

saveCharacterPanel.CharacterSaved += controllerPawns.SavePawn;

Expand Down
17 changes: 5 additions & 12 deletions Source/PanelXenotype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,20 @@ public override float Draw(float y) {
CustomizedPawn pawn = ViewState.CurrentPawn;
Pawn_GeneTracker geneTracker = pawn.Pawn.genes;
XenotypeDef xenotypeDef = geneTracker?.Xenotype;
CustomXenotype customXenotype = null;
CustomXenotype customXenotype = geneTracker?.CustomXenotype;

FieldXenotype.Rect = FieldRect.OffsetBy(0, y);
labelTrimmer.Rect = FieldXenotype.Rect.InsetBy(8, 0);

if (customXenotype != null) {
FieldXenotype.Label = customXenotype.name != null ? labelTrimmer.TrimLabelIfNeeded(customXenotype.name.CapitalizeFirst()) : "";
}
else if (xenotypeDef != null) {
FieldXenotype.Label = labelTrimmer.TrimLabelIfNeeded(xenotypeDef.LabelCap);
}
FieldXenotype.Label = geneTracker.XenotypeLabelCap;
FieldXenotype.Enabled = true;
FieldXenotype.ClickAction = () => {
Find.WindowStack.Add(new Dialog_ViewGenes(pawn.Pawn));
};
FieldXenotype.DrawIconFunc = (Rect rect) => {
if (customXenotype != null) {
GUI.DrawTexture(rect, customXenotype.IconDef?.Icon);
}
else if (xenotypeDef != null) {
GUI.DrawTexture(rect, xenotypeDef.Icon);
Texture iconTexture = geneTracker.iconDef?.Icon ?? xenotypeDef?.Icon;
if (iconTexture != null) {
GUI.DrawTexture(rect, geneTracker.iconDef?.Icon ?? xenotypeDef?.Icon);
}
};
FieldXenotype.IconSizeFunc = () => new Vector2(24, 24);
Expand Down
33 changes: 22 additions & 11 deletions Source/PawnCustomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,32 @@ public void ApplyHairCustomizationsToPawn(Pawn pawn, CustomizationsPawn customiz
}

public void ApplyGeneCustomizationsToPawn(Pawn pawn, CustomizationsPawn customizations) {
//Logger.Debug("ApplyGeneCustomizationsToPawn()");
if (!ModsConfig.BiotechActive || pawn == null || customizations == null) {
return;
}
//Logger.Debug(" customizations.UniqueXenotype = " + customizations.UniqueXenotype);
if (customizations.UniqueXenotype) {
pawn.genes.xenotypeName = customizations.XenotypeName;
}
//Logger.Debug(" pawn.genes.xenotypeName = " + pawn.genes.xenotypeName);
//Logger.Debug(" XenotypeLabelCap = " + pawn.genes.XenotypeLabelCap);
// May not include any customizations for genes (if loading from an older save format or from a save where
// Biotech was disabled). In that case, we'll leave the genes from the original pawn.
if (customizations.Genes != null) {
// TODO
//var genesToRemove = new List<Gene>();
//pawn?.genes?.GenesListForReading.ForEach(gene => genesToRemove.Add(gene));
//genesToRemove.ForEach(gene => pawn?.genes?.RemoveGene(gene));
//customizations?.Genes?.ForEach(gene => pawn?.genes.AddGene(gene.GeneDef, gene.Xenogene));
// Note that if you add a gene that affects appearance (i.e. hair color), it may overwrite
// any override value in the pawn story or style, so be sure to set those overrides again
// afterwards
}
var genesToRemove = new List<Gene>();
pawn?.genes?.GenesListForReading?.ForEach(gene => genesToRemove.Add(gene));
genesToRemove.ForEach(gene => pawn?.genes?.RemoveGene(gene));
customizations?.Genes?.Endogenes?.ForEach(gene => {
pawn?.genes.AddGene(gene.GeneDef, false);
});
customizations?.Genes?.Xenogenes?.ForEach(gene => {
pawn?.genes.AddGene(gene.GeneDef, true);
});
}
// Note that if you add a gene that affects appearance (i.e. hair color), it may overwrite
// any override value in the pawn story or style, so be sure to set those overrides again
// afterwards
}

public void ApplyApparelCustomizationsToPawn(Pawn pawn, CustomizationsPawn customizations) {
Expand All @@ -130,7 +141,7 @@ public void ApplyApparelCustomizationsToPawn(Pawn pawn, CustomizationsPawn custo

public void ApplyAbilityCustomizationsToPawn(Pawn pawn, CustomizationsPawn customizations) {
var abilities = customizations.Abilities;
List<AbilityDef> toRemove = new List<AbilityDef>(pawn.abilities.abilities.Select(a => a.def));
HashSet<AbilityDef> toRemove = new HashSet<AbilityDef>(pawn.abilities.abilities.Select(a => a.def));
foreach (var def in toRemove) {
pawn.abilities.RemoveAbility(def);
}
Expand Down Expand Up @@ -331,7 +342,7 @@ public void ApplyImplantToPawn(Pawn pawn, Implant implant) {
if (pawn == null || implant == null) {
return;
}
//Logger.Debug("Adding implant to pawn, recipe = " + implant.Recipe?.defName + ", hediff = " + implant.HediffDef?.defName);
Logger.Debug("Adding implant to pawn, recipe = " + implant.Recipe?.defName + ", hediff = " + implant.HediffDef?.defName);
if (implant.BodyPartRecord == null) {
Logger.Warning("Could not add implant to pawn because no BodyPartRecord is defined");
}
Expand Down
3 changes: 2 additions & 1 deletion Source/PawnGenerationRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public PawnGenerationRequest BuildFromCustomizations(CustomizationsPawn customiz
FixedBiologicalAge = biologicalAge,
FixedChronologicalAge = chronologicalAge,
ForceBodyType = customizations.BodyType,
ForcedXenotype = customizations.XenotypeDef
ForcedXenotype = customizations.XenotypeDef,
ForcedCustomXenotype = customizations.CustomXenotype,
};
if (customizations.PawnKind is CreepJoinerFormKindDef) {
wrapper.IsCreepJoiner = true;
Expand Down
23 changes: 16 additions & 7 deletions Source/PawnLoaderV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,25 @@ public PawnLoaderResult ConvertSaveRecordToCustomizedPawn(SaveRecordPawnV5 recor
}

if (record.genes != null) {
if (!record.genes.xenotypeDef.NullOrEmpty()) {
XenotypeDef xenotypeDef = DefDatabase<XenotypeDef>.GetNamedSilentFail(record.genes.xenotypeDef);
if (xenotypeDef != null) {
customizations.XenotypeDef = xenotypeDef;
}
}
else if (!record.genes.customXenotypeName.NullOrEmpty()) {
if (!record.genes.customXenotypeName.NullOrEmpty()) {
var customXenotypes = ReflectionUtil.GetStaticPropertyValue<List<CustomXenotype>>(typeof(CharacterCardUtility), "CustomXenotypes");
if (customXenotypes == null) {
Logger.Debug("Go no custom xenotypes from the reflected property");
}
CustomXenotype xenotype = customXenotypes?.Where(x => { return x.name == record.genes.customXenotypeName; }).FirstOrDefault();
if (xenotype != null) {
customizations.CustomXenotype = xenotype;
}
else {
customizations.UniqueXenotype = true;
customizations.XenotypeName = record.genes.customXenotypeName;
}
}
else if (!record.genes.xenotypeDef.NullOrEmpty()) {
XenotypeDef xenotypeDef = DefDatabase<XenotypeDef>.GetNamedSilentFail(record.genes.xenotypeDef);
if (xenotypeDef != null) {
customizations.XenotypeDef = xenotypeDef;
}
}

if (record.genes?.endogenes != null || record.genes?.xenogenes != null) {
Expand Down Expand Up @@ -571,6 +578,8 @@ public PawnLoaderResult ConvertSaveRecordToCustomizedPawn(SaveRecordPawnV5 recor
};
// TODO: This looks weird; something to do with caching the label. Should rework it.
implant.label = implant.Label;
customizations.Implants.Add(implant);
Logger.Debug("Added implant customizations " + recipeDef?.defName);
}
else if (implantRecord.hediffDef != null) {
HediffDef hediffDef = DefDatabase<HediffDef>.GetNamedSilentFail(implantRecord.hediffDef);
Expand Down
6 changes: 2 additions & 4 deletions Source/PawnSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ public SaveRecordPawnV5 ConvertCustomizedPawnToSaveRecord(CustomizedPawn customi
color = apparel.Color
});
}
foreach (var ability in customizations.Abilities) {
result.abilities.Add(ability.AbilityDef.defName);
}

OptionsHealth healthOptions = ProviderHealthOptions.GetOptions(customizedPawn.Pawn);
foreach (Implant implant in customizations.Implants) {
Expand Down Expand Up @@ -157,7 +154,8 @@ public SaveRecordPawnV5 ConvertCustomizedPawnToSaveRecord(CustomizedPawn customi
if (ModsConfig.BiotechActive) {
result.genes = new SaveRecordGenesV5() {
xenotypeDef = customizations.XenotypeDef?.defName,
customXenotypeName = customizations.CustomXenotype?.name,
customXenotypeName = customizations.XenotypeName,
uniqueXenotype = customizations.UniqueXenotype,
endogenes = customizedPawn.Pawn.genes?.Endogenes.ConvertAll(g => g.def?.defName),
xenogenes = customizedPawn.Pawn.genes?.Xenogenes.ConvertAll(g => g.def?.defName)
};
Expand Down
2 changes: 1 addition & 1 deletion Source/PresetLoaderV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public PresetLoaderResult Load(string presetName) {
try {
Scribe_Collections.Look<SaveRecordPawnV3>(ref hiddenPawns, "hiddenPawns", LookMode.Deep, null);
}
catch (Exception e) {
catch (Exception) {
//Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig);
//Logger.Warning("Error while loading preset. Failed to load hidden pawns", e);
//Logger.Warning("Preset was created with the following mods: " + ModString);
Expand Down
2 changes: 2 additions & 0 deletions Source/Version5/SaveRecordGenesV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace EdB.PrepareCarefully {
public class SaveRecordGenesV5 : IExposable {
public string xenotypeDef;
public string customXenotypeName;
public bool uniqueXenotype;
public List<string> endogenes;
public List<string> xenogenes;

Expand All @@ -17,6 +18,7 @@ public SaveRecordGenesV5() {
public void ExposeData() {
Scribe_Values.Look<string>(ref this.xenotypeDef, "xenotypeDef", null, false);
Scribe_Values.Look<string>(ref this.customXenotypeName, "customXenotypeName", null, false);
Scribe_Values.Look<bool>(ref this.uniqueXenotype, "uniqueXenotype", false);
Scribe_Collections.Look<string>(ref this.endogenes, "endogenes");
Scribe_Collections.Look<string>(ref this.xenogenes, "xenogenes");
}
Expand Down

0 comments on commit e6b0d41

Please sign in to comment.