Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rigidity slider fix #5778

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/microbe_stage/editor/CellEditorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,18 +1261,21 @@ public void OnRigidityChanged(int desiredRigidity)
if (previousRigidity == desiredRigidity)
return;

int costPerStep = (int)Math.Min(Constants.MEMBRANE_RIGIDITY_COST_PER_STEP * CostMultiplier, 100);
var costPerStep = Math.Min(Constants.MEMBRANE_RIGIDITY_COST_PER_STEP * CostMultiplier, 100);

var data = new RigidityActionData(desiredRigidity / Constants.MEMBRANE_RIGIDITY_SLIDER_TO_VALUE_RATIO, Rigidity)
{
CostMultiplier = CostMultiplier,
};

var cost = Editor.WhatWouldActionsCost(new[] { data });
// In some cases "theoreticalCost" might get rounded improperly
var theoreticalCost = Editor.WhatWouldActionsCost(new[] { data });
var cost = (int)Math.Ceiling(Math.Ceiling(theoreticalCost / costPerStep) * costPerStep);

if (cost > Editor.MutationPoints)
// Cases where mutation points are equal 0 are handled below in the next "if" statement
if (cost > Editor.MutationPoints && Editor.MutationPoints != 0)
hhyyrylainen marked this conversation as resolved.
Show resolved Hide resolved
{
int stepsToCutOff = (int)Math.Ceiling((float)(cost - Editor.MutationPoints) / costPerStep);
int stepsToCutOff = (int)Math.Ceiling((cost - Editor.MutationPoints) / costPerStep);
data.NewRigidity -= (desiredRigidity - previousRigidity > 0 ? 1 : -1) * stepsToCutOff /
Constants.MEMBRANE_RIGIDITY_SLIDER_TO_VALUE_RATIO;

Expand All @@ -1281,6 +1284,14 @@ public void OnRigidityChanged(int desiredRigidity)
return;
}

// Make sure that if there are no mutation points the player cannot drag the slider
// when the cost is rounded to zero
if (theoreticalCost >= 0 && (Editor.MutationPoints - cost < 0 || costPerStep > Editor.MutationPoints))
{
UpdateRigiditySlider(previousRigidity);
return;
}

var action = new SingleEditorAction<RigidityActionData>(DoRigidityChangeAction, UndoRigidityChangeAction, data);

Editor.EnqueueAction(action);
Expand Down