events but cooler

This commit is contained in:
Yoshman29
2022-10-10 13:31:55 +02:00
parent 8091f5463a
commit 50976d770b
11 changed files with 135 additions and 87 deletions
+10
View File
@@ -0,0 +1,10 @@
import funkin.system.Conductor;
import flixel.tweens.FlxTween;
import funkin.scripting.events.NoteHitEvent;
function onPlayerHit(event:NoteHitEvent) {
if (event.note.isSustainNote) return;
event.preventDeletion();
FlxTween.tween(event.note, {strumTime: event.note.strumTime + (Conductor.crochet * 2)}, Conductor.crochet / 500, {ease: FlxEase.cubeOut});
event.note.wasGoodHit = false;
}
+1 -1
View File
@@ -1 +1 @@
300
306
+9 -3
View File
@@ -25029,9 +25029,9 @@
<c path="cpp.RawConstPointer"><c path="discord_rpc.JoinRequest"/></c>
<x path="Void"/>
</f></_onRequest>
<__touch get="inline" set="null" expr="&quot;1.665394232e+012&quot;" line="22" static="1">
<__touch get="inline" set="null" expr="&quot;1.665397787e+012&quot;" line="22" static="1">
<c path="String"/>
<meta><m n=":value"><e>"1.665394232e+012"</e></m></meta>
<meta><m n=":value"><e>"1.665397787e+012"</e></m></meta>
</__touch>
<meta>
<m n=":directlyUsed"/>
@@ -80736,7 +80736,13 @@
<m n=":dox"><e>hide</e></m>
</meta>
</cancel>
<toString public="1" set="method" line="33"><f a=""><c path="String"/></f></toString>
<toString public="1" set="method" line="39">
<f a=""><c path="String"/></f>
<haxe_doc>* Returns a string representation of the event, in this format:
* `[CancellableEvent]`
* `[CancellableEvent (Cancelled)]`
* @return String</haxe_doc>
</toString>
<new public="1" set="method" line="31">
<f a=""><x path="Void"/></f>
<haxe_doc>* Creates a new cancellable event.
@@ -8,4 +8,6 @@
text-shadow: 0 0 0 transparent;
}
</style><nav class="nav"><div class="navbar"><div class="navbar-inner" style="background:#FAFAFA; border-bottom:1px solid rgba(0,0,0,.09)"><div class="container"><a class="brand" style="color:#000000" href="../../../">API Documentation</a><a href="#" id="theme-toggle" class="brand" style="color:#000000" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa fa-moon-o"></i></a></div></div></div></nav><div class="container main-content"><div class="row-fluid"><div class="span3"><div class="well sidebar-nav"><form class="form-search" id="searchForm"><div class="input-prepend input-block-level"><span class="add-on"><i class="fa fa-search"></i></span><input id="search" type="text" placeholder="Filter (Ctrl+P)" autocomplete="off"/></div></form></div><div class="well sidebar-nav" id="explorer"><div id="nav"></div></div></div><div class="span9"><div class="page-header"><h1><small>class</small> CancellableEvent</h1><h4><small>package <a href="../../../funkin/scripting/events/index.html">funkin.scripting.events</a></small></h4> <h4><small><span class="muted">extended by </span><a class="type" title="funkin.scripting.events.InputSystemEvent" href="../../../funkin/scripting/events/InputSystemEvent.html">InputSystemEvent</a>, <a class="type" title="funkin.scripting.events.NoteHitEvent" href="../../../funkin/scripting/events/NoteHitEvent.html">NoteHitEvent</a></small></h4><span class="label label-meta label-meta-allow" title="Allows private access from package, type or field.">@:allow(ScriptPack)</span></div><div class="body"><div class="doc doc-main"><p></p></div><h3 class="section">Constructor</h3><div class="fields"><div class="field "><a name="new"></a><h3 class="anchor"><code><a href="#new"><span class="identifier">new</span></a>()</code></h3><div class="doc"><p>Creates a new cancellable event.
This allows scripts to call <code>cancel()</code> to cancel the event.</p></div></div></div><h3 class="section">Variables</h3><div class="fields"><div class="field "><a name="data"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ })</span><a href="#data"><span class="identifier">data</span></a>:<span class="type">Dynamic</span><span> = { }</span></code></h3><div class="doc"><p>Additional data if used in scripts</p></div></div></div><h3 class="section">Methods</h3><div class="fields"><div class="field "><a name="preventDefault"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ c : true })</span><a href="#preventDefault"><span class="identifier">preventDefault</span></a>(<span style="white-space:nowrap">c:<span class="type">Bool</span> = true</span>):<span class="type">Void</span></code></h3><div class="doc"><p>Prevents default action from occuring.</p><p class="javadoc">Parameters:</p><table class="table table-bordered params"><tr><th style="width:25%;"><code>c</code></th><td><p>Whenever the scripts following this one should be called or not. (Defaults to <code>true</code>)</p></td></tr></table></div></div><div class="field "><a name="toString"></a><h3 class="anchor"><code><a href="#toString"><span class="identifier">toString</span></a>():<span class="type">String</span></code></h3><div class="doc"><p></p></div></div></div></div></div></div></div><footer class="section site-footer" style="background:#FAFAFA"><div class="container"><div class="copyright"><p style="color:#000000">&copy; 2022 &nbsp;</p></div></div></footer><script src="../../..//highlighter.js"></script><link href="../../../highlighter.css" rel="stylesheet"/></body></html>
This allows scripts to call <code>cancel()</code> to cancel the event.</p></div></div></div><h3 class="section">Variables</h3><div class="fields"><div class="field "><a name="data"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ })</span><a href="#data"><span class="identifier">data</span></a>:<span class="type">Dynamic</span><span> = { }</span></code></h3><div class="doc"><p>Additional data if used in scripts</p></div></div></div><h3 class="section">Methods</h3><div class="fields"><div class="field "><a name="preventDefault"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ c : true })</span><a href="#preventDefault"><span class="identifier">preventDefault</span></a>(<span style="white-space:nowrap">c:<span class="type">Bool</span> = true</span>):<span class="type">Void</span></code></h3><div class="doc"><p>Prevents default action from occuring.</p><p class="javadoc">Parameters:</p><table class="table table-bordered params"><tr><th style="width:25%;"><code>c</code></th><td><p>Whenever the scripts following this one should be called or not. (Defaults to <code>true</code>)</p></td></tr></table></div></div><div class="field "><a name="toString"></a><h3 class="anchor"><code><a href="#toString"><span class="identifier">toString</span></a>():<span class="type">String</span></code></h3><div class="doc"><p>Returns a string representation of the event, in this format:
<code>[<a href="../../../funkin/scripting/events/CancellableEvent.html#CancellableEvent">CancellableEvent</a>]</code>
<code>[<a href="../../../funkin/scripting/events/CancellableEvent.html#CancellableEvent">CancellableEvent</a> (Cancelled)]</code></p><p class="javadoc">Returns:</p><div class="indent inline-content"><p>String</p></div></div></div></div></div></div></div></div><footer class="section site-footer" style="background:#FAFAFA"><div class="container"><div class="copyright"><p style="color:#000000">&copy; 2022 &nbsp;</p></div></div></footer><script src="../../..//highlighter.js"></script><link href="../../../highlighter.css" rel="stylesheet"/></body></html>
@@ -10,4 +10,6 @@
</style><nav class="nav"><div class="navbar"><div class="navbar-inner" style="background:#FAFAFA; border-bottom:1px solid rgba(0,0,0,.09)"><div class="container"><a class="brand" style="color:#000000" href="../../../">API Documentation</a><a href="#" id="theme-toggle" class="brand" style="color:#000000" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa fa-moon-o"></i></a></div></div></div></nav><div class="container main-content"><div class="row-fluid"><div class="span3"><div class="well sidebar-nav"><form class="form-search" id="searchForm"><div class="input-prepend input-block-level"><span class="add-on"><i class="fa fa-search"></i></span><input id="search" type="text" placeholder="Filter (Ctrl+P)" autocomplete="off"/></div></form></div><div class="well sidebar-nav" id="explorer"><div id="nav"></div></div></div><div class="span9"><div class="page-header"><h1><small>class</small> InputSystemEvent</h1><h4><small>package <a href="../../../funkin/scripting/events/index.html">funkin.scripting.events</a></small></h4><h4><small>extends <a class="type" title="funkin.scripting.events.CancellableEvent" href="../../../funkin/scripting/events/CancellableEvent.html">CancellableEvent</a></small></h4> <span class="label label-meta label-meta-directlyUsed" title="Marks types that are directly referenced by non-extern code.">@:directlyUsed</span></div><div class="body"><div class="doc doc-main"><p></p></div><h3 class="section">Constructor</h3><div class="fields"><div class="field "><a name="new"></a><h3 class="anchor"><code><a href="#new"><span class="identifier">new</span></a>(<span style="white-space:nowrap">pressed:<span class="type">Array</span>&lt;<span class="type">Bool</span>&gt;,</span> <span style="white-space:nowrap">justPressed:<span class="type">Array</span>&lt;<span class="type">Bool</span>&gt;,</span> <span style="white-space:nowrap">justReleased:<span class="type">Array</span>&lt;<span class="type">Bool</span>&gt;</span>)</code></h3><div class="doc"><p></p></div></div></div><h3 class="section">Variables</h3><div class="fields"><div class="field "><a name="justPressed"></a><h3 class="anchor"><code><a href="#justPressed"><span class="identifier">justPressed</span></a>:<span class="type">Array</span>&lt;<span class="type">Bool</span>&gt;</code></h3><div class="doc"><p>Array containing whenever a specific control was pressed (not hold) this frame or not.
For example, <code>justPressed[0]</code> will return whenever the left strum was just pressed.</p></div></div><div class="field "><a name="justReleased"></a><h3 class="anchor"><code><a href="#justReleased"><span class="identifier">justReleased</span></a>:<span class="type">Array</span>&lt;<span class="type">Bool</span>&gt;</code></h3><div class="doc"><p>Array containing whenever a specific control was released this frame or not.
For example, <code>justReleased[0]</code> will return whenever the left strum was just released.</p></div></div><div class="field "><a name="pressed"></a><h3 class="anchor"><code><a href="#pressed"><span class="identifier">pressed</span></a>:<span class="type">Array</span>&lt;<span class="type">Bool</span>&gt;</code></h3><div class="doc"><p>Array containing whenever a specific control is pressed or not.
For example, <code>pressed[0]</code> will return whenever the left strum was pressed.</p></div></div></div> <div class="inherited-fields well"><h3 class="section">Inherited Variables</h3><div class="fields"><h4><a href="#" class="expand-button"><i class="fa fa-arrow-circle-o-right"></i></a> Defined by <a class="type" title="funkin.scripting.events.CancellableEvent" href="../../../funkin/scripting/events/CancellableEvent.html">CancellableEvent</a></h4><div style="display:none"><div class="field "><a name="data"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ })</span><a href="#data"><span class="identifier">data</span></a>:<span class="type">Dynamic</span><span> = { }</span></code></h3><div class="doc"><p>Additional data if used in scripts</p></div></div></div></div><h3 class="section">Inherited Methods</h3><div class="fields"><h4><a href="#" class="expand-button"><i class="fa fa-arrow-circle-o-right"></i></a> Defined by <a class="type" title="funkin.scripting.events.CancellableEvent" href="../../../funkin/scripting/events/CancellableEvent.html">CancellableEvent</a></h4><div style="display:none"><div class="field "><a name="preventDefault"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ c : true })</span><a href="#preventDefault"><span class="identifier">preventDefault</span></a>(<span style="white-space:nowrap">c:<span class="type">Bool</span> = true</span>):<span class="type">Void</span></code></h3><div class="doc"><p>Prevents default action from occuring.</p><p class="javadoc">Parameters:</p><table class="table table-bordered params"><tr><th style="width:25%;"><code>c</code></th><td><p>Whenever the scripts following this one should be called or not. (Defaults to <code>true</code>)</p></td></tr></table></div></div><div class="field "><a name="toString"></a><h3 class="anchor"><code><a href="#toString"><span class="identifier">toString</span></a>():<span class="type">String</span></code></h3><div class="doc"><p></p></div></div></div></div></div></div></div></div></div><footer class="section site-footer" style="background:#FAFAFA"><div class="container"><div class="copyright"><p style="color:#000000">&copy; 2022 &nbsp;</p></div></div></footer><script src="../../..//highlighter.js"></script><link href="../../../highlighter.css" rel="stylesheet"/></body></html>
For example, <code>pressed[0]</code> will return whenever the left strum was pressed.</p></div></div></div> <div class="inherited-fields well"><h3 class="section">Inherited Variables</h3><div class="fields"><h4><a href="#" class="expand-button"><i class="fa fa-arrow-circle-o-right"></i></a> Defined by <a class="type" title="funkin.scripting.events.CancellableEvent" href="../../../funkin/scripting/events/CancellableEvent.html">CancellableEvent</a></h4><div style="display:none"><div class="field "><a name="data"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ })</span><a href="#data"><span class="identifier">data</span></a>:<span class="type">Dynamic</span><span> = { }</span></code></h3><div class="doc"><p>Additional data if used in scripts</p></div></div></div></div><h3 class="section">Inherited Methods</h3><div class="fields"><h4><a href="#" class="expand-button"><i class="fa fa-arrow-circle-o-right"></i></a> Defined by <a class="type" title="funkin.scripting.events.CancellableEvent" href="../../../funkin/scripting/events/CancellableEvent.html">CancellableEvent</a></h4><div style="display:none"><div class="field "><a name="preventDefault"></a><h3 class="anchor"><code><span class="label label-meta label-meta-value" title="Used to store default values for fields and function arguments.">@:value({ c : true })</span><a href="#preventDefault"><span class="identifier">preventDefault</span></a>(<span style="white-space:nowrap">c:<span class="type">Bool</span> = true</span>):<span class="type">Void</span></code></h3><div class="doc"><p>Prevents default action from occuring.</p><p class="javadoc">Parameters:</p><table class="table table-bordered params"><tr><th style="width:25%;"><code>c</code></th><td><p>Whenever the scripts following this one should be called or not. (Defaults to <code>true</code>)</p></td></tr></table></div></div><div class="field "><a name="toString"></a><h3 class="anchor"><code><a href="#toString"><span class="identifier">toString</span></a>():<span class="type">String</span></code></h3><div class="doc"><p>Returns a string representation of the event, in this format:
<code>[<a href="../../../funkin/scripting/events/CancellableEvent.html#CancellableEvent">CancellableEvent</a>]</code>
<code>[<a href="../../../funkin/scripting/events/CancellableEvent.html#CancellableEvent">CancellableEvent</a> (Cancelled)]</code></p><p class="javadoc">Returns:</p><div class="indent inline-content"><p>String</p></div></div></div></div></div></div></div></div></div></div><footer class="section site-footer" style="background:#FAFAFA"><div class="container"><div class="copyright"><p style="color:#000000">&copy; 2022 &nbsp;</p></div></div></footer><script src="../../..//highlighter.js"></script><link href="../../../highlighter.css" rel="stylesheet"/></body></html>
File diff suppressed because one or more lines are too long
+7
View File
@@ -52,6 +52,13 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
}
public function playSingAnim(direction:Int, suffix:String = "") {
// TODO: Script Events
var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
playAnim('${anims[direction]}$suffix', true);
}
public function new(x:Float, y:Float, ?character:String = "bf", ?isPlayer:Bool = false)
{
super(x, y);
+2 -2
View File
@@ -60,7 +60,7 @@ class Note extends FlxSprite
this.noteData = noteData;
var daStage:String = PlayState.instance.curStage;
var daStage:String = PlayState.instance == null ? "stage" : PlayState.instance.curStage;
switch (daStage)
{
@@ -154,7 +154,7 @@ class Note extends FlxSprite
x -= width / 2;
if (PlayState.instance.curStage.startsWith('school'))
if (daStage.startsWith('school'))
x += 30;
if (prevNote.isSustainNote)
+29 -63
View File
@@ -209,7 +209,7 @@ class PlayState extends MusicBeatState
// ADD YOUR HARDCODED SCRIPTS HERE!
default:
trace('charts/${SONG.song}/');
var content = Paths.getFolderContent('charts/${SONG.song}/', false, true, false);
var content = Paths.getFolderContent('charts/${SONG.song}/', false, true, !fromMods);
trace(content);
for(file in content) {
@@ -1351,72 +1351,38 @@ class PlayState extends MusicBeatState
{
if (!note.wasGoodHit)
{
camZooming = true;
if (note.mustPress) {
// TODO: See TODO above
var event = scripts.event("onPlayerHit", new NoteHitEvent(note, boyfriend, true, note.noteType, note.strumID));
if (!event.cancelled) {
if (!note.isSustainNote)
{
combo++;
popUpScore(note.strumTime);
}
if (note.noteData >= 0)
health += 0.023;
else
health += 0.004;
if (!event.animCancelled) {
switch (event.direction)
{
case 0:
boyfriend.playAnim('singLEFT', true);
case 1:
boyfriend.playAnim('singDOWN', true);
case 2:
boyfriend.playAnim('singUP', true);
case 3:
boyfriend.playAnim('singRIGHT', true);
}
}
playerStrums.forEach(function(str:Strum) {
if (str.ID == Math.abs(note.noteData % 4)) {
str.press(note.strumTime);
}
});
}
} else {
// TODO: See TODO above the todo above
var event = scripts.event("onDadHit", new NoteHitEvent(note, dad, false, note.noteType, note.strumID));
if (!event.cancelled) {
if (!event.animCancelled) {
switch (event.direction)
{
case 0:
dad.playAnim('singLEFT', true);
case 1:
dad.playAnim('singDOWN', true);
case 2:
dad.playAnim('singUP', true);
case 3:
dad.playAnim('singRIGHT', true);
}
}
note.wasGoodHit = true;
cpuStrums.forEach(function(str:Strum) {
if (str.ID == Math.abs(note.noteData % 4)) {
str.press(note.strumTime);
}
});
var event:NoteHitEvent;
if (note.mustPress)
event = scripts.event("onPlayerHit", new NoteHitEvent(note, boyfriend, true, note.noteType, note.strumID, note.noteData > 0 ? 0.023 : 0.004));
else
event = scripts.event("onDadHit", new NoteHitEvent(note, dad, false, note.noteType, note.strumID, 0));
if (!event.cancelled) {
if (event.player && !note.isSustainNote)
{
combo++;
popUpScore(note.strumTime);
}
health += event.healthGain;
if (!event.animCancelled) {
event.character.playSingAnim(event.direction);
}
(event.player ? playerStrums : cpuStrums).forEach(function(str:Strum) {
if (str.ID == Math.abs(note.strumID)) {
str.press(note.strumTime);
}
});
}
note.wasGoodHit = true;
vocals.volume = 1;
if (event.unmuteVocals) vocals.volume = 1;
if (event.enableCamZooming) camZooming = true;
if (!note.isSustainNote) deleteNote(note);
if (event.deleteNote && !note.isSustainNote) deleteNote(note);
}
}
@@ -1482,4 +1448,4 @@ class PlayState extends MusicBeatState
}
public var curLight:Int = 0;
}
}
@@ -30,9 +30,16 @@ class CancellableEvent {
*/
public function new() {}
/**
* Returns a string representation of the event, in this format:
* `[CancellableEvent]`
* `[CancellableEvent (Cancelled)]`
* @return String
*/
public function toString():String {
var rep = '[CancellableEvent ${cancelled ? "(Cancelled)" : ""} - ]';
// TODO: List all fields
var fields = Reflect.fields(this);
var claName = Type.getClassName(Type.getClass(this)).split(".");
var rep = '[${claName[claName.length-1]}${cancelled ? " (Cancelled)" : ""}]';
return rep;
}
}
+59 -13
View File
@@ -5,28 +5,47 @@ import funkin.game.Character;
class NoteHitEvent extends CancellableEvent {
@:dox(hide) public var animCancelled:Bool = false;
public var note:Note;
public var character:Character;
public var player:Bool;
public var noteType:String;
public var direction:Int;
@:dox(hide) public var deleteNote:Bool = true;
@:dox(hide) public var unmuteVocals:Bool = true;
@:dox(hide) public var enableCamZooming:Bool = true;
/**
* Creates a new NoteHitEvent with the following values:
* @param note
* @param character
* @param player
* @param noteType
* Note that has been pressed
*/
public function new(note:Note, character:Character, player:Bool, noteType:String, direction:Int) {
public var note:Note;
/**
* Character that pressed the note
*/
public var character:Character;
/**
* Whenever the Character is the player
*/
public var player:Bool;
/**
* Note Type name (null if default note)
*/
public var noteType:String;
/**
* Direction of the press (0 = Left, 1 = Down, 2 = Up, 3 = Right)
*/
public var direction:Int;
/**
* The amount of health that'll be gained from pressing that note.
*/
public var healthGain:Float;
/**
* Creates a new NoteHitEvent.
*/
public function new(note:Note, character:Character, player:Bool, noteType:String, direction:Int, healthGain:Float) {
super();
this.note = note;
this.character = character;
this.player = player;
this.noteType = noteType;
this.direction = direction;
this.direction = cast direction;
this.healthGain = healthGain;
}
/**
@@ -38,4 +57,31 @@ class NoteHitEvent extends CancellableEvent {
@:dox(hide)
public function cancelAnim() {preventAnim();}
/**
* Prevents the note from being deleted.
*/
public function preventDeletion() {
deleteNote = false;
}
@:dox(hide)
public function cancelDeletion() {preventDeletion();}
/**
* Prevents the vocals volume from being set to 1 after pressing the note.
*/
public function preventVocalsUnmute() {
unmuteVocals = false;
}
@:dox(hide)
public function cancelVocalsUnmute() {preventVocalsUnmute();}
/**
* Prevents the camera zoom every 4 beats from enabling.
*/
public function preventCamZooming() {
enableCamZooming = false;
}
@:dox(hide)
public function cancelCamZooming() {preventCamZooming();}
}