-
Notifications
You must be signed in to change notification settings - Fork 0
/
read-scene.rb
executable file
·4446 lines (3941 loc) · 124 KB
/
read-scene.rb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/local/bin/ruby
# = read-scene.rb
#
# Author:: Dirk Meyer
# Copyright:: Copyright (c) 2018-2023 Dirk Meyer
# License:: Distributes under the same terms as Ruby
#
require 'yaml'
require 'json'
require 'csv'
require 'cgi'
$: << '.'
# global config file
CONFIG_FILE = 'read-scene.yml'.freeze
# config file for groups of roles
ROLES_CONFIG_FILE = 'roles.wiki'.freeze
# config file for patterns to replace
SUBS_CONFIG_FILE = 'subs.wiki'.freeze
# list of puppets and image html code
PUPPET_POOL_FILE = 'puppet_pool.csv'.freeze
# general header for html output files
HTML_HEADER_FILE = 'header.html'.freeze
# output to debug timeframe data
TIMEFRAME_FILE = 'read-scene.json'.freeze
# output for actors to wiki lines
WIKI_ACTORS_FILE = 'wiki-actors.json'.freeze
# output for actors assigment
ASSIGNMENT_FILE = 'assignment-list.json'.freeze
# output for todo list
TODO_LIST_FILE = 'todo-list.csv'.freeze
# header for todo list
TODO_LIST_HEADER = [ 'Scene', 'Category', 'Item' ].freeze
# output for assignment list
ASSIGNMENT_LIST_FILE = 'assignment-list.csv'.freeze
# output for people list
PEOPLE_LIST_FILE = 'people.json'.freeze
# regular expression for matching names
# U+0430, 0xD0 0xB0, Cyrillic Small Letter A
MATCH_NAME = "[A-Za-z0-9\u0430_\'-]+".freeze
# regular expression for matching names within a tag
MATCH_SNAME = '[^<]+'.freeze
$nat_sort = true
$compat = false
$compat2 = true
$debug = 0
$debug = 1
# read global config options
def read_yaml( filename, default = {} )
config = default
return config unless File.exist?( filename )
config.merge!( YAML.load_file( filename ) )
end
# check if downloaded file has changed
def downloaded?( filename, buffer )
return false unless File.exist?( filename )
old = File.read( filename )
return true if buffer == old
false
end
# write buffer to file
def file_put_contents( filename, buffer, mode = 'w+' )
return if downloaded?( filename, buffer )
File.open( filename, mode ) do |f|
f.write( buffer )
f.close
end
end
# sort arry by natural order
def nat_sort_list( list )
if $nat_sort
list.sort_by do |e|
e.downcase.split( /(\d+)/ ).map { |a| a =~ /\d+/ ? a.to_i : a }
end
else
list.sort_by( &:downcase )
end
end
# sort arry by first element by natural order
def nat_sort_hash( hash )
if $nat_sort
hash.sort_by do |e|
e[ 0 ].downcase.split( /(\d+)/ ).map { |a| a =~ /\d+/ ? a.to_i : a }
end
else
hash.sort_by { |e| e[ 0 ].downcase }
end
end
# quote a string
def quoted( text )
"\"#{text.gsub( '"', '\"' )}\""
end
# quote a string
def quoted_noescape( text )
"\"#{text}\""
end
# convert special characters to html codes
def html_escape( text )
html = text.dup
html.gsub!( '<', '<' )
html.gsub!( "\xe2\x80\x8b", '​' )
html.gsub!( "\xe2\x80\x93", '–' )
html.gsub!( "\xe2\x80\x99", '’' )
html.gsub!( "\xe2\x80\x9c", '“' )
html.gsub!( "\xe2\x80\x9d", '”' )
if $compat
html.gsub!( "\xc3\xb6", 'ö' )
html.gsub!( "\xc3\xbc", 'ü' )
end
# p [ 'html_escape', text, html ] if text != html
html
end
# make a hash with name and given type
def tname( type, name )
{ type: type, name: name }
end
# make a hash with name and Role type
def role( name )
{ type: 'Role', name: name }
end
# make a hash with name and Actor type
def actor( name )
{ type: 'Actor', name: name }
end
# make a hash with name and Puppet type
def puppet( name )
{ type: 'Puppet', name: name }
end
# make a hash with name and Costume type
def clothing( name )
{ type: 'Costume', name: name }
end
# read patters for replacements from given file
def read_subs( filename )
$subs = {}
$subs_count = {}
return unless File.exist?( filename )
scene = 'global'
File.read( filename ).split( "\n" ).each do |line|
next if line =~ /^#/
next if line =~ /^<[\/]*file/
unless line.include?( ';' )
scene = line.delete( '[]' )
next
end
pattern, text = line.split( ';', 2 )
$subs[ scene ] = {} unless $subs.key?( scene )
$subs[ scene ][ pattern ] = text
$subs_count[ pattern ] = 0
end
end
# read puppet data from given file
def read_puppet( filename )
$puppet_pool = {}
$puppet_builders = {}
File.read( filename ).split( "\n" ).each do |line|
next if /^#/ =~ line
name, builder, image = line.split( ';', 3 )
$puppet_pool[ name ] = image
$puppet_builders[ name ] = builder
end
end
# === Class Functions
# RolesConfig.new( scene, filename )
# RolesConfig.roles_map
# RolesConfig.add_roles( name, list )
# RolesConfig.map_roles( name )
# RolesConfig.ununsed
class RolesConfig
# get the raw hash
attr_accessor :roles_map
# create a mapping table
def initialize( scene, filename )
@roles_map = {}
@roles_seen = {}
return unless File.exist?( filename )
File.read( filename ).split( "\n" ).each do |line|
next if /^#/ =~ line
next if line =~ /^<[\/]*file/
list = line.split( ';' )
scene2, group = list[ 0 .. 1 ]
next if scene2 != scene
roles = list[ 2 .. ]
p [ scene, group, '=', roles ]
@roles_map[ group ] = roles
@roles_seen[ group ] = 0
end
end
# add a mapping to the table
def add_roles( name, list )
@roles_map[ name ] = list
@roles_seen[ name ] = 0
end
# read a mapping from the table
def map_roles( name )
return [ name ] unless @roles_map.key?( name )
@roles_seen[ name ] += 1
@roles_map[ name ]
end
# show unused entries
def unused
@roles_seen.each_pair do |name, count|
next if count.positive?
puts "Role Group #{name} is not used."
end
end
end
# === Class Functions
# QScript.new
# QScript.lines
# QScript.puts( line )
# QScript.puts_list( arr )
# QScript.puts_key_list( key, list )
# QScript.puts_key( key, name, text = nil )
# QScript.puts_key_token( key, token, name, text = nil )
# QScript.save( filename )
class QScript
# current line number of qscript
attr_reader :lines
# create a qscript buffer
def initialize
@script = ''
@lines = 0
end
# add a line to qscript
def puts( line )
@script << line
@script << "\n"
@lines += 1
end
# build a line from given list and add the line to qscript
def puts_list( list )
key = list.shift
text = "\t#{key}"
list.each do |item|
next if item.nil?
item = item[ :name ] if item.respond_to?( :key? )
text << " #{quoted( item )}"
end
puts text
end
# merge key and list, then add the line to qscript
def puts_key_list( key, list )
puts_list( [ key ].concat( list ) )
end
# merge key, list and text, then add the line to qscript
def puts_key( key, name, text = nil )
puts_list( [ key, name, text ] )
end
# merge key, token, name and text, then add the line to qscript
def puts_key_token( key, token, name, text = nil )
puts_list( [ "#{key}#{token}", name, text ] )
end
# write the final qscript into the given file
def save( filename )
file_put_contents( filename, @script )
end
end
# === Class Timeframe
# Timeframe.new( qscript )
# Timeframe.qscript
# Timeframe.timeframe
# Timeframe.timeframe_count
# Timeframe.timeframes
# Timeframe.timeframes_lines
# Timeframe.wiki_highlite
# Timeframe.assignment
# Timeframe.scene( title, filename )
# Timeframe.this_timeframe
# Timeframe.add_wiki_actor_for( actor, role )
# Timeframe.add_wiki_group_for( roles, group )
# Timeframe.add_assignment_actor_for( actor, role, suffix )
# Timeframe.add_actor_for( actor, role, suffix = nil )
# Timeframe.seen?( key, name )
# Timeframe.add( key, val )
# Timeframe.add_once( key, val )
# Timeframe.add_hash( hashkey, key, val )
# Timeframe.add_table( hashkey, table )
# Timeframe.add_list_text( storekey, reportkey, name, text )
# Timeframe.add_list( storekey, reportkey, token, name )
# Timeframe.add_prop( storekey, reportkey, token, list )
# Timeframe.add_spoken( name )
# Timeframe.list( key )
class Timeframe
# List of items to monitor per timeframe
TIMEFRAME_FIELDS = {
'Front props' => 'FrontProp',
'Second level props' => 'SecondLevelProp',
'Backdrop panels' => 'Backdrop',
'Lights' => 'Light',
'Ambiences' => 'Ambience',
'Sounds' => 'Sound',
'Videos' => 'Video',
'Effects' => 'Effect',
'Roles' => 'Role',
'Person' => 'Actor',
'Puppets' => 'Puppet',
'Costumes' => 'Costume',
'Personal props' => 'PersonalProp',
'Hand props' => 'HandProp',
'Tech props' => 'TechProp',
'Special effect' => 'SpecialEffect',
'Todos' => 'Todo'
}.freeze
# the current qscript object
attr_reader :qscript
# the current timeframe
attr_reader :timeframe
# the current timeframe number
attr_reader :timeframe_count
# the full timeframe list
attr_reader :timeframes
# the full timeframe lines
attr_reader :timeframes_lines
# the full wiki_highlite
attr_reader :wiki_highlite
# the assignment list
attr_reader :assignment
# create a timeframe
def initialize( qscript )
@timeframe = nil
@timeframe_count = -1
@timeframes = {}
@timeframes_lines = {}
@qscript = qscript
@wiki_highlite = {}
@assignment = {}
end
# start a new scene
def scene( title, filename )
@timeframe = title
@timeframe_count += 1
@timeframes[ @timeframe ] = { number: @timeframe_count, filename: filename }
@wiki_highlite[ filename ] = {}
@assignment[ @timeframe ] = {}
end
# get the list of the current timeframe
def this_timeframe
@timeframes[ @timeframe ]
end
# add an actor for highlite in wiki
def add_wiki_actor_for( actor, pattern )
filename = @timeframes[ @timeframe ][ :filename ]
@wiki_highlite[ filename ][ actor ] = [] \
unless @wiki_highlite[ filename ].key?( actor )
@wiki_highlite[ filename ][ actor ].push( pattern ) \
unless @wiki_highlite[ filename ][ actor ].include?( pattern )
end
# add an group for highlite in wiki
def add_wiki_group_for( roles, group )
filename = @timeframes[ @timeframe ][ :filename ]
@wiki_highlite[ filename ].each_pair do |actor, list|
roles.each do |role|
next unless list.include?( role )
puts "Adding: #{actor}: role=#{role}, group=#{group} " \
unless $debug.zero?
add_wiki_actor_for( actor, group )
end
end
end
# add an actor for assignment list
def add_assignment_actor_for( actor, pattern, suffix )
pattern2 =
if suffix.nil?
pattern
else
"#{pattern}.#{suffix}"
end
@assignment[ @timeframe ][ actor ] = [] \
unless @assignment[ @timeframe ].key?( actor )
@assignment[ @timeframe ][ actor ].push( pattern2 ) \
unless @assignment[ @timeframe ][ actor ].include?( pattern2 )
end
# add an actor for assignment and highlite
def add_actor_for( actor, pattern, suffix = nil )
add_assignment_actor_for( actor, pattern, suffix )
add_wiki_actor_for( actor, pattern )
end
# check if we have a new item in the current timeframe
def seen?( key, name )
return false unless @timeframes[ @timeframe ].key?( key )
return false unless @timeframes[ @timeframe ][ key ].include?( name )
true
end
# add an new item to the current timeframe
def add( key, val )
if val.nil?
pp @error_line
warn @error_line
end
raise if val.nil?
@timeframes[ @timeframe ][ key ] = [] \
unless @timeframes[ @timeframe ].key?( key )
@timeframes[ @timeframe ][ key ].push( val )
end
# add an item to the current timeframe if it is new
def add_once( key, val )
raise if val.nil?
@timeframes[ @timeframe ][ key ] = [] \
unless @timeframes[ @timeframe ].key?( key )
return if @timeframes[ @timeframe ][ key ].include?( val )
@timeframes[ @timeframe ][ key ].push( val )
end
# add a hash to the current timeframe
def add_hash( hashkey, key, val )
@timeframes[ @timeframe ][ hashkey ] = {} \
unless @timeframes[ @timeframe ].key?( hashkey )
@timeframes[ @timeframe ][ hashkey ][ key ] = val
end
# add a table to the current timeframe
def add_table( hashkey, table )
@timeframes[ @timeframe ][ hashkey ] = table
end
# add an full entry to the timeframes lines
def add_list_text( storekey, reportkey, name, text )
@timeframes_lines[ storekey ] = {} unless @timeframes_lines.key?( storekey )
@timeframes_lines[ storekey ][ name ] = [] \
unless @timeframes_lines[ storekey ].key?( name )
@timeframes_lines[ storekey ][ name ].push(
loc: "loc#{@qscript.lines}_2", scene: @timeframe,
key: reportkey, text: text
)
end
# add an item to the timeframes lines
def add_list( storekey, reportkey, token, name )
reportkey2 = "#{reportkey}#{token}"
add_list_text( storekey, reportkey2, name, tname( storekey, name ) )
end
# add an prop to the timeframes lines
def add_prop( storekey, reportkey, token, list )
name, owner, hands, puppet = list
reportkey2 = "#{reportkey}#{token}"
line = [ role( owner ), tname( storekey, name ) ]
add_list_text( storekey, reportkey2, name, line )
add_list_text( 'Role', reportkey2, owner, line )
unless hands.nil?
hands.each do |hand|
next if hand.casecmp( 'none' ).zero?
add( 'Actor', hand )
add_list_text( 'Actor', reportkey2, hand, line )
add_actor_for( hand, name )
end
end
return if puppet.nil?
return if reportkey == 'HanP'
add_list_text( 'Puppet', reportkey2, puppet, line )
end
# add a spoken line to the current timeframe
def add_spoken( type, name )
add_list_text( "#{type}_sum_spoken", 'Spokn', name, nil )
end
# add a full list or hash to the current timeframe
def list( key )
return [] unless @timeframes[ @timeframe ].key?( key )
timeframes[ @timeframe ][ key ]
end
end
# === Class Store
# Store.new( timeframe )
# Store.items
# Store.collection
# Store.current_roles
# Store.timeframe
# Store.ignore
# Store.add( collection, key, val )
# Store.count( collection, key )
# Store.add_item( type, name, hash )
# Store.error_message( list )
# Store.check_actor( name )
# Store.check_puppet( role, name )
# Store.check_puppet_pool( role, name )
# Store.check_clothing( puppet, name )
# Store.uniq_player( player, prefix, name )
# Store.add_role_collection( name, what, player )
# Store.last_role( role, what )
# Store.add_person( name, what, player, prefix )
# Store.add_voice( name, voice )
# Store.add_puppet( name, puppet )
# Store.add_clothing( name, clothing )
# Store.drop_one_clothing( role, puppet, clothing )
# Store.store_role( name, list )
# Store.add_role( name, list )
# Store.add_backdrop( position, backdrop )
class Store
# map items type to location index
ITEM_TYPE_INDEX = {
'FrontProp' => 0,
'SecondLevelProp' => 1,
'Backdrop' => 2,
'Light' => 3,
'Ambience' => 4,
'Sound' => 5,
'Video' => 6,
'Effect' => 7,
'Role' => 8,
'Actor' => 9,
'Puppet' => 10,
'Costume' => 11,
'PersonalProp' => 12,
'HandProp' => 13,
'TechProp' => 13,
'SpecialEffect' => 14,
'Todo' => 15
}.freeze
# list we will collect over all scenes
COLLECTION_FIELDS = [
'notes',
'role_puppets',
'role_costumes',
'role_old_costumes',
'owned_props',
'PersonalProp_owner',
'HandProp_owner',
'TechProp_owner',
'SpecialEffect_owner',
'stagehand',
'todos'
].freeze
# items list
attr_reader :items
# collection list
attr_reader :collection
# current roles list
attr_reader :current_roles
# timeframe object
attr_reader :timeframe
# hash of placeholder names
attr_reader :ignore
# create a store
def initialize( timeframe )
@items = {}
@collection = {}
@current_roles = {}
ITEM_TYPE_INDEX.each_key do |key|
@items[ key ] = {}
@collection[ key ] = {}
@collection[ "#{key}_count" ] = {}
end
COLLECTION_FIELDS.each do |field|
@collection[ field ] = {}
end
@roles = {}
@timeframe = timeframe
@ignore = {
'Actor' => 0,
'Hands' => 0,
'Puppet' => 0,
'Costume' => 0,
nil => 0
}
end
# add an item to the collection
def add( collection, key, val )
@collection[ collection ][ key ] = val
end
# count an item in the collection
def count( collection, key )
storekey = "#{collection}_count"
@collection[ storekey ] = {} unless @collection.key?( storekey )
if @collection[ storekey ].key?( key )
@collection[ storekey ][ key ] += 1
else
@collection[ storekey ][ key ] = 1
end
end
# add an item to the collection
def add_item( type, name, hash )
unless @items[ type ].key?( name )
count = @items[ type ].size
item_index = ITEM_TYPE_INDEX[ type ]
@items[ type ][ name ] = {}
@items[ type ][ name ][ :ref ] = "item#{item_index}_#{count}"
@items[ type ][ name ][ :list ] = []
# @items[ type ][ name ][ :name ] = name
end
play = {
loc: "loc#{@timeframe.qscript.lines}_2",
scene: @timeframe.timeframe
}.merge( hash )
@items[ type ][ name ][ :name ] = hash[ :text ] \
unless @items[ type ][ name ].key?( :name )
@items[ type ][ name ][ :list ] << play
end
# add an error_message
def error_message( *list )
list.join( ' ' )
end
# check an actor for collisions
def check_actor( name )
return nil unless @items[ 'Actor' ].key?( name )
seen = {}
# pp @items[ 'Actor' ][ name ]
# pp @items[ 'Actor' ][ name ][ :list ]
@items[ 'Actor' ][ name ][ :list ].each do |item|
next if item[ :scene ] != @timeframe.timeframe
if item.key?( :stagehand )
unless $debug.zero?
if seen.key?( :player )
return error_message(
"Person '#{name}' can't act as a stagehand",
"for '#{item[ :prop ]}',",
"because it's already Player/Hands",
"for '#{seen[ :player ].join( ',' )}'"
)
end
seen[ :stagehand ] = [] unless seen.key?( :stagehand )
seen[ :stagehand ].push( item[ :prop ] )
end
next
end
next if !item.key?( :player ) && !item.key?( :hands )
unless $debug.zero?
if seen.key?( :stagehand )
return error_message(
"Player/Hands for '#{item[ :role ]}' can't be set to '#{name}',",
"because it's already a stagehand",
"for '#{seen[ :stagehand ].join( ',' )}'"
)
end
end
seen[ :player ] = [] unless seen.key?( :player )
seen[ :player ].push( item[ :role ] )
if seen[ :player ].uniq.size > 1
return error_message(
"Player/Hands for '#{item[ :role ]}' can't be set to '#{name}',",
"because it's already a Player/Hands",
"of role '#{seen[ :player ].join( ',' )}'"
)
end
end
nil
end
# check a puppet for collisions
def check_puppet( role, name )
return nil unless @items[ 'Costume' ].key?( name )
seen = []
@items[ 'Costume' ][ name ][ :list ].each do |item|
next if item[ :scene ] != @timeframe.timeframe
seen.push( item[ :role ] )
end
if seen.uniq.size > 1
return error_message(
"Puppet for '#{role}' can't be set to '#{name}',",
"because it's already a Puppet",
"of role '#{seen.join( ',' )}'"
)
end
nil
end
# check a puppet for wiki pool
def check_puppet_pool( role, name )
return nil if $puppet_builders.key?( name )
error_message( "Puppet '#{name}' for '#{role}' is not in the pool" )
end
# check a costume for collisions
def check_clothing( puppet, name )
return nil unless @items[ 'Costume' ].key?( name )
return nil if name.casecmp( 'none' ).zero?
seen = {}
@items[ 'Costume' ][ name ][ :list ].each do |item|
next if item[ :scene ] != @timeframe.timeframe
seen[ :puppet ] = [] unless seen.key?( :puppet )
seen[ :puppet ].push( item[ :puppet ] )
end
if seen[ :puppet ].uniq.size > 1
return error_message(
"Costume for '#{puppet}' can't be set to '#{name}',",
"because it's already a Costume",
"of puppet '#{seen[ :puppet ].join( ',' )}'"
)
end
nil
end
# create a uniq player name if needed
def uniq_player( player, prefix, name )
if player.nil? || @ignore.key?( player )
@ignore[ prefix ] += 1
return "#{prefix}_#{name}"
end
player.strip!
player.sub( /^\(/, '' ).sub( /\)$/, '' )
end
# track changing players
def add_role_collection( name, what, player )
@current_roles[ name ] = {} unless @current_roles.key?( name )
@current_roles[ name ][ what ] = player
return if player.nil?
@collection[ 'Role' ][ name ] = {} unless @collection[ 'Role' ].key?( name )
unless @collection[ 'Role' ][ name ].key?( what )
@collection[ 'Role' ][ name ][ what ] = [ player ]
return
end
return if @collection[ 'Role' ][ name ][ what ].include?( player )
@collection[ 'Role' ][ name ][ what ].push( player )
end
# get current player
def last_role( role, what )
return nil unless @current_roles[ role ].key?( what )
@current_roles[ role ][ what ]
end
# add an actor to a role
def add_person( name, what, player, prefix )
player = uniq_player( player, prefix, name )
return player if player.casecmp( 'none' ).zero?
add_role_collection( name, what, player )
add( 'Actor', player, name )
if what == 'voice'
if last_role( name, 'player' ) != player
@timeframe.add( 'Actor', player )
@timeframe.add_actor_for( player, name, what )
end
else
@timeframe.add( 'Actor', player )
@timeframe.add_actor_for( player, name, what )
end
@timeframe.add_list_text(
'Role', 'Pers+', name, [ [ role( name ), what ], actor( player ) ]
)
@timeframe.add_list_text(
'Actor', 'Pers+', player, [ [ role( name ), what ], actor( player ) ]
)
player
end
# add a hands to a role
def add_hands( name, hands )
# p [ 'add_hands', name, hands ]
uhands = []
hands.each do |player|
player = uniq_player( player, 'Hands', name )
uhands.push( player )
next if player.casecmp( 'none' ).zero?
add( 'Actor', player, name )
@timeframe.add( 'Actor', player )
@timeframe.add_actor_for( player, name, 'hands' )
@timeframe.add_list_text(
'Role', 'Pers+', name, [ [ role( name ), 'hands' ], actor( player ) ]
)
@timeframe.add_list_text(
'Actor', 'Pers+', player, [ [ role( name ), 'hands' ], actor( player ) ]
)
end
add_role_collection( name, 'hands', uhands )
uhands
end
# add a voice to a role
def add_voice( name, voice )
add_person( name, 'voice', voice, 'Actor' )
end
# add a puppet to a role
def add_puppet( name, puppet )
puppet = uniq_player( puppet, 'Puppet', name )
return puppet if puppet.casecmp( 'none' ).zero?
add( 'role_puppets', name, puppet )
add( 'Puppet', puppet, name )
@timeframe.add( 'Puppet', puppet )
@timeframe.add_list_text(
'Role', 'Pupp+', name, [ role( name ), puppet( puppet ) ]
)
@timeframe.add_list_text(
'Puppet', 'Pupp+', puppet, [ role( name ), puppet( puppet ) ]
)
puppet
end
# add a clothing to a role
def add_clothing( name, clothing )
clothing = uniq_player( clothing, 'Costume', name )
return clothing if clothing.casecmp( 'none' ).zero?
add( 'role_costumes', name, clothing )
add( 'Costume', clothing, name )
@timeframe.add( 'Costume', clothing )
@timeframe.add_list_text( 'Role', 'Clth+', name, [ name, clothing ] )
puppet = @collection[ 'role_puppets' ][ name ]
@timeframe.add_list_text(
'Puppet', 'Clth+', puppet, [ name, clothing ]
)
@timeframe.add_list_text(
'Costume', 'Clth+', clothing, [ name, clothing ]
)
clothing
end
# drop a clothing for a role
def drop_one_clothing( role, puppet, clothing )
# p [ 'drop_one_clothing', role, puppet, clothing ]
collection[ 'role_old_costumes' ][ role ] = clothing
add( 'role_old_costumes', role, clothing )
@timeframe.add_list_text(
'Role', 'Clth-', role, [ role( role ), clothing( clothing ) ]
)
@timeframe.add_list_text(
'Costume', 'Clth-', clothing, [ role( role ), clothing( clothing ) ]
)
puppet = @collection[ 'role_puppets' ][ role ] if puppet.nil?
return if puppet.nil?
@timeframe.add_list_text(
'Puppet', 'Clth-', puppet, [ role( role ), clothing( clothing ) ]
)
end
# save a role with all actors, puppet and clothing
def store_role( name, list )
player, hands, voice, puppet, clothing = list
voice = voice.nil? ? player : voice
hands = hands.nil? ? player : hands
add_item(
'Role', name,
player: player, hands: hands, voice: voice,
puppet: puppet, clothing: clothing
)
add_item( 'Actor', player, role: name, player: true ) \
unless player.casecmp( 'none' ).zero?
add_item( 'Actor', voice, role: name, voice: true ) \
unless voice.casecmp( 'none' ).zero?
hands.each do |hand|
next if hand.casecmp( 'none' ).zero?
add_item( 'Actor', hand, role: name, hands: true )
end
add_item( 'Puppet', puppet, role: name, clothing: clothing )
return if clothing.nil?
add_item( 'Costume', clothing, role: name, puppet: puppet )
end
# add a role
def add_role( name, list )
# p [ 'add_role', name, list ]
count( 'Role', name )
# add( 'Role', name, {} )
@timeframe.add( 'Role', name )
player, hands, voice, puppet, clothing = list
uplayer = add_person( name, 'player', player, 'Actor' )
voice = voice.nil? ? uplayer : voice
uvoice = add_voice( name, voice )
hands = hands.nil? ? [ uplayer ] : hands
uhands = add_hands( name, hands )
upuppet = add_puppet( name, puppet )
uclothing = add_clothing( name, clothing )
uhands.each do |uhand|
@timeframe.add_hash(
'puppet_plays', upuppet, [ name, uplayer, uhand, uvoice, uclothing ]
)
end
store_role( name, [ uplayer, uhands, uvoice, upuppet, uclothing ] )
end
# add a backdrop at given position
def add_backdrop( position, backdrop )
key = "#{backdrop} #{position}"
count( 'Backdrop', key )
@timeframe.add( 'Backdrop', key )
add_item( 'Backdrop', key, position: position )
key
end
end
# === Class Functions
# Report.new( store, qscript )
# Report.puppet_costumes
# Report.todo_list
# Report.assignment_list
# Report.put_html( line )
# Report.puts_html( line )
# Report.find_item_of_type( name, type )
# Report.find_item( name )
# Report.html_object_ref( name )
# Report.to_html( ref, name )
# Report.html_object_name( name )
# Report.html_p( arr )
# Report.puts2_key( key, name, text = nil )
# Report.puts2_key_token( key, token, name, text = nil )
# Report.capitalize( item )
# Report.href( item )
# Report.html_li_ref_item( ref, item )
# Report.html_li_p_ref_item( ref, item )
# Report.html_li_p2_ref_item( ref, scene, key, item )
# Report.html_li_item( item )
# Report.html_u_ref_item( ref, item )
# Report.html_u_item( item )
# Report.add_head( item )
# Report.add_script( item )
# Report.list_title_quoted( list, prefix )
# Report.list_quoted( list, prefix, type )
# Report.make_unsorted( list, type )