Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 9b8c137f17be7efd6fa1ed828ad7fb7e1d906544 Mike Kenyon committed Apr 16, 2012
Showing with 235 additions and 0 deletions.
  1. +13 −0 LICENSE
  2. +20 −0 README.md
  3. +64 −0 Rakefile
  4. +5 −0 bin/map-rotation
  5. +3 −0 lib/map_rotation.rb
  6. +93 −0 lib/map_rotation/map_rotation.rb
  7. +3 −0 lib/map_rotation/version.rb
  8. +17 −0 map_rotation.gemspec
  9. +10 −0 test/helper.rb
  10. +7 −0 test/test_maprotation.rb
13 LICENSE
@@ -0,0 +1,13 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
20 README.md
@@ -0,0 +1,20 @@
+MapRotation
+===========
+
+Builds a new map rotation file for hl2-based games
+
+Usage
+-----
+
+Usage: `map-rotation` [options]
+
+The possible options are:
+
+ -v, --verbose print the maplist to STDOUT as well as to file
+ --dump-config print out current configuration and exit
+
+To start building a configuration fie, run `map-rotation --dump-config >
+map-rotation.yaml` and edit it. The config file is a YAML file that specifies
+the tiers of maps and how many maps to select from each tier. It also has a
+few configuration options for map-rotation itself, but those are all specified
+when you dump the config.
64 Rakefile
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'rake'
+
+def gemspec
+ @gemspec ||= begin
+ file = File.expand_path('../map_rotation.gemspec', __FILE__)
+ eval(File.read(file), binding, file)
+ end
+end
+
+begin
+ require 'rake/gempackagetask'
+rescue LoadError
+ task(:gem) { $stderr.puts '`gem install rake` to package gems' }
+else
+ Rake::GemPackageTask.new(gemspec) do |pkg|
+ pkg.gem_spec = gemspec
+ end
+ task :gem => :gemspec
+end
+
+desc "validate the gemspec"
+task :gemspec do
+ gemspec.validate
+end
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+ end
+rescue LoadError
+ task :rcov do
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
+ end
+end
+
+task :test => :check_dependencies
+
+task :default => :test
+
+task :clean do
+ gems = Dir.glob("**/*.gem")
+ puts gems
+end
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "git-up #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
5 bin/map-rotation
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require 'map_rotation'
+
+MapRotation.new.run
3 lib/map_rotation.rb
@@ -0,0 +1,3 @@
+require 'map_rotation/map_rotation'
+
+MapRotation.new.run
93 lib/map_rotation/map_rotation.rb
@@ -0,0 +1,93 @@
+#!/usr/bin/env ruby
+
+require "yaml"
+
+CONFIG_FN = "map-rotation.yaml"
+DEFAULT_TARGET = "maplist.txt"
+
+USAGE = <<EOS
+Usage: map-rotation [options]
+
+The possible options are:
+
+ -v, --verbose print the maplist to STDOUT as well as to file
+ --dump-config print out current configuration and exit
+
+To start building a configuration fie, run `map-rotation --dump-config >
+map-rotation.yaml` and edit it. The config file is a YAML file that specifies
+the tiers of maps and how many maps to select from each tier. It also has a
+few configuration options for map-rotation itself, but those are all specified
+when you dump the config.
+EOS
+
+if ARGV.delete("--help") || ARGV.delete("-h")
+ puts USAGE
+ exit
+end
+
+class MapRotation
+ class << self
+ attr_accessor :default_cfg
+ end
+
+ @default_cfg = {"tiers"=>[{"tier"=>1, "name"=>"Premier", "choose"=>3, "maps"=>["pl_goldrush", "cp_dustbowl", "pl_badwater"]}, {"tier"=>2, "name"=>"Lengthy Maps", "choose"=>1, "maps"=>["tc_hydro", "plr_hightower", "cp_freight_final1", "cp_fastlane", "cp_well", "cp_granary", "cp_coldfront"]}, {"tier"=>3, "name"=>"Payload", "choose"=>1, "maps"=>["pl_hoodoo_final", "plr_pipeline", "pl_upward", "pl_frontier_final", "pl_barnblitz", "plr_nightfall_final"]}, {"tier"=>4, "name"=>"KOTH", "choose"=>1, "maps"=>["koth_badlands", "koth_harvest_final", "koth_harvest_event", "koth_nucleus", "koth_sawmill", "koth_viaduct", "koth_lakeside_final"]}, {"tier"=>5, "name"=>"CP", "choose"=>1, "maps"=>["cp_gullywash_final1", "cp_gravelpit", "cp_badlands", "cp_gorge", "cp_steel", "cp_5gorge", "cp_degrootkeep", "cp_manor_event", "cp_mountainlab", "cp_yukon_final", "cp_egypt_final", "cp_junction_final"]}, {"tier"=>6, "name"=>"CTF", "choose"=>1, "maps"=>["ctf_doublecross", "ctf_turbine", "ctf_2fort", "ctf_well", "ctf_sawmill"]}, {"tier"=>7, "name"=>"Custom", "choose"=>1, "maps"=>["cp_crossroads_b5", "ctf_turbine_pro_b1", "cp_warmfront", "ctf_2fort_mario_b4", "cp_lwobtsud", "cp_tiplevarg", "pl_retawdab", "cp_warpath2", "cp_lazytown_e", "cp_lazytown_lazynite", "pl_halfacre", "ctf_hallofdeath", "pl_donkeykong_final", "ctf_mach4", "cp_busytown", "ctf_impact2", "cp_castle4", "cp_bighalls_b1", "cp_toy_fort_alt2", "cp_wolf"]}, {"tier"=>8, "name"=>"Arena", "choose"=>1, "maps"=>["arena_badlands", "arena_granary", "arena_lumberyard", "arena_ravine", "arena_well", "arena_offblast_final", "arena_sawmill", "arena_nucleus", "arena_watchtower"]}], "targetFile"=>"maplist.txt", "verbose"=>true}
+
+ def run
+ # Load config
+ cfg = MapRotation.default_cfg.merge begin
+ fn = CONFIG_FN
+ if File.exists?(fn) && (h = YAML::load_file(fn))
+ h
+ else
+ {}
+ end
+ end
+ cfg["verbose"] = true if ARGV.delete("--verbose") || ARGV.delete("-v")
+ cfg["targetFile"] ||= DEFAULT_TARGET
+
+ if ARGV.delete("--dump-config")
+ puts cfg.to_yaml
+ exit 0
+ end
+
+ results = cfg["tiers"].map do |t|
+ t["maps"].shuffle.take(t["choose"].to_i)
+ end
+ results.shuffle!
+ File.open(cfg["targetFile"], 'w') do |f|
+ results.each do |r|
+ f.puts r
+ puts r if cfg["verbose"]
+ end
+ end
+ exit 0
+ end
+end
+
+AUTHOR = "Mike Kenyon"
+
+LICENSE = <<EOS
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+EOS
+
+WARRANTY = <<EOS
+This program is free software. It comes without any warranty, to
+the extent permitted by applicable law. You can redistribute it
+and/or modify it under the terms of the Do What The Fuck You Want
+To Public License, Version 2, as published by Sam Hocevar. See
+http://sam.zoy.org/wtfpl/COPYING for more details.
+EOS
+
+
3 lib/map_rotation/version.rb
@@ -0,0 +1,3 @@
+class Version
+ VERSION = "0.1.0"
+end
17 map_rotation.gemspec
@@ -0,0 +1,17 @@
+lib = File.expand_path('../lib/', __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+require 'map_rotation/version'
+
+Gem::Specification.new do |s|
+ s.name = 'map-rotation'
+ s.version = Version::VERSION
+ s.authors = ["Mike Kenyon"]
+ s.email = ["mike.kenyon@gmail.com"]
+ s.homepage = "http://github.com/mkenyon/map-rotation"
+ s.summary = "Builds a new map rotation file for hl2-based games"
+
+ s.files = Dir.glob("{bin,lib}/**/*") + %w(LICENSE README.md)
+ s.require_path = 'lib'
+ s.executables = Dir.glob("bin/*").map(&File.method(:basename))
+end
10 test/helper.rb
@@ -0,0 +1,10 @@
+require 'rubygems'
+require 'test/unit'
+require 'shoulda'
+
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'git-up'
+
+class Test::Unit::TestCase
+end
7 test/test_maprotation.rb
@@ -0,0 +1,7 @@
+require 'helper'
+
+class TestMapRotation < Test::Unit::TestCase
+ should "probably rename this file and start testing for real" do
+ flunk "hey buddy, you should probably rename this file and start testing for real"
+ end
+end

0 comments on commit 9b8c137

Please sign in to comment.
Something went wrong with that request. Please try again.