Adds sized (S, M, L) power cells and a generic component for battery powered items (#2352)
* Refactor battery/powercell assets and add new ones. * committing before I fuck things up * slot component doned I think * dictionary update * Fixes * Moving flashlight to powerslotcomponent * har har i am using the message tubes * Better documentation comment * Reverting this overengineered garbage. * Off with ye I said * Examine texts. * Some minor fixes to IDE complaints * slot size from yaml * Ignored component + removing a useless typo entry * Making stunbatons use this * Handle the message and remove some unnecessary dirtiness * actionblocker checks * remove unused file * remove updatevisual * make these nullable * make these nullable too * Unrename sprite folder * check itemcomponent on insertion * Use SendMessage over Owner.SendMessage * Add support for auto-recharging batteries, an auto-recharging cell, and make flashlight status update correctly if one is inserted in it. * get rid of public fields which are Bad * add a description for the stun baton while i'm in here * one more public field * Add the blinky animation to the atomic cell * Fix the charge indicator being STUPID * better comments * this is a better function * add pause for flashlight, remove unnecessary imports from battery * potato battery copyright link * WHO DID THAT * mr clean has come * Random pitch * pausing * round to nearest levels
This commit is contained in:
@@ -56,5 +56,53 @@ namespace Content.Shared.Utility
|
||||
return (int)Math.Floor(preround);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the segment <paramref name="actual"/> lies on on a decimal scale from 0 to <paramref name="max"/> divided into
|
||||
/// <paramref name="levels"/> sections. In less mathematical terms, same as <see cref="RoundToLevels"/>
|
||||
/// except <paramref name="actual"/> is rounded to the nearest matching level instead of 0 and the highest level being
|
||||
/// precisely 0 and max and no other value.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// You have a 5-segment progress bar used to display a percentile value.
|
||||
/// You want the display to match the percentile value as accurately as possible, so that eg.
|
||||
/// 95% is rounded up to 5, 89.99% is rounded down to 4, 15% is rounded up to 1 and 5% is rounded down
|
||||
/// to 0, in terms of number of segments lit.
|
||||
/// In this case you would use <code>RoundToNearestLevels(value, max, 5)</code>
|
||||
/// </example>
|
||||
/// <param name="actual">The point to be rounded to the nearest level.</param>
|
||||
/// <param name="max">The maximum value of the scale.</param>
|
||||
/// <param name="levels">Number of segments the scale is subdivided into.</param>
|
||||
/// <returns>The segment <paramref name="actual"/> lies on.</returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static int RoundToNearestLevels(double actual, double max, int levels)
|
||||
{
|
||||
if (levels <= 1)
|
||||
{
|
||||
throw new ArgumentException("Levels must be greater than 1.", nameof(levels));
|
||||
}
|
||||
if (actual >= max)
|
||||
{
|
||||
return levels;
|
||||
}
|
||||
if (actual <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
double step = max / levels;
|
||||
|
||||
int nearest = 0;
|
||||
double nearestDiff = actual;
|
||||
for (var i = 1; i <= levels; i++)
|
||||
{
|
||||
var diff = Math.Abs(actual - i * step);
|
||||
if (diff < nearestDiff)
|
||||
{
|
||||
nearestDiff = diff;
|
||||
nearest = i;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user