-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathgenerate_logos.rb
69 lines (58 loc) · 2.48 KB
/
generate_logos.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
# frozen_string_literal: true
require_relative 'scripts_helper'
DB.extension :pg_array, :pg_advisory_lock, :pg_json, :pg_enum
def generate_logos(game_title, simple = false, overwrite = false, minors = false)
return 'invalid title, use GAME_TITLE' unless (game_class = Engine.game_by_title(game_title))
players = Array.new(game_class::PLAYER_RANGE.max) { |n| "Player #{n + 1}" }
game = game_class.new(players)
# Regenerate to avoid corps that are hidden
corporations = game.send(:init_corporations, game.stock_market)
corporations.concat(game.send(:init_minors)) if minors
# TODO: special handling for 18ZOO maps, 1822+, maybe more?
corporations.each do |corp|
next if simple && corp.logo == corp.simple_logo
filename = "public#{simple ? corp.simple_logo : corp.logo}"
if File.exist?(filename) && !overwrite
puts "File #{filename} already exists"
else
text_adjust = ' textLength="7.2" lengthAdjust="spacingAndGlyphs"'
if /^\d+$/.match?(corp.id)
# numbered minors/privates; force white on black due to 1822
text_color = ' fill="#fff"'
bg_color = '' # default == black
font_size = 5
extra = ''
else
text_color = corp.text_color == 'black' ? '' : " fill=\"#{corp.text_color}\"".gsub('#ffffff', '#fff')
bg_color = if ['black', '#000', '#000000'].include?(corp.color)
''
else
" fill=\"#{corp.color}\"".gsub('#ffffff', '#fff')
end
font_size, extra =
case corp.id.size
when 1, 2
[4, '']
when 3
text_adjust = '' if /[Iijlt]/.match?(corp.id)
[3.25, text_adjust]
when 4
text_adjust = '' if /^[A-Z][a-z]+$/.match?(corp.id)
[3, text_adjust]
else
[2.5, text_adjust]
end
end
y = 3.8 + (font_size * 0.4)
y = y.to_int if (y % 1).zero?
svg = <<~SVG.chomp
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8"><circle cx="4" cy="4" r="4"#{bg_color}/><text x="4" y="#{y}" text-anchor="middle" font-weight="700" font-size="#{font_size}"#{extra} font-family="Arial"#{text_color}>#{corp.id.gsub('&', '&')}</text></svg>
SVG
File.write(filename, svg)
puts "Generated #{filename}"
end
end
end
def generate_all_logos(simple = true, overwrite = false, minors = false)
Engine.all_game_titles.each { |title| generate_logos(title, simple, overwrite, minors) }
end