Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Add Trait documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tong committed Dec 15, 2023
1 parent 8bf6b8f commit d353826
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion Sources/iron/Trait.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import iron.object.Object;
class Trait {

public var name: String = "";
public var object: Object; // Object this trait belongs to

/**
Object this trait belongs to.
**/
public var object: Object;

var _add: Array<Void->Void> = null;
var _init: Array<Void->Void> = null;
Expand All @@ -17,65 +21,101 @@ class Trait {

public function new() {}

/**
Remove the trait from the object.
**/
public function remove() {
object.removeTrait(this);
}

/**
Trait is added to an object.
**/
public function notifyOnAdd(f: Void->Void) {
if (_add == null) _add = [];
_add.push(f);
}

/**
Object which this trait belongs to is added to scene.
**/
public function notifyOnInit(f: Void->Void) {
if (_init == null) _init = [];
_init.push(f);
App.notifyOnInit(f);
}

/**
Object which this trait belongs to is removed from scene.
**/
public function notifyOnRemove(f: Void->Void) {
if (_remove == null) _remove = [];
_remove.push(f);
}

/**
Add game logic handler.
**/
public function notifyOnUpdate(f: Void->Void) {
if (_update == null) _update = [];
_update.push(f);
App.notifyOnUpdate(f);
}

/**
Remove game logic handler.
**/
public function removeUpdate(f: Void->Void) {
_update.remove(f);
App.removeUpdate(f);
}

/**
Add late game logic handler.
**/
public function notifyOnLateUpdate(f: Void->Void) {
if (_lateUpdate == null) _lateUpdate = [];
_lateUpdate.push(f);
App.notifyOnLateUpdate(f);
}

/**
Remove late game logic handler.
**/
public function removeLateUpdate(f: Void->Void) {
_lateUpdate.remove(f);
App.removeLateUpdate(f);
}

/**
Add render handler.
**/
public function notifyOnRender(f: kha.graphics4.Graphics->Void) {
if (_render == null) _render = [];
_render.push(f);
App.notifyOnRender(f);
}

/**
Remove render handler.
**/
public function removeRender(f: kha.graphics4.Graphics->Void) {
_render.remove(f);
App.removeRender(f);
}

/**
Add 2D render handler.
**/
public function notifyOnRender2D(f: kha.graphics2.Graphics->Void) {
if (_render2D == null) _render2D = [];
_render2D.push(f);
App.notifyOnRender2D(f);
}

/**
Remove 2D render handler.
**/
public function removeRender2D(f: kha.graphics2.Graphics->Void) {
_render2D.remove(f);
App.removeRender2D(f);
Expand Down

0 comments on commit d353826

Please sign in to comment.