Skip to content

Commit

Permalink
Fixed uncensor swap not always occuring when needed on scene load
Browse files Browse the repository at this point in the history
  • Loading branch information
thojmr committed Jul 31, 2021
1 parent 3851927 commit 44b8a60
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,33 @@ internal void CheckBellyPreservation()
}
}


/// <summary>
/// When loading or changing characters, check for any save blendshapes that need to be loaded from the character card
/// </summary>
internal void CheckBlendShapes()
{
//If the uncensor changed just before this Reload(), then is was probably a character swap.
if (uncensorChanged)
{
uncensorChanged = false;

//When in maker or studio we want to reset inflation values when uncensor changes to reset clothes
if (StudioAPI.InsideStudio || MakerAPI.InsideMaker) ResetInflation();
//Load any saved blendshapes from card, and can trigger uncensor change when necessary
//Give any existing uncensor changes time to process first
StartCoroutine(ILoadBlendshapes(0.1f, checkUncensor: true));
}
else
{
//When character first loads in studio, always check for uncensor match if a saved blendshape exists
var needsUncensorCheck = firstStart && (StudioAPI.InsideStudio || MakerAPI.InsideMaker);

//Load any saved blendshapes from card, or trigger uncensor change when necessary
StartCoroutine(ILoadBlendshapes(0f, checkUncensor: needsUncensorCheck));
}
}

}
}

Expand Down
43 changes: 17 additions & 26 deletions PregnancyPlus/PregnancyPlus.Core/PPCharaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public partial class PregnancyPlusCharaController: CharaCustomFunctionController
{

internal bool initialized = false;//Prevent some actions from happening before character data loads
internal bool firstStart = true;//When this class just loaded for the first time

public BellyInfo bellyInfo;
public string charaFileName = null;
Expand Down Expand Up @@ -89,6 +90,7 @@ protected override void OnCardBeingSaved(GameMode currentGameMode)
protected override void Start()
{
uncensorChanged = false;//reset value to signify its not a change made manually by the user
firstStart = true;

//Character card name
charaFileName = ChaFileControl.parameter.fullname;
Expand All @@ -100,6 +102,8 @@ protected override void Start()

//When HScene starts, pre compute inflated size blendshape
#if !KKS //TODO add gameAPI later when KKS releases fully

//TODO this fires for all chaaracters, even those not in Hscene...
GameAPI.StartH += (object sender, EventArgs e) =>
{
if (PregnancyPlusPlugin.DebugLog.Value) PregnancyPlusPlugin.Logger.LogInfo($"+= $StartH {charaFileName}");
Expand All @@ -117,12 +121,6 @@ protected override void Start()

#endif

// CharacterApi.CharacterReloaded += (object sender, CharaReloadEventArgs e) =>
// {
// if (e.ReloadedCharacter == null || e.ReloadedCharacter.name != ChaControl.name) return;
// if (PregnancyPlusPlugin.DebugLog.Value) PregnancyPlusPlugin.Logger.LogInfo($"+= OnCharacterReloaded ");
// };

base.Start();
}

Expand Down Expand Up @@ -155,34 +153,24 @@ protected override void OnReload(GameMode currentGameMode)
charaFileName = ChaFileControl.parameter.fullname;

ReadAndSetCardData();
//When char swap determine which char belly to use
//When char was swaped, determine which char's belly shape to use
CheckBellyPreservation();
//Check for saved blendshapes to load from char card
CheckBlendShapes();

//If the uncensor changed just before this Reload(), then is was probably a character swap.
if (uncensorChanged)
{
uncensorChanged = false;

//When in maker or studio we want to reset inflation values when uncensor changes to reset clothes
if (StudioAPI.InsideStudio || MakerAPI.InsideMaker) ResetInflation();
//Load any saved blendshapes from card, and can trigger uncensor change when necessary
//Give any existing uncensor changes time to process first
StartCoroutine(ILoadBlendshapes(0.1f, checkUncensor: true));
}
else
{
//Load any saved blendshapes from card, or trigger uncensor change when necessary
StartCoroutine(ILoadBlendshapes(0f));
}

//Apply belly shape slider values saved on char card
StartCoroutine(ReloadStoryInflation(0.5f, "Reload-story"));
StartCoroutine(ReloadStudioMakerInflation(1.5f, reMeasure: true, "Reload")); //Give time for character to load, and settle

firstStart = false;
}


protected override void Update()
{
//Used to inflate/deflate in main game
WatchForUserKeyPress();
//Used to incrementally inflate belly during HScene
ComputeInflationChange();

//just for debugging belly during animations, very compute heavy for Update()
Expand All @@ -191,9 +179,12 @@ protected override void Update()
if (Time.frameCount % 60 == 0) MeshInflate(new MeshInflateFlags(this, _checkForNewMesh: true, _freshStart: true, _reMeasure: true), "Update");
}



///** Threading **

//Execute thread results in main thread, when existing threads are done processing
threading.WatchAndExecuteThreadResults();

threading.WatchAndExecuteThreadResults();
//Clear some values when all threads finished
if (threading.AllDone) RemoveMeshCollider();

Expand Down

0 comments on commit 44b8a60

Please sign in to comment.