spritesheet 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/lib/spritesheet/base.rb +14 -0
- data/lib/spritesheet/packer.rb +89 -0
- data/lib/spritesheet/spritesheet.rb +6 -6
- data/lib/spritesheet/version.rb +2 -2
- data/lib/spritesheet.rb +6 -10
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42558ded0ba665a79897c0945feb3ac4f45dd7898e91c07273b208f61c1683f3
|
4
|
+
data.tar.gz: 579fce5675a690b90c3156c706b227871a30f83aad5c71f441d6c88cf8d287a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: decc64366caccc575170a3d0d92ead2b089e00b4f2822a61f360c1d9d0f638d1a2f77d8f5a90ab5f9f5eae11d2bba1560488f755e18dad633d601129fb87f4ea
|
7
|
+
data.tar.gz: 80757ac10d6a0bdd5b2c804ea2745237170b8e4af935d21480ada8793078a5f19783239ba3e20edba0ae9fd742d40d960dba909ce99592285d62a7962f40936d
|
data/Manifest.txt
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
## 3rd party
|
2
|
+
require 'pixelart/base'
|
3
|
+
|
4
|
+
|
5
|
+
## our own code
|
6
|
+
require 'spritesheet/version' # note: let version always go first
|
7
|
+
require 'spritesheet/spritesheet'
|
8
|
+
require 'spritesheet/packer'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
puts Pixelart::Module::Spritesheet.banner # say hello
|
14
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
module Pixelart
|
3
|
+
|
4
|
+
|
5
|
+
class Spritesheet
|
6
|
+
|
7
|
+
def self.pack( path,
|
8
|
+
cols: 10,
|
9
|
+
dir: '.',
|
10
|
+
width: 24,
|
11
|
+
height: 24 )
|
12
|
+
|
13
|
+
## check - change dir to image_dir or such - why? why not?
|
14
|
+
|
15
|
+
attributes = CsvHash.read( path )
|
16
|
+
puts " #{attributes.size} record(s)" #=> ??
|
17
|
+
|
18
|
+
|
19
|
+
total = attributes.size
|
20
|
+
|
21
|
+
rows = total/cols
|
22
|
+
rows += 1 if (total % cols) != 0 ## add extra row for remainder
|
23
|
+
|
24
|
+
sheet = ImageComposite.new( cols, rows,
|
25
|
+
width: width,
|
26
|
+
height: height )
|
27
|
+
|
28
|
+
meta = [] ## output meta(data) records
|
29
|
+
|
30
|
+
####
|
31
|
+
# add attributes
|
32
|
+
attributes.each do |rec|
|
33
|
+
img_path = rec['path']
|
34
|
+
sheet << Image.read( "#{dir}/#{img_path}" )
|
35
|
+
|
36
|
+
name = rec['name']
|
37
|
+
more_names = (rec['more_names'] || '').split( '|' )
|
38
|
+
|
39
|
+
if name.nil? || name.empty?
|
40
|
+
name = File.basename( img_path, File.extname( img_path ))
|
41
|
+
end
|
42
|
+
|
43
|
+
## normalize spaces in more names
|
44
|
+
names = [name] + more_names
|
45
|
+
names = names.map {|str| str.strip.gsub(/[ ]{2,}/, ' ' )}
|
46
|
+
|
47
|
+
|
48
|
+
meta << { 'id' => meta.size.to_s, ## note: always strings expected (NOT integer numbers)
|
49
|
+
'category' => rec['type'] || rec['category'],
|
50
|
+
'name' => names[0],
|
51
|
+
'more_names' => names[1..-1].join( ' | ')}
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
## pp meta
|
56
|
+
## puts " #{meta.size} record(s)"
|
57
|
+
|
58
|
+
new( sheet, _build_recs( meta ),
|
59
|
+
width: width,
|
60
|
+
height: height )
|
61
|
+
end # method self.pack
|
62
|
+
|
63
|
+
|
64
|
+
def export( path='./spritesheet.csv', format: 'csv' )
|
65
|
+
if format.downcase.to_s == 'csv'
|
66
|
+
headers = ['id', 'category', 'name', 'more_names']
|
67
|
+
|
68
|
+
## todo/fix: make sure dirname path exists!!!
|
69
|
+
File.open( path, "w:utf-8" ) do |f|
|
70
|
+
f.write( headers.join( ', '))
|
71
|
+
f.write( "\n")
|
72
|
+
records.each do |rec|
|
73
|
+
values = [rec.id,
|
74
|
+
rec.type,
|
75
|
+
rec.name,
|
76
|
+
rec.more_names.join( ' | ')]
|
77
|
+
f.write( values.join( ', ' ))
|
78
|
+
f.write( "\n" )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
else
|
82
|
+
puts "!! ERROR - unsupported export format >#{format}<; sorry"
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end # class Spritesheet
|
88
|
+
end # module Pixelart
|
89
|
+
|
@@ -39,6 +39,7 @@ module Pixelart
|
|
39
39
|
|
40
40
|
|
41
41
|
|
42
|
+
|
42
43
|
def self._build_recs( recs ) ## build and normalize (meta data) records
|
43
44
|
## sort by id
|
44
45
|
recs = recs.sort do |l,r|
|
@@ -74,7 +75,6 @@ module Pixelart
|
|
74
75
|
recs
|
75
76
|
end # method build_recs
|
76
77
|
|
77
|
-
|
78
78
|
def self.read_records( path )
|
79
79
|
recs = CsvHash.read( path )
|
80
80
|
_build_recs( recs )
|
@@ -120,27 +120,27 @@ module Pixelart
|
|
120
120
|
alias_method :meta, :records
|
121
121
|
|
122
122
|
|
123
|
-
def find_meta_by( name: )
|
123
|
+
def find_meta_by( name:, warn: true )
|
124
124
|
key = normalize_key( name ) ## normalize q(uery) string/symbol
|
125
125
|
|
126
126
|
rec = @attributes_by_name[ key ]
|
127
127
|
if rec
|
128
128
|
puts " lookup >#{key}< => #{rec.id}: #{rec.name} / #{rec.type}"
|
129
129
|
else
|
130
|
-
puts "!! WARN - no lookup found for key >#{key}<"
|
130
|
+
puts "!! WARN - no lookup found for key >#{key}<" if warn
|
131
131
|
end
|
132
132
|
|
133
133
|
rec
|
134
134
|
end
|
135
135
|
|
136
|
-
def find_by( name: )
|
137
|
-
rec = find_meta_by( name: name )
|
136
|
+
def find_by( name:, warn: true )
|
137
|
+
rec = find_meta_by( name: name, warn: warn )
|
138
138
|
|
139
139
|
## return (cropped/sliced) image from image composite if record found
|
140
140
|
rec ? @image[ rec.id ] : nil
|
141
141
|
end
|
142
142
|
|
143
|
-
def _find( name ) find_by( name: name ); end
|
143
|
+
def _find( name ) find_by( name: name, warn: false ); end
|
144
144
|
alias_method :[], :_find
|
145
145
|
|
146
146
|
|
data/lib/spritesheet/version.rb
CHANGED
data/lib/spritesheet.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
##
|
2
|
-
require '
|
1
|
+
## our own code (without "top-level" shortcuts e.g. "modular version")
|
2
|
+
require 'spritesheet/base' # aka "strict(er)" version
|
3
3
|
|
4
4
|
|
5
|
+
###
|
6
|
+
# add convenience top-level shortcuts / aliases
|
7
|
+
# make Image, Color, Palette8bit, etc top-level
|
8
|
+
include Pixelart
|
5
9
|
|
6
|
-
## our own code
|
7
|
-
require 'spritesheet/version' # note: let version always go first
|
8
|
-
require 'spritesheet/spritesheet'
|
9
10
|
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
puts Pixelart::Module::Spritesheet.banner # say hello
|
15
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spritesheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pixelart
|
@@ -72,6 +72,8 @@ files:
|
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
74
74
|
- lib/spritesheet.rb
|
75
|
+
- lib/spritesheet/base.rb
|
76
|
+
- lib/spritesheet/packer.rb
|
75
77
|
- lib/spritesheet/spritesheet.rb
|
76
78
|
- lib/spritesheet/version.rb
|
77
79
|
homepage: https://github.com/pixelartexchange/pixelart
|