forked from Mirrors/openclonk
SwitchTarget: Single callback
parent
43636c4941
commit
f9cd3aa77e
|
@ -21,7 +21,6 @@ public func Construction(object by_object)
|
|||
{
|
||||
_inherited(by_object, ...);
|
||||
lib_mechanism = {
|
||||
old_signal = nil, // the last received signal
|
||||
set_plr_view = true, // sets the player view to this object when the input signal changes
|
||||
temp_light = nil, // temporary light, so that the player can see something when the object is being operated
|
||||
};
|
||||
|
@ -32,47 +31,36 @@ public func Construction(object by_object)
|
|||
/*
|
||||
Sets the input signal of this mechanism.
|
||||
|
||||
The function issues two callbacks to the object:
|
||||
a) OnInputSignalChanged(operator, sender, value) => gets called only if the value changes
|
||||
b) OnInputSignalSet(operator, sender, value) => gets called every time the signal is set
|
||||
This function should handle everything that happens when the input
|
||||
signal is set (on the generic level).
|
||||
For the object-specific functionality this function issues a callback to the object:
|
||||
* OnSetInputSignal(operator, sender, value)
|
||||
|
||||
Use these callbacks to activate or deactivate certain functions in the mechanism.
|
||||
Use the callback to activate or deactivate certain functions in the mechanism.
|
||||
For example, the stone door opens if you pass 'true', and closes if you pass 'false'
|
||||
|
||||
Usually only the signal changed callback should be relevant, but who knows. Callback b)
|
||||
can be removed at any time if it turns out to be unnecessary.
|
||||
|
||||
That callback happens after the generic handling is done, so that the object
|
||||
can safely be deleted in the callback.
|
||||
|
||||
@par operator this object is operating the mechanism or the object that sent the signal-
|
||||
@par sender this object sent the signal - this is usually a switch.
|
||||
@par value this value is sent.
|
||||
*/
|
||||
public func SetInputSignal(object operator, object sender, bool new_signal)
|
||||
public func SetInputSignal(object operator, object sender, bool value)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
// Callback type 1: rising/falling edge
|
||||
if (lib_mechanism.old_signal != new_signal)
|
||||
// Show the object being operated
|
||||
if (operator && lib_mechanism.set_plr_view)
|
||||
{
|
||||
this->~OnInputSignalChanged(operator, sender, new_signal);
|
||||
lib_mechanism.old_signal = new_signal;
|
||||
|
||||
// Show the object being operated
|
||||
if (self && operator && lib_mechanism.set_plr_view)
|
||||
SetPlrView(operator->GetController(), this);
|
||||
if (lib_mechanism.temp_light)
|
||||
{
|
||||
SetPlrView(operator->GetController(), this);
|
||||
if (lib_mechanism.temp_light)
|
||||
{
|
||||
lib_mechanism.temp_light->RemoveObject();
|
||||
}
|
||||
lib_mechanism.temp_light = Global->CreateLight(this->GetX(), this->GetY() + this->~GetFloorOffset(), 30, Fx_Light.LGT_Temp, operator->GetController(), 30, 50);
|
||||
lib_mechanism.temp_light->RemoveObject();
|
||||
}
|
||||
lib_mechanism.temp_light = Global->CreateLight(this->GetX(), this->GetY() + this->~GetFloorOffset(), 30, Fx_Light.LGT_Temp, operator->GetController(), 30, 50);
|
||||
}
|
||||
|
||||
// Callback type 2: current signal
|
||||
if (self)
|
||||
{
|
||||
this->~OnInputSignalSet(operator, sender, new_signal);
|
||||
}
|
||||
// Callback: current signal
|
||||
this->~OnSetInputSignal(operator, sender, value);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ private func ForceDigFree()
|
|||
/*-- Switch control --*/
|
||||
|
||||
// Reaction to operation by a switch: if open_door is true the door opens, otherwise it closes
|
||||
public func OnInputSignalChanged(object operator, object switch, bool open_door)
|
||||
public func OnSetInputSignal(object operator, object switch, bool open_door)
|
||||
{
|
||||
if (open_door)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue