Skip to content

Commit

Permalink
Implement a task to auto-generate ordered carboxes
Browse files Browse the repository at this point in the history
- The format carboxes/ is generated in is used by the RVA Website.
  • Loading branch information
BGMP committed May 15, 2022
1 parent 228ce58 commit 0d3ff0e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
# Packaging
*.zip
packages.json
carboxes
48 changes: 47 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'zip'
require 'digest'
require_relative 'data'

task default: %i[clean package version]
task default: %i[clean package carboxes version]

task :clean do
deleted_bytes = 0.0.to_f
Expand Down Expand Up @@ -87,6 +87,52 @@ task version: [:package] do
end
end

task :carboxes do
car_ratings = {
0 => 'rookie',
1 => 'amateur',
2 => 'advanced',
3 => 'semi-pro',
4 => 'pro',
5 => 'super-pro',
6 => 'clockwork'
}

Dir.mkdir('carboxes') unless File.exist?('carboxes')
(0..6).each do |i|
Dir.mkdir("carboxes/#{car_ratings[i]}") unless File.exist?("carboxes/#{car_ratings[i]}")
end

Dir.entries('cars').each do |f|
next if f.eql?('.') || f.eql?('..')

params_path = "cars/#{f}/parameters.txt"
carbox_path = if File.exist?("cars/#{f}/carbox.bmp")
"cars/#{f}/carbox.bmp"
else
"cars/#{f}/box.bmp"
end

car_rating = nil
car_slug = nil
File.open(params_path) do |pf|
pf.each_line do |l|
car_slug = l.split.drop(1).join(' ').gsub('"', '').gsub(' ', '_').downcase if l.start_with? 'Name'

next unless l.start_with? 'Rating'

car_rating = if !car_slug.nil? && car_slug.start_with?('clockwork')
6
else
l.split[1].to_i
end
end
end

FileUtils.cp(carbox_path, "carboxes/#{car_ratings[car_rating]}/#{car_slug}.bmp")
end
end

def bytes_to_mb(bytes)
format_number((bytes.to_f / 2**20).round(2))
end
Expand Down

0 comments on commit 0d3ff0e

Please sign in to comment.