Skip to content

Commit

Permalink
feat/ActivableModifiers: Final version for activable modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoko84 committed Jan 28, 2020
1 parent 492f987 commit fb34be7
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 11 deletions.
5 changes: 5 additions & 0 deletions FightSabers/FightSabers/Core/ModifierManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class ModifierManager : MonoBehaviour

public int noteCountDuration;

public float noteShrinkerStrength = 1f;
public float colorSuckerStrength = 1f;
public float timeWarperStrength = 1f;

public float lerpValue;
public Vector2 LerpValueRange { get; private set; }

Expand All @@ -36,6 +40,7 @@ public IEnumerator ConfigureModifiers(float delay = 0)
else if (modifier == typeof(TimeWarper))
{
timeWarper = gameObject.AddComponent<TimeWarper>();
timeWarper.strength = timeWarperStrength;
timeWarper.EnableModifier();
}
}
Expand Down
1 change: 1 addition & 0 deletions FightSabers/FightSabers/Models/Modifiers/NoteShrinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public override void EnableModifier()
strength = strength < 0 ? 1 : strength;
ScaleApplied = BaseScaleApplied * (1 / strength);
ScaleApplied = ScaleApplied.x >= 1 ? Vector3.one : ScaleApplied;
ScaleApplied = ScaleApplied.x <= 0 ? new Vector3(Mathf.Abs(ScaleApplied.x), Mathf.Abs(ScaleApplied.y), Mathf.Abs(ScaleApplied.z)) : ScaleApplied;
_oldScale = transform.localScale;
var t = gameObject.Tween("ShrinkerScaleTransition" + gameObject.GetInstanceID(), transform.localScale, ScaleApplied, 0.35f,
TweenScaleFunctions.Linear, tween => { transform.localScale = tween.CurrentValue; });
Expand Down
11 changes: 9 additions & 2 deletions FightSabers/FightSabers/Patches/GameNoteControllerAwakePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FightSabers.Models;
using FightSabers.Models.Abstracts;
using FightSabers.Models.Modifiers;
using FightSabers.UI.Controllers;

