Skip to content

Commit

Permalink
seed adminu
Browse files Browse the repository at this point in the history
  • Loading branch information
padrta committed Sep 27, 2016
1 parent 0d8ac72 commit 99b342e
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 10 deletions.
6 changes: 5 additions & 1 deletion app/models/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions app/models/house/atreides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

class House::Atreides < House

def self.model_name
House.model_name
end
end
3 changes: 3 additions & 0 deletions app/models/house/corrino.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

class House::Corrino < House

def self.model_name
House.model_name
end
end
3 changes: 3 additions & 0 deletions app/models/house/empire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

class House::Empire < House

def self.model_name
House.model_name
end
end
3 changes: 3 additions & 0 deletions app/models/house/harkonnen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

class House::Harkonnen < House

def self.model_name
House.model_name
end
end
3 changes: 3 additions & 0 deletions app/models/house/renegat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

class House::Renegat < House

def self.model_name
House.model_name
end
end
3 changes: 3 additions & 0 deletions app/models/house/titan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

class House::Titan < House

def self.model_name
House.model_name
end
end
8 changes: 4 additions & 4 deletions app/models/planet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/planet/caladan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ def self.vytvor
fields_count: 0
)
end

def fields_creation

end
end
4 changes: 4 additions & 0 deletions app/models/planet/giedi_prima.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ def self.vytvor
fields_count: 0
)
end

def fields_creation

end
end
4 changes: 4 additions & 0 deletions app/models/planet/kaitan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ def self.vytvor
fields_count: 0
)
end

def fields_creation

end
end
4 changes: 4 additions & 0 deletions app/models/planet/salusa_secundus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ def self.vytvor
fields_count: 0
)
end

def fields_creation

end
end
4 changes: 4 additions & 0 deletions app/models/planet/titania.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ def self.vytvor
exp_bonus: 50
)
end

def fields_creation

end
end
4 changes: 4 additions & 0 deletions app/models/planet/tulapin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ def self.vytvor
fields_count: 0
)
end

def fields_creation

end
end
4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/devise_permitted_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20160924193431_add_username_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUsernameToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :username, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,16 @@
Planet::Titania.vytvor

p 'Planet done'

User.create(:username => 'Norma_Cenva', :name => 'Norma Cenva', :email => '[email protected]', :house_id => titan.id, :password => 'doktoros', :password_confirmation => 'doktoros', :admin => true)
User.create(:username => 'Doktor', :name => 'Doktor', :email => '[email protected]', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true)
User.create(:username => 'Gilbertus_Albans', :name => 'Gilbertus Albans', :email => '[email protected]', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true)
# User.create(:username => 'Simi', :name => 'Simi', :email => '[email protected]', :house_id => titan.id, :password => 'Abcd1234', :password_confirmation => 'Abcd1234', :admin => true)
# User.create(:username => 'minohimself', :name => 'minohimself', :email => '[email protected]', :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')

0 comments on commit 99b342e

Please sign in to comment.