full saving pets, serving assets directly from this domain
This commit is contained in:
parent
ff629b9419
commit
04138ac4a7
8 changed files with 47 additions and 11 deletions
|
@ -104,8 +104,9 @@ class Item < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def before_save
|
||||
sold_in_mall = false
|
||||
def before_create
|
||||
self.sold_in_mall = false
|
||||
true
|
||||
end
|
||||
|
||||
def origin_registry_info=(info)
|
||||
|
|
|
@ -32,6 +32,11 @@ class Pet < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def before_save
|
||||
self.pet_type.save
|
||||
self.items.each(&:save)
|
||||
end
|
||||
|
||||
def self.load(name)
|
||||
pet = Pet.find_or_initialize_by_name(name)
|
||||
pet.load!
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'open-uri'
|
||||
|
||||
class PetType < ActiveRecord::Base
|
||||
IMAGE_CPN_FORMAT = 'http://pets.neopets.com/cpn/%s/1/1.png';
|
||||
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/1/1\.png$};
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
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'
|
||||
|
||||
delegate :depth, :to => :zone
|
||||
|
@ -13,11 +15,7 @@ class SwfAsset < ActiveRecord::Base
|
|||
}
|
||||
|
||||
def local_url
|
||||
uri = URI.parse(url)
|
||||
uri.host = RemoteImpressHost
|
||||
pieces = uri.path.split('/')
|
||||
uri.path = "/assets/swf/outfit/#{pieces[2]}/#{pieces[4..7].join('/')}"
|
||||
uri.to_s
|
||||
'/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)
|
||||
end
|
||||
|
||||
def as_json(options={})
|
||||
|
@ -50,4 +48,36 @@ class SwfAsset < ActiveRecord::Base
|
|||
self.zone_id = data[:zone_id].to_i
|
||||
self.url = data[:asset_url]
|
||||
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
|
||||
|
|
|
@ -217,13 +217,13 @@ Preview = new function Preview() {
|
|||
this.embed = function (id) {
|
||||
swf_id = id;
|
||||
swfobject.embedSWF(
|
||||
impressUrl('/assets/swf/preview.swf?v=2'), // URL
|
||||
'/swfs/preview.swf?v=2', // URL
|
||||
id, // ID
|
||||
'100%', // width
|
||||
'100%', // height
|
||||
'9', // required version
|
||||
impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL
|
||||
{'swf_assets_path': impressUrl('/assets')}, // flashvars
|
||||
{}, // flashvars
|
||||
{'wmode': 'transparent', 'allowscriptaccess': 'always'} // params
|
||||
);
|
||||
}
|
||||
|
|
1
public/swfs/.gitignore
vendored
Normal file
1
public/swfs/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
outfit/*
|
1
public/swfs/outfit
Symbolic link
1
public/swfs/outfit
Symbolic link
|
@ -0,0 +1 @@
|
|||
/home/matchu/public_html/dev/wearables/www/assets/swf/outfit/
|
BIN
public/swfs/preview.swf
Executable file
BIN
public/swfs/preview.swf
Executable file
Binary file not shown.
Loading…
Reference in a new issue