Skip to content

Commit

Permalink
#79 untested: implement the addon manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Aelto committed Dec 25, 2021
1 parent 28b6856 commit 11a2be6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/addons/addons_manager.ws
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

statemachine class RER_AddonManager {
var master: CRandomEncounters;

/**
* the queue of states to process, once a state is processed it
* is removed from the queue. It goes from last item in the queue
* to the first.
*/
var states_to_process: array<name>;

/**
* the queue of states that were already processed. The first states
* to be processed are first in the queue.
*/
var processed_states: array<name>;

public function init(master: CRandomEncounters) {
this.master = master;
this.GotoState('Loading');
}
}

15 changes: 15 additions & 0 deletions src/addons/states/base.ws
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

state Addon in RER_AddonManager {
event OnEnterState(previous_state_name: name) {
super.OnEnterState(previous_state_name);
NLOG("RER_AddonManager - state " + parent.GetCurrentStateName());
}

public function getMaster(): CRandomEncounters {
return parent.master;
}

public function finish() {
parent.GotoState('Waiting');
}
}
16 changes: 16 additions & 0 deletions src/addons/states/loading.ws
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

state Loading in RER_AddonManager {
event OnEnterState(previous_state_name: name) {
super.OnEnterState(previous_state_name);
NLOG("RER_AddonManager - state Loading");

this.Loading_main();
}

entry function Loading_main() {
parent.states_to_process = theGame.GetDefinitionsManager()
.GetItemsWithTag('RER_Addon');

parent.GotoState('Waiting');
}
}
28 changes: 28 additions & 0 deletions src/addons/states/waiting.ws
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

state Waiting in RER_AddonManager {
event OnEnterState(previous_state_name: name) {
super.OnEnterState(previous_state_name);
NLOG("RER_AddonManager - state WAITING");

this.Waiting_main(previous_state_name);
}

entry function Waiting_main(previous_state_name: name) {
if (previous_state_name != 'Loading') {
parent.processed_states.PushBack(previous_state_name);
}

this.startProcessingLastState();
}

function startProcessingLastState() {
var last_state: name;

if (parent.states_to_process.Size() <= 0) {
return;
}

last_state = parent.states_to_process.PopBack();
parent.GotoState(last_state);
}
}
2 changes: 2 additions & 0 deletions src/main.ws
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ statemachine class CRandomEncounters extends CEntity {
var bounty_manager: RER_BountyManager;
var horde_manager: RER_HordeManager;
var contract_manager: RER_ContractManager;
var addon_manager: RER_AddonManager;

var ticks_before_spawn: float;

Expand Down Expand Up @@ -63,6 +64,7 @@ statemachine class CRandomEncounters extends CEntity {
bounty_manager = new RER_BountyManager in this;
horde_manager = new RER_HordeManager in this;
contract_manager = new RER_ContractManager in this;
addon_manager = new RER_AddonManager in this;

if (this.isEnabled()) {
NLOG("RER is enabled");
Expand Down
2 changes: 2 additions & 0 deletions src/states/loading.ws
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ state Loading in CRandomEncounters {

SU_updateMinimapPins();

parent.addon_manager.init(parent);

parent.GotoState('Waiting');
}

Expand Down

0 comments on commit 11a2be6

Please sign in to comment.