Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
126 lines (110 sloc) 4.19 KB
«IMPORT iaml»
«EXTENSION template::GeneratorExtensions»
/**
* @implementation Gate
* When all incoming {@model Condition Conditions} to an activated exit {@model Gate} fail,
* that exit {@model Gate} is disabled.
*/
«DEFINE runExitGate FOR model::components::Gate-»
/* exit gate '«safeName()»' */
// TODO move into include
function exit_gate_needs_activating_«safeName()»($frame_id) {
«FOREACH getRoot().eAllContents.typeSelect(model::visual::Frame) AS frame»
if ($frame_id == "«safeName(frame)»") {
return «IF exitGateNeedsActivating(this, frame)»true«ELSE»false«ENDIF»;
}
«ENDFOREACH»
throw new IamlRuntimeException("Fell out of exit_gate_needs_activating (gate ID = «id»)");
}
/* firstly, if we are in the scope that this gate is contained in,
we need to activate it. */
if (exit_gate_needs_activating_«safeName()»(get_frame_id())) {
«IF containingSession(this) != null»
$_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_active"] = true;
«ELSE»
set_application_value("«safeNameString(id)»_active", true);
«ENDIF»
} else {
// not activated by this frame
}
function exit_gate_needs_to_redirect_«safeName()»($frame_id) {
«FOREACH getRoot().eAllContents.typeSelect(model::visual::Frame) AS frame»
if ($frame_id == "«safeName(frame)»") {
return «IF exitGateNeedsToRedirect(this, frame)»true«ELSE»false«ENDIF»;
}
«ENDFOREACH»
throw new IamlRuntimeException("Fell out of exit_gate_needs_activating (gate ID = «id»)");
}
«REM»ignore gates which are inside the current scope«ENDREM»
if (exit_gate_needs_to_redirect_«safeName()»(get_frame_id())) {
/* secondly, is this gate activated? (may have been activated just before) */
if (
«IF containingSession(this) != null»
isset($_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_active"])
&& $_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_active"]
«ELSE»
get_application_value("«safeNameString(id)»", null) !== null
«ENDIF»
) {
log_message("[exitgate] Checking exit gate «name»");
/* expand conditions - do any of them fail? */
if (!(
«EXPAND template::conditions::Runtime::callCondition(true, false) FOREACH conditions SEPARATOR " && "»
)) {
// one condition failed
log_message("[exitgate] Exit gate «name» failed");
// save the current frame, for resuming
$resume = get_frame_id();
«IF containingSession(this) != null»
$_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_resume"] = $resume;
«ELSE»
set_application_value("«safeNameString(id)»_resume", $resume);
«ENDIF»
// execute gate wires
«EXPAND template::events::Frame::runGateWires FOR this»
} else {
// otherwise, disable the activation (it has passed at least once)
log_message("[exitgate] Exit gate «name» passed");
«IF containingSession(this) != null»
unset($_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_active"]);
«ELSE»
set_application_value("«safeNameString(id)»_active", null);
«ENDIF»
}
}
}
«ENDDEFINE»
/**
* If we have been asked to navigate to the given Gate,
* where should we resume?
*
* Should set '$arg' to the new frame ID, or empty if the resume is not set.
*/
«DEFINE getExitResumeTarget(String arg) FOR model::components::Gate»
«IF containingSession(this) != null»
$«arg-» = null;
if (isset($_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_resume"]))
$«arg-» = $_SESSION["«safeName(containingSession(this))»_«safeNameString(id)»_resume"];
«ELSE»
$«arg-» = get_application_value("«safeNameString(id)»_resume", null);
«ENDIF»
// check that this is a valid value for this resume
$is_valid = false;
«FOREACH getExitResumeTargets(this) AS target»
if ($«arg-» == "«safeName(target)»")
$is_valid = true;
«ENDFOREACH»
if (!$is_valid) {
log_message("[gate] resume target '$resume' is not valid");
$«arg-» = ""; // reset
}
«ENDDEFINE»
/**
* Find _any_ target for the Gate (i.e. the resume has not been set)
*/
«DEFINE getExitAnyTarget(String arg) FOR model::components::Gate»
«IF getExitResumeTargets(this).isEmpty»
«throwException("Gate '" + this + "' did not have any possible resume targets")»
«ENDIF»
$«arg-» = "«safeName(getExitResumeTargets(this).first())»";
«ENDDEFINE»
You can’t perform that action at this time.