mirror of
https://gitlab.com/niansa/storybuilder.git
synced 2025-03-06 20:48:28 +01:00
Many optimisations, removal of useless corruptionhandler
This commit is contained in:
parent
6c4885c352
commit
f1af39a88d
10 changed files with 57 additions and 30 deletions
|
@ -6,4 +6,5 @@
|
|||
├── story ------------ All story data excluding stages
|
||||
├── storybase -------- Story internals
|
||||
├── cheat ------------ Cheating
|
||||
├── playertools ------ Some command for the player to mess with its game progress
|
||||
└── thirdparty ------- 3rd party modules
|
||||
|
|
9
mods/playertools/api.lua
Normal file
9
mods/playertools/api.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
playertools ={}
|
||||
|
||||
-- remove_player
|
||||
function playertools.remove_player(name)
|
||||
minetest.after(1, function()
|
||||
local removal = minetest.remove_player(name)
|
||||
print("[corruptionhandler] The player '"..name.."' has been removed: "..removal)
|
||||
end)
|
||||
end
|
18
mods/playertools/commands.lua
Normal file
18
mods/playertools/commands.lua
Normal file
|
@ -0,0 +1,18 @@
|
|||
-- gamereset
|
||||
minetest.register_chatcommand("gamereset", {
|
||||
privs = "interact",
|
||||
func = function(name, param)
|
||||
-- Check if current game is a singleplayer game
|
||||
if minetest.is_singleplayer() then
|
||||
return false, "You are in singleplayer mode, so your game data can't be removed automatically."
|
||||
end
|
||||
-- Make sure the player does not run this by accident
|
||||
if param ~= "I am sure" then
|
||||
return false, "Use following command to agree that all your data will be removed: \"/gamereset I am sure\""
|
||||
else
|
||||
minetest.kick_player(name, "Your gamedata is being removed, so you have to reconnect now.")
|
||||
playertools.remove_player(name)
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
3
mods/playertools/init.lua
Normal file
3
mods/playertools/init.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
local modpath = minetest.get_modpath("playertools")
|
||||
dofile(modpath.."/api.lua")
|
||||
dofile(modpath.."/commands.lua")
|
|
@ -1,12 +1,3 @@
|
|||
-- corruptionhelp
|
||||
minetest.register_chatcommand("corruptionhelp", {
|
||||
privs = "corruption",
|
||||
func = function(name, param)
|
||||
minetest.chat_send_player(name, "Here are a few tipps how to fix playerdata corruption:")
|
||||
corruption.send_info(name)
|
||||
return true
|
||||
end
|
||||
})
|
||||
-- gamereset
|
||||
minetest.register_chatcommand("gamereset", {
|
||||
privs = "corruption",
|
|
@ -1,4 +1,3 @@
|
|||
local storage = minetest.get_mod_storage()
|
||||
local modpath = minetest.get_modpath("story")
|
||||
local worldpath = minetest.get_worldpath()
|
||||
story = {}
|
||||
|
@ -44,23 +43,18 @@ function story.reload_stage(name)
|
|||
local stage = storybase.get_stage(name)
|
||||
local object = minetest.get_player_by_name(name)
|
||||
-- Get stage positions
|
||||
minetest.chat_send_player(name, "Loading stage " .. stage .. "...")
|
||||
storybase.debugmsg(name, "Loading stage " .. stage .. "...")
|
||||
if not story.get_stage(stage) then
|
||||
-- Players data is corrupted, let corruptionhandler handle this
|
||||
corruption.handle(name)
|
||||
storybase.crashmsg(name, "reload_stage", "No such stage")
|
||||
return false
|
||||
end
|
||||
-- Players data does not seem to be corrupted, so make sure corruption flag is not set
|
||||
corruption.unflag(name)
|
||||
-- Set this stage as backup stage
|
||||
storybase.set_backup_stage(name, stage)
|
||||
-- Show loading screen
|
||||
story.loading_screen(name)
|
||||
-- Place matching schematic
|
||||
minetest.chat_send_player(name, "Loading schematic, please be patient...")
|
||||
storybase.debugmsg(name, "Loading schematic, please be patient...")
|
||||
schem.load("", spos, "stage_"..stage)
|
||||
-- Teleport the player to the schematic
|
||||
minetest.chat_send_player(name, "Done! Positions: "..spos.x.." "..spos.y.." "..spos.z)
|
||||
storybase.debugmsg(name, "Done! Positions: "..spos.x.." "..spos.y.." "..spos.z)
|
||||
object:set_pos({ x = spos.x + spos.x_off, y = spos.y + spos.y_off, z = spos.z + spos.z_off })
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local storage = minetest.get_mod_storage()
|
||||
local worldpath = minetest.get_worldpath()
|
||||
storybase = {}
|
||||
|
||||
-- internals
|
||||
|
@ -11,7 +12,7 @@ end
|
|||
-- init
|
||||
function storybase.init(name)
|
||||
-- Initalize database
|
||||
local data = { stage = 1, backupstage = 1, score = 0}
|
||||
local data = { stage = 1, score = 0}
|
||||
storage:set_string(name, minetest.serialize(data))
|
||||
-- Initalize privileges
|
||||
minetest.set_player_privs(name, defaultprivs)
|
||||
|
@ -27,10 +28,6 @@ function storybase.get_stage(name)
|
|||
local data = minetest.deserialize(storage:get_string(name))
|
||||
return data.stage
|
||||
end
|
||||
function storybase.get_backup_stage(name)
|
||||
local data = minetest.deserialize(storage:get_string(name))
|
||||
return data.backupstage
|
||||
end
|
||||
|
||||
-- set
|
||||
function storybase.set_score(name, newscore)
|
||||
|
@ -40,17 +37,15 @@ function storybase.set_score(name, newscore)
|
|||
return true
|
||||
end
|
||||
function storybase.set_stage(name, newstage)
|
||||
if not loadfile(worldpath.."/stages/"..newstage..".pos") then
|
||||
storybase.crashmsg(name, "set_stage", "No such stage")
|
||||
return false
|
||||
end
|
||||
local data = minetest.deserialize(storage:get_string(name))
|
||||
data.stage = newstage
|
||||
storage:set_string(name, minetest.serialize(data))
|
||||
return true
|
||||
end
|
||||
function storybase.set_backup_stage(name, newstage)
|
||||
local data = minetest.deserialize(storage:get_string(name))
|
||||
data.backupstage = newstage
|
||||
storage:set_string(name, minetest.serialize(data))
|
||||
return true
|
||||
end
|
||||
|
||||
-- inc
|
||||
function storybase.inc_score(name, amount)
|
||||
|
@ -65,3 +60,18 @@ function storybase.inc_stage(name, amount)
|
|||
storybase.set_stage(name, newstage)
|
||||
return newstage
|
||||
end
|
||||
|
||||
-- debugmsg
|
||||
function storybase.debugmsg(name, message)
|
||||
if debugmsgs ~= true then
|
||||
print("[storybase] "..name..": "..message)
|
||||
return false
|
||||
end
|
||||
minetest.chat_send_player(name, "Debug: "..message)
|
||||
return true
|
||||
end
|
||||
|
||||
-- crashmsg
|
||||
function storybase.crashmsg(name, where, what)
|
||||
return minetest.kick_player(name, "\nAn internal error occured in "..where..": "..what.."\nPlease report this to the developer of this story!")
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
buildmode = false
|
||||
noreload = false
|
||||
allow_cheating = minetest.is_singleplayer()
|
||||
debugmsgs = true
|
||||
defaultprivs = {
|
||||
interact = true,
|
||||
shout = true,
|
||||
|
|
Loading…
Add table
Reference in a new issue