Module: CARPS::Launcher

Defined in:
lib/carps/mod/launch.rb

Overview

Functions which launch mods.

Class Method Summary collapse

Class Method Details

.get_mailer(uri) ⇒ Object



35
36
37
38
# File 'lib/carps/mod/launch.rb', line 35

def Launcher::get_mailer uri
   DRb.start_service
   mailer = DRbObject.new_with_uri uri
end

.launch(mod) ⇒ Object

Use to launch a mod

Pass a module, containing the mod: this will do the rest.

The module must contain two further modules, Player and DM

Each of Player and DM must also contain a create_mod method (And I mean defined like ‘def Player::create_mod`).

Player::create_mod should take one parameter: the mailer.

DM::create_mod should take two parameters: the campaign, then the mailer.

Each of Player and DM should also contain a launch method (which should be defined as per above), this method should take one parameter: the mod



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/carps/mod/launch.rb', line 74

def Launcher::launch mod

   CARPS::with_crash_report true do
      # Start DRB
      DRb.start_service
      # Should use optparse?
      if ARGV.empty?
         usage
      else
         role = ARGV.shift
         if role == "-h"
            if ARGV.length == 2
               CARPS::config_dir "dm"
               campaign = ARGV.shift
               Launcher::launch_dm_mod mod::DM, campaign, Launcher::get_mailer(ARGV.shift)
            else
               usage
            end
         elsif role == "-p"
            if ARGV.length == 1
               CARPS::config_dir "player"
               Launcher::launch_player_mod mod::Player, Launcher::get_mailer(ARGV.shift)
            else
               Launcher::usage
            end
         else
            Launcher::usage
         end
      end
   end
end

.launch_dm_mod(role, campaign, mailer) ⇒ Object

Either get the mod from the mailer or create a new one



51
52
53
54
55
56
57
58
# File 'lib/carps/mod/launch.rb', line 51

def Launcher::launch_dm_mod role, campaign, mailer
   mod = nil
   unless mod = mailer.load
      mod = role.create_mod campaign
   end
   mod.mailer = mailer
   role.launch mod
end

.launch_player_mod(role, mailer, *args) ⇒ Object

Either get the mod from the mailer or create a new one



41
42
43
44
45
46
47
48
# File 'lib/carps/mod/launch.rb', line 41

def Launcher::launch_player_mod role, mailer, *args 
   mod = nil
   unless mod = mailer.load
      mod = role.create_mod
   end
   mod.mailer = mailer
   role.launch mod
end

.usageObject

Print an error message



30
31
32
33
# File 'lib/carps/mod/launch.rb', line 30

def Launcher::usage
   puts "Mod requires argument -p URI for player\nor -h CAMPAIGN URI for DMs."
   CARPS::enter_quit 1
end