better on_activate for canvas

master
obneq 2012-08-17 22:54:43 +02:00
parent f2bb7d4ab3
commit 2bbd04d3c7
1 changed files with 8 additions and 13 deletions

View File

@ -91,13 +91,13 @@ picent = {
local p = intersect(ppos, l, pos, normal) local p = intersect(ppos, l, pos, normal)
local off = -0.5 local off = -0.5
pos = { x = pos.x + off * od.x, y=pos.y + off, z=pos.z + off * od.z } pos = { x = pos.x + off * od.x, y = pos.y + off, z = pos.z + off * od.z }
p = sub(p, pos) p = sub(p, pos)
local x = math.abs(p.x + p.z) local x = math.abs(p.x + p.z)
local y = p.y local y = p.y
x = round(x/(1/res)) x = round(x / (1/res))
y = round((1-y)/(1/res)) y = round((1-y) / (1/res))
x = clamp(x) x = clamp(x)
y = clamp(y-1) y = clamp(y-1)
@ -107,17 +107,12 @@ picent = {
end, end,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
local pos = self.object:getpos() self.grid = minetest.deserialize(staticdata) or initgrid()
local meta = minetest.env:get_meta(pos) self.object:set_properties({textures = { to_imagestring(self.grid) }})
local data = meta:get_string("painting:picturedata") end,
if data == "" then get_staticdata = function(self)
self.grid = initgrid() return minetest.serialize(self.grid)
else
data = minetest.deserialize(data)
data = to_imagestring(data)
self.object:set_properties({textures = { data }})
end
end end
} }