Class: GamesAndRpgParadise::Lpc::RoomGenerator
- Inherits:
-
Base
- Object
- Base
- GamesAndRpgParadise::Lpc::RoomGenerator
show all
- Defined in:
- lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb
Constant Summary
collapse
- DEBUG =
false
- BE_VERBOSE =
false
- BASE_INDENT =
#
BASE_INDENT
BASE_INDENT tells us how many ‘ ’ chars we use. GEAS wants a 4 spaces indent.
#
4
- STD_ROOM_YAML =
#
STD_ROOM_YAML
We read in the default description from this file here.
bl $GEAS/YAML/std_room.yml
#
ENV['GEAS'].to_s+'/YAML/std_room.yml'
- ARRAY_MACROS =
%w( DATE )
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Instance Method Summary
collapse
ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow
#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments
#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into
Constructor Details
#initialize(optional_commandline_options = nil, run_already = true) ⇒ RoomGenerator
#
initialize
The @indent_level can be 0, 2, 4 and so forth.
#
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 60
def initialize(
optional_commandline_options = nil,
run_already = true
)
reset
set_commandline(
optional_commandline_options
)
run if run_already
end
|
Instance Method Details
#_(input = N, use_indent_level = true) ⇒ Object
Also known as:
add_newline
#
_
This method is used and also sets the proper indent.
#
396
397
398
399
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 396
def _(input = N, use_indent_level = true)
@s << (' ' * @indent_level) if use_indent_level
@s << input
end
|
#add_coordinates ⇒ Object
#
add_coordinates (coordinates tag coord tag coords tag)
#
352
353
354
355
356
357
358
359
360
361
362
363
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 352
def add_coordinates
c = @_['coordinates']
= c['comment'].to_s
x = c['x'].to_s
y = c['y'].to_s
z = c['z'].to_s
d = c['d'].to_s
_ N+'int *query_coordinates()'+()+N
otag
_ 'return ({ '+x+', '+y+', '+z+', '+d+'});'+N
ctag
end
|
#add_exits(n_exits = nil) ⇒ Object
#
add_exits (exit tag, exits tag)
#
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 198
def add_exits(n_exits = nil)
if n_exits
n_exits.times {|entry|
_ 'add_exit(FOO+"entrance", "down");'+N
}
else
exits = @_['exits']
pp exits if DEBUG
keys = exits.keys
keys.each { |key|
value = exits[key]
= nil
if value.include? ','
value = value.split(',')
= value[1].strip
value = value.first.to_s
end
tmp = key.dup.quotes
string = 'add_exit('+tmp+', '
value.cexit!
string << value.quotes
string << ', '+('@@'+).quotes if
string << ');'
_ string+N
}
end
end
|
#add_includes ⇒ Object
#
add_includes
This will add all #includes.
#
344
345
346
347
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 344
def add_includes
_ @_['includes'].gsub(/^/,'#include ')
_
end
|
#add_indent_level(i = @indent_level) ⇒ Object
179
180
181
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 179
def add_indent_level(i = @indent_level)
return ' ' * i
end
|
#add_inherits ⇒ Object
334
335
336
337
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 334
def add_inherits
_ @_['inherits'].gsub(/^/,'inherit ')
_
end
|
#add_objects(i = ) ⇒ Object
#
add_objects (object tag)
This method expects an Array.
#
306
307
308
309
310
311
312
313
314
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 306
def add_objects(i = @_['objects'])
if i s = 'object '+i.shift+', '+N
i.each {|entry| s << ' '+entry+','+N }
s[-2,2] = ''
s << ';'+N+N
_ s
end
end
|
#add_reset_room ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 284
def add_reset_room
_ N+'void '+N
_ 'reset_room()'+N
_ '{'+N+N
if @_['objects']
p
if @_['objects'].size == 1
@_['objects'] = @_['objects'].to_s+' = clone_here(ARB_MONSTER+"/humanoid/gnoll");'+N
else
@_['objects'] = @_['objects'].join(', '+' = clone_here(ARB_MONSTER+"/humanoid/gnoll");'+N)
end
_ @_['objects']
m
end
_ '}'+N
end
|
#add_room_messages ⇒ Object
#
add_room_messages (messages tag)
#
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 319
def add_room_messages
string = ''
@_['room_messages'].each_pair { |msg, conditions|
string << 'add_room_message('
string << msg.quotes
string << ','+conditions
string << ');'+N
}
_ string
end
|
#add_room_properties ⇒ Object
#
add_room_properties (prop tag)
#
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 404
def add_room_properties
@_['properties'].sort.each { |key, value|
if key.only_caps? else
key = key.to_s.quotes
end
if value.to_s =~ /^(|-)\d*$/ value = value.to_i.to_s
else
value = value.quotes
end
_ 'add_prop('+key+', '+value+');'+N
}
add_newline
end
|
#add_these_items ⇒ Object
#
add_these_items (items tag, item tag)
#
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 269
def add_these_items
@_['add_these_items'].each { |name, description|
aliased_name = name.inner_quotes
_ 'add_item(({"'+aliased_name+'"}),'+N
p
_ ';'+description.sanitize(0,50)+'\n);'+N
m
}
_ end
|
#apply_macro_expansion(i) ⇒ Object
#
apply_macro_expansion
This replaces some macros. Currently only DATE.
#
148
149
150
151
152
153
154
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 148
def apply_macro_expansion(i)
_ = ARRAY_MACROS.first
if i.include? 'DATE'
i = i.gsub(/DATE/, get_real_date)
end
return i
end
|
#build_string ⇒ Object
#
build_string
Combined method.
#
240
241
242
243
244
245
246
247
248
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 240
def build_string
add_inherits
add_includes
add_objects
create_room add_reset_room
add_coordinates
end
|
#check_for_add_sign ⇒ Object
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 253
def check_for_add_sign
if @_['add_sign']
@_['add_sign'].each { |name, description|
aliased_name = name.inner_quotes
_ 'add_sign(({"'+aliased_name+'"}),'+N
p
_ ';'+description.sanitize(0, 70)+'\n);'+N
m
}
_
end
end
|
186
187
188
189
190
191
192
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 186
def (i = @_['comment_header'])
if i
_ '/*'+N
_ ' * '+apply_macro_expansion(i).split(N).join(N+' * ')
_ N+' */'+N+N
end
end
|
#close_tag ⇒ Object
Also known as:
ctag
#
close_tag
Will append } bracket.
#
386
387
388
389
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 386
def close_tag
m
_ '}'+N
end
|
#create_room(optional_hash = nil) ⇒ Object
#
create_room (room tag)
#
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 448
def create_room(optional_hash = nil)
_ 'nomask void'+N
_ 'create_room()'+N
otag
if optional_hash and optional_hash.is_a?(Hash)
h = optional_hash
set_short(h[:short_description])
set_long(h[:long_description])
add_room_properties
add_these_items
check_for_add_sign
add_exits(h[:n_exits])
else
set_short
set_long
add_room_properties
add_these_items
check_for_add_sign
add_exits
end
ctag
end
|
#debug ⇒ Object
#
debug
This method will output the string that will be generated.
#
231
232
233
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 231
def debug
e @s
end
|
#get_real_date ⇒ Object
#
get_real_date
Apply date.
#
161
162
163
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 161
def get_real_date
return Time.now.strftime('%d.%m.%Y')
end
|
#load_yaml_template(from_where = STD_ROOM_YAML) ⇒ Object
#
load_yaml_template
This assigns the @_ variable to point to the yaml file.
#
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 129
def load_yaml_template(
from_where = STD_ROOM_YAML
)
if $stdout.tty? if @be_verbose
opn; e 'The yaml file was read in from '
e
e " #{sfile(from_where)}"
e
end
end
@_ = @yaml_file = YAML.load_file(from_where)
end
|
#m ⇒ Object
424
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 424
def m; @indent_level -= BASE_INDENT; end
|
#open_tag ⇒ Object
Also known as:
otag
376
377
378
379
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 376
def open_tag
_ '{'+N
p
end
|
#p ⇒ Object
#
Play with the indent level. (p tag, m tag)
#
423
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 423
def p; @indent_level += BASE_INDENT; end
|
#process_commandline ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 104
def process_commandline
case @commandline.downcase when /$inte/,'i','int'
set_run_in_interactive_way
when 'help','hel','h'
show_help_then_exit
end
end
|
#reset ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 74
def reset
@hash = {}
@be_verbose = BE_VERBOSE
@run_in_interactive_way = false
@s = @string = '' @indent_level = 0 end
|
#run ⇒ Object
496
497
498
499
500
501
502
503
504
505
506
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 496
def run
load_yaml_template
process_commandline
if @run_in_interactive_way
start_interactive_way
else
build_string
end
debug
store_string
end
|
#set_commandline(i) ⇒ Object
88
89
90
91
92
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 88
def set_commandline(i)
i = i.first if i.is_a? Array i = i.dup if i
@commandline = i
end
|
#set_long(i = @_['long']) ⇒ Object
#
set_long (long tag)
Sets the long description of a room.
#
170
171
172
173
174
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 170
def set_long(i = @_['long'])
_ 'set_long(BS('+N
_ i.sanitize(@indent_level)+'+'+N
_ add_indent_level+'"\n"));'+N+N, F
end
|
#set_run_in_interactive_way ⇒ Object
#
set_run_in_interactive_way
#
97
98
99
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 97
def set_run_in_interactive_way
@run_in_interactive_way = true
end
|
#set_short(i = ) ⇒ Object
368
369
370
371
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 368
def set_short(i = @_['short'])
i[0,1] = i[0,1].upcase
_ 'set_short("'+i+'");'+N
end
|
#show_help_then_exit ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 116
def show_help_then_exit
opn; e 'Currently these help options exist:'
e
opn; e ' - interactive #'+CYAN+' run in an interactive mode.'+rev
e
exit
end
|
#start_interactive_way ⇒ Object
#
start_interactive_way (interactive tag, int tag)
Use this method to setup things in an interactive manner.
#
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 477
def start_interactive_way
opn; e 'We will now run the room-generator in an interactive way.'
opn; e 'Please input how many exits this room should have:'
@hash[:n_exits] = uinput.to_i
opn; e 'Please set the short description now.'
@hash[:short_description] = uinput
opn; e 'Please set the long description now.'
@hash[:long_description] = uinput
opn; e 'Thank you. Now we will generate a room.'
add_inherits
add_includes
add_objects
create_room(@hash) end
|
#store_string ⇒ Object
#
store_string
Use this to store the string.
#
431
432
433
434
435
436
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 431
def store_string
what = @s
where = 'autogenerated_room.c'
opn; e 'Also storing into '+sfile(where)+'.'
SaveFile.write_what_into(what, where)
end
|
441
442
443
|
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/room_generator.rb', line 441
def uinput
return $stdin.gets.chomp
end
|