-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add MSU.Class.Event class #321
Open
LordMidas
wants to merge
1
commit into
development
Choose a base branch
from
msu-class-event
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
::MSU.Class.Event <- class | ||
{ | ||
__Functions = null; | ||
|
||
constructor() | ||
{ | ||
this.__Functions = []; | ||
} | ||
|
||
function register( _env, _function ) | ||
{ | ||
// ::MSU.requireFunction(_function); | ||
foreach (i, funcInfo in this.__Functions) | ||
{ | ||
if (funcInfo[1] == _function) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
this.__Functions.push([_env, _function]); | ||
} | ||
|
||
function unregister( _function ) | ||
{ | ||
// ::MSU.requireFunction(_function); | ||
foreach (i, funcInfo in this.__Functions) | ||
{ | ||
if (funcInfo[1] == _function) | ||
{ | ||
this.__Functions.remove[i]; | ||
return; | ||
} | ||
} | ||
|
||
throw ::MSU.Exception.KeyNotFound(_function); | ||
} | ||
|
||
function invoke( _argsArray = null ) | ||
{ | ||
if (_argsArray == null) _argsArray = [null]; | ||
else _argsArray.insert(0, null); | ||
|
||
foreach (funcInfo in this.__Functions) | ||
{ | ||
_argsArray[0] = funcInfo[0]; | ||
funcInfo[1].acall(_argsArray); | ||
} | ||
} | ||
|
||
// Will iterate over every registered function and check _conditionFunction | ||
// if _conditionFunction returns false, stops iteration immediately | ||
function conditionalInvoke( _conditionFunction, _argsArray = null ) | ||
{ | ||
if (_argsArray == null) _argsArray = [null]; | ||
else _argsArray.insert(0, null); | ||
|
||
foreach (funcInfo in this.__Functions) | ||
{ | ||
if (_conditionFunction() == false) | ||
return; | ||
|
||
_argsArray[0] = funcInfo[0]; | ||
funcInfo[1].acall(_argsArray); | ||
} | ||
} | ||
|
||
function clear() | ||
{ | ||
this.__Functions.clear(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels to me like this should perhaps be based on the actual functions that are being called,ie if they return
false
then stop or something along those lines.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, those functions can be anything. They don't necessarily have to be Boolean returning functions. This
conditionalInvoke
is more along the lines of replicating theisAlive
feature of skill_container events where the iteration stops if the actor is no longer alive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning false to stop an event from continuing feels quite natural, it's how it's done in JS event bubbling for example. Using some otherwise decoupled thing to check for a state is weird in contrast.