Skip to content

Instantly share code, notes, and snippets.

@frederikaalund
Created June 8, 2019 10:20
Show Gist options
  • Save frederikaalund/38d5724bab9f956118561a36a9efc766 to your computer and use it in GitHub Desktop.
Save frederikaalund/38d5724bab9f956118561a36a9efc766 to your computer and use it in GitHub Desktop.
package ArchCameraControl
import ArchOnePerPlayer
import ArchCallback
import ArchPlayers
import ClosureEvents
public class CameraControl
use OnePerPlayer
protected CameraConfig cc
/** Takes ownership of data and onStop */
private construct(player p, CameraConfig cc, CallbackNullary onStop)
this.p = p
this.cc = cc
this.start(onStop)
ondestroy
destroy this.cc
/** Takes ownership of onStop. onStop may be null. */
protected function start(CallbackNullary onStop)
this.cc.start(this.p) ->
destroy this
if null != onStop
onStop.callAndDestroy()
protected function stop()
this.cc.stop(p)
/** Takes ownership of cc */
static function setFor(player p, CameraConfig cc) returns thistype
return setFor(p, cc, null)
/** Takes ownership of cc and onStop */
static function setFor(player p, CameraConfig cc, CallbackNullary onStop) returns thistype
destroyFor(p)
return new CameraControl(p, cc, onStop)
override static function destroyFor(player p)
let instance = getFor(p)
if null != instance
instance.stop()
override static function destroyForAll()
for p in ALL_PLAYERS_IN_GAME
destroyFor(p)
public abstract class CameraConfig
private CallbackNullary onStop
protected boolean canPlayerStop
construct(boolean canPlayerStop)
this.onStop = null
this.canPlayerStop = canPlayerStop
abstract protected function startCamera(player p)
abstract protected function stopCamera(player p)
/** Only the CameraControl class should call this */
protected function start(player p, CallbackNullary onStop)
this.onStop = onStop
this.startCamera(p)
/** Call when the camera config is done (if it is ever done) */
protected function stop(player p)
this.stopCamera(p)
this.onStop.callAndDestroy()
/* Init */
init
EventListener.add(EVENT_PLAYER_END_CINEMATIC) ->
let p = GetTriggerPlayer()
let instance = CameraControl.getFor(p)
if null != instance and instance.cc.canPlayerStop
instance.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment