forked from rpherbig/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.lic
99 lines (87 loc) · 3.36 KB
/
bootstrap.lic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
# quiet
=begin
Documentation: https://elanthipedia.play.net/Lich_script_development#bootstrap
=end
$BOOTSTRAP_VERSION = '1.0.3'
DRINFOMON_IN_CORE_LICH ||= false
DRINFOMON_CORE_LICH_DEFINES ||= []
class_defs = {
'drinfomon' => :DRINFOMON,
'equipmanager' => :EquipmentManager,
'common' => :DRC,
'common-travel' => :DRCT,
'common-crafting' => :DRCC,
'common-summoning' => :DRCS,
'common-money' => :DRCM,
'common-arcana' => :DRCA,
'common-items' => :DRCI,
'common-healing' => :DRCH,
'common-validation' => :CharacterValidator,
'common-moonmage' => :DRCMM,
'common-theurgy' => :DRCTH
}
arg_definitions = [
[
{ name: 'wipe_constants', regex: /wipe_constants/i, optional: true }
]
]
args = parse_args(arg_definitions, true)
def constant_defined?(symbol)
if $MODERN_LICH && $MODERN_RUBY
Object.constants.include?(symbol)
else
Scripting.constants.include?(symbol)
end
end
def remove_constant(symbol)
if $MODERN_LICH && $MODERN_RUBY
Object.send(:remove_const, symbol)
else
Scripting.send(:remove_const, symbol)
end
end
$MODERN_RUBY = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
lich_version = Gem::Version.new(LICH_VERSION.gsub(/(f)/, ''))
$MODERN_LICH = lich_version >= if Regexp.last_match(1)
Gem::Version.new('4.12.0')
else
Gem::Version.new('4.6.49')
end
if args.wipe_constants && !DRINFOMON_IN_CORE_LICH
class_defs.each_value { |symb| remove_constant(symb) if constant_defined?(symb) }
exit
end
scripts_to_run = args.flex || []
echo scripts_to_run.to_s if UserVars.bootstrap_debug
if (scripts_to_run & DRINFOMON_CORE_LICH_DEFINES).any?
scripts_to_run -= DRINFOMON_CORE_LICH_DEFINES
echo("Removing core lich defines from scripts_to_run") if UserVars.bootstrap_debug
end
until scripts_to_run.empty?
script_to_run = scripts_to_run.shift
respond("BS:#{script_to_run}:#{scripts_to_run}") if UserVars.bootstrap_debug
next if (!class_defs[script_to_run] && Script.running?(script_to_run)) || (class_defs[script_to_run] && constant_defined?(class_defs[script_to_run]))
respond("BS:starting:#{script_to_run}") if UserVars.bootstrap_debug
exit unless verify_script(script_to_run)
start_script(script_to_run)
pause 0.05
snapshot = Time.now
if class_defs[script_to_run]
# Most of the scripts we wait on are common utility scripts.
# They run and define a bunch of methods then end. Awesome.
# `drinfomon` is different and has a continuous background loop,
# so it's an "always on" script. But we also need to wait for it
# to have run long enough to parse and define some core data.
# Therefore, our condition on how long to wait for `drinfomon`
# is just until the constant has been defined, otherwise we'd wait forever.
# Alternatively, `drinfomon` could be refactored where the background loop
# is in a script separate from what initially parses exp/info so it behaves
# like the common scripts, but that seemed more stressful/risky than this change.
pause 0.05 until constant_defined?(class_defs[script_to_run]) && (!Script.running?(script_to_run) || script_to_run == 'drinfomon')
pause 0.05
else
until !Script.running?(script_to_run) || Time.now - snapshot > 0.25
pause 0.05
end
end
end