summaryrefslogtreecommitdiffhomepage
path: root/cards/card.rb
blob: 3d76d22346fbb84c8425daf1ba4a34a109c391e5 (plain)
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
require 'paggio'
require 'paggio/markdown'
class Card
  attr_accessor(
    :attrib_top_left,     :attrib_top_left_icon, 
    :attrib_top_right,    :attrib_top_right_icon,
    :attrib_bottom_left,  :attrib_bottom_left_icon,
    :attrib_bottom_right, :attrib_bottom_right_icon,
    :color,
    :title,
    :flavour,
    :type
  )

  def actions
    @actions ||= []
  end

  def initialize(
    title:,
    color:,
    attrib_top_right: nil,
    attrib_top_right_icon: '🩸',
    blood: nil,
    attrib_top_left: nil,
    attrib_top_left_icon: '🎲',
    roll: nil,
    attrib_bottom_right: nil,
    attrib_bottom_right_icon: '🛡️',
    reposte: nil,
    defence: nil,
    attrib_bottom_left: nil,
    attrib_bottom_left_icon: '⚔️',
    damage: nil,
    actions: [],
    flavour: nil,
    type: nil
  )
    attrib_top_right ||= blood.to_s unless blood.nil?
    attrib_bottom_right ||= defence.to_s unless defence.nil?
    attrib_bottom_right ||= reposte.to_s unless reposte.nil?
    attrib_bottom_left ||= damage.to_s unless damage.nil?
    attrib_top_left ||= roll.to_s unless roll.nil?
    self.title = title
    self.color = color
    self.attrib_top_left = attrib_top_left
    self.attrib_top_left_icon = attrib_top_left_icon
    self.attrib_top_right = attrib_top_right
    self.attrib_top_right_icon = attrib_top_right_icon
    self.attrib_bottom_right = attrib_bottom_right
    self.attrib_bottom_right_icon = attrib_bottom_right_icon
    self.attrib_bottom_left = attrib_bottom_left
    self.attrib_bottom_left_icon = attrib_bottom_left_icon
    self.actions.push *actions
    self.flavour = flavour
    self.type = type
  end

  class Action
    attr_accessor :content, :symbol, :seperator

    def initialize(content:, symbol: nil, seperator: false)
      self.content = content
      self.symbol = Array(symbol)
      self.seperator = seperator
    end

    def symbol
      @symbol ||= []
    end

  end

  class << self
    def build(cards)
      Paggio.html do |_|
        _.head do
          _.style do
            rule 'body' do
              background color: '#1e1e1e'
            end
            rule 'p' do
              margin 0
            end
            rule 'button' do
              font size: 50.px
              padding 30.px
              margin 30.px
            end
            rule '.card_wrapper' do
              min height: (1425 * 2).px
              width (825 * 7).px
              display :flex
              flex wrap: :wrap
              height 100.%
            end
            rule '.card' do
              height 1425.px
              width 825.px
              background color: :black
              display :flex
            end
            rule '.group' do
              margin '50px 50px 0px 50px'
              border radius: 25.px
              display :flex
              flex direction: :column
              #background color: :black
              align content: 'space-between'
              height :auto
              flex 2
              gap 35.px
            end
            rule '.title' do
              background color: :black
              color :antiquewhite
              flex 3
              border radius: 25.px
              overflow :hidden

              position :relative
              font size: 85.px
              display :flex
              align items: :center
              justify content: :center
              text align: :center
              flex direction: :column
              padding 25.px
              border width: '2px 2px 2px 2px'
              border color: :black
              border style: :solid
            end
            rule '.attrib_icon' do
              background color: 'rgba(255,255,255,0.10)'
            end
            rule '.attrib_tl' do
              position :absolute
              top 0
              left 0
              border radius: '0 0 50px 0'
              border color: 'rgba(255,255,255,0.50)'
              border style: :solid
              border width: '0 5px 5px 0'
              padding '15px 25px 15px 15px'
            end
            rule '.attrib_tr' do
              position :absolute
              top 0
              right 0
              border radius: '0 0 0 50px'
              border color: 'rgba(255,255,255,0.50)'
              border style: :solid
              border width: '0 0 5px 5px'
              padding '15px 15px 15px 25px'
            end
            rule '.attrib_br' do
              position :absolute
              bottom 0
              right 0
              border radius: '50px 0 0 0'
              border color: 'rgba(255,255,255,0.50)'
              border style: :solid
              border width: '5px 0 0 5px'
              padding '15px 15px 15px 25px'
            end
            rule '.attrib_bl' do
              position :absolute
              bottom 0
              left 0
              border radius: '0 50px 0 0'
              border color: 'rgba(255,255,255,0.50)'
              border style: :solid
              border width: '5px 5px 0 0'
              padding '15px 25px 15px 15px'
            end
            rule '.attrib_top_icons' do
              top 0
            end
            rule '.attrib_bottom_icons' do
              bottom 0
            end
            rule '.content' do
              background color: :antiquewhite
              color :black
              flex 5
              border radius: 25.px
              overflow :hidden
              position :relative

              font size: 50.px
              display :flex
              justify content: 'flex-start'
              gap 5.px
              text align: :left
              padding '35px 30px 30px 30px'
              flex direction: :column
              border width: '2px 2px 2px 2px'
              border color: :black
              border style: :solid
            end
            rule '.tap_icon' do
              background color: :black
            end
            rule '.joker_icon' do
              background color: :black
              padding '6px 3px 2px 5px'
            end
            rule '.blood_icon' do
              background color: :black
              padding '6px 3px 2px 5px'
            end
            rule '.suit_icon' do
              background color: :black
              text align: :center
              font size: 60.px
              line height: 40.px
            end
            rule '.spades_icon' do
              color :antiquewhite
            end
            rule '.clubs_icon' do
              color :antiquewhite
            end
            rule '.diamonds_icon' do
              color :orangered
            end
            rule '.hearts_icon' do
              color :orangered
            end
            rule '.odd_icon' do
              background color: :black
              padding '12px 0px 0px 12px'
              font size: 30.px
              height 48.px
              width 48.px
            end
            rule '.even_icon' do
              background color: :black
              padding '12px 0px 0px 12px'
              font size: 30.px
              height 48.px
              width 48.px
            end
            rule '.greater_icon' do
              background color: :black
              padding '12px 0px 0px 12px'
              font size: 30.px
              height 48.px
              width 48.px
            end
            rule '.lesser_icon' do
              background color: :black
              padding '12px 0px 0px 12px'
              font size: 30.px
              height 48.px
              width 48.px
            end
            rule '.face_icon' do
              background color: :black
              #padding '12px 0px 0px 12px'
              #font size: 30.px
              #height 48.px
              #width 48.px
              padding '6px 3px 2px 5px'
            end
            rule '.icon' do
              display 'inline-block'
              padding '8px 4px 0px 4px'
              border radius: 15.px
              aspect ratio: '1/1'
              font size: 40.px
              height 52.px
              width 52.px
            end
            rule '.card_type' do
              background color: :antiquewhite
              text align: :center
              font size: 40.px
              padding 10.px
              border radius: '15px 15px 0 0'
              font weight: :bold
              border width: '2px 2px 0 2px'
              border color: :black
              border style: :solid
            end
            rule '.symbol_wrapper_outer' do
              display 'flex'
              gap 20.px
            end
            rule '.symbol_wrapper_inner' do
              display 'flex'
              flex direction: 'column'
              gap 5.px
            end
            rule '.action_detail' do
              padding top: 0.px
              text align: :left
            end
            rule '.flavour_wrapper' do
              position :absolute
              bottom 0
              left 0
              width 100.%
                text align: :center
            end
            rule '.flavour' do
              color 'rgba(0,0,0,0.5)'
              padding 35.px
              font size: 35.px
            end
          end
        end
      _.button onclick: "downloadAsImage()" do
        "Download"
      end
      _.div.card_wrapper.card_wrapper! do
        cards.each do |card|
          _.div.card(style: "background:linear-gradient(225deg, rgba(0,0,0,1) -50%, #{card.color} 100%)") do
            _.div.group do
              _.div.title do
                if card.attrib_top_left && card.attrib_top_left_icon
                  _.div.attrib_icon.attrib_tl do
                    card.attrib_top_left_icon + ' ' + card.attrib_top_left
                  end
                end
                if card.attrib_top_right && card.attrib_top_right_icon
                  _.div.attrib_icon.attrib_tr do
                    card.attrib_top_right + ' ' + card.attrib_top_right_icon
                  end
                end
                _.p card.title if card.title
                if card.attrib_bottom_left && card.attrib_bottom_left_icon
                  _.div.attrib_icon.attrib_bl do
                    card.attrib_bottom_left_icon + ' ' + card.attrib_bottom_left
                  end
                end
                if card.attrib_bottom_right && card.attrib_bottom_right_icon
                  _.div.attrib_icon.attrib_br do
                    card.attrib_bottom_right + ' ' + card.attrib_bottom_right_icon
                  end
                end
              end
              _.div.content do
                card.actions.each do |action|
                  _.div.action do
                    _.hr if action.seperator
                    if !action.symbol.empty?
                      _.div.symbol_wrapper_outer do
                        _.div.symbol_wrapper_inner do
                          #build_symbol
                          if action.symbol.include? :tap
                            _.span.icon.tap_icon do
                              "↪️"
                            end
                          end
                          if action.symbol.include? :spades
                            _.span.icon.suit_icon.spades_icon do
                              "♠️"
                            end
                          end
                          if action.symbol.include? :clubs
                            _.span.icon.suit_icon.clubs_icon do
                              "♣️"
                            end
                          end
                          if action.symbol.include? :diamonds
                            _.span.icon.suit_icon.diamonds_icon do
                              "♦️"
                            end
                          end
                          if action.symbol.include? :hearts
                            _.span.icon.suit_icon.hearts_icon do
                              "♥️"
                            end
                          end
                          if action.symbol.include? :joker
                            _.span.icon.joker_icon do
                              "🃏"
                            end
                          end
                          if action.symbol.include? :blood
                            _.span.icon.blood_icon do
                              "🩸"
                            end
                          end
                          if action.symbol.include? :odd
                            _.span.icon.odd_icon do
                              "🔻"
                            end
                          end
                          if action.symbol.include? :even
                            _.span.icon.even_icon do
                              "⬜"
                            end
                          end
                          if action.symbol.include? :face
                            _.span.icon.face_icon do
                              "🎭"
                            end
                          end
                          if action.symbol.include? :greater
                            _.span.icon.greater_icon do
                              "➕"
                            end
                          end
                          if action.symbol.include? :lesser
                            _.span.icon.lesser_icon do
                              "➖"
                            end
                          end
                        end
                        _.div.action_detail do
                          _.markdown <<-MD
              #{action.content}
                          MD
                        end
                      end
                    else
                      _.markdown <<-MD
            #{action.content}
                      MD
                    end
                  end
                end
                if card.flavour
                  _.div.flavour_wrapper do
                    _.div.flavour do
                      _.hr
                      _.markdown <<-MD
              #{card.flavour}
                      MD
                    end
                  end
                end
                #_.p do
                #  _.span.tap_icon do
                #    "↪️"
                #  end
                #  _.markdown <<-MD
                #    Attack with a 🎲 **d6** roll.  
                #    On success deal ⚔️ **2 damage**.
                #  MD
                #end
                ##p "↪️ My content will go here at some point."
                #_.p do
                #  _.span.face_icon do 
                #    "♠️"
                #  end
                #  _.text "My content will go here at some point."
                #end
                #_.div do
                #  _.hr
                #  _.p "this is just some flavour text"
                #end
              end
              _.div.card_type do
                card.type
              end
            end
          end
        end
      end
      _.script src: "./web/bundle.js"
      _.script do
        <<-SCRIPT
function downloadAsImage() {
  htmlToImage.toPng(document.getElementById('card_wrapper'))
    .then(function (dataUrl) {
      download(dataUrl, 'card_wrapper.png');
    });
}
        SCRIPT
      end
      end
    end
  end
end