rpg-tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +15 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +6 -0
  4. data/.yardopts +3 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.textile +28 -0
  8. data/Rakefile +27 -0
  9. data/app/models/tools/check_roll.rb +82 -0
  10. data/app/models/tools/die.rb +35 -0
  11. data/app/models/tools/throw.rb +71 -0
  12. data/config/locales/en.yml +11 -0
  13. data/lib/generators/rpg_tools/install_generator.rb +21 -0
  14. data/lib/generators/rpg_tools/templates/initializer.rb +3 -0
  15. data/lib/rpg_tools.rb +11 -0
  16. data/lib/rpg_tools/engine.rb +11 -0
  17. data/rpg_tools.gemspec +30 -0
  18. data/spec/dummy/Gemfile +6 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  21. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  22. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  23. data/spec/dummy/config.ru +4 -0
  24. data/spec/dummy/config/application.rb +45 -0
  25. data/spec/dummy/config/boot.rb +10 -0
  26. data/spec/dummy/config/database.yml +22 -0
  27. data/spec/dummy/config/environment.rb +5 -0
  28. data/spec/dummy/config/environments/development.rb +26 -0
  29. data/spec/dummy/config/environments/production.rb +49 -0
  30. data/spec/dummy/config/environments/test.rb +35 -0
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/dummy/config/initializers/inflections.rb +10 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  34. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  35. data/spec/dummy/config/initializers/session_store.rb +8 -0
  36. data/spec/dummy/config/locales/en.yml +5 -0
  37. data/spec/dummy/config/routes.rb +60 -0
  38. data/spec/dummy/db/test.sqlite3 +0 -0
  39. data/spec/dummy/public/404.html +26 -0
  40. data/spec/dummy/public/422.html +26 -0
  41. data/spec/dummy/public/500.html +26 -0
  42. data/spec/dummy/public/favicon.ico +0 -0
  43. data/spec/dummy/public/javascripts/application.js +2 -0
  44. data/spec/dummy/public/javascripts/controls.js +965 -0
  45. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  46. data/spec/dummy/public/javascripts/effects.js +1123 -0
  47. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  48. data/spec/dummy/public/javascripts/rails.js +191 -0
  49. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  50. data/spec/dummy/public/stylesheets/scaffold.css +56 -0
  51. data/spec/dummy/script/rails +6 -0
  52. data/spec/integration/navigation_spec.rb +9 -0
  53. data/spec/models/tools/check_roll_spec.rb +116 -0
  54. data/spec/models/tools/die_spec.rb +29 -0
  55. data/spec/models/tools/throw_spec.rb +55 -0
  56. data/spec/rpg_tools_spec.rb +7 -0
  57. data/spec/spec_helper.rb +36 -0
  58. metadata +216 -0
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/log/*.log
5
+ spec/dummy/tmp/
6
+ spec/dummy/.project
7
+ **.tmp_*
8
+ Gemfile.lock
9
+ .idea
10
+ .project
11
+ .document
12
+ .settings/
13
+ rdoc/
14
+ doc/
15
+ .yardoc/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - rbx
5
+ - ree
6
+
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ lib/**/*.rb
2
+ app/**/*.rb
3
+ app/models/tools/*.rb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Eduardo Casanova Cuesta
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,28 @@
1
+ h1. RPG Tools
2
+
3
+ #TODO
4
+
5
+ h2. Installation
6
+
7
+ Add to your Gemfile:
8
+ <pre><code>
9
+ gem 'rpg_tools'
10
+ </code></pre>
11
+ Then run:
12
+ <pre><code>
13
+ bundle update
14
+ </code></pre>
15
+
16
+ h2. Using RPG Tools. API
17
+
18
+ #TODO
19
+
20
+ h2. License
21
+
22
+ Copyright (c) 2011 Eduardo Casanova Cuesta
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
25
+
26
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ begin
3
+ require 'bundler/setup'
4
+ require 'bundler'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+ require 'rake'
9
+ require 'rake/rdoctask'
10
+
11
+ require 'rspec/core'
12
+ require 'rspec/core/rake_task'
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ task :default => :spec
17
+
18
+ Rake::RDocTask.new do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = "Fuzion RPG"
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README.rdoc')
23
+ rdoc.rdoc_files.include('lib/**/*.rb', 'app/**/*.rb')
24
+ end
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,82 @@
1
+ class Tools::CheckRoll
2
+
3
+ attr_accessor :throw, :threshold, :rolling_chances, :greater_than_threshold, :equal_than_threshold
4
+ attr_reader :result
5
+ def initialize throw, threshold, rolling_chances=1, greater_than_threshold=true, equal_than_threshold=true
6
+ @throw = throw
7
+ @threshold = threshold
8
+ @rolling_chances = rolling_chances
9
+ @greater_than_threshold = greater_than_threshold
10
+ @equal_than_threshold = equal_than_threshold
11
+ end
12
+
13
+ #[true/false,best_rolled]
14
+ def roll
15
+ return @result if @result
16
+ best_rolled = 0
17
+ @rolling_chances.times do
18
+ rolled_throw = @throw.roll 1,true #Detailed throw
19
+ best_rolled = rolled_throw if rolled_throw[0] > best_rolled[0]
20
+ end
21
+ @result = [compare(best_rolled[0], @threshold),best_rolled]
22
+ result
23
+ end
24
+
25
+ def reroll
26
+ @result = nil
27
+ roll
28
+ end
29
+
30
+ def is_successful?
31
+ roll if @result.blank?
32
+ return @result[0]
33
+ end
34
+
35
+ def result
36
+ [@result[0],@result[1][0]]
37
+ end
38
+
39
+ def detailed_result
40
+ @result
41
+ end
42
+
43
+ def to_s
44
+ string = "#{@throw.to_s} #{I18n.t('rpg_tools.check_roll.must_be')} #{comparatives_text} #{@threshold}."
45
+ if @result
46
+ string << " #{I18n.t('rpg_tools.check_roll.already_checked')}"
47
+ string << " #{@result[0] ? I18n.t('rpg_tools.check_roll.success') : I18n.t('rpg_tools.check_roll.failure')}"
48
+ string << " (#{@result[1][0]})."
49
+ end
50
+ string
51
+ end
52
+
53
+ private
54
+
55
+ def compare rolled_throw, threshold
56
+ gtt = @greater_than_threshold
57
+ ett = @equal_than_threshold
58
+ if gtt and ett
59
+ return rolled_throw >= threshold
60
+ elsif gtt and !ett
61
+ return rolled_throw > threshold
62
+ elsif !gtt and !ett
63
+ return rolled_throw < threshold
64
+ elsif !gtt and ett
65
+ return rolled_throw <= threshold
66
+ end
67
+ end
68
+
69
+ def comparatives_text
70
+ gtt = @greater_than_threshold
71
+ ett = @equal_than_threshold
72
+ if gtt and ett
73
+ return I18n.t 'rpg_tools.check_roll.greater_and_equal'
74
+ elsif gtt and !ett
75
+ return I18n.t 'rpg_tools.check_roll.greater'
76
+ elsif !gtt and !ett
77
+ return I18n.t 'rpg_tools.check_roll.less'
78
+ elsif !gtt and ett
79
+ return I18n.t 'rpg_tools.check_roll.less_and_equal'
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,35 @@
1
+ class Tools::Die
2
+ attr_accessor :sides
3
+
4
+ def initialize sides=20
5
+ @sides = sides
6
+ end
7
+
8
+ # Rolls the die and returns result as +Fixnum+ if rolls==1 or as +Array+ of +Fixnum+
9
+ # if rolls>1.
10
+ def roll rolls=1
11
+ return simple_roll if rolls==1
12
+ results = Array.new
13
+ rolls.times do
14
+ results << simple_roll
15
+ end
16
+ return results
17
+ end
18
+
19
+ # Returns the die as a string with the format Dx, where x is the number of sides. Example "D6", "D20", "D100", etc.
20
+ def to_s
21
+ return "D#{@sides}"
22
+ end
23
+
24
+ # Return true if the dice are equal, i.e. they have the same number of sides.
25
+ def eql? die
26
+ return false if die==nil or die.sides!=@sides
27
+ return true
28
+ end
29
+
30
+ private
31
+
32
+ def simple_roll
33
+ 1 + rand(sides)
34
+ end
35
+ end
@@ -0,0 +1,71 @@
1
+ class Tools::Throw
2
+ attr_accessor :dice, :offset
3
+
4
+ def initialize dice, offset=0
5
+ @dice = dice.sort_by{|die| die.sides}
6
+ @offset = offset
7
+ end
8
+
9
+ # Rolls the dice, add the offset and returns result as +Fixnum+ if rolls==1 or as
10
+ # +Array+ of +Fixnum+ if rolls>1.
11
+ def roll rolls=1, detailed=false
12
+ return simple_roll if rolls==1 and !detailed
13
+ return detailed_roll if rolls==1 and detailed
14
+ results = Array.new
15
+ rolls.times do
16
+ results << simple_roll if !detailed
17
+ results << detailed_roll if detailed
18
+ end
19
+ return results
20
+ end
21
+
22
+ # Returns the dice as a string with the format aDx,bDy,cDz+n, where a,b,c are the number of dice,
23
+ # x,y,z are the number of sides and n the offset. Example "D6,D20,D100+8", etc.
24
+ def to_s
25
+ throw_dice_number = Array.new
26
+ throw_dice = Array.new
27
+ temp_dice = dice.sort_by{|die| die.sides}
28
+ last_die = nil
29
+ temp_dice.each do |temp_die|
30
+ if !temp_die.eql? last_die
31
+ last_die = temp_die
32
+ throw_dice << temp_die
33
+ throw_dice_number << temp_dice.count{|die| die.eql? temp_die}
34
+ end
35
+ end
36
+ throw_string = ""
37
+ throw_dice.each_index do |i|
38
+ throw_string << "," if i>0
39
+ throw_string << throw_dice_number[i].to_s + throw_dice[i].to_s
40
+ end
41
+ throw_string << "+" if @offset>0
42
+ throw_string << "#{@offset}" if @offset!=0
43
+ return throw_string
44
+ end
45
+
46
+ private
47
+
48
+ def simple_roll
49
+ total = 0
50
+ dice.each do |die|
51
+ total+= die.roll
52
+ end
53
+ total += offset
54
+ return total
55
+ end
56
+
57
+ def detailed_roll
58
+ results = Array.new
59
+ total = 0
60
+ dice.each do |die|
61
+ roll = die.roll
62
+ total+= roll
63
+ results << roll
64
+ end
65
+ total += offset
66
+ detailed_throw = Array.new
67
+ detailed_throw[0] = total
68
+ detailed_throw[1] = results
69
+ return detailed_throw
70
+ end
71
+ end
@@ -0,0 +1,11 @@
1
+ en:
2
+ rpg_tools:
3
+ check_roll:
4
+ already_checked: "Has already been rolled with"
5
+ failure: "failure"
6
+ greater: "greater than"
7
+ greater_and_equal: "greater or equal to"
8
+ less: "less than"
9
+ less_and_equal: "less or equal to"
10
+ must_be: "must be"
11
+ success: "succes"
@@ -0,0 +1,21 @@
1
+ class RPG_Tools::InstallGenerator < Rails::Generators::Base #:nodoc:
2
+ include Rails::Generators::Migration
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ require 'rails/generators/active_record'
7
+
8
+ def self.next_migration_number(dirname)
9
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
10
+ end
11
+
12
+ def create_initializer_file
13
+ template 'initializer.rb', 'config/initializers/rpg_tools.rb'
14
+ end
15
+
16
+ def create_migration_file
17
+ require 'rake'
18
+ Rails.application.load_tasks
19
+ Rake::Task['rpg_tools_engine:install:migrations'].invoke
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ RPG_Tools.setup do |config|
2
+
3
+ end
data/lib/rpg_tools.rb ADDED
@@ -0,0 +1,11 @@
1
+ module FuzionRPG
2
+ class << self
3
+ def setup
4
+ yield self
5
+ end
6
+ end
7
+
8
+ end
9
+ # reopen ActiveRecord and include all the above to make
10
+ # them available to all our models if they want it
11
+ require 'rpg_tools/engine'
@@ -0,0 +1,11 @@
1
+ module RPG_Tools
2
+ class Engine < Rails::Engine
3
+ =begin
4
+ initializer "rpg_tools.models.*whatever*" do
5
+ ActiveSupport.on_load(:active_record) do
6
+ include RPG_Tools::Models::Whatever
7
+ end
8
+ end
9
+ =end
10
+ end
11
+ end
data/rpg_tools.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rpg-tools"
3
+ s.version = "0.1.0"
4
+ s.authors = ["Eduardo Casanova Cuesta"]
5
+ s.summary = "Some tools useful when creating a RPG: Die, Throw and CheckRoll."
6
+ s.description = "Some tools useful when creating a RPG: Die, Throw and CheckRoll."
7
+ s.email = "ecasanovac@gmail.com"
8
+ s.homepage = "https://github.com/roendal/rpg-tools"
9
+ s.files = `git ls-files`.split("\n")
10
+
11
+ # Gem dependencies
12
+ #
13
+ s.add_runtime_dependency('rails', '~> 3.0.0')
14
+
15
+ # Development Gem dependencies
16
+ #
17
+ # Testing database
18
+ s.add_development_dependency('sqlite3-ruby')
19
+ # Debugging
20
+ if RUBY_VERSION < '1.9'
21
+ s.add_development_dependency('ruby-debug', '~> 0.10.3')
22
+ end
23
+ # Specs
24
+ s.add_development_dependency('rspec-rails', '~> 2.6.1')
25
+ # Fixtures
26
+ s.add_development_dependency('factory_girl', '~> 1.3.2')
27
+ # Integration testing
28
+ s.add_development_dependency('capybara', '~> 1.0.1')
29
+ end
30
+
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rpg_tools', :path => '../../../rpg_tools'
4
+
5
+ gem 'mysql', '2.8.1'
6
+
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>