full saving pets, serving assets directly from this domain

This commit is contained in:
Emi Matchu 2010-10-09 10:53:58 -04:00
parent ff629b9419
commit 04138ac4a7
8 changed files with 47 additions and 11 deletions

View file

@ -104,8 +104,9 @@ class Item < ActiveRecord::Base
} }
end end
def before_save def before_create
sold_in_mall = false self.sold_in_mall = false
true
end end
def origin_registry_info=(info) def origin_registry_info=(info)

View file

@ -32,6 +32,11 @@ class Pet < ActiveRecord::Base
true true
end end
def before_save
self.pet_type.save
self.items.each(&:save)
end
def self.load(name) def self.load(name)
pet = Pet.find_or_initialize_by_name(name) pet = Pet.find_or_initialize_by_name(name)
pet.load! pet.load!

View file

@ -1,5 +1,3 @@
require 'open-uri'
class PetType < ActiveRecord::Base class PetType < ActiveRecord::Base
IMAGE_CPN_FORMAT = 'http://pets.neopets.com/cpn/%s/1/1.png'; IMAGE_CPN_FORMAT = 'http://pets.neopets.com/cpn/%s/1/1.png';
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/1/1\.png$}; IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/1/1\.png$};

View file

@ -1,4 +1,6 @@
class SwfAsset < ActiveRecord::Base class SwfAsset < ActiveRecord::Base
PUBLIC_ASSET_DIR = File.join('swfs', 'outfit')
LOCAL_ASSET_DIR = Rails.root.join('public', PUBLIC_ASSET_DIR)
set_inheritance_column 'inheritance_type' set_inheritance_column 'inheritance_type'
delegate :depth, :to => :zone delegate :depth, :to => :zone
@ -13,11 +15,7 @@ class SwfAsset < ActiveRecord::Base
} }
def local_url def local_url
uri = URI.parse(url) '/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)
uri.host = RemoteImpressHost
pieces = uri.path.split('/')
uri.path = "/assets/swf/outfit/#{pieces[2]}/#{pieces[4..7].join('/')}"
uri.to_s
end end
def as_json(options={}) def as_json(options={})
@ -50,4 +48,36 @@ class SwfAsset < ActiveRecord::Base
self.zone_id = data[:zone_id].to_i self.zone_id = data[:zone_id].to_i
self.url = data[:asset_url] self.url = data[:asset_url]
end end
def before_create
uri = URI.parse url
response = Net::HTTP.get_response(uri)
if response.is_a? Net::HTTPSuccess
new_local_path = File.join(LOCAL_ASSET_DIR, local_path_within_outfit_swfs)
new_local_dir = File.dirname new_local_path
content = response.body.force_encoding 'utf-8'
FileUtils.mkdir_p new_local_dir
File.open(new_local_path, 'w') do |f|
f.print content
end
else
begin
response.error!
rescue Exception => e
raise "Error loading SWF at #{url}: #{e.message}"
else
raise "Error loading SWF at #{url}. Response: #{response.inspect}"
end
end
end
private
def local_path_within_outfit_swfs
uri = URI.parse(url)
pieces = uri.path.split('/')
relevant_pieces = pieces[4..7]
relevant_pieces.unshift pieces[2]
File.join(relevant_pieces)
end
end end

View file

@ -217,13 +217,13 @@ Preview = new function Preview() {
this.embed = function (id) { this.embed = function (id) {
swf_id = id; swf_id = id;
swfobject.embedSWF( swfobject.embedSWF(
impressUrl('/assets/swf/preview.swf?v=2'), // URL '/swfs/preview.swf?v=2', // URL
id, // ID id, // ID
'100%', // width '100%', // width
'100%', // height '100%', // height
'9', // required version '9', // required version
impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL
{'swf_assets_path': impressUrl('/assets')}, // flashvars {}, // flashvars
{'wmode': 'transparent', 'allowscriptaccess': 'always'} // params {'wmode': 'transparent', 'allowscriptaccess': 'always'} // params
); );
} }

1
public/swfs/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
outfit/*

1
public/swfs/outfit Symbolic link
View file

@ -0,0 +1 @@
/home/matchu/public_html/dev/wearables/www/assets/swf/outfit/

BIN
public/swfs/preview.swf Executable file

Binary file not shown.