Add 'error' level for movement setting check

This is a temporary place for the player to end up
to avoid the intro sequence screwing up the initial warning
if the game has detected bad movement settings.
This commit is contained in:
Wuzzy 2024-07-12 18:45:37 +02:00
parent f860d4f36c
commit d2a9efd8da
7 changed files with 96 additions and 17 deletions

View File

@ -1,3 +1,8 @@
# Movement settings for Glitch.
# Important physics settings, all levels have been carefully balanced
# to work with those. Changing them might make levels unsolvable!
# IMPORTANT: The values MUST be equal to the values in glitch_check_movement_settings!
movement_speed_walk = 5.8
movement_speed_crouch = 5.8
movement_speed_climb = 4.0

View File

@ -21,23 +21,28 @@ Minetest and fix the problem or to ignore it and
continue playing.
Both a dialog message and a chat message will be displayed.
Design problem: If this is the first time the player
starts the game, the intro sequence will run and the
starting dialog might override the warning dialog.
Not great usability, but the same message also redundantly
appears in chat. This solution is imperfect and incomplete
FIXME: Find a non-hacky (!) way for Glitch to force player-movement
settings, then remove this mod.
]]
glitch_check_movement_settings = {}
-- Ignore the physics problems if in editor mode
if glitch_editor.is_active() then
glitch_check_movement_settings.check_movement_settings = function()
return true
end
return
end
local S = minetest.get_translator("glitch_check_movement_settings")
-- Threshold for floating-point equality check
local EPSILON = 0.0001
-- This is the list of
-- This is the list of settings that needed to be checked, and their
-- expected value.
-- IMPORTANT: This MUST be equal to minetest.conf in this game's root directory!
local settings_to_check = {
movement_speed_walk = 5.8,
movement_speed_crouch = 5.8,
@ -70,31 +75,33 @@ local STR_WARNING_2 = S("Please exit the game and reset the following Minetest s
local STR_INVALID_SETTINGS = table.concat(invalid_settings, S(", "))
local disconnect = function(player)
minetest.log("action", "[glitch_check_movement_settings] "..player:get_player_name().." chose to leave the game")
minetest.disconnect_player(player:get_player_name(), S("You quit. Remember, Glitch expects the following Minetest settings to be reset to the default value: @1", STR_INVALID_SETTINGS))
end
glitch_dialog.register_dialogtree("glitch:non_default_movement_settings", {
force_stay = true,
speeches = {
{
start = {
speaker = "glitch:warning",
text = STR_WARNING_1.."\n"..
STR_WARNING_2.."\n"..
STR_INVALID_SETTINGS,
options = {
{
-- This will exit the game because speech 2 is special
-- This will exit the game
text = S("Exit game"),
action = "speech",
next_speech = 2,
next_speech = "exit_game",
},
{
text = S("Continue playing anyway"),
action = "quit",
action = "speech",
next_speech = "play",
}
},
},
{
exit_game = {
-- Fake speech that will cause an immediate disconnect when entered
speaker = "glitch:warning",
-- Speech text not needed here
@ -102,10 +109,24 @@ glitch_dialog.register_dialogtree("glitch:non_default_movement_settings", {
on_enter = function(player)
disconnect(player)
end,
},
play = {
speaker = "glitch:info",
text = S("Okay, have fun!"),
on_exit = function(player)
disconnect(player)
-- Move the player to the start of the game if intro was not completed yet
local pmeta = player:get_meta()
if pmeta:get_int("glitch_levels:intro_complete") == 0 then
minetest.log("action", "[glitch_check_movement_settings] "..player:get_player_name().." chose to play game despite the non-default movement settings")
if minetest.global_exists("glitch_levels") then
glitch_levels.move_to_level(player, glitch_levels.START_LEVEL, glitch_levels.START_SPAWN_NO)
else
minetest.log("error", "[glitch_check_movement_settings] Could not teleport player to start level!")
end
end
end,
},
},
})
@ -115,6 +136,7 @@ minetest.register_on_joinplayer(function(player)
return
end
minetest.log("action", "[glitch_check_movement_settings] Non-default movement settings detected, game physics might be degraded")
-- Chat messages
local function msg(text)
minetest.chat_send_player(pname, minetest.colorize("#FF8000", text))
@ -128,3 +150,14 @@ minetest.register_on_joinplayer(function(player)
end)
-- Expose checker function publicly
glitch_check_movement_settings = {}
glitch_check_movement_settings.check_movement_settings = function()
local t = check_settings()
if #t == 0 then
return true
else
return false
end
end

View File

@ -1,2 +1,2 @@
name = glitch_check_movement_settings
depends = glitch_dialog
depends = glitch_editor, glitch_dialog

View File

@ -395,6 +395,36 @@ glitch_levels.add_level("outro2", {
end,
})
-- An empty room that is completely black.
-- Not a proper level, only a temporary landing space
-- used for glitch_check_movement_settings
glitch_levels.add_level("error", {
description = "Error Room", -- not translatable because it's internal-use only
pos = generate_pos(),
spawns = {
{
pos = vector.new(3, 3, 3),
},
},
schematic = "glitch_levels_error.mts",
gateways = {},
sky = "dark",
ambience = "silence",
on_rejoin = function(player)
if glitch_check_movement_settings.check_movement_settings() then
local pmeta = player:get_meta()
minetest.log("action", player:get_player_name().." moves from error room back to void level due to valid movement settings")
if pmeta:get_int("glitch_levels:intro_complete") == 0 then
glitch_levels.move_to_level(player, glitch_levels.START_LEVEL, glitch_levels.START_SPAWN_NO)
else
glitch_levels.move_to_level(player, glitch_levels.START_LEVEL)
end
end
end,
})
minetest.after(0, function()
local levels = glitch_levels.get_levels()
for name, def in pairs(levels) do

View File

@ -1,3 +1,3 @@
name = glitch_levels
description = Level handling, loading, resetting, gateway usage and the levels themselves (in-game called "sectors")
depends = glitch_utils, glitch_inventory_formspec, glitch_editor, glitch_entities, glitch_sky, glitch_ambience, playerphysics
depends = glitch_utils, glitch_inventory_formspec, glitch_editor, glitch_entities, glitch_sky, glitch_ambience, playerphysics, glitch_check_movement_settings

View File

@ -1,11 +1,22 @@
local S = minetest.get_translator("glitch_levels")
minetest.register_on_newplayer(function(player)
if glitch_check_movement_settings.check_movement_settings() == false then
glitch_levels.move_to_level(player, "error")
else
glitch_levels.move_to_level(player, glitch_levels.START_LEVEL, glitch_levels.START_SPAWN_NO)
end
end)
minetest.register_on_joinplayer(function(player)
local meta = player:get_meta()
if glitch_check_movement_settings.check_movement_settings() == false then
if meta:get_int("glitch_levels:intro_complete") == 0 then
glitch_levels.move_to_level(player, "error")
return
end
end
local current_level = meta:get_string("glitch_levels:current_level")
if current_level == "" then
current_level = glitch_levels.START_LEVEL

Binary file not shown.