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

Add Trait documentation #203

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading