Permalink
Browse files

Created a pack (contains scenes) resource. Made imported scenes autom…

…atically get put into a pack(s). Added pack selector when picking scenes.
  • Loading branch information...
1 parent 3695c59 commit 439a26cd14c49679a0a692d141ef2908faf32bdb @Spooner committed Oct 31, 2010
@@ -6,12 +6,17 @@ module Sidney
class ResourceBrowser < Composite
DEFAULT_BORDER_COLOR = Color.rgb(255, 255, 255)
- attr_reader :value
+ def value; @group.value; end
- def refresh
- refresh_group
+ def type=(type)
+ @type = type
+ refresh
+ value
+ end
- selected_resource = @value
+ def refresh
+ selected_resource = @group.value
+ recreate_group
# TODO: This search should be _very_ much better...
resources = @type.all
@@ -24,10 +29,11 @@ def refresh
end
@label.text = "#{@object_grid.size} found from #{resources.size}"
+ # See if the previously selected resource is still in the list and if so, select it again.
if resources.find {|r| r == selected_resource }
@group.value = selected_resource
else
- publish :changed, @value
+ publish :changed, nil
end
nil
@@ -53,17 +59,18 @@ def initialize(parent, type, options = {})
@label = Label.new(inner_container)
+ @group = RadioButton::Group.new(inner_container) # Dummy group. Will be replaced.
+
@text_entry.text = options[:search] # This will create the group and new radios.
end
protected
- def refresh_group
- inner_container.remove @group if @group
+ def recreate_group
+ inner_container.remove @group
@group = RadioButton::Group.new(inner_container) do |group|
@object_grid = GridPacker.new(group, width: 135, num_columns: 3)
group.subscribe :changed do |sender, value|
- @value = value
publish :changed, value
end
end
View
@@ -1,7 +1,8 @@
# encoding: utf-8
+require_relative 'resources/pack'
+require_relative 'resources/room'
require_relative 'resources/sprite'
require_relative 'resources/tile'
-require_relative 'resources/room'
require_relative 'resources/state_object'
-require_relative 'resources/scene'
+require_relative 'resources/scene'
@@ -0,0 +1,20 @@
+# encoding: utf-8
+
+require_relative 'visual_resource'
+
+module Sidney
+ class Pack < Resource
+ has_and_belongs_to_many :scenes
+ has_one :sprite
+
+ def image
+ @image ||= Image.create(32, 32, color: :red)
+ @image.rect 10, 10, 22, 22
+ @image
+ end
+
+ def thumbnail
+ image
+ end
+ end
+end
@@ -4,19 +4,23 @@
require_relative 'visual_resource'
require_relative 'room'
require_relative 'state_object_layer'
+require_relative 'pack'
module Sidney
class Scene < VisualResource
belongs_to :room
has_many :state_object_layers
has_many :state_objects, through: :state_object_layers
+ has_and_belongs_to_many :packs
# Manage saving tint (Gosu::Color) as json.
before_save JsonSerializationWrapper.new(:tint)
after_save JsonSerializationWrapper.new(:tint)
after_find JsonSerializationWrapper.new(:tint)
+ after_create :link_to_packs
+
CURRENT_VERSION = 2
DEFAULT_OBJECT_ZERO_FROZEN = false
DEFAULT_TINT = Color.rgba(0, 0, 0, 0)
@@ -95,6 +99,36 @@ def self.default_attributes(attributes = {})
super(attributes)
end
+ # After creating, link the scene to a pack.
+ def link_to_packs
+ # If a scene has a prefix, put it into that pack. E.g. JPNmegacat will be put into the pack JPN.
+ if pack_name = name[/^[A-Z]{2,}/]
+ add_to_pack(pack_name)
+ else
+ add_to_pack('NOPACK') # Put in this if we couldn't find a prefix.
+ end
+
+ add_to_pack('IMPORTED') # All SiD resources are put in this pack.
+
+ nil
+ end
+
+ # Add to a pack, by name. If the pack does not exist, create it.
+ def add_to_pack(pack_name)
+ # TODO: Need to calculate a better ID. But from what?
+ pack_id = pack_name.downcase.tr(' ', 'x').ljust(12, "x")
+
+ if Pack.exists?(pack_id)
+ packs << Pack.find(pack_id)
+ else
+ pack = packs.build(name: pack_name, sprite_id: "dummysprite1")
+ pack.id = pack_id
+ pack.save!
+ end
+
+ nil
+ end
+
protected
def to_binary
layers = @state_object_layers ? @state_object_layers : state_object_layers.order(:z)
View
@@ -127,12 +127,17 @@
t.primary_key :id
t.string :name, null: false
-
- t.string :scene_id, null: false
+ t.string :sprite_id, limit: uid_length, null: false
end
add_index :packs, :id, unique: true
+ # Packs->Scenes join table.
+ create_table :packs_scenes, id: false do |t|
+ t.string :pack_id, limit: uid_length, null: false
+ t.string :scene_id, limit: uid_length, null: false
+ end
+
# Stories (contains scenes via frames).
create_table :stories, id: false do |t|
t.string :id, limit: uid_length, null: false
@@ -9,6 +9,13 @@ def initialize
super
HorizontalPacker.new(container) do |packer|
+ # Picking a pack limits which scenes will be found in the scene picker.
+ @pack_picker = ResourceBrowser.new(packer, Pack) do |picker|
+ picker.subscribe :changed do |sender, value|
+ @scene_picker.type = value.scenes
+ end
+ end
+
@scene_picker = ResourceBrowser.new(packer, Scene, search: 'jp', square_icons: false) do |picker|
picker.subscribe :changed do |sender, value|
if value
@@ -0,0 +1,8 @@
+require_relative 'resource_helper'
+
+require 'pack'
+include Sidney
+
+describe Pack do
+
+end

0 comments on commit 439a26c

Please sign in to comment.