namespace FightSabers.Patches
{
Expand All @@ -22,11 +23,17 @@ public static void Postfix(GameNoteController __instance)
if (__instance)
{
if (!__instance.noteTransform.gameObject.GetComponent<NoteShrinker>())
__instance.noteTransform.gameObject.AddComponent<NoteShrinker>().gameNoteController = __instance;
{
var noteShrinker = __instance.noteTransform.gameObject.AddComponent<NoteShrinker>();
noteShrinker.gameNoteController = __instance;
noteShrinker.strength = ModifierManager.instance.noteShrinkerStrength;

}
if (!__instance.noteTransform.gameObject.GetComponent<ColorSucker>())
{
var colorSucker = __instance.noteTransform.gameObject.AddComponent<ColorSucker>();
colorSucker.gameNoteController = __instance;
colorSucker.strength = ModifierManager.instance.colorSuckerStrength;
colorSuckers.Add(colorSucker);
}

Expand All @@ -50,7 +57,7 @@ void OnMonsterRemoved(object self, MonsterStatus status)

if (!Plugin.config.Value.Enabled)
{
ModifierManager.instance.noteCountDuration = 35;
ModifierManager.instance.noteCountDuration = (int)Math.Ceiling(35 * FightSabersGameplaySetup.instance.ColorSuckerStrength);
foreach (var monsterModifier in ModifierManager.instance.modifiers)
{
if (__instance.noteTransform.gameObject.GetComponent(monsterModifier) is Modifier modifier)
Expand Down
3 changes: 3 additions & 0 deletions FightSabers/FightSabers/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ private static void OnGameSceneActive()
if (FightSabersGameplaySetup.instance.TimeWarperEnabled)
modifiers.Add(typeof(TimeWarper));
modifierManager.modifiers = modifiers.ToArray();
modifierManager.noteShrinkerStrength = FightSabersGameplaySetup.instance.NoteShrinkerStrength;
modifierManager.colorSuckerStrength = FightSabersGameplaySetup.instance.ColorSuckerStrength;
modifierManager.timeWarperStrength = FightSabersGameplaySetup.instance.TimeWarperStrength;
new UnityTask(modifierManager.ConfigureModifiers(0.05f));
var scoreControllerManager = go.AddComponent<ScoreControllerManager>();
scoreControllerManager.BombCut += self => {
Expand Down
4 changes: 2 additions & 2 deletions FightSabers/FightSabers/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.2")]
[assembly: AssemblyFileVersion("0.3.2")]
[assembly: AssemblyVersion("0.3.1")]
[assembly: AssemblyFileVersion("0.3.1")]
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.Components;
using FightSabers.Models.Modifiers;

namespace FightSabers.UI.Controllers
{
class FightSabersGameplaySetup : PersistentSingleton<FightSabersGameplaySetup>
internal class FightSabersGameplaySetup : NotifiableSingleton<FightSabersGameplaySetup>
{
[UIValue("warning-hint-text")] private string _warningHintText = "<color=#e74c3c>You will not encounter any monsters if you enable one of these modifiers, and will also disable the score submission.</color>";
[UIValue("note-shrinker")] public bool NoteShrinkerEnabled;
[UIValue("note-shrinker-strength")] public float NoteShrinkerStrength = 1f;
private string _noteShrinkerHint = "If enabled, notes will be scaled at <color=#FFA500>x0.65</color> of their size.";
[UIValue("note-shrinker-hint")]
public string NoteShrinkerHint {
get { return _noteShrinkerHint; }
private set {
_noteShrinkerHint = value;
NotifyPropertyChanged();
}
}
[UIValue("color-sucker")] public bool ColorSuckerEnabled;
[UIValue("color-sucker-strength")] public float ColorSuckerStrength = 1f;
private string _colorSuckerHint = "If enabled, notes will restore <color=#FFA500>2.56%</color> of their color when cut.";
[UIValue("color-sucker-hint")]
public string ColorSuckerHint {
get { return _colorSuckerHint; }
private set {
_colorSuckerHint = value;
NotifyPropertyChanged();
}
}
[UIValue("time-warper")] public bool TimeWarperEnabled;
[UIValue("time-warper-strength")] public float TimeWarperStrength = 1f;
private string _timeWarperHint = "If enabled, the song will be speed up by <color=#FFA500>x1.2</color>.";
[UIValue("time-warper-hint")] public string TimeWarperHint
{
get { return _timeWarperHint; }
private set
{
_timeWarperHint = value;
NotifyPropertyChanged();
}
}

[UIAction("update-ns-hint-act")]
public void UpdateNoteShrinkerHint(float value)
{
NoteShrinkerHint = $"If enabled, notes will be scaled at <color=#FFA500>x{NoteShrinker.BaseScaleApplied.x * (1 / NoteShrinkerStrength):F}</color> of their size.";
}

[UIAction("update-cs-hint-act")]
public void UpdateColorSuckerHint(float value)
{
ColorSuckerHint = $"If enabled, notes will restore <color=#FFA500>{(float)(0.8 / (35 * ColorSuckerStrength * 0.85) * 100):F}%</color> of their color when cut.";
}

[UIAction("update-tw-hint-act")]
public void UpdateTimeWarperHint(float value)
{
TimeWarperHint = $"If enabled, the song will be speed up by <color=#FFA500>x{1 + 0.2 * TimeWarperStrength:F}</color>.";
}
}
}
18 changes: 13 additions & 5 deletions FightSabers/FightSabers/UI/Views/FightSabersGameplaySetupView.bsml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<bg xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'>
<modifier-container>
<modifier source='#BatteryIcon' text='Note Shrinker' value='note-shrinker' apply-on-change='true'></modifier>
<modifier source='#NoBombsIcon' text='Color Sucker' value='color-sucker' apply-on-change='true'></modifier>
<modifier source='#FasterSongIcon' text='Time Warper' value='time-warper' apply-on-change='true'></modifier>
</modifier-container>
<horizontal horizontal-fit='PreferredSize'>
<modifier-container pref-width='65'>
<modifier source='#GameNoteIcon' text='Note Shrinker' value='note-shrinker' apply-on-change='true' hover-hint='~warning-hint-text'/>
<increment-setting text='Strength' font-size='4' value='note-shrinker-strength' min='0.7' max='130' increment='0.05' apply-on-change='true'
hover-hint='~note-shrinker-hint' on-change='update-ns-hint-act'/>
<modifier source='#LightIcon' text='Color Sucker' value='color-sucker' apply-on-change='true' hover-hint='~warning-hint-text'/>
<increment-setting text='Strength' font-size='4' value='color-sucker-strength' min='0.05' increment='0.05' apply-on-change='true'
hover-hint='~color-sucker-hint' on-change='update-cs-hint-act'/>
<modifier source='#FasterSongIcon' text='Time Warper' value='time-warper' apply-on-change='true' hover-hint='~warning-hint-text'/>
<increment-setting text='Strength' font-size='4' value='time-warper-strength' min='0.05' increment='0.05' apply-on-change='true'
hover-hint='~time-warper-hint' on-change='update-tw-hint-act'/>
</modifier-container>
</horizontal>
</bg>
2 changes: 1 addition & 1 deletion FightSabers/FightSabers/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"gameVersion": "1.6.2",
"id": "FightSabers",
"name": "FightSabers",
"version": "0.3.2",
"version": "0.3.1",
"dependsOn": {
"BeatSaberMarkupLanguage": "^1.1.3",
"BS Utils": "^1.4.1"
Expand Down

0 comments on commit fb34be7

Please sign in to comment.