improve parsing error alert
This commit is contained in:
parent
fe1ac69b57
commit
18d473b673
@ -25,13 +25,17 @@ package = {
|
||||
}
|
||||
local __cached_scripts = {}
|
||||
|
||||
function on_deprecated_call(name)
|
||||
debug.warning("deprecated function called ("..name..")\n"..debug.traceback())
|
||||
end
|
||||
|
||||
-- Load script with caching
|
||||
--
|
||||
-- path - script path `contentpack:filename`.
|
||||
-- Example `base:scripts/tests.lua`
|
||||
--
|
||||
-- nocache - ignore cached script, load anyway
|
||||
function load_script(path, nocache)
|
||||
local function __load_script(path, nocache)
|
||||
local packname, filename = parse_path(path)
|
||||
|
||||
-- __cached_scripts used in condition because cached result may be nil
|
||||
@ -68,7 +72,7 @@ end
|
||||
|
||||
function require(path)
|
||||
local prefix, file = parse_path(path)
|
||||
return load_script(prefix..":modules/"..file..".lua")
|
||||
return __load_script(prefix..":modules/"..file..".lua")
|
||||
end
|
||||
|
||||
function sleep(timesec)
|
||||
@ -78,24 +82,6 @@ function sleep(timesec)
|
||||
end
|
||||
end
|
||||
|
||||
_dofile = dofile
|
||||
-- Replaces dofile('*/content/packid/*') with load_script('packid:*')
|
||||
function dofile(path)
|
||||
local index = string.find(path, "/content/")
|
||||
if index then
|
||||
local newpath = string.sub(path, index+9)
|
||||
index = string.find(newpath, "/")
|
||||
if index then
|
||||
local label = string.sub(newpath, 1, index-1)
|
||||
newpath = label..':'..string.sub(newpath, index+1)
|
||||
if file.isfile(newpath) then
|
||||
return load_script(newpath, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return _dofile(path)
|
||||
end
|
||||
|
||||
function pack.is_installed(packid)
|
||||
return file.isfile(packid..":package.json")
|
||||
end
|
||||
@ -301,7 +287,7 @@ end
|
||||
|
||||
math.randomseed(time.uptime()*1536227939)
|
||||
|
||||
-- Deprecated functions
|
||||
-- --------- Deprecated functions ------ --
|
||||
block_index = block.index
|
||||
block_name = block.name
|
||||
blocks_count = block.defs_count
|
||||
@ -318,3 +304,27 @@ get_block_rotation = block.get_rotation
|
||||
set_block_rotation = block.set_rotation
|
||||
get_block_user_bits = block.get_user_bits
|
||||
set_block_user_bits = block.set_user_bits
|
||||
|
||||
function load_script(path, nocache)
|
||||
on_deprecated_call("load_script")
|
||||
__load_script(path, nocache)
|
||||
end
|
||||
|
||||
_dofile = dofile
|
||||
-- Replaces dofile('*/content/packid/*') with load_script('packid:*')
|
||||
function dofile(path)
|
||||
on_deprecated_call("dofile")
|
||||
local index = string.find(path, "/content/")
|
||||
if index then
|
||||
local newpath = string.sub(path, index+9)
|
||||
index = string.find(newpath, "/")
|
||||
if index then
|
||||
local label = string.sub(newpath, 1, index-1)
|
||||
newpath = label..':'..string.sub(newpath, index+1)
|
||||
if file.isfile(newpath) then
|
||||
return __load_script(newpath, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return _dofile(path)
|
||||
end
|
||||
|
||||
@ -123,12 +123,7 @@ bool files::write_binary_json(const fs::path& filename, const dynamic::Map* obj,
|
||||
|
||||
std::shared_ptr<dynamic::Map> files::read_json(const fs::path& filename) {
|
||||
std::string text = files::read_string(filename);
|
||||
try {
|
||||
return json::parse(filename.string(), text);;
|
||||
} catch (const parsing_error& error) {
|
||||
std::cerr << error.errorLog() << std::endl;
|
||||
throw std::runtime_error("could not to parse "+filename.string());
|
||||
}
|
||||
return json::parse(filename.string(), text);
|
||||
}
|
||||
|
||||
std::shared_ptr<dynamic::Map> files::read_binary_json(const fs::path& file) {
|
||||
|
||||
@ -29,7 +29,7 @@ void guiutil::alert(GUI* gui, const std::wstring& text, const runnable& on_hidde
|
||||
|
||||
auto label = std::make_shared<Label>(text);
|
||||
label->setMultiline(true);
|
||||
label->setSize(glm::vec2(1, 80));
|
||||
label->setSize(glm::vec2(1, 90));
|
||||
panel->add(label);
|
||||
panel->add(std::make_shared<Button>(
|
||||
langs::get(L"Ok"), glm::vec4(10.f),
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "EngineController.hpp"
|
||||
|
||||
#include "../coders/commons.hpp"
|
||||
#include "../content/ContentLUT.hpp"
|
||||
#include "../debug/Logger.hpp"
|
||||
#include "../engine.hpp"
|
||||
@ -103,6 +104,10 @@ static bool loadWorldContent(Engine* engine, const fs::path& folder) {
|
||||
util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return false;
|
||||
} catch (const parsing_error& error) {
|
||||
engine->setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(engine->getGUI(), util::str2wstr_utf8(error.errorLog()));
|
||||
return false;
|
||||
} catch (const std::runtime_error& error) {
|
||||
engine->setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(
|
||||
@ -204,6 +209,10 @@ void EngineController::createWorld(
|
||||
L":\n"+util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return;
|
||||
} catch (const parsing_error& error) {
|
||||
engine->setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(engine->getGUI(), util::str2wstr_utf8(error.errorLog()));
|
||||
return;
|
||||
} catch (const std::runtime_error& error) {
|
||||
engine->setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user