pooled events

This commit is contained in:
Yoshman29
2023-01-09 16:51:14 +01:00
parent e0c2a9da7a
commit 6060032235
35 changed files with 207 additions and 222 deletions
+22
View File
@@ -0,0 +1,22 @@
package funkin.scripting;
import funkin.scripting.events.*;
class EventManager {
// map doesnt work for that
public static var eventValues:Array<CancellableEvent> = [];
public static var eventKeys:Array<Class<CancellableEvent>> = [];
public static function get<T:CancellableEvent>(cl:Class<T>):T {
var c:Class<CancellableEvent> = cast cl;
var index = eventKeys.indexOf(c);
if (index < 0) {
eventKeys.push(c);
eventValues.push(Type.createInstance(c, []));
return cast eventValues.last();
}
return cast eventValues[index];
}
}
@@ -30,13 +30,4 @@ class CamMoveEvent extends CancellableEvent {
* Whenever the camera focuses BF more than dad.
*/
public var focusBF:Bool = false;
public function new(bfCamPos:FlxPoint, dadCamPos:FlxPoint, ratio:Float, position:FlxPoint) {
super();
this.bfCamPos = bfCamPos;
this.dadCamPos = dadCamPos;
this.ratio = ratio;
this.position = position;
this.focusBF = ratio >= 0.5;
}
}
@@ -3,6 +3,7 @@ package funkin.scripting.events;
import funkin.scripting.ScriptPack;
@:allow(ScriptPack)
@:autoBuild(funkin.macros.EventMacro.build())
class CancellableEvent {
@:dox(hide) public var cancelled:Bool = false;
@:dox(hide) private var __continueCalls:Bool = true;
@@ -30,6 +31,12 @@ class CancellableEvent {
*/
public function new() {}
public function recycleBase() {
data = {};
cancelled = false;
__continueCalls = true;
}
/**
* Returns a string representation of the event, in this format:
* `[CancellableEvent]`
@@ -43,14 +43,4 @@ class CountdownEvent extends CancellableEvent {
* Created sound, only available in `onPostCountdown`
*/
public var sound:FlxSound;
public function new(swagCounter:Int, spritePath:String, soundPath:String, scale:Float = 1, volume:Float = 1, antialiasing:Bool = true) {
super();
this.swagCounter = swagCounter;
this.volume = volume;
this.soundPath = soundPath;
this.spritePath = spritePath;
this.scale = scale;
this.antialiasing = antialiasing;
}
}
@@ -2,8 +2,4 @@ package funkin.scripting.events;
class DanceEvent extends CancellableEvent {
public var danced:Bool;
public function new(danced:Bool = false) {
super();
this.danced = danced;
}
}
@@ -15,10 +15,6 @@ class DirectionAnimEvent extends CancellableEvent {
The suffix of the animation (ex: "-alt") - Defaults to ""
**/
public var suffix:String;
/**
Whenever the animation will play reversed or not.
**/
public var reversed:Bool;
/**
Context of the animation. Is either equal to `SING` or `MISS`.
**/
@@ -26,20 +22,13 @@ class DirectionAnimEvent extends CancellableEvent {
/**
Whenever the animation will play reversed or not.
**/
public var force:Bool;
public var reversed:Bool;
/**
At what frame the animation will start playing
**/
public var frame:Int;
public function new(animName:String, direction:Int, suffix:String = "", context:PlayAnimContext = SING, reversed:Bool = false, frame:Int = 0) {
super();
this.animName = animName;
this.direction = direction;
this.suffix = suffix;
this.context = context;
this.reversed = reversed;
this.force = true;
this.frame = frame;
}
/**
Whenever the animation will play reversed or not.
**/
public var force:Bool = true;
}
@@ -18,11 +18,4 @@ class InputSystemEvent extends CancellableEvent {
* 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;
}
}
@@ -1,16 +1,16 @@
package funkin.scripting.events;
class MenuChangeEvent extends CancellableEvent {
/**
* Value after the change
*/
public var value:Int;
/**
* Value before the change
*/
public var oldValue:Int;
/**
* Value after the change
*/
public var value:Int;
/**
* Amount of change
*/
@@ -20,12 +20,4 @@ class MenuChangeEvent extends CancellableEvent {
* Whenever the menu SFX should be played.
*/
public var playMenuSFX:Bool = true;
public function new(oldValue:Int, value:Int, change:Int, playMenuSFX:Bool = true) {
super();
this.value = value;
this.oldValue = value;
this.change = change;
this.playMenuSFX = playMenuSFX;
}
}
@@ -5,9 +5,4 @@ class NameEvent extends CancellableEvent {
* Name
*/
public var name:String;
public function new(name:String) {
super();
this.name = name;
}
}
@@ -42,24 +42,4 @@ class NoteCreationEvent extends CancellableEvent {
* Sing animation suffix. "-alt" for alt anim or "" for normal notes.
*/
public var animSuffix:String;
/**
* [Description] Creates a new NoteCreationEvent
* @param note
* @param strumID
* @param noteType
* @param noteTypeID
* @param mustHit
*/
public function new(note:Note, strumID:Int, noteType:String, noteTypeID:Int, mustHit:Bool, noteSprite:String, noteScale:Float, animSuffix:String) {
super();
this.note = note;
this.strumID = strumID;
this.noteType = noteType;
this.noteTypeID = noteTypeID;
this.mustHit = mustHit;
this.noteSprite = noteSprite;
this.noteScale = noteScale;
this.animSuffix = animSuffix;
}
}
+6 -31
View File
@@ -75,14 +75,6 @@ class NoteHitEvent extends CancellableEvent {
* Rating name. Defaults to "sick", "good", "bad" and "shit". Customisable.
*/
public var rating:String = "sick";
/**
* Scale of ratings.
*/
public var ratingScale:Float = 0.7;
/**
* Whenever antialiasing should be enabled on ratings.
*/
public var ratingAntialiasing:Bool = true;
/**
* Scale of combo numbers.
*/
@@ -91,31 +83,14 @@ class NoteHitEvent extends CancellableEvent {
* Whenever antialiasing should be enabled on combo number.
*/
public var numAntialiasing:Bool = true;
/**
* Creates a new NoteHitEvent.
* Scale of ratings.
*/
public function new(note:Note, characters:Array<Character>, player:Bool, noteType:String,
direction:Int, healthGain:Float, unmuteVocals:Bool = true, score:Int = 350,
animSuffix:String = "", rating:String = "sick", ?accuracy:Null<Float>, ratingPrefix:String = "",
ratingSuffix:String = "") {
super();
this.note = note;
this.characters = characters;
this.player = player;
this.noteType = noteType;
this.direction = direction;
this.healthGain = healthGain;
this.unmuteVocals = unmuteVocals;
this.score = score;
this.animSuffix = animSuffix;
this.countAsCombo = !note.isSustainNote && note.mustPress;
this.rating = rating;
this.accuracy = accuracy;
this.ratingPrefix = ratingPrefix;
this.ratingSuffix = ratingSuffix;
}
public var ratingScale:Float = 0.7;
/**
* Whenever antialiasing should be enabled on ratings.
*/
public var ratingAntialiasing:Bool = true;
/**
* Prevents the default sing animation from being played.
@@ -22,13 +22,6 @@ class NoteUpdateEvent extends CancellableEvent {
*/
public var strum:Strum;
public function new(note:Note, elapsed:Float, strum:Strum) {
super();
this.note = note;
this.elapsed = elapsed;
this.strum = strum;
}
/**
* Cancels the hit window update.
*/
@@ -13,11 +13,4 @@ class PauseCreationEvent extends CancellableEvent {
* All option names
*/
public var options:Array<String>;
public function new(music:String, options:Array<String>) {
super();
this.music = music;
this.options = options;
}
}
@@ -25,15 +25,6 @@ class PlayAnimEvent extends CancellableEvent {
Context of the animation
**/
public var context:PlayAnimContext;
public function new(animName:String, force:Bool, reverse:Bool, startingFrame:Int, context:PlayAnimContext) {
super();
this.animName = animName;
this.force = force;
this.reverse = reverse;
this.startingFrame = startingFrame;
this.context = context;
}
}
/**
@@ -9,9 +9,4 @@ class PointEvent extends CancellableEvent {
Y position
**/
public var y:Float;
public function new(x:Float, y:Float) {
super();
this.x = x;
this.y = y;
}
}
@@ -10,9 +10,4 @@ class RatingUpdateEvent extends CancellableEvent {
**/
public var oldRating:ComboRating;
public function new(rating:ComboRating, oldRating:ComboRating) {
super();
this.rating = rating;
this.oldRating = oldRating;
}
}
@@ -19,11 +19,4 @@ class ResizeEvent extends CancellableEvent {
* Old height (may be null)
*/
public var oldHeight:Null<Int>;
public function new(width:Int, height:Int, ?oldWidth:Int, ?oldHeight:Int) {
super();
this.width = width;
this.height = height;
this.oldWidth = oldWidth;
this.oldHeight = oldHeight;
}
}
@@ -7,9 +7,4 @@ class SimpleNoteEvent extends CancellableEvent {
Note that is affected.
**/
public var note:Note;
public function new(note:Note) {
super();
this.note = note;
}
}
@@ -7,9 +7,4 @@ class StateEvent extends CancellableEvent {
* Substate that is about to be opened/closed
*/
public var substate:FlxState;
public function new(substate:FlxState) {
super();
this.substate = substate;
}
}
@@ -3,7 +3,7 @@ package funkin.scripting.events;
import funkin.game.Strum;
class StrumCreationEvent extends CancellableEvent {
@:dox(hide) public var __doAnimation = !PlayState.isStoryMode;
@:dox(hide) public var __doAnimation = true;
/**
@@ -11,7 +11,7 @@ class StrumCreationEvent extends CancellableEvent {
*/
public var strum:Strum;
/**
/**s
* Player ID
*/
public var player:Int;
@@ -26,13 +26,6 @@ class StrumCreationEvent extends CancellableEvent {
*/
public var sprite:String = "game/NOTE_assets";
public function new(strum:Strum, player:Int, strumID:Int) {
super();
this.strum = strum;
this.player = player;
this.strumID = strumID;
}
/**
* Cancels the animation that makes the strum "land" in the strumline.
*/
@@ -22,13 +22,4 @@ class WeekSelectEvent extends CancellableEvent {
* At which emplacement the difficulty is. Goes from 0 to the number of weeks - 1.
*/
public var difficultyID:Int;
public override function new(week:WeekData, difficulty:String, weekID:Int, difficultyID:Int) {
super();
this.week = week;
this.difficulty = difficulty;
this.weekID = weekID;
this.difficultyID = difficultyID;
}
}