Fixed some encoding and decoding issues

Still working on why node data is not stored in the sources table when a
player joins in creative.
master
Austin Shenk 2013-01-06 00:10:57 -05:00
parent 9fb793b959
commit eb2892d0fe
3 changed files with 25 additions and 24 deletions

View File

@ -2,21 +2,21 @@
minetest.register_on_joinplayer(function(obj)
local file = io.open(minetest.get_worldpath().."/adventures_previousmode", "r")
if(file:read("*l") == adventures.normal) then
if(file:read("*l") ~= adventures.creative) then
file:close()
local creative = minetest.setting_get("creative_mode")
local node = nil
local pos = nil
for _,data in ipairs(adventures.sourceData) do
node = data[1]
pos = {x=data[2],y=data[3],z=data[4]}
minetest.env:add_node({name=node}, pos)
for pos,data in pairs(adventures.sourceData) do
print("Added")
minetest.env:add_node({name=data[1]}, pos)
end
file = io.open(minetest.get_worldpath().."/adventures_previousmode", "w")
file:write(adventures.creative)
file:close()
else
file:close()
for pos,data in pairs(adventures.sourceData) do
print("Stored")
adventures.sources[pos] = data[1]
end
end
end)
@ -166,6 +166,7 @@ minetest.register_node("adventures:invincible_source" ,{
meta:set_string("formspec", updateInvincibleSourceFormspec(meta))
end,
on_destruct = function(pos)
adventures.sources[pos] = nil
adventures.findArea(minetest.env:get_meta(pos), pos, {x=0,y=0,z=0}):remove()
end,
})
@ -173,7 +174,11 @@ minetest.register_node("adventures:invincible_source" ,{
minetest.register_chatcommand("save", {
description = "saveAdventure : Save all node data to files",
func = function(name, param)
dofile(minetest.get_modpath("adventures").."/encode.lua")
print(name)
local saved = dofile(minetest.get_modpath("adventures").."/encode.lua")
if saved then
minetest.chat_send_player(name, "ADVENTURE SAVED")
else
minetest.chat_send_player(name, "ADVENTURE NOT SAVED")
end
end,
})

View File

@ -2,6 +2,9 @@ local file = io.open(minetest.get_worldpath().."/adventures_sources", "r")
if(file ~= nil) then
local start = 1
for line in file:lines() do
if line == "initialized" or line == "" then
return
end
local comma = line:find(",")
local data = {}
data[1] = line:sub(start,comma-1)
@ -12,10 +15,7 @@ if(file ~= nil) then
start = comma+1
comma = line:find(",", start)
end
local creative = minetest.setting_get("creative_mode")
if(creative) then
adventures.sourceData[{x=data[2],y=data[3],z=data[4]}] = data
end
adventures.sourceData[{x=data[2],y=data[3],z=data[4]}] = data
end
end
io.close()
file:close()

View File

@ -1,20 +1,16 @@
local file = io.open(minetest.get_worldpath().."/adventures_sources", "w")
local saved = false
local str = ""
for pos,name in pairs(adventures.sources) do
local meta = minetest.env:get_meta(pos)
local str = ""
if(name == "adventures:invincible_source") then
str = name..","..pos.x..","..pos.y..","..pos.z..","..
str = str..name..","..pos.x..","..pos.y..","..pos.z..","..
meta:get_int("x")..","..meta:get_int("y")..","..meta:get_int("z")..","..
meta:get_int("width")..","..meta:get_int("length")..","..meta:get_int("height")..","
.."\n"
end
file:write(str)
saved = true
end
if(saved) then
print("ADVENTURE SAVED")
else
print("ERROR IN ADVENTURE")
end
file:close()
file:write(str)
file:close()
return saved