Skip to content

Commit

Permalink
cherry pick the SpinnerDriftSpeed commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LozenChen committed Dec 30, 2024
1 parent 7c77792 commit 025acd4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Dialog/English.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ TAS_HELPER_COUNTDOWN_EXACT_GROUP_DESCRIPTION= ExactGroup % 3/15: ma
\S Hazard turn on/off on this frame.{n}
Equivalently, hazards with ExactGroup lying in (y, y + 1) are temporarily in one group.
(Doesn't work when TimeActive is too large)
TAS_HELPER_SHOW_DRIFT_SPEED= Show Hazard Cycle Drift Speed
TAS_HELPER_DRIFT_SPEED_DESCRIPTION= Only works when in ExactGroup % 3/15 mode.{n}
The formula of Drift Speed is:{n}
\S (ExactGroup of this frame) - (ExactGroup of last frame) - 1
TAS_HELPER_FONT= Font
TAS_HELPER_HIRES_FONT= Hires Font
TAS_HELPER_PIXEL_FONT= Pixel Font
Expand Down
1 change: 1 addition & 0 deletions Dialog/Simplified Chinese.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ TAS_HELPER_COUNTDOWN_MODE_DESCRIPTION= 每 3 帧一次, 检
每 15 帧一次, 检测以下行为的条件:{n}
- Spinner become invisible (InView),{n}
- Lightning turn off collision (InView).
TAS_HELPER_SHOW_DRIFT_SPEED= 显示 Spinner Drift 速度
TAS_HELPER_FONT= 字体
TAS_HELPER_HIRES_FONT= 高清字体
TAS_HELPER_PIXEL_FONT= 像素字体
Expand Down
49 changes: 43 additions & 6 deletions Source/Gameplay/Spinner/ExactSpinnerGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static class ExactSpinnerGroup {
public static bool Enabled = false;

// hazard with offset group in (LevelGroup, LevelGroup + 1] will activate this frame (when TimeRate = 1)
public static double ExactLevelGroup => ((double)Engine.Scene.TimeActive * 60 - 1 + GroupPeriod) % GroupPeriod;
public static double ExactLevelGroup => ((double)Engine.Scene.TimeActive * 60 - 1 + GroupPeriod) % GroupPeriod;

public static double LastExactLevelGroup;

internal static Dictionary<Entity, Tuple<bool, string>> offsetGroup = new();

Expand All @@ -24,13 +26,13 @@ public static double ExactHazardGroup(Entity entity) {
}

public static void SetModulo(int modulo) {
if (Enabled && modulo < 0) {
UnloadExactSpinnerGroup();
if (Enabled && modulo < 0) {
Enabled = false;
UnloadExactSpinnerGroup();
}
else if (!Enabled && modulo > 0) {
Enable();
else if (!Enabled && modulo > 0) {
Enabled = true;
Enable();
}
else if (Enabled && modulo > 0) {
if (modulo != GroupPeriod) {
Expand Down Expand Up @@ -73,8 +75,23 @@ public static void LoadExactSpinnerGroup() {
}
}

public static void LoadExactLevelGroup() {
public static void LoadExactLevelGroup() {
if (!Enabled && GroupPeriod < 0) {
// impossible in normal cases, but do this
// so if someone wants to have both LevelGroup and CountdownModes._3fCycle
// they can just Invoke this method
GroupPeriod = TasHelperSettings.CountdownMode == Module.TASHelperSettings.CountdownModes._15fCycle ? 15 : 3;
}
ExactLevelGroupRenderer.AddIfNecessary();
}

[Load]
private static void Load() {
EventOnHook._Scene.AfterUpdate += PatchAfterUpdate;
}

private static void PatchAfterUpdate(Scene scene) {
LastExactLevelGroup = ExactLevelGroup;
}

private class ExactLevelGroupRenderer : Message {
Expand All @@ -95,6 +112,9 @@ public static bool AddIfNecessary() {
if (Instance is null || !level.Entities.Contains(Instance)) {
Instance = new();
level.AddImmediately(Instance);
}
else {
Instance.Visible = true;
}
return true;
}
Expand All @@ -115,7 +135,24 @@ public override void Update() {
}
if (ShowTimeRateTimer > 0) {
text += $"\nTimeRate {Engine.TimeRate:0.00}";
}
if (TasHelperSettings.ShowDriftSpeed) {
text += $"\nDriftSpeed: {ToMinimumAbsResidue(ExactLevelGroup - LastExactLevelGroup - 1, GroupPeriod).ToString(DriftSpeedFormat)}";
}
}

private const string DriftSpeedFormat = "+0.0000000000;-0.0000000000;+0.0000000000";

private static double ToMinimumAbsResidue(double d, double modulo) {
// this assumes (- modulo < d < modulo)
// otherwise, you should first do (d % modulo)
if (d > modulo / 2) {
return d - modulo;
}
else if (d < -modulo / 2) {
return d + modulo;
}
return d;
}

public override void Render() {
Expand Down
5 changes: 5 additions & 0 deletions Source/Module/Menu/TASHelperMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ private static EaseInSubMenu CreateCountdownSubMenu(TextMenu menu) {
TextMenu.Item CountdownBoostItem;
subMenu.Add(CountdownBoostItem = new TextMenu.OnOff("Countdown Boost".ToDialogText(), TasHelperSettings.CountdownBoost).Change(value => TasHelperSettings.CountdownBoost = value));
subMenu.AddDescription(menu, CountdownBoostItem, "Countdown Boost Description".ToDialogText());

TextMenu.Item DriftSpeedItem;
subMenu.Add(DriftSpeedItem = new TextMenu.OnOff("Show Drift Speed".ToDialogText(), TasHelperSettings.ShowDriftSpeed).Change(value => TasHelperSettings.ShowDriftSpeed = value));
subMenu.AddDescription(menu, DriftSpeedItem, "Drift Speed Description".ToDialogText());

subMenu.Add(new EnumerableSliderExt<CountdownFonts>("Font".ToDialogText(), CreateCountdownFontOptions(),
TasHelperSettings.CountdownFont).Change(value => TasHelperSettings.CountdownFont = value));
subMenu.Add(new TextMenu.OnOff("Darken When Uncollidable".ToDialogText(), TasHelperSettings.DarkenWhenUncollidable).Change(value => TasHelperSettings.DarkenWhenUncollidable = value));
Expand Down
2 changes: 2 additions & 0 deletions Source/Module/TASHelperSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public enum CountdownFonts { PixelFont, HiresFont };

public bool DarkenWhenUncollidable = true;

public bool ShowDriftSpeed = false;

#endregion

#region LoadRange
Expand Down
1 change: 1 addition & 0 deletions Source/Module/WhatsNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static void CreateUpdateLog() {
AddLog("2.0.11", "Rewrite some codes to be compatible with ghost mod.");
AddLog("2.0.12", "Feature: Auto-Watch now decrypts Auroras Hashed DashCode Trigger.", "Support Stunning Helper's hazards. (thanks @trans_alexa)");
AddLog("2.0.13", "Feature: Auto-Watch supports SwitchGate.");
AddLog("2.0.14", "Feature: Add Spinner Drift Speed (in Hazard Countdown). (thanks @trans_alexa)", "Bugfix: Simplified Spinner doesn't handle old versions of XaphanHelper properly, and crash with latest XaphanHelper.");
UpdateLogs.Sort((x, y) => new Version(y.Item1).CompareTo(new Version(x.Item1)));
}

Expand Down

0 comments on commit 025acd4

Please sign in to comment.