using Naninovel;
using Naninovel.Commands;
using UniRx.Async;
[InitializeAtRuntime]
public class ChangeNextRevealSpeedService : IStatefulService<GameStateMap>
{
[System.Serializable]
class GameState { public float Modifier; }
public float NextRevealSpeedMofifier { get; set; }
public UniTask InitializeServiceAsync () => UniTask.CompletedTask;
public void ResetService () => NextRevealSpeedMofifier = 1;
public void DestroyService () { }
public void SaveServiceState (GameStateMap stateMap)
{
var state = new GameState() { Modifier = NextRevealSpeedMofifier };
stateMap.SetState(state);
}
public UniTask LoadServiceStateAsync (GameStateMap stateMap)
{
NextRevealSpeedMofifier = stateMap.GetState<GameState>()?.Modifier ?? 1;
return UniTask.CompletedTask;
}
}
[CommandAlias("s")]
public class ChangeNextRevealSpeedCommand : Command
{
[ParameterAlias(NamelessParameterAlias), RequiredParameter]
public DecimalParameter Modifier;
public override UniTask ExecuteAsync (CancellationToken cancellationToken = default)
{
Engine.GetService<ChangeNextRevealSpeedService>().NextRevealSpeedMofifier = Modifier;
return UniTask.CompletedTask;
}
}
[CommandAlias("print")]
public class MyCustomPrintCommand : PrintText
{
protected override float AssignedRevealSpeed => base.AssignedRevealSpeed *
Engine.GetService<ChangeNextRevealSpeedService>().NextRevealSpeedMofifier;
public override async UniTask ExecuteAsync (CancellationToken cancellationToken = default)
{
await base.ExecuteAsync(cancellationToken);
Engine.GetService<ChangeNextRevealSpeedService>().NextRevealSpeedMofifier = 1f;
}
}
Then re-import any existing naninovel script assets (right-click over a folder they're stored at, then click "Reimport") in order for the changes to take effect.
Cool command, thanks for sharing! This is also a nice example on how to serialize gamestates. I've only used them by inheriting CustomUI but this makes it very clear if a more independent solution is needed.
Main question (because its drivin me crazy), is there a way to have the vscode extension not read this as an error?
Secondly, will this ever be fully implemented into NN outside of print? I'd love to just have native support of a crucial feature like this I did use the 1.17 update posted a few months ago