Module: Cocoslicer
- Defined in:
- lib/cocoslicer.rb,
lib/cocoslicer/version.rb
Defined Under Namespace
Classes: ImageInfo, Point, Rect, Size
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.main ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/cocoslicer.rb', line 135 def self.main if ARGV[0] == nil puts 'Need a argv as plist filename' exit end doc = Plist::parse_xml(ARGV[0]) if doc == nil puts ARGV[0] + ' is not a valid plist file.' exit end path = ARGV[0].gsub(/(.*)\/(.*)/, '\1/') = doc['metadata'] tex_name = ['realTextureFileName'] if tex_name != nil then tex_name = path + tex_name if not FileTest::exist? tex_name then puts tex_name + ' is not exist.' exit end else tex_name = ARGV[0].gsub(/(.*)\.plist/, '\1.png') if not FileTest::exist? tex_name then puts tex_name + ' is not exist.' exit end end frames = doc['frames'] if frames == nil puts ARGV[0] + ' is not a valid cocos2d resource plist file.' exit end infos = [] frames.each { |key, value| puts "#{key} => #{value}" info = ImageInfo.new info.name = path + key info.frame = Rect.new.import_from_str(value['frame']) info.offset = Point.new.import_from_str(value['offset']) info.rotated = value['rotated'] info.source_color_rect = Rect.new.import_from_str(value['sourceColorRect']) info.source_size = Size.new.import_from_str(value['sourceSize']) puts info info.slice_img(tex_name) } end |