# -*- ruby -*- # # $Id$ # # smagacor - a collection of small games in ruby # Copyright (C) 2004 Thomas Leitner # # This program is free software; you can redistribute it and/or modify it under the terms of the GNU # General Public License as published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along with this program; if not, # write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # begin require 'rubygems' require 'rake/gempackagetask' rescue Exception nil end require 'rake/clean' require 'rake/packagetask' require 'rake/rdoctask' require 'rake/testtask' # General actions ############################################################## $:.push "lib" require 'smagacor/util' PKG_NAME = "smagacor" PKG_VERSION = Smagacor::VERSION.join( '.' ) PKG_FULLNAME = PKG_NAME + "-" + PKG_VERSION PKG_SUMMARY = "A collection of small games in ruby" PKG_DESCRIPTION = "Smagacor is a collection of some small games, like TicTacToe and Pong. Adding new games should not be to hard, as Smagacor provides some useful classes for games." SRC_RB = FileList['lib/**/*.rb', 'bin/**/*', 'data/**/*.rb'] # The default task is run if rake is given no explicit arguments. desc "Default Task" task :default => :version # End user tasks ################################################################ desc "Prepares for installation" task :prepare do ruby "setup.rb config" ruby "setup.rb setup" end desc "Installs the package #{PKG_NAME}" task :install => [:prepare] do ruby "setup.rb install" end task :clean do ruby "setup.rb clean" end CLOBBER << "doc/output" << FileList['texput.*'].to_a desc "Builds the documentation (needs webgen installed)" task :doc => [:rdoc, :gen_version] do chdir "doc" do sh "webgen -V 3" end end rd = Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'doc/output/rdoc' rdoc.title = PKG_NAME rdoc.options << '--line-numbers' << '--inline-source' << '-m README' rdoc.rdoc_files.include( 'README' ) rdoc.rdoc_files.include( SRC_RB ) end task 'test' do |t| ruby "-Ilib -Itest test/runtests.rb" end # Developer tasks ############################################################## PKG_FILES = FileList.new( [ 'setup.rb', 'TODO', 'COPYING', 'README', 'Rakefile', 'ChangeLog', 'VERSION', 'bin/**/*', 'lib/**/*', 'doc/**/*', 'test/**/*', 'data/**/*' ]) do |fl| fl.exclude( 'doc/output' ) end PKG_FILES_DUPPED = PKG_FILES.clone task :gen_changelog do sh "svn log -r HEAD:1 -v > ChangeLog" end task :gen_version do puts "Generating VERSION file" File.open( 'VERSION', 'w+' ) do |file| file.write( PKG_VERSION + "\n" ) end end task :gen_files => [:gen_changelog, :gen_version, :gen_otherdata] CLOBBER << "ChangeLog" << "VERSION" desc "Workaround because generated graphcis are not included" task :check_gen_included do if !(PKG_FILES == PKG_FILES_DUPPED) puts puts puts "!!! File list changed! You need to invoke the rake task again!" puts puts exit end end task :package => [:gen_files, :check_gen_included] Rake::PackageTask.new( PKG_NAME, PKG_VERSION ) do |p| p.need_tar = true p.need_zip = true p.package_files = PKG_FILES end if defined? Gem spec = Gem::Specification.new do |s| #### Basic information s.name = PKG_NAME s.version = PKG_VERSION s.summary = PKG_SUMMARY s.description = PKG_DESCRIPTION #### Dependencies, requirements and files s.files = PKG_FILES s.autorequire = nil s.executables = [ 'smagacor'] s.default_executable = 'smagacor' #### Documentation s.has_rdoc = true s.extra_rdoc_files = rd.rdoc_files.reject do |fn| fn =~ /\.rb$/ end.to_a s.rdoc_options = ['--line-numbers', '-m', 'README'] #### Author and project details s.author = "Thomas Leitner" s.email = "t_leitner@gmx.at" s.homepage = "smagacor.rubyforge.org" s.rubyforge_project = "smagacor" end Rake::GemPackageTask.new( spec ) do |pkg| pkg.need_zip = true pkg.need_tar = true end end desc "Upload documentation to homepage" task :uploaddoc => [:doc] do Dir.chdir('doc/output') sh "scp -r * gettalong@rubyforge.org:/var/www/gforge-projects/#{PKG_NAME}/" end # Misc tasks ################################################################### begin require 'RMagick' include Magick ICON_SIZE=64 def data_path( game ) "data/smagacor/#{game}" end def src_newer?( src, dest ) !File.exists?( dest ) || File.mtime( src ) > File.mtime( dest ) end def inkscape_export_svg( svg, png, width ) sh "inkscape -z --export-png=#{png} -w #{width} -j -i layer1 #{svg}" if src_newer?( svg, png ) end def povray( pov, png, size ) sh "povray #{pov} -geometry #{size[0]}x#{size[1]} +Q9 +A +O'#{png}'" if src_newer?( pov, png ) end CLOBBER << File.join( data_path('tictactoe'), 'tictactoe.png' ) CLOBBER << File.join( data_path('tictactoe'), 'x.png' ) CLOBBER << File.join( data_path('tictactoe'), 'o.png' ) task :gen_game_tictactoe do inkscape_export_svg( 'otherdata/tictactoe/tictactoe.svg', File.join( data_path('tictactoe'), 'tictactoe.png' ), ICON_SIZE ) inkscape_export_svg( 'otherdata/tictactoe/x.svg', File.join( data_path('tictactoe'), 'x.png' ), 100 ) inkscape_export_svg( 'otherdata/tictactoe/o.svg', File.join( data_path('tictactoe'), 'o.png' ), 100 ) end CLOBBER << File.join( data_path('sokoban'), 'sokoban.png' ) CLOBBER << File.join( data_path('sokoban'), 'crate.png' ) CLOBBER << File.join( data_path('sokoban'), 'storage.png' ) CLOBBER << File.join( data_path('sokoban'), 'floor.png' ) CLOBBER << File.join( data_path('sokoban'), 'wall.png' ) CLOBBER << File.join( data_path('sokoban'), 'man.png' ) task :gen_game_sokoban do cd 'otherdata/sokoban' do %w[crate storage floor wall man].each do |pov| dest = File.join( '../../' + data_path('sokoban'), pov + '.png') povray( pov + '.pov', dest, [128,128] ) end end # make crate.png, storage.png pixels transparent ['crate.png', 'storage.png', 'man.png'].each do |png| img = Image.read( File.join( data_path( 'sokoban'), png ) ).first img.fuzz = 10 img = img.matte_replace( 0, 0 ) img.write( File.join( data_path( 'sokoban' ), png ) ) end # create logo w = ICON_SIZE/4 img = Image.new( ICON_SIZE, ICON_SIZE ) { self.background_color = 'white' } tiles = ImageList.new( *%w[crate storage floor wall man].collect {|f| File.join( data_path( 'sokoban'), f+'.png' ) } ) tiles.each { |tile| tile.change_geometry!( "#{w}x#{w}" ) {|c,r,i| i.resize!(c,r)} } lvl = "3333 3013 3243 3333" lvl.split( /\n/ ).each_with_index do |line, y| line.unpack( 'C*' ).each_with_index do |c,x| img.composite!( tiles[2], w*x, w*y, OverCompositeOp ) img.composite!( tiles[c.chr.to_i], w*x, w*y, OverCompositeOp ) end end img.write( File.join( data_path( 'sokoban' ), 'sokoban.png' ) ) end task :gen_otherdata => [:gen_game_tictactoe, :gen_game_sokoban] rescue end