mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 02:49:46 +00:00
Merge branch 'main' into update-base-pack
This commit is contained in:
commit
607bb64307
23 changed files with 173 additions and 36 deletions
|
|
@ -3,5 +3,6 @@
|
||||||
<panel id='content_panel' size='480,100' color='#00000080' scrollable='true' max-length='400'>
|
<panel id='content_panel' size='480,100' color='#00000080' scrollable='true' max-length='400'>
|
||||||
<!-- content is generated in script -->
|
<!-- content is generated in script -->
|
||||||
</panel>
|
</panel>
|
||||||
|
<button onclick="delete_content(report)" context="world">@Delete Content</button>
|
||||||
<button onclick='menu:back()'>@Back to Main Menu</button>
|
<button onclick='menu:back()'>@Back to Main Menu</button>
|
||||||
</panel>
|
</panel>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,18 @@
|
||||||
|
content_report = nil
|
||||||
|
|
||||||
|
function delete_content()
|
||||||
|
local units = {}
|
||||||
|
for i, entry in ipairs(content_report.content) do
|
||||||
|
table.insert(units, entry.name)
|
||||||
|
end
|
||||||
|
local request = {
|
||||||
|
units = units
|
||||||
|
}
|
||||||
|
app.delete_world_content(content_report.world, request, true)
|
||||||
|
end
|
||||||
|
|
||||||
function on_open(report)
|
function on_open(report)
|
||||||
|
content_report = report
|
||||||
for i, entry in ipairs(report.content) do
|
for i, entry in ipairs(report.content) do
|
||||||
document.content_panel:add(gui.template("content_entry", entry))
|
document.content_panel:add(gui.template("content_entry", entry))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ require("core:io_stream").wrap_bytearray = require "core:internal/stream_provide
|
||||||
|
|
||||||
network.__as_stream = require "core:internal/stream_providers/socket"
|
network.__as_stream = require "core:internal/stream_providers/socket"
|
||||||
|
|
||||||
math.randomseed(time.uptime() * 1536227939)
|
math.randomseed(time.precise_utc_time())
|
||||||
|
|
||||||
rules = require "core:internal/rules"
|
rules = require "core:internal/rules"
|
||||||
time.schedules = {}
|
time.schedules = {}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ error.dependency-version-not-met=Dependency pack version is not met.
|
||||||
world.delete-confirm=Do you want to delete world forever?
|
world.delete-confirm=Do you want to delete world forever?
|
||||||
world.generators.default=Default
|
world.generators.default=Default
|
||||||
world.generators.flat=Flat
|
world.generators.flat=Flat
|
||||||
|
world.delete-content-confirm=Delete missing content from the world __**(irreversible)**__?
|
||||||
|
|
||||||
editor.info.tooltip=CTRL+S - Save\nCTRL+R - Run\nCTRL+Z - Undo\nCTRL+Y - Redo
|
editor.info.tooltip=CTRL+S - Save\nCTRL+R - Run\nCTRL+Z - Undo\nCTRL+Y - Redo
|
||||||
devtools.traceback=Traceback (most recent call first)
|
devtools.traceback=Traceback (most recent call first)
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,8 @@ world.upgrade-request=Формат мира устарел! Конвертиро
|
||||||
world.convert-with-loss=Конвертировать мир с потерями?
|
world.convert-with-loss=Конвертировать мир с потерями?
|
||||||
world.convert-block-layouts=Есть изменения в полях блоков! Конвертировать мир?
|
world.convert-block-layouts=Есть изменения в полях блоков! Конвертировать мир?
|
||||||
world.delete-confirm=Удалить мир безвозвратно?
|
world.delete-confirm=Удалить мир безвозвратно?
|
||||||
|
world.Delete Content=Удалить контент
|
||||||
|
world.delete-content-confirm=Удалить отсутствующий контент из мира __**(безвозвратно)**__?
|
||||||
|
|
||||||
# Настройки
|
# Настройки
|
||||||
settings.Ambient=Фон
|
settings.Ambient=Фон
|
||||||
|
|
|
||||||
|
|
@ -275,8 +275,7 @@ void ALStream::update(double delta) {
|
||||||
unqueueBuffers(alsource);
|
unqueueBuffers(alsource);
|
||||||
uint preloaded = enqueueBuffers(alsource);
|
uint preloaded = enqueueBuffers(alsource);
|
||||||
|
|
||||||
// alspeaker->stopped is assigned to false at ALSpeaker::play(...)
|
if (speaker->isStopped()) {
|
||||||
if (speaker->isStopped() && !alspeaker->manuallyStopped) { //TODO: -V560 false-positive?
|
|
||||||
if (preloaded) {
|
if (preloaded) {
|
||||||
speaker->play();
|
speaker->play();
|
||||||
} else if (isStopOnEnd()){
|
} else if (isStopOnEnd()){
|
||||||
|
|
|
||||||
|
|
@ -361,7 +361,8 @@ void remove_lower_priority_speaker(int priority) {
|
||||||
for (auto it = speakers.begin(); it != speakers.end();) {
|
for (auto it = speakers.begin(); it != speakers.end();) {
|
||||||
if (it->second->getPriority() < priority && it->second->isPaused()) {
|
if (it->second->getPriority() < priority && it->second->isPaused()) {
|
||||||
it->second->stop();
|
it->second->stop();
|
||||||
it = speakers.erase(it);
|
streams.erase(it->first);
|
||||||
|
speakers.erase(it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it++;
|
it++;
|
||||||
|
|
@ -369,7 +370,8 @@ void remove_lower_priority_speaker(int priority) {
|
||||||
for (auto it = speakers.begin(); it != speakers.end();) {
|
for (auto it = speakers.begin(); it != speakers.end();) {
|
||||||
if (it->second->getPriority() < priority) {
|
if (it->second->getPriority() < priority) {
|
||||||
it->second->stop();
|
it->second->stop();
|
||||||
it = speakers.erase(it);
|
streams.erase(it->first);
|
||||||
|
speakers.erase(it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it++;
|
it++;
|
||||||
|
|
@ -457,6 +459,7 @@ speakerid_t audio::play_stream(
|
||||||
int channel
|
int channel
|
||||||
) {
|
) {
|
||||||
std::shared_ptr<Stream> stream(open_stream(file, false));
|
std::shared_ptr<Stream> stream(open_stream(file, false));
|
||||||
|
stream->setStopOnEnd(true);
|
||||||
return play(stream, position, relative, volume, pitch, loop, channel);
|
return play(stream, position, relative, volume, pitch, loop, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -532,8 +535,8 @@ void audio::update(double delta) {
|
||||||
if (speaker->isStopped()) {
|
if (speaker->isStopped()) {
|
||||||
auto foundStream = streams.find(it->first);
|
auto foundStream = streams.find(it->first);
|
||||||
if (foundStream == streams.end() ||
|
if (foundStream == streams.end() ||
|
||||||
(!speaker->isManuallyStopped() &&
|
speaker->isManuallyStopped() ||
|
||||||
foundStream->second->isStopOnEnd())) {
|
foundStream->second->isStopOnEnd()) {
|
||||||
streams.erase(it->first);
|
streams.erase(it->first);
|
||||||
it = speakers.erase(it);
|
it = speakers.erase(it);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -35,16 +35,16 @@ void ServerMainloop::run() {
|
||||||
|
|
||||||
double targetDelta = 1.0 / static_cast<double>(coreParams.tps);
|
double targetDelta = 1.0 / static_cast<double>(coreParams.tps);
|
||||||
double delta = targetDelta;
|
double delta = targetDelta;
|
||||||
auto begin = system_clock::now();
|
const auto tickDuration =
|
||||||
auto startupTime = begin;
|
duration_cast<steady_clock::duration>(duration<double>(targetDelta));
|
||||||
|
auto startupTime = steady_clock::now();
|
||||||
|
auto nextTick = startupTime;
|
||||||
|
|
||||||
while (!engine.isQuitSignal() && !engine.getAppScripts().isFinished()) {
|
while (!engine.isQuitSignal() && !engine.getAppScripts().isFinished()) {
|
||||||
if (coreParams.testMode) {
|
if (coreParams.testMode) {
|
||||||
time.step(delta);
|
time.step(delta);
|
||||||
} else {
|
} else {
|
||||||
auto now = system_clock::now();
|
time.update(duration<double>(nextTick - startupTime).count());
|
||||||
time.update(
|
|
||||||
duration_cast<microseconds>(now - startupTime).count() / 1e6);
|
|
||||||
delta = time.getDelta();
|
delta = time.getDelta();
|
||||||
}
|
}
|
||||||
if (controller) {
|
if (controller) {
|
||||||
|
|
@ -55,13 +55,15 @@ void ServerMainloop::run() {
|
||||||
engine.postUpdate();
|
engine.postUpdate();
|
||||||
|
|
||||||
if (!coreParams.testMode) {
|
if (!coreParams.testMode) {
|
||||||
auto end = system_clock::now();
|
nextTick += tickDuration;
|
||||||
int64_t millis = targetDelta * 1000 -
|
auto now = steady_clock::now();
|
||||||
duration_cast<microseconds>(end - begin).count() / 1000;
|
if (nextTick > now) {
|
||||||
if (millis > 0) {
|
platform::sleep(
|
||||||
platform::sleep(millis);
|
duration_cast<milliseconds>(nextTick - now).count()
|
||||||
|
);
|
||||||
|
} else if (now - nextTick > tickDuration * 5) {
|
||||||
|
nextTick = now;
|
||||||
}
|
}
|
||||||
begin = system_clock::now();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.info() << "script finished";
|
logger.info() << "script finished";
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,9 @@ UiDocument* menus::show(
|
||||||
|
|
||||||
auto documentPtr = UiDocument::read(
|
auto documentPtr = UiDocument::read(
|
||||||
engine.getGUI(),
|
engine.getGUI(),
|
||||||
scripting::get_root_environment(),
|
scripting::create_doc_environment(
|
||||||
|
scripting::get_root_environment(), fullname, true
|
||||||
|
),
|
||||||
fullname,
|
fullname,
|
||||||
file,
|
file,
|
||||||
"core:layouts/" + name
|
"core:layouts/" + name
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,25 @@ LevelScreen::LevelScreen(
|
||||||
resetChunks(false);
|
resetChunks(false);
|
||||||
frontend->getContentGfxCache().refresh();
|
frontend->getContentGfxCache().refresh();
|
||||||
}));
|
}));
|
||||||
keepAlive(settings.graphics.shadowsQuality.observe([=](int quality) {
|
auto graphics = &settings.graphics;
|
||||||
|
auto shadowsMeshing = std::make_shared<bool>(
|
||||||
|
graphics->shadowsQuality.get() > 0 && graphics->advancedRender.get()
|
||||||
|
);
|
||||||
|
auto updateShadowsMeshing = [=]() {
|
||||||
|
bool enabled =
|
||||||
|
graphics->shadowsQuality.get() > 0 && graphics->advancedRender.get();
|
||||||
|
if (enabled == *shadowsMeshing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*shadowsMeshing = enabled;
|
||||||
resetChunks(false);
|
resetChunks(false);
|
||||||
frontend->getContentGfxCache().refresh();
|
frontend->getContentGfxCache().refresh();
|
||||||
|
};
|
||||||
|
keepAlive(settings.graphics.shadowsQuality.observe([=](int) {
|
||||||
|
updateShadowsMeshing();
|
||||||
|
}));
|
||||||
|
keepAlive(settings.graphics.advancedRender.observe([=](bool) {
|
||||||
|
updateShadowsMeshing();
|
||||||
}));
|
}));
|
||||||
keepAlive(settings.camera.fov.observe([=](double value) {
|
keepAlive(settings.camera.fov.observe([=](double value) {
|
||||||
player->fpCamera->setFov(glm::radians(value));
|
player->fpCamera->setFov(glm::radians(value));
|
||||||
|
|
|
||||||
|
|
@ -696,7 +696,8 @@ SortingMeshData BlocksRenderer::renderTranslucent(
|
||||||
void BlocksRenderer::build(
|
void BlocksRenderer::build(
|
||||||
const Chunk* chunk, const VoxelsRenderVolume& volume
|
const Chunk* chunk, const VoxelsRenderVolume& volume
|
||||||
) {
|
) {
|
||||||
directionalLightFactor = settings.graphics.shadowsQuality.get() > 0.0f
|
directionalLightFactor = settings.graphics.shadowsQuality.get() > 0 &&
|
||||||
|
settings.graphics.advancedRender.get()
|
||||||
? 0.0f
|
? 0.0f
|
||||||
: DEFAULT_DIRECTIONAL_LIGHT_FACTOR;
|
: DEFAULT_DIRECTIONAL_LIGHT_FACTOR;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ void Decorator::updateAcoustics(const Camera& camera) {
|
||||||
acoustics.reverbReflectionsDelay = minDistance / speedOfSound;
|
acoustics.reverbReflectionsDelay = minDistance / speedOfSound;
|
||||||
acoustics.reverbLateReflectionsDelay = averageDistance / speedOfSound;
|
acoustics.reverbLateReflectionsDelay = averageDistance / speedOfSound;
|
||||||
acoustics.reverbDecayTime = decayTime;
|
acoustics.reverbDecayTime = decayTime;
|
||||||
acoustics.reverbRoomRolloff = escapeRatio * 1.5f;
|
acoustics.reverbRoomRolloff = 0.1f + escapeRatio * 1.5f;
|
||||||
acoustics.reverbAbsorption = averageAbsorption;
|
acoustics.reverbAbsorption = averageAbsorption;
|
||||||
|
|
||||||
audio::set_acoustics(std::move(acoustics));
|
audio::set_acoustics(std::move(acoustics));
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ void Container::act(float delta) {
|
||||||
intervalEvents[i].timer += delta;
|
intervalEvents[i].timer += delta;
|
||||||
if (intervalEvents[i].timer > intervalEvents[i].interval) {
|
if (intervalEvents[i].timer > intervalEvents[i].interval) {
|
||||||
auto callback = intervalEvents[i].callback;
|
auto callback = intervalEvents[i].callback;
|
||||||
callback();
|
gui.postRunnable(callback);
|
||||||
IntervalEvent& event = intervalEvents[i];
|
IntervalEvent& event = intervalEvents[i];
|
||||||
if (event.repeat == 0) {
|
if (event.repeat == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ void guiutil::confirm(
|
||||||
label->setSize(glm::vec2(600, 50));
|
label->setSize(glm::vec2(600, 50));
|
||||||
label->setMultiline(true);
|
label->setMultiline(true);
|
||||||
label->setTextWrapping(true);
|
label->setTextWrapping(true);
|
||||||
|
label->setMarkup("md");
|
||||||
|
|
||||||
panel->add(label);
|
panel->add(label);
|
||||||
auto subpanel = std::make_shared<Panel>(gui, glm::vec2(600, 53));
|
auto subpanel = std::make_shared<Panel>(gui, glm::vec2(600, 53));
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,32 @@ void EngineController::deleteWorld(const std::string& name) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EngineController::deleteWorldContent(
|
||||||
|
const std::string& name, ContentRemovalRequest request, bool loadWorld
|
||||||
|
) {
|
||||||
|
io::path folder = engine.getPaths().getWorldFolderByName(name);
|
||||||
|
auto deletion = [this, folder, loadWorld, request=std::move(request)]() {
|
||||||
|
logger.info() << "deleting content from the world";
|
||||||
|
WorldFiles worldFiles(folder);
|
||||||
|
worldFiles.deleteContent(std::move(request));
|
||||||
|
if (loadWorld) {
|
||||||
|
openWorld(folder.name(), true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (engine.isHeadless()) {
|
||||||
|
deletion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
guiutil::confirm(
|
||||||
|
engine,
|
||||||
|
langs::get(L"delete-content-confirm", L"world") + L" (" +
|
||||||
|
util::str2wstr_utf8(folder.string()) + L")",
|
||||||
|
deletion
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Task> create_converter(
|
std::shared_ptr<Task> create_converter(
|
||||||
Engine& engine,
|
Engine& engine,
|
||||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||||
|
|
@ -174,20 +200,20 @@ static dv::value create_missing_content_report(
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineController::onMissingContent(
|
void EngineController::onMissingContent(
|
||||||
|
const std::string& worldName,
|
||||||
const std::shared_ptr<ContentReport>& report
|
const std::shared_ptr<ContentReport>& report
|
||||||
) {
|
) {
|
||||||
|
auto fullReport = create_missing_content_report(report);
|
||||||
|
fullReport["world"] = worldName;
|
||||||
|
|
||||||
if (engine.isHeadless()) {
|
if (engine.isHeadless()) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"missing content: " +
|
"missing content: " +
|
||||||
util::quote(json::stringify(create_missing_content_report(report), true, " "))
|
util::quote(json::stringify(std::move(fullReport), true, " "))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||||
menus::show(
|
menus::show(engine, "reports/missing_content", {std::move(fullReport)});
|
||||||
engine,
|
|
||||||
"reports/missing_content",
|
|
||||||
{create_missing_content_report(report)}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +260,7 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (report->hasMissingContent()) {
|
if (report->hasMissingContent()) {
|
||||||
onMissingContent(report);
|
onMissingContent(name, report);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,16 @@ class Engine;
|
||||||
class World;
|
class World;
|
||||||
class ContentReport;
|
class ContentReport;
|
||||||
class LevelController;
|
class LevelController;
|
||||||
|
struct ContentRemovalRequest;
|
||||||
|
|
||||||
class EngineController {
|
class EngineController {
|
||||||
Engine& engine;
|
Engine& engine;
|
||||||
|
|
||||||
int64_t localPlayer = -1;
|
int64_t localPlayer = -1;
|
||||||
void onMissingContent(const std::shared_ptr<ContentReport>& report);
|
void onMissingContent(
|
||||||
|
const std::string& worldName,
|
||||||
|
const std::shared_ptr<ContentReport>& report
|
||||||
|
);
|
||||||
public:
|
public:
|
||||||
EngineController(Engine& engine);
|
EngineController(Engine& engine);
|
||||||
|
|
||||||
|
|
@ -27,6 +31,10 @@ public:
|
||||||
/// @param name world name
|
/// @param name world name
|
||||||
void deleteWorld(const std::string& name);
|
void deleteWorld(const std::string& name);
|
||||||
|
|
||||||
|
void deleteWorldContent(
|
||||||
|
const std::string& name, ContentRemovalRequest request, bool loadWorld
|
||||||
|
);
|
||||||
|
|
||||||
void reconfigPacks(
|
void reconfigPacks(
|
||||||
LevelController* controller,
|
LevelController* controller,
|
||||||
const std::vector<std::string>& packsToAdd,
|
const std::vector<std::string>& packsToAdd,
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
|
#include "world/files/WorldFiles.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
@ -327,6 +328,35 @@ static int l_delete_world(lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ContentRemovalRequest parse_content_removal_request(lua::State* L, int idx) {
|
||||||
|
ContentRemovalRequest request;
|
||||||
|
if (!lua::istable(L, idx)) {
|
||||||
|
throw std::runtime_error("table expected as argument");
|
||||||
|
}
|
||||||
|
if (!lua::getfield(L, "units", idx)) {
|
||||||
|
throw std::runtime_error("table with 'units' field expected");
|
||||||
|
}
|
||||||
|
if (!lua::istable(L, -1)) {
|
||||||
|
throw std::runtime_error("'units' field must be a table");
|
||||||
|
}
|
||||||
|
int len = lua::objlen(L, -1);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
lua::rawgeti(L, i + 1);
|
||||||
|
request.units.emplace_back(lua::require_lstring(L, -1));
|
||||||
|
lua::pop(L);
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_delete_world_content(lua::State* L) {
|
||||||
|
auto name = lua::require_string(L, 1);
|
||||||
|
auto controller = engine->getController();
|
||||||
|
auto request = parse_content_removal_request(L, 2);
|
||||||
|
bool loadWorld = lua::toboolean(L, 3);
|
||||||
|
controller->deleteWorldContent(name, request, loadWorld);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get engine version
|
/// @brief Get engine version
|
||||||
/// @return major, minor, [patch]
|
/// @return major, minor, [patch]
|
||||||
static int l_get_version(lua::State* L) {
|
static int l_get_version(lua::State* L) {
|
||||||
|
|
@ -538,6 +568,7 @@ const luaL_Reg applib[] = {
|
||||||
{"save_world", lua::wrap<l_save_world>},
|
{"save_world", lua::wrap<l_save_world>},
|
||||||
{"close_world", lua::wrap<l_close_world>},
|
{"close_world", lua::wrap<l_close_world>},
|
||||||
{"delete_world", lua::wrap<l_delete_world>},
|
{"delete_world", lua::wrap<l_delete_world>},
|
||||||
|
{"delete_world_content", lua::wrap<l_delete_world_content>},
|
||||||
/// other
|
/// other
|
||||||
{"get_version", lua::wrap<l_get_version>},
|
{"get_version", lua::wrap<l_get_version>},
|
||||||
{"create_memory_device", lua::wrap<l_create_memory_device>},
|
{"create_memory_device", lua::wrap<l_create_memory_device>},
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] scriptenv scripting::create_doc_environment(
|
[[nodiscard]] scriptenv scripting::create_doc_environment(
|
||||||
const scriptenv& parent, const std::string& name
|
const scriptenv& parent, const std::string& name, bool app
|
||||||
) {
|
) {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
int id = lua::create_environment(L, *parent);
|
int id = lua::create_environment(L, *parent);
|
||||||
|
|
@ -226,6 +226,12 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
||||||
lua::pushstring(L, name);
|
lua::pushstring(L, name);
|
||||||
lua::setfield(L, "DOC_NAME");
|
lua::setfield(L, "DOC_NAME");
|
||||||
|
|
||||||
|
if (app) {
|
||||||
|
if (lua::getregistry(L, "app")) {
|
||||||
|
lua::setfield(L, "app");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (lua::getglobal(L, "Document")) {
|
if (lua::getglobal(L, "Document")) {
|
||||||
if (lua::getfield(L, "new")) {
|
if (lua::getfield(L, "new")) {
|
||||||
lua::pushstring(L, name);
|
lua::pushstring(L, name);
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace scripting {
|
||||||
scriptenv create_pack_environment(const ContentPack& pack);
|
scriptenv create_pack_environment(const ContentPack& pack);
|
||||||
scriptenv create_environment(const scriptenv& parent);
|
scriptenv create_environment(const scriptenv& parent);
|
||||||
scriptenv create_doc_environment(
|
scriptenv create_doc_environment(
|
||||||
const scriptenv& parent, const std::string& name
|
const scriptenv& parent, const std::string& name, bool app = false
|
||||||
);
|
);
|
||||||
|
|
||||||
void process_post_runnables();
|
void process_post_runnables();
|
||||||
|
|
|
||||||
|
|
@ -296,8 +296,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
Pathfinding::Pathfinding(const Level& level)
|
Pathfinding::Pathfinding(const Level& level)
|
||||||
: level(level),
|
: chunks(*level.chunks),
|
||||||
chunks(*level.chunks),
|
|
||||||
blockDefs(level.content.getIndices()->blocks) {
|
blockDefs(level.content.getIndices()->blocks) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,6 @@ namespace voxels {
|
||||||
|
|
||||||
const std::unordered_map<int, Agent>& getAgents() const;
|
const std::unordered_map<int, Agent>& getAgents() const;
|
||||||
private:
|
private:
|
||||||
const Level& level;
|
|
||||||
const GlobalChunks& chunks;
|
const GlobalChunks& chunks;
|
||||||
const ContentUnitIndices<Block, blockid_t>& blockDefs;
|
const ContentUnitIndices<Block, blockid_t>& blockDefs;
|
||||||
std::unordered_map<int, Agent> agents;
|
std::unordered_map<int, Agent> agents;
|
||||||
|
|
|
||||||
|
|
@ -235,3 +235,23 @@ void WorldFiles::removeIndices(const std::vector<std::string>& packs) {
|
||||||
io::path WorldFiles::getFolder() const {
|
io::path WorldFiles::getFolder() const {
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void replace_all(
|
||||||
|
dv::value& list, const std::string& unit, const std::string& placeholder
|
||||||
|
) {
|
||||||
|
for (uint i = 0; i < list.size(); i++) {
|
||||||
|
auto& name = list[i].asString();
|
||||||
|
if (name == unit) {
|
||||||
|
list[i] = placeholder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldFiles::deleteContent(const ContentRemovalRequest& request) {
|
||||||
|
auto root = io::read_json(getIndicesFile());
|
||||||
|
for (const auto& unit : request.units) {
|
||||||
|
replace_all(root["blocks"], unit, CORE_AIR);
|
||||||
|
replace_all(root["items"], unit, CORE_EMPTY);
|
||||||
|
}
|
||||||
|
io::write_json(getIndicesFile(), root);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@ class World;
|
||||||
struct WorldInfo;
|
struct WorldInfo;
|
||||||
struct DebugSettings;
|
struct DebugSettings;
|
||||||
|
|
||||||
|
struct ContentRemovalRequest {
|
||||||
|
std::vector<std::string> units;
|
||||||
|
};
|
||||||
|
|
||||||
class WorldFiles {
|
class WorldFiles {
|
||||||
io::path directory;
|
io::path directory;
|
||||||
WorldRegions regions;
|
WorldRegions regions;
|
||||||
|
|
@ -77,5 +81,7 @@ public:
|
||||||
return doWriteLights;
|
return doWriteLights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteContent(const ContentRemovalRequest& request);
|
||||||
|
|
||||||
static const inline std::string WORLD_FILE = "world.json";
|
static const inline std::string WORLD_FILE = "world.json";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue