forked from CasimirKaPazi/gemalde
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimated.lua
More file actions
209 lines (181 loc) · 5 KB
/
animated.lua
File metadata and controls
209 lines (181 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
-- Settings
local default_speed = 2.0
-- Extra
-- x is the paintings number. s is the animation speed.
local frames = {
-- {x, s},
-- {2, 1.0}, -- Example. Speed of 1.0 for the second animated painting.
}
-- Count the number of pictures.
local function get_picture(number)
local filename = minetest.get_modpath("gemalde").."/textures/gemalde_animated_"..number..".png"
local file = io.open(filename, "r")
if file ~= nil then io.close(file) return true else return false end
end
local function after_place(pos, placer)
if placer then
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
end
end
local N = 1
while get_picture(N) == true do
N = N + 1
end
N = N - 1
-- register for each picture
for n=1, N do
local groups = {choppy=2, dig_immediate=3, animated_picture=1, not_in_creative_inventory=1}
if n == 1 then
groups = {choppy=2, dig_immediate=3, animated_picture=1}
end
-- Look in the frames table for settings.
local frames_speed = default_speed
for _,frames in ipairs(frames) do
if frames[1] == n then
frames_speed = frames[2]
end
end
-- node
minetest.register_node("gemalde:node_animated_"..n.."", {
description = "Animation #"..n.."",
drawtype = "signlike",
use_texture_alpha = "clip",
tiles = {
{
image="gemalde_animated_"..n..".png",
animation={type="vertical_frames", length=frames_speed}
},
},
visual_scale = 3.0,
inventory_image = "gemalde_animated_node.png",
wield_image = "gemalde_animated_node.png",
paramtype = "light",
paramtype2 = "wallmounted",
sunlight_propagates = true,
walkable = false,
selection_box = {
type = "wallmounted",
},
groups = groups,
after_place_node = after_place,
on_rightclick = function(pos, node, clicker)
local length = string.len (node.name)
local number = string.sub (node.name, 23, length)
local player = clicker:get_player_name()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if player == owner then
-- TODO. Reducing currently not working, because sneaking prevents right click.
local keys=clicker:get_player_control()
if keys["sneak"]==false then
if number == tostring(N) then
number = 1
else
number = number + 1
end
else
if number == 1 then
number = N - 1
else
number = number - 1
end
end
-- print("[gemalde] number is "..number.."")
node.name = "gemalde:node_animated_"..number..""
-- minetest.env:set_node(pos, node)
minetest.swap_node(pos, node)
end
end,
-- TODO.
-- on_place = minetest.rotate_node
})
-- crafts
if n < N then
minetest.register_craft({
output = 'gemalde:node_animated_'..n..'',
recipe = {
{'gemalde:node_animated_'..(n+1)..''},
}
})
end
n = n + 1
end
-- close the craft loop
minetest.register_craft({
output = 'gemalde:node_animated_'..N..'',
recipe = {
{'gemalde:node_animated_1'},
}
})
-- initial craft
minetest.register_craft({
output = 'gemalde:node_animated_1',
recipe = {
{'default:book', 'default:book'},
{'default:book', 'default:book'},
{'default:book', 'default:book'},
}
})
-- reset several pictures to #1
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 2',
recipe = {'group:animated_picture', 'group:animated_picture'},
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 3',
recipe = {'group:animated_picture', 'group:animated_picture', 'group:animated_picture'},
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 4',
recipe = {
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture'
}
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 5',
recipe = {
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture'
}
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 6',
recipe = {
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture', 'group:animated_picture'
}
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 7',
recipe = {
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture'
}
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 8',
recipe = {
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture'
}
})
minetest.register_craft({
type = 'shapeless',
output = 'gemalde:node_animated_1 9',
recipe = {
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture', 'group:animated_picture',
'group:animated_picture', 'group:animated_picture', 'group:animated_picture'
}
})