mineskin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/mineskin.rb +3 -0
- data/lib/mineskin/preview.rb +1 -0
- data/lib/mineskin/preview/2d.rb +66 -0
- data/lib/mineskin/skin_data.rb +170 -0
- data/lib/mineskin/unit.rb +8 -0
- data/lib/mineskin/version.rb +3 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f2ad5a0b0f013880ad8da88118d4fc97f2e2c5cf
|
4
|
+
data.tar.gz: ed9dedbc558433fbd8a8ff74d477fe6ebd49c4cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1d186e77ac6a4ef8fa2f3f3d70f75dd28fe903182f4edbb2da927dedde18a4210711b8c24abd6c37bcbdca0d191cd152ee74a89c7882fd37d17e80be8308346
|
7
|
+
data.tar.gz: 7c60577555742245618811e2baadf037d71e3fd2e25c2533253e76a11de71faae7755a42fe12e274edfd9a692662878348b5b8aec3ae2d2dfd227ccb411b113e
|
data/lib/mineskin.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mineskin/preview/2d'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
require 'mineskin/unit'
|
3
|
+
module MineSkin
|
4
|
+
module Preview
|
5
|
+
# 2D preview
|
6
|
+
class Preview2D
|
7
|
+
include Unit
|
8
|
+
|
9
|
+
def initialize(skin_data)
|
10
|
+
@skin_data = skin_data
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(width, background: 'white')
|
14
|
+
@unit = image_unit size: width, count: 12
|
15
|
+
@image = Magick::Image.new(width, 5 * width / 6) do
|
16
|
+
self.background_color = background
|
17
|
+
end
|
18
|
+
render_head!
|
19
|
+
render_body!
|
20
|
+
render_legs!
|
21
|
+
render_arms!
|
22
|
+
@image
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def resize(img)
|
28
|
+
img.sample(@unit.to_f / @skin_data.unit.to_f)
|
29
|
+
end
|
30
|
+
|
31
|
+
def composite_texture!(tex, x, y, op: Magick::SrcOverCompositeOp)
|
32
|
+
@image.composite!(resize(tex.texture), x * @unit, y * @unit, op)
|
33
|
+
@image.composite!(
|
34
|
+
resize(tex.overlay),
|
35
|
+
x * @unit,
|
36
|
+
y * @unit,
|
37
|
+
op
|
38
|
+
) if tex.overlay
|
39
|
+
end
|
40
|
+
|
41
|
+
def render_head!
|
42
|
+
composite_texture! @skin_data.head.front, 2, 1
|
43
|
+
composite_texture! @skin_data.head.back, 8, 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_body!
|
47
|
+
composite_texture! @skin_data.body.front, 2, 3
|
48
|
+
composite_texture! @skin_data.body.back, 8, 3
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_legs!
|
52
|
+
composite_texture! @skin_data.left_leg.front, 3, 6
|
53
|
+
composite_texture! @skin_data.right_leg.front, 2, 6
|
54
|
+
composite_texture! @skin_data.left_leg.back, 8, 6
|
55
|
+
composite_texture! @skin_data.right_leg.back, 9, 6
|
56
|
+
end
|
57
|
+
|
58
|
+
def render_arms!
|
59
|
+
composite_texture! @skin_data.left_arm.front, 4, 3
|
60
|
+
composite_texture! @skin_data.right_arm.front, 1, 3
|
61
|
+
composite_texture! @skin_data.left_arm.back, 7, 3
|
62
|
+
composite_texture! @skin_data.right_arm.back, 10, 3
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
require 'mineskin/unit'
|
3
|
+
|
4
|
+
module MineSkin
|
5
|
+
Cuboid = Struct.new(:top, :bottom, :left, :right, :front, :back)
|
6
|
+
Texture = Struct.new(:texture, :overlay)
|
7
|
+
|
8
|
+
# rubocop:disable ClassLength
|
9
|
+
# Skin Data class
|
10
|
+
class SkinData
|
11
|
+
include Unit
|
12
|
+
|
13
|
+
attr_accessor(
|
14
|
+
:head,
|
15
|
+
:body,
|
16
|
+
:left_arm,
|
17
|
+
:right_arm,
|
18
|
+
:left_leg,
|
19
|
+
:right_leg
|
20
|
+
)
|
21
|
+
attr_reader :unit
|
22
|
+
|
23
|
+
def new_format?
|
24
|
+
@new_format
|
25
|
+
end
|
26
|
+
|
27
|
+
# rubocop:disable AbcSize
|
28
|
+
def initialize(filename)
|
29
|
+
@image = Magick::Image.read(filename).first
|
30
|
+
@new_format = @image.columns == @image.rows
|
31
|
+
@unit = image_unit size: @image.columns
|
32
|
+
@head = extract_head
|
33
|
+
@body = extract_body
|
34
|
+
@left_leg, @right_leg = extract_legs
|
35
|
+
@left_arm, @right_arm = extract_arms
|
36
|
+
end
|
37
|
+
|
38
|
+
def crop(texture)
|
39
|
+
@image.crop(
|
40
|
+
texture[:x] * @unit,
|
41
|
+
texture[:y] * @unit,
|
42
|
+
texture[:width] * @unit,
|
43
|
+
texture[:height] * @unit
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def part(texture: { x: 0, y: 0, width: 0, height: 0 }, overlay: nil)
|
48
|
+
tex = crop coords_to_h texture
|
49
|
+
|
50
|
+
part = Texture.new(tex, nil)
|
51
|
+
if overlay
|
52
|
+
over = crop coords_to_h overlay
|
53
|
+
part.overlay = over
|
54
|
+
end
|
55
|
+
|
56
|
+
part
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract(hash)
|
60
|
+
Cuboid.new(
|
61
|
+
part(hash[:top]),
|
62
|
+
part(hash[:bottom]),
|
63
|
+
part(hash[:left]),
|
64
|
+
part(hash[:right]),
|
65
|
+
part(hash[:front]),
|
66
|
+
part(hash[:back])
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def coords_to_h(c)
|
73
|
+
if c.is_a? Array
|
74
|
+
{
|
75
|
+
x: c[0],
|
76
|
+
y: c[1],
|
77
|
+
width: c[2],
|
78
|
+
height: c[3]
|
79
|
+
}
|
80
|
+
else
|
81
|
+
c
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def new_only(*x)
|
86
|
+
if new_format?
|
87
|
+
return x.first if x.first.is_a? Array
|
88
|
+
return x
|
89
|
+
end
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
|
93
|
+
def extract_head
|
94
|
+
extract(
|
95
|
+
top: { texture: [2, 0, 2, 2], overlay: [10, 0, 2, 2] },
|
96
|
+
bottom: { texture: [4, 0, 2, 2], overlay: [12, 0, 2, 2] },
|
97
|
+
right: { texture: [0, 2, 2, 2], overlay: [8, 2, 2, 2] },
|
98
|
+
left: { texture: [4, 2, 2, 2], overlay: [12, 2, 2, 2] },
|
99
|
+
front: { texture: [2, 2, 2, 2], overlay: [10, 2, 2, 2] },
|
100
|
+
back: { texture: [6, 2, 2, 2], overlay: [14, 2, 2, 2] }
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def extract_left_arm
|
105
|
+
return extract(
|
106
|
+
top: { texture: [9, 12, 1, 1], overlay: [13, 12, 1, 1] },
|
107
|
+
bottom: { texture: [10, 12, 1, 1], overlay: [14, 12, 1, 1] },
|
108
|
+
right: { texture: [8, 13, 1, 3], overlay: [12, 13, 1, 3] },
|
109
|
+
left: { texture: [10, 13, 1, 3], overlay: [14, 13, 1, 3] },
|
110
|
+
front: { texture: [9, 13, 1, 3], overlay: [13, 13, 1, 3] },
|
111
|
+
back: { texture: [11, 13, 1, 3], overlay: [15, 13, 1, 3] }
|
112
|
+
) if new_format?
|
113
|
+
extract_right_arm
|
114
|
+
end
|
115
|
+
|
116
|
+
def extract_right_arm
|
117
|
+
extract(
|
118
|
+
top: { texture: [11, 4, 1, 1], overlay: new_only(11, 8, 1, 1) },
|
119
|
+
bottom: { texture: [12, 4, 1, 1], overlay: new_only(12, 8, 1, 1) },
|
120
|
+
right: { texture: [10, 5, 1, 3], overlay: new_only(10, 9, 1, 3) },
|
121
|
+
left: { texture: [12, 5, 1, 3], overlay: new_only(12, 9, 1, 3) },
|
122
|
+
front: { texture: [11, 5, 1, 3], overlay: new_only(11, 9, 1, 3) },
|
123
|
+
back: { texture: [13, 5, 1, 3], overlay: new_only(13, 9, 1, 3) }
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
# rubocop:disable RedundantReturn
|
128
|
+
def extract_arms
|
129
|
+
return extract_left_arm, extract_right_arm
|
130
|
+
end
|
131
|
+
|
132
|
+
def extract_right_leg
|
133
|
+
extract(
|
134
|
+
top: { texture: [1, 4, 1, 1], overlay: new_only(1, 8, 1, 1) },
|
135
|
+
bottom: { texture: [2, 4, 1, 1], overlay: new_only(2, 8, 1, 1) },
|
136
|
+
right: { texture: [0, 5, 1, 3], overlay: new_only(0, 9, 1, 3) },
|
137
|
+
left: { texture: [2, 5, 1, 3], overlay: new_only(2, 9, 1, 3) },
|
138
|
+
front: { texture: [1, 5, 1, 3], overlay: new_only(1, 9, 1, 3) },
|
139
|
+
back: { texture: [3, 5, 1, 3], overlay: new_only(3, 9, 1, 3) }
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
def extract_left_leg
|
144
|
+
return extract(
|
145
|
+
top: { texture: [5, 12, 1, 1], overlay: [1, 12, 1, 1] },
|
146
|
+
bottom: { texture: [6, 12, 1, 1], overlay: [2, 12, 1, 1] },
|
147
|
+
right: { texture: [4, 13, 1, 3], overlay: [0, 13, 1, 3] },
|
148
|
+
left: { texture: [6, 13, 1, 3], overlay: [2, 13, 1, 3] },
|
149
|
+
front: { texture: [5, 13, 1, 3], overlay: [1, 13, 1, 3] },
|
150
|
+
back: { texture: [7, 13, 1, 3], overlay: [3, 13, 1, 3] }
|
151
|
+
) if new_format?
|
152
|
+
extract_right_leg
|
153
|
+
end
|
154
|
+
|
155
|
+
def extract_legs
|
156
|
+
return extract_right_leg, extract_left_leg
|
157
|
+
end
|
158
|
+
|
159
|
+
def extract_body
|
160
|
+
extract(
|
161
|
+
top: { texture: [5, 4, 2, 1], overlay: new_only(5, 8, 2, 1) },
|
162
|
+
bottom: { texture: [7, 4, 2, 1], overlay: new_only(7, 8, 2, 1) },
|
163
|
+
right: { texture: [4, 5, 1, 3], overlay: new_only(4, 9, 1, 3) },
|
164
|
+
left: { texture: [7, 5, 1, 3], overlay: new_only(7, 9, 1, 3) },
|
165
|
+
front: { texture: [5, 5, 2, 3], overlay: new_only(5, 9, 2, 3) },
|
166
|
+
back: { texture: [8, 5, 2, 3], overlay: new_only(8, 9, 2, 3) }
|
167
|
+
)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mineskin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stepan Melnikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A tool to manipulate minecraft skins
|
28
|
+
email: smelnikov871@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/mineskin.rb
|
34
|
+
- lib/mineskin/preview.rb
|
35
|
+
- lib/mineskin/preview/2d.rb
|
36
|
+
- lib/mineskin/skin_data.rb
|
37
|
+
- lib/mineskin/unit.rb
|
38
|
+
- lib/mineskin/version.rb
|
39
|
+
homepage: https://github.com/unn4m3d/mineskin
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.6.8
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: A tool to manipulate minecraft skins
|
63
|
+
test_files: []
|