documentation
This commit is contained in:
@@ -1267,8 +1267,12 @@ class PlayState extends MusicBeatState
|
||||
var justPressed = [controls.LEFT_P, controls.DOWN_P, controls.UP_P, controls.RIGHT_P];
|
||||
var justReleased = [controls.LEFT_R, controls.DOWN_R, controls.UP_R, controls.RIGHT_R];
|
||||
|
||||
// TODO: Events like param:OnKeyEvent for better compatibility
|
||||
scripts.call("onKeyShit", [pressed, justPressed, justReleased]);
|
||||
var event = scripts.event("onKeyShit", new InputSystemEvent([controls.LEFT, controls.DOWN, controls.UP, controls.RIGHT], [controls.LEFT_P, controls.DOWN_P, controls.UP_P, controls.RIGHT_P], [controls.LEFT_R, controls.DOWN_R, controls.UP_R, controls.RIGHT_R]));
|
||||
if (event.cancelled) return;
|
||||
justReleased = CoolUtil.getDefault(event.pressed, []);
|
||||
justReleased = CoolUtil.getDefault(event.justPressed, []);
|
||||
justReleased = CoolUtil.getDefault(event.justReleased, []);
|
||||
|
||||
var funcsToExec:Array<Note->Void> = [];
|
||||
if (pressed.contains(true)) {
|
||||
funcsToExec.push(function(note:Note) {
|
||||
|
||||
@@ -130,7 +130,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
* Calls the function `func` defined in the script.
|
||||
* @param func Name of the function
|
||||
* @param parameters (Optional) Parameters of the function.
|
||||
* @return Dynamic Result (if void, then null)
|
||||
* @return Result (if void, then null)
|
||||
*/
|
||||
public function call(func:String, ?parameters:Array<Dynamic>):Dynamic {
|
||||
var oldScript = curScript;
|
||||
@@ -151,14 +151,14 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
/**
|
||||
* Gets the variable `variable` from the script's variables.
|
||||
* @param variable Name of the variable.
|
||||
* @return Dynamic Variable (or null if it doesn't exists)
|
||||
* @return Variable (or null if it doesn't exists)
|
||||
*/
|
||||
public function get(variable:String):Dynamic {return null;}
|
||||
|
||||
/**
|
||||
* Gets the variable `variable` from the script's variables.
|
||||
* @param variable Name of the variable.
|
||||
* @return Dynamic Variable (or null if it doesn't exists)
|
||||
* @return Variable (or null if it doesn't exists)
|
||||
*/
|
||||
public function set(variable:String, value:Dynamic):Void {}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class ScriptPack extends Script {
|
||||
* Sends an event to every single script, and returns the event.
|
||||
* @param func Function to call
|
||||
* @param event Event (will be the first parameter of the function)
|
||||
* @return Event (modified by scripts)
|
||||
* @return (modified by scripts)
|
||||
*/
|
||||
public function event<T:CancellableEvent>(func:String, event:T):T {
|
||||
for(e in scripts) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package funkin.scripting.events;
|
||||
|
||||
class InputSystemEvent extends CancellableEvent {
|
||||
/**
|
||||
* Array containing whenever a specific control is pressed or not.
|
||||
* For example, `pressed[0]` will return whenever the left strum was pressed.
|
||||
*/
|
||||
public var pressed:Array<Bool>;
|
||||
|
||||
/**
|
||||
* Array containing whenever a specific control was pressed (not hold) this frame or not.
|
||||
* For example, `justPressed[0]` will return whenever the left strum was just pressed.
|
||||
*/
|
||||
public var justPressed:Array<Bool>;
|
||||
|
||||
/**
|
||||
* Array containing whenever a specific control was released this frame or not.
|
||||
* For example, `justReleased[0]` will return whenever the left strum was just released.
|
||||
*/
|
||||
public var justReleased:Array<Bool>;
|
||||
|
||||
public function new(pressed:Array<Bool>, justPressed:Array<Bool>, justReleased:Array<Bool>) {
|
||||
super();
|
||||
this.pressed = pressed;
|
||||
this.justPressed = justPressed;
|
||||
this.justReleased = justReleased;
|
||||
}
|
||||
}
|
||||
@@ -16,22 +16,44 @@ typedef BPMChangeEvent =
|
||||
|
||||
class Conductor
|
||||
{
|
||||
/**
|
||||
* Current BPM
|
||||
*/
|
||||
public static var bpm:Int = 100;
|
||||
|
||||
/**
|
||||
* Current Crochet (time per beat), in milliseconds.
|
||||
*/
|
||||
public static var crochet:Float = ((60 / bpm) * 1000); // beats in milliseconds
|
||||
|
||||
/**
|
||||
* Current StepCrochet (time per step), in milliseconds.
|
||||
*/
|
||||
public static var stepCrochet:Float = crochet / 4; // steps in milliseconds
|
||||
|
||||
|
||||
/**
|
||||
* Current position of the song, in milliseconds.
|
||||
*/
|
||||
public static var songPosition:Float;
|
||||
public static var lastSongPos:Float;
|
||||
public static var offset:Float = 0;
|
||||
|
||||
@:dox(hide) public static var lastSongPos:Float;
|
||||
@:dox(hide) public static var offset:Float = 0;
|
||||
|
||||
public static var safeFrames:Int = 10;
|
||||
public static var safeZoneOffset:Float = (safeFrames / 60) * 1000; // is calculated in create(), is safeFrames in milliseconds
|
||||
@:dox(hide) public static var safeFrames:Int = 10;
|
||||
@:dox(hide) public static var safeZoneOffset:Float = (safeFrames / 60) * 1000; // is calculated in create(), is safeFrames in milliseconds
|
||||
|
||||
/**
|
||||
* Array of all BPM changes that have been mapped.
|
||||
*/
|
||||
public static var bpmChangeMap:Array<BPMChangeEvent> = [];
|
||||
|
||||
public function new()
|
||||
{
|
||||
}
|
||||
@:dox(hide) public function new() {}
|
||||
|
||||
/**
|
||||
* Maps BPM changes from a song.
|
||||
* @param song Song to map BPM changes from.
|
||||
*/
|
||||
public static function mapBPMChanges(song:SwagSong)
|
||||
{
|
||||
bpmChangeMap = [];
|
||||
|
||||
@@ -16,7 +16,7 @@ class CoolUtil
|
||||
* Returns `v` if not null, `defaultValue` otherwise.
|
||||
* @param v The value
|
||||
* @param defaultValue The default value
|
||||
* @return T The return value
|
||||
* @return The return value
|
||||
*/
|
||||
public static function getDefault<T>(v:T, defaultValue:T):T {
|
||||
return v == null ? defaultValue : v;
|
||||
@@ -72,15 +72,15 @@ class CoolUtil
|
||||
/**
|
||||
* Modifies a lerp ratio based on current FPS to keep a stable speed on higher framerate.
|
||||
* @param ratio Ratio
|
||||
* @return Float FPS-Modified Ratio
|
||||
* @return FPS-Modified Ratio
|
||||
*/
|
||||
public static function getFPSRatio(ratio:Float) {
|
||||
public static function getFPSRatio(ratio:Float):Float {
|
||||
return FlxMath.bound(ratio * 60 * FlxG.elapsed, 0, 1);
|
||||
}
|
||||
/**
|
||||
* Tries to get a color from a `Dynamic` variable.
|
||||
* @param c `Dynamic` color.
|
||||
* @return Null<FlxColor> The result color
|
||||
* @return The result color, or `null` if invalid.
|
||||
*/
|
||||
public static function getColorFromDynamic(c:Dynamic):Null<FlxColor> {
|
||||
// -1
|
||||
|
||||
@@ -15,11 +15,31 @@ class MusicBeatState extends FlxUIState
|
||||
private var lastBeat:Float = 0;
|
||||
private var lastStep:Float = 0;
|
||||
|
||||
private var curStep:Int = 0;
|
||||
private var curBeat:Int = 0;
|
||||
private var curStepFloat:Float = 0;
|
||||
private var curBeatFloat:Float = 0;
|
||||
private var controls(get, never):Controls;
|
||||
/**
|
||||
* Current step
|
||||
*/
|
||||
public var curStep:Int = 0;
|
||||
|
||||
/**
|
||||
* Current beat
|
||||
*/
|
||||
public var curBeat:Int = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Current step, as a `Float` (ex: 4.94, instead of 4)
|
||||
*/
|
||||
public var curStepFloat:Float = 0;
|
||||
|
||||
/**
|
||||
* Current beat, as a `Float` (ex: 1.24, instead of 1)
|
||||
*/
|
||||
public var curBeatFloat:Float = 0;
|
||||
|
||||
/**
|
||||
* Game Controls.
|
||||
*/
|
||||
public var controls(get, never):Controls;
|
||||
|
||||
inline function get_controls():Controls
|
||||
return PlayerSettings.player1.controls;
|
||||
@@ -67,7 +87,7 @@ class MusicBeatState extends FlxUIState
|
||||
curStep = Math.floor(curStepFloat = lastChange.stepTime + ((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet));
|
||||
}
|
||||
|
||||
public function stepHit():Void
|
||||
@:dox(hide) public function stepHit():Void
|
||||
{
|
||||
for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep);
|
||||
|
||||
@@ -75,11 +95,18 @@ class MusicBeatState extends FlxUIState
|
||||
beatHit();
|
||||
}
|
||||
|
||||
public function beatHit():Void
|
||||
@:dox(hide) public function beatHit():Void
|
||||
{
|
||||
for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to `FlxMath.lerp` or `CoolUtil.lerp`, depending on `fpsSensitive`
|
||||
* @param v1 Value 1
|
||||
* @param v2 Value 2
|
||||
* @param ratio Ratio
|
||||
* @param fpsSensitive Whenever the ratio should not be adjusted to run at the same speed independant of framerate.
|
||||
*/
|
||||
public function lerp(v1:Float, v2:Float, ratio:Float, fpsSensitive:Bool = false) {
|
||||
if (fpsSensitive)
|
||||
return FlxMath.lerp(v1, v2, ratio);
|
||||
|
||||
@@ -16,9 +16,26 @@ class MusicBeatSubstate extends FlxSubState
|
||||
private var lastBeat:Float = 0;
|
||||
private var lastStep:Float = 0;
|
||||
|
||||
private var curStep:Int = 0;
|
||||
private var curBeat:Int = 0;
|
||||
private var controls(get, never):Controls;
|
||||
/**
|
||||
* Current step
|
||||
*/
|
||||
public var curStep:Int = 0;
|
||||
/**
|
||||
* Current beat
|
||||
*/
|
||||
public var curBeat:Int = 0;
|
||||
/**
|
||||
* Current step, as a `Float` (ex: 4.94, instead of 4)
|
||||
*/
|
||||
public var curStepFloat:Float = 0;
|
||||
/**
|
||||
* Current beat, as a `Float` (ex: 1.24, instead of 1)
|
||||
*/
|
||||
public var curBeatFloat:Float = 0;
|
||||
/**
|
||||
* Game Controls.
|
||||
*/
|
||||
public var controls(get, never):Controls;
|
||||
|
||||
inline function get_controls():Controls
|
||||
return PlayerSettings.player1.controls;
|
||||
@@ -54,17 +71,24 @@ class MusicBeatSubstate extends FlxSubState
|
||||
curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet);
|
||||
}
|
||||
|
||||
public function stepHit():Void
|
||||
@:dox(hide) public function stepHit():Void
|
||||
{
|
||||
if (curStep % 4 == 0)
|
||||
beatHit();
|
||||
}
|
||||
|
||||
public function beatHit():Void
|
||||
@:dox(hide) public function beatHit():Void
|
||||
{
|
||||
//do literally nothing dumbass
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut to `FlxMath.lerp` or `CoolUtil.lerp`, depending on `fpsSensitive`
|
||||
* @param v1 Value 1
|
||||
* @param v2 Value 2
|
||||
* @param ratio Ratio
|
||||
* @param fpsSensitive Whenever the ratio should not be adjusted to run at the same speed independant of framerate.
|
||||
*/
|
||||
public function lerp(v1:Float, v2:Float, ratio:Float, fpsSensitive:Bool = false) {
|
||||
if (fpsSensitive)
|
||||
return FlxMath.lerp(v1, v2, ratio);
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package scripting;
|
||||
|
||||
import funkin.scripting.events.*;
|
||||
|
||||
/**
|
||||
* Contains all callbacks you can add in modcharts and stage scripts.
|
||||
*
|
||||
* NOTE: In case you're scripting a stage, all sprites of that stage are directly accessible via their name.
|
||||
* Ex: If you added a `superCoolBG` element in your stage XML, you'll be able to access it via scripts by using `superCoolBG`.
|
||||
*/
|
||||
interface PlayStateScript {
|
||||
/**
|
||||
* Triggered after the characters has been created, during PlayState's creation.
|
||||
*/
|
||||
public function create():Void;
|
||||
|
||||
/**
|
||||
* Triggered at the very end of PlayState's creation
|
||||
*/
|
||||
public function createPost():Void;
|
||||
|
||||
/**
|
||||
* Triggered every frame.
|
||||
* @param elapsed Time elapsed since last frame.
|
||||
*/
|
||||
public function update(elapsed:Float):Void;
|
||||
|
||||
/**
|
||||
* Triggered at the end of every frame.
|
||||
* @param elapsed Time elapsed since last frame.
|
||||
*/
|
||||
public function updatePost(elapsed:Float):Void;
|
||||
|
||||
/**
|
||||
* Triggered every step
|
||||
* @param curStep Current step.
|
||||
*/
|
||||
public function stepHit(curStep:Int):Void;
|
||||
|
||||
/**
|
||||
* Triggered every beat.
|
||||
* @param curBeat Current beat.
|
||||
*/
|
||||
public function beatHit(curBeat:Int):Void;
|
||||
|
||||
/**
|
||||
* Triggered whenever the player hits a note.
|
||||
* @param note Event object with the note being pressed, the character who pressed it, and functions to alter or cancel the default behaviour.
|
||||
*/
|
||||
public function onPlayerHit(note:NoteHitEvent):Void;
|
||||
|
||||
/**
|
||||
* Triggered whenever the opponent hits a note.
|
||||
* @param note Event object with the note being pressed, the character who pressed it, and functions to alter or cancel the default behaviour.
|
||||
*/
|
||||
public function onDadHit(note:NoteHitEvent):Void;
|
||||
|
||||
/**
|
||||
* Triggered whenever the input system updates.
|
||||
* @param note Event object with the pressed notes, which allows you to alter which notes are being pressed during this frame, or simply cancel the input update.
|
||||
*/
|
||||
public function inputUpdate(note:InputSystemEvent):Void;
|
||||
|
||||
/**
|
||||
* Triggered after the input system updates.
|
||||
* @param note Event object with the pressed, justPressed and justReleased notes.
|
||||
*/
|
||||
public function inputUpdatePost(note:InputSystemEvent):Void;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
== THESE FILES ARE ONLY FOR THE DOCUMENTATION ==
|
||||
== THEYRE NOT USED NOR COMPILED BY THE GAME AND CAN BE SAFELY DELETED ==
|
||||
Reference in New Issue
Block a user