切切切...

烁灵 posted @ 2015年1月03日 21:50 in Ruby with tags plist , 1560 阅读
require 'sdl'
require "rexml/document"  
include REXML  
SDL.init(SDL::INIT_VIDEO)

row = 4
col = 4

filename = "citizen-1.png"
image = SDL::Surface.load(filename)
w, h = image.w, image.h
if filename[/^(.*)?\.(png|jpg|bmp)?/i]
	p $1, $2
end

picname = $1
ext = $2


doc = Document.new("<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">")
doc << XMLDecl.new(1.0, "utf-8")
root_node = doc.add_element("plist")
root_node.attributes["version"] = "1.0"
root_dict = root_node.add_element("dict") 

# frames
frame_key = root_dict.add_element("key")
frame_key.text = "frames"
frame_dict =  root_dict.add_element("dict")

for i in 0...row
	for j in 0...col
		key = Element.new("key")
		key.text = "#{picname}_#{i * col + j}.#{ext}"
		dict = Element.new("dict")
		# dict
		ek = []
		ev = []
		
		ek[0] = Element.new("key")
		ek[0].text = "width"
		ev[0] = Element.new("integer")
		ev[0].text = (w / col).to_s
		
		ek[1] = Element.new("key")
		ek[1].text = "height"
		ev[1] = Element.new("integer")
		ev[1].text = (h / row).to_s
		
		ek[2] = Element.new("key")
		ek[2].text = "originalWidth"
		ev[2] = Element.new("integer")
		ev[2].text = (w / col).to_s
		
		ek[3] = Element.new("key")
		ek[3].text = "originalHeight"
		ev[3] = Element.new("integer")
		ev[3].text = (h / row).to_s
		
		ek[4] = Element.new("key")
		ek[4].text = "x"
		ev[4] = Element.new("integer")
		ev[4].text = (j * w / row).to_s
		
		ek[5] = Element.new("key")
		ek[5].text = "y"
		ev[5] = Element.new("integer")
		ev[5].text = (i * h / col).to_s
		
		ek[6] = Element.new("key")
		ek[6].text = "offsetX"
		ev[6] = Element.new("real")
		ev[6].text = "0"
		
		ek[7] = Element.new("key")
		ek[7].text = "offsetY"
		ev[7] = Element.new("real")
		ev[7].text = "0"
		
		for t in 0...ek.size
			dict.elements << ek[t]
			dict.elements << ev[t]
		end
		
		frame_dict.elements << key
		frame_dict.elements << dict
		
		# end dict
	end
end
# end frames
	
# metadata
metadata_key = root_dict.add_element("key")
metadata_key.text = "metadata"
metadatat_dict =  root_dict.add_element("dict")

ek = []
ev = []

ek[0] = Element.new("key")
ek[0].text = "format"
ev[0] = Element.new("integer")
ev[0].text = "2"	

ek[1] = Element.new("key")
ek[1].text = "textureFileName"
ev[1] = Element.new("string")
ev[1].text = filename

ek[2] = Element.new("key")
ek[2].text = "realTextureFileName"
ev[2] = Element.new("string")
ev[2].text = filename

ek[3] = Element.new("key")
ek[3].text = "size"
ev[3] = Element.new("string")
ev[3].text = "{#{w},#{h}}"

for t in 0...ek.size
	metadatat_dict.elements << ek[t]
	metadatat_dict.elements << ev[t]
end
#end metadata

# texture
texture_key = root_dict.add_element("key")
texture_key.text = "texture"
texture_dict =  root_dict.add_element("dict")

ek = []
ev = []

ek[0] = Element.new("key")
ek[0].text = "width"
ev[0] = Element.new("integer")
ev[0].text = "#{w}"	

ek[1] = Element.new("key")
ek[1].text = "height"
ev[1] = Element.new("integer")
ev[1].text = "#{h}"

for t in 0...ek.size
	texture_dict.elements << ek[t]
	texture_dict.elements << ev[t]
end
# end texture

file = File.open("#{picname}.plist", "w")
doc.write(file, 4, false, true)
file.close

p doc.xml_decl()

bug啥的慢慢修。

Avatar_small
 https://idnpoker97. 说:
2021年4月03日 07:01

Very nice article. I enjoyed reading your post. very nice share. I want to twit this to my followers. Thanks !.

Avatar_small
poker 说:
2021年4月03日 10:00

Nice post. I was checking constantly this blog and I am impressed!

Avatar_small
Extreme Bio Hazard C 说:
2021年4月04日 00:02

You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!!

Avatar_small
Weebly tradesmen quo 说:
2021年4月05日 22:22

This really is additionally an excellent publish that we truly loved reading through. It's not daily which i possess the likelihood to determine some thing.

Avatar_small
pawn shop goodyear a 说:
2021年4月07日 05:34

Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day!

Avatar_small
keto allergies 说:
2021年4月10日 11:52

Thanks for taking the time to discuss that, I feel strongly about this and so really like getting to know more on this kind of field. Do you mind updating your blog post with additional insight? It should be really useful for all of us.

Avatar_small
where can i sell wat 说:
2021年4月14日 09:00

I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers

Avatar_small
pawn shop in glendal 说:
2021年5月04日 08:57

Everything has its own value, but this is really precious information shared by Author of

Avatar_small
pawn shop in glendal 说:
2021年7月06日 21:55

Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day!

Avatar_small
web 说:
2021年10月27日 16:04

I read this article. I think You put a lot of effort to create this article. I appreciate your work matka result

Avatar_small
WEB 说:
2022年7月14日 17:11

A decent blog dependably concocts new and energizing data and keeping in mind that understanding I have feel that this blog is truly have each one of those quality that qualify a blog to be a one. satta matka

Avatar_small
russian math student 说:
2022年8月20日 02:51

Russian School of Mathematics, RSM Student homework problems, assignments, test in our blog, So come and join Online RSM Student Portal 2021. Please note that you will need your Student Id which you can find by logging into your RSM Portal. All students who wish to attend Homework Help 2021. Russian School of Mathematics, russian math student portal RSM Student homework problems, assignments, test in our blog, So come and join Online RSM Student Portal

Avatar_small
Uttarakhand Board Mo 说:
2022年9月17日 22:03

UK Board Model Paper 2023 Class 11 Pdf Download for School Education Board of Uttarakhand Intermediate 1st Year Solved Question Bank for Arts, Science & Commerce Stream Theory, Objective (MCQ) Question for Paper-1 & Paper-2 Exams at Uttarakhand Board Model Paper Class 11 Uttarakhand Board of School Education (UBSE) have introduced the Higher Secondary Level Intermediate Education Class 11th Standard Arts, Science and Commerce Stream Subject wide Sample Paper suggestions with Answers for all Languages & Subject of the Course to know the new exam scheme or question pattern of Paper-1 & Paper-2 exams of the First Year Intermediate.

Avatar_small
civaget 说:
2024年1月17日 21:22

오피타임's serene environment is my escape from daily stress.

Avatar_small
civaget 说:
2024年1月18日 04:35

The stone massage therapy at 제주출장마사지 is a must-try!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter