Fixed scroll bars not appearing. Also implemented load/save of Collections; tied the Library to a collection (libraries are per-project); Most of the File menu works now. Library manager works. Ready to start working on the drag and drop library pallette and tabbed page display at this point.
This commit is contained in:
63
lib/tailor/Collection.rb
Normal file
63
lib/tailor/Collection.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
require 'singleton'
|
||||
|
||||
module Tailor
|
||||
module Collection
|
||||
include Singleton
|
||||
|
||||
attr_accessor :library
|
||||
|
||||
def initialize
|
||||
@metadata = {
|
||||
"author": "",
|
||||
"name": "",
|
||||
"license": ""
|
||||
}
|
||||
self.library = Tailor::Library.new
|
||||
@pages = {}
|
||||
end
|
||||
|
||||
def to_json
|
||||
js = {
|
||||
"metadata" => metadata,
|
||||
"library" => {},
|
||||
"pages" => {}
|
||||
}
|
||||
|
||||
@library.each do |tileset|
|
||||
js['library'][tileset['name']] = tileset.get_filename
|
||||
end
|
||||
@pages.each do |page|
|
||||
js['pages'][page.page_name] = page.to_json
|
||||
end
|
||||
end
|
||||
|
||||
def save_json(filename)
|
||||
dname = File.dirname(filename)
|
||||
Dir.mkdir(dname) unless Dir.exist?(dname)
|
||||
|
||||
File.open(filename, "w") do |file|
|
||||
file.write(JSON.pretty_generate(to_json))
|
||||
end
|
||||
end
|
||||
|
||||
def from_json(js)
|
||||
js['library'].each_pair do |name, filename|
|
||||
@library.load_tileset(filename)
|
||||
end
|
||||
js['pages'].each_pair do |name, data|
|
||||
@pages[name] = Tailor::Page.new
|
||||
@pages[name].from_json(data)
|
||||
end
|
||||
end
|
||||
|
||||
def load_json(filename)
|
||||
dname = File.dirname(filename)
|
||||
Dir.mkdir(dname) unless Dir.exist?(dname)
|
||||
File.open(filename, "r") do |file|
|
||||
js = JSON.parse(file.read)
|
||||
end
|
||||
from_json(js)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
30
lib/tailor/GUI/LibraryManager.rb
Normal file
30
lib/tailor/GUI/LibraryManager.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
require 'wx'
|
||||
require 'Tailor/Library'
|
||||
|
||||
module Tailor
|
||||
module GUI
|
||||
class LibraryManager
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
@library = Tailor::Library.instance
|
||||
@panel = Wx::Panel.new(self)
|
||||
@sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
||||
|
||||
horizSizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
|
||||
vertSizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
||||
@tilesetList = Wx::ListBox.new(@panel,
|
||||
Wx::ID_ANY,
|
||||
Wx::DEFAULT_POSITION,
|
||||
Wx::DEFAULT_SIZE,
|
||||
@library.tileset_names,
|
||||
Wx::LB_SORT | Wx::LB_SINGLE)
|
||||
vertSizer.add(@tilesetList, 0, flags = Wx::EXPAND|Wx::ALL)
|
||||
horizSizer.add(vertSizer, 0, flags = Wx::EXPAND|Wx::ALL)
|
||||
@sizer.add(horizSizer, 1, flag=Wx::EXPAND|Wx::ALL)
|
||||
@panel.set_sizer(@sizer)
|
||||
@sizer.set_size_hints(self)
|
||||
show()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
34
lib/tailor/Library.rb
Normal file
34
lib/tailor/Library.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
require 'Tailor/Tileset'
|
||||
require 'singleton'
|
||||
|
||||
module Tailor
|
||||
class Library
|
||||
include Singleton
|
||||
|
||||
attr_accessor :tilesets
|
||||
|
||||
def initialize
|
||||
self.tilesets = []
|
||||
end
|
||||
|
||||
def tileset_names
|
||||
x = []
|
||||
idx = 0
|
||||
self.tilesets.each do |tileset|
|
||||
x << [idx, tileset.tileset_name]
|
||||
idx += 1
|
||||
end
|
||||
end
|
||||
|
||||
def unload_tileset(tileset)
|
||||
self.tilesets.delete(tileset)
|
||||
end
|
||||
|
||||
def add_tileset(path)
|
||||
ts = Tailor::Tileset.new
|
||||
ts.from_json(JSON.parse(File.read(path)))
|
||||
self.tilesets << ts
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user