1
0
Fork 0
forked from OpenNeo/impress

needed objects

This commit is contained in:
Emi Matchu 2010-11-06 13:07:12 -04:00
parent 446a117ec8
commit ef004cc6cb
9 changed files with 85 additions and 34 deletions

View file

@ -1,8 +1,6 @@
class ItemsController < ApplicationController
before_filter :set_query
layout 'items'
def index
if params.has_key?(:q)
begin
@ -41,6 +39,21 @@ class ItemsController < ApplicationController
@item = Item.find params[:id]
end
def needed
if params[:color] && params[:species]
@pet_type = PetType.find_by_color_id_and_species_id(
params[:color],
params[:species]
)
end
unless @pet_type
raise ActiveRecord::RecordNotFound, 'Pet type not found'
end
@items = @pet_type.needed_items.alphabetize
@pet_name = params[:name]
render :layout => 'application'
end
private
def set_query

View file

@ -16,7 +16,7 @@ class PetsController < ApplicationController
@pet.save
respond_to do |format|
format.html do
destination = params[:destination]
destination = params[:destination] || params[:origin]
destination = 'root' unless DESTINATIONS[destination]
query_joiner = DESTINATIONS[destination]
path = send("#{destination}_path") + query_joiner + @pet.wardrobe_query

View file

@ -68,6 +68,28 @@ class PetType < ActiveRecord::Base
self.color.human_name + ' ' + self.species.human_name
end
def needed_items
items = Item.arel_table
species_matchers = [
"#{species_id},%",
"%,#{species_id},%",
"%,#{species_id}"
]
species_condition = nil
species_matchers.each do |matcher|
condition = items[:species_support_ids].matches(matcher)
if species_condition
species_condition = species_condition.or(condition)
else
species_condition = condition
end
end
unneeded_item_ids = Item.select(items[:id]).joins(:parent_swf_asset_relationships => :object_asset).
where(SwfAsset.arel_table[:body_id].in([0, self.body_id])).map(&:id)
Item.where(items[:id].in(unneeded_item_ids).not).
where(species_condition)
end
def add_pet_state_from_biology!(biology)
pet_state = PetState.from_pet_type_and_biology_info(self, biology)
self.pet_states << pet_state

View file

@ -198,6 +198,15 @@ dd
.current
font-weight: bold
.object .nc-icon
height: 16px
position: absolute
right: ($object-width - $object-img-size) / 2 + $object-padding
top: $object-img-size - $nc-icon-size
width: 16px
&:hover
+opacity(0.5)
/* Fonts
/* A font by Jos Buivenga (exljbris) -> www.exljbris.nl

View file

@ -8,15 +8,6 @@ body.items-index
form
margin-bottom: 2em
.object .nc-icon
height: 16px
position: absolute
right: ($object-width - $object-img-size) / 2 + $object-padding
top: $object-img-size - $nc-icon-size
width: 16px
&:hover
+opacity(0.5)
#search-help
+main_unit
padding-right: 1%

View file

@ -0,0 +1,16 @@
- title "Needed items for #{@pet_type.human_name}"
%h2
= image_tag "http://pets.neopets.com/cpn/#{@pet_name}/1/1.png",
:class => 'inline-image'
%span.pet-name= @pet_name
can model&hellip;
%ul.buttons
%li
= form_tag load_pet_path do
= origin_tag 'needed_items'
= hidden_field_tag 'name', @pet_name
= submit_tag "I'm wearing one now!", :class => 'loud'
%li
= link_to 'What do I own?', 'http://www.neopets.com/closet.phtml',
:class => 'button', :target => '_blank'
= render @items

View file

@ -3,7 +3,6 @@ OpenneoImpressItems::Application.routes.draw do |map|
match '/' => 'items#index', :as => :items
match '/index.js' => 'items#index', :format => :js
match '/items.json' => 'items#index', :format => :json
match '/items/:id' => 'items#show', :as => :item
match '/item_zone_sets.js' => 'ItemZoneSets#index'
match '/item_zone_sets.json' => 'ItemZoneSets#index'
@ -16,7 +15,7 @@ OpenneoImpressItems::Application.routes.draw do |map|
match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show'
resources :contributions, :only => [:index]
resources :items, :only => [:index] do
resources :items, :only => [:index, :show] do
collection do
get :needed
end

View file

@ -175,7 +175,7 @@ function Item(id) {
Item.LOAD_ERROR = new LoadError("$species_article $species wear a $item");
Item.createFromLocation = function () {
var item = new Item(parseInt(document.location.pathname.substr(1))),
var item = new Item(parseInt(document.location.pathname.substr(7), 10)),
z = CURRENT_ITEM_ZONES_RESTRICT, zl = z.length;
item.restricted_zones = [];
for(i = 0; i < zl; i++) {

View file

@ -327,6 +327,22 @@ dd {
font-weight: bold;
}
/* line 201, ../../../app/stylesheets/_layout.sass */
.object .nc-icon {
height: 16px;
position: absolute;
right: 16px;
top: 64px;
width: 16px;
}
/* line 207, ../../../app/stylesheets/_layout.sass */
.object .nc-icon:hover {
-moz-opacity: 0.5;
-webkit-opacity: 0.5;
-o-opacity: 0.5;
-khtml-opacity: 0.5;
}
/* Fonts */
/* A font by Jos Buivenga (exljbris) -> www.exljbris.nl */
@font-face {
@ -457,21 +473,6 @@ body.items-index form {
margin-bottom: 2em;
}
/* line 11, ../../../app/stylesheets/items/_index.sass */
body.items-index .object .nc-icon {
height: 16px;
position: absolute;
right: 16px;
top: 64px;
width: 16px;
}
/* line 17, ../../../app/stylesheets/items/_index.sass */
body.items-index .object .nc-icon:hover {
-moz-opacity: 0.5;
-webkit-opacity: 0.5;
-o-opacity: 0.5;
-khtml-opacity: 0.5;
}
/* line 20, ../../../app/stylesheets/items/_index.sass */
body.items-index #search-help {
float: left;
width: 49%;
@ -481,15 +482,15 @@ body.items-index #search-help {
body.items-index #search-help h2 {
font-size: 125%;
}
/* line 23, ../../../app/stylesheets/items/_index.sass */
/* line 14, ../../../app/stylesheets/items/_index.sass */
body.items-index #search-help dl {
text-align: left;
}
/* line 25, ../../../app/stylesheets/items/_index.sass */
/* line 16, ../../../app/stylesheets/items/_index.sass */
body.items-index #search-help dd {
margin-bottom: 1em;
}
/* line 28, ../../../app/stylesheets/items/_index.sass */
/* line 19, ../../../app/stylesheets/items/_index.sass */
body.items-index #species-search-links {
float: left;
width: 49%;
@ -499,7 +500,7 @@ body.items-index #species-search-links {
body.items-index #species-search-links h2 {
font-size: 125%;
}
/* line 31, ../../../app/stylesheets/items/_index.sass */
/* line 22, ../../../app/stylesheets/items/_index.sass */
body.items-index #species-search-links img {
height: 80px;
width: 80px;