Skip to content

Commit

Permalink
Add lua api for setters
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamQiufeng committed Nov 5, 2024
1 parent 1f9bac3 commit efbab03
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Quaver.API/Maps/Structures/ScrollSpeedFactorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Text;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using YamlDotNet.Serialization;

namespace Quaver.API.Maps.Structures
{
Expand All @@ -23,6 +25,50 @@ public class ScrollSpeedFactorInfo : IStartTime
/// </summary>
public float Multiplier { get; [MoonSharpHidden] set; }

/// <summary>
/// Returns if the SSF is allowed to be edited in lua scripts
/// </summary>
[YamlIgnore]
public bool IsEditableInLuaScript
{
get;
[MoonSharpVisible(false)]
set;
}

/// <summary>
/// Sets the start time of the SSF.
/// FOR USE IN LUA SCRIPTS ONLY.
/// </summary>
/// <param name="time"></param>
/// <exception cref="InvalidOperationException"></exception>
public void SetStartTime(float time)
{
ThrowUneditableException();
StartTime = time;
}

/// <summary>
/// Sets the multiplier of the SSF.
/// FOR USE IN LUA SCRIPTS ONLY.
/// </summary>
/// <param name="multiplier"></param>
/// <exception cref="InvalidOperationException"></exception>
public void SetMultiplier(float multiplier)
{
ThrowUneditableException();
Multiplier = multiplier;
}

/// <summary>
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
private void ThrowUneditableException()
{
if (!IsEditableInLuaScript)
throw new InvalidOperationException("Value is not allowed to be edited in lua scripts.");
}

private sealed class StartTimeRelationalComparer : IComparer<ScrollSpeedFactorInfo>
{
public int Compare(ScrollSpeedFactorInfo x, ScrollSpeedFactorInfo y)
Expand Down

0 comments on commit efbab03

Please sign in to comment.