diff --git a/app/models/field.rb b/app/models/field.rb index d7bc98d..2d6e78d 100644 --- a/app/models/field.rb +++ b/app/models/field.rb @@ -24,7 +24,11 @@ class Field < ApplicationRecord after_create :zalozeni def zalozeni - + return true if planet.is_a? Planet::Arrakis + self.update_attributes(population: 20000, material: 5000.0) + Estate.create(field_id: self.id, building_id: Building::Population::Town.first.id, number: 2) + Estate.create(field_id: self.id, building_id: Building::Solar::Market.first.id, number: 1) + Estate.create(field_id: self.id, building_id: Building::Material::Mine.first.id, number: 1) end end diff --git a/app/models/house/atreides.rb b/app/models/house/atreides.rb index c3ce750..55caffe 100644 --- a/app/models/house/atreides.rb +++ b/app/models/house/atreides.rb @@ -20,4 +20,7 @@ class House::Atreides < House + def self.model_name + House.model_name + end end diff --git a/app/models/house/corrino.rb b/app/models/house/corrino.rb index 6073d7c..f9c6819 100644 --- a/app/models/house/corrino.rb +++ b/app/models/house/corrino.rb @@ -20,4 +20,7 @@ class House::Corrino < House + def self.model_name + House.model_name + end end diff --git a/app/models/house/empire.rb b/app/models/house/empire.rb index 607daf1..6846c79 100644 --- a/app/models/house/empire.rb +++ b/app/models/house/empire.rb @@ -20,4 +20,7 @@ class House::Empire < House + def self.model_name + House.model_name + end end diff --git a/app/models/house/harkonnen.rb b/app/models/house/harkonnen.rb index ad593a8..04ec012 100644 --- a/app/models/house/harkonnen.rb +++ b/app/models/house/harkonnen.rb @@ -20,4 +20,7 @@ class House::Harkonnen < House + def self.model_name + House.model_name + end end diff --git a/app/models/house/renegat.rb b/app/models/house/renegat.rb index 517c89b..3daa364 100644 --- a/app/models/house/renegat.rb +++ b/app/models/house/renegat.rb @@ -20,4 +20,7 @@ class House::Renegat < House + def self.model_name + House.model_name + end end diff --git a/app/models/house/titan.rb b/app/models/house/titan.rb index 1dd7f24..31a891b 100644 --- a/app/models/house/titan.rb +++ b/app/models/house/titan.rb @@ -20,4 +20,7 @@ class House::Titan < House + def self.model_name + House.model_name + end end diff --git a/app/models/planet.rb b/app/models/planet.rb index 9cf8abf..ebb1f23 100644 --- a/app/models/planet.rb +++ b/app/models/planet.rb @@ -62,15 +62,15 @@ def self.vytvor(name, system, position, to_all = false) bonuses[k] = [n = rand(100), p = rand(100)] negative += n positive += p - }.each { |k, v| + }.each { |ke, va| # vypocitame pomerove procenta pro kazdou polozku jak zaporna tak kladna (pokud by nahodnou vsechna vysla 0 obejdeme deleni nulou) - n_percent = (negative == 0 ? 0 : (v[0].to_f / negative.to_f) * (Bonus::TYPES.keys.length * Bonus::PER_TYPE)) - p_percent = (positive == 0 ? 0 : (v[1].to_f / positive.to_f) * (Bonus::TYPES.keys.length * Bonus::PER_TYPE)) + n_percent = (negative == 0 ? 0 : (va[0].to_f / negative.to_f) * (Bonus::TYPES.keys.length * Bonus::PER_TYPE)) + p_percent = (positive == 0 ? 0 : (va[1].to_f / positive.to_f) * (Bonus::TYPES.keys.length * Bonus::PER_TYPE)) # zjistime jestli hodnota bonusu neprevysuje maximalni povolenou hodnotu a pokud ano nastavime ji na maximum a nasledne zapornou odecteme od kladne bonus = (p_percent > Bonus::MAX_PER_TYPE ? Bonus::MAX_PER_TYPE : p_percent) - (n_percent > Bonus::MIN_PER_TYPE ? Bonus::MIN_PER_TYPE : n_percent) # procenta bonusu prevedeme na realne hodnoty bonusu definovane v konstantach a prevedeme na procentualni hodnotu # mozna by nebylo od veci to prevest na int, protoze napriklad lena jsou jen cela cisla, da se poresit prepisem metody, viz. nize - bonuses[k] = ((Bonus::TYPES[k] / 100.0) * bonus * 100.0).round + bonuses[ke] = ((Bonus::TYPES[ke] / 100.0) * bonus * 100.0).round } system_id = System.where(name: system).first.id diff --git a/app/models/planet/caladan.rb b/app/models/planet/caladan.rb index a2ca508..abd3898 100644 --- a/app/models/planet/caladan.rb +++ b/app/models/planet/caladan.rb @@ -28,4 +28,8 @@ def self.vytvor fields_count: 0 ) end + + def fields_creation + + end end diff --git a/app/models/planet/giedi_prima.rb b/app/models/planet/giedi_prima.rb index 415298c..bca4f98 100644 --- a/app/models/planet/giedi_prima.rb +++ b/app/models/planet/giedi_prima.rb @@ -28,4 +28,8 @@ def self.vytvor fields_count: 0 ) end + + def fields_creation + + end end diff --git a/app/models/planet/kaitan.rb b/app/models/planet/kaitan.rb index d267961..ded71c5 100644 --- a/app/models/planet/kaitan.rb +++ b/app/models/planet/kaitan.rb @@ -28,4 +28,8 @@ def self.vytvor fields_count: 0 ) end + + def fields_creation + + end end diff --git a/app/models/planet/salusa_secundus.rb b/app/models/planet/salusa_secundus.rb index 17d97f7..7d65710 100644 --- a/app/models/planet/salusa_secundus.rb +++ b/app/models/planet/salusa_secundus.rb @@ -28,4 +28,8 @@ def self.vytvor fields_count: 0 ) end + + def fields_creation + + end end diff --git a/app/models/planet/titania.rb b/app/models/planet/titania.rb index 453c2b4..25254e1 100644 --- a/app/models/planet/titania.rb +++ b/app/models/planet/titania.rb @@ -32,4 +32,8 @@ def self.vytvor exp_bonus: 50 ) end + + def fields_creation + + end end diff --git a/app/models/planet/tulapin.rb b/app/models/planet/tulapin.rb index 78bc4f9..68378be 100644 --- a/app/models/planet/tulapin.rb +++ b/app/models/planet/tulapin.rb @@ -28,4 +28,8 @@ def self.vytvor fields_count: 0 ) end + + def fields_creation + + end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 707e8fa..53f9ffd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -4,10 +4,10 @@ # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + config.cache_classes = true # Do not eager load code on boot. - config.eager_load = false + config.eager_load = true # Show full error reports. config.consider_all_requests_local = true diff --git a/config/initializers/devise_permitted_parameters.rb b/config/initializers/devise_permitted_parameters.rb index cbbee2a..7553cf7 100644 --- a/config/initializers/devise_permitted_parameters.rb +++ b/config/initializers/devise_permitted_parameters.rb @@ -8,8 +8,8 @@ module DevisePermittedParameters protected def configure_permitted_parameters - devise_parameter_sanitizer.for(:sign_up) << :name - devise_parameter_sanitizer.for(:account_update) << :name + devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) + devise_parameter_sanitizer.permit(:account_update, keys: [:name]) end end diff --git a/config/routes.rb b/config/routes.rb index 5b03e97..369f07a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,10 @@ resources :fields resources :planets resources :houses + # House.subclasses.each do |klass| + # k = klass.name.pluralize.underscore.to_sym + # resources k, :controller => 'houses' + # end root to: 'visitors#index' devise_for :users resources :users diff --git a/db/migrate/20160924193431_add_username_to_users.rb b/db/migrate/20160924193431_add_username_to_users.rb new file mode 100644 index 0000000..d110a94 --- /dev/null +++ b/db/migrate/20160924193431_add_username_to_users.rb @@ -0,0 +1,5 @@ +class AddUsernameToUsers < ActiveRecord::Migration[5.0] + def change + add_column :users, :username, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 4badb20..ab17f72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160923212649) do +ActiveRecord::Schema.define(version: 20160924193431) do create_table "buildings", force: :cascade do |t| t.string "type" @@ -119,6 +119,7 @@ t.decimal "melange", default: "0.5" t.integer "research", default: 250 t.integer "influence", default: 0 + t.string "username" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/db/seeds.rb b/db/seeds.rb index d7b732a..1a511ec 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -353,3 +353,16 @@ Planet::Titania.vytvor p 'Planet done' + +User.create(:username => 'Norma_Cenva', :name => 'Norma Cenva', :email => 'normacenva@spojka.vg', :house_id => titan.id, :password => 'doktoros', :password_confirmation => 'doktoros', :admin => true) +User.create(:username => 'Doktor', :name => 'Doktor', :email => 'admin@dunaonline.cz', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true) +User.create(:username => 'Gilbertus_Albans', :name => 'Gilbertus Albans', :email => 'administr@dunaonline.cz', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true) +# User.create(:username => 'Simi', :name => 'Simi', :email => 'administrator@dunaonline.cz', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true) +# User.create(:username => 'minohimself', :name => 'minohimself', :email => 'adminhimself@dunaonline.cz', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true) +puts 'User done' + +norma = User.find_by_username('Norma_Cenva') +doktor = User.find_by_username('Doktor') +gilbertus = User.find_by_username('Gilbertus_Albans') +# simi = User.find_by_username('Simi') +# mino = User.find_by_username('minohimself') \ No newline at end of file