Merge branch 'dev' into generated-pcm-stream
This commit is contained in:
commit
3856d63ae5
@ -139,8 +139,12 @@ void BasicParser<CharT>::skipLine() {
|
|||||||
|
|
||||||
template<typename CharT>
|
template<typename CharT>
|
||||||
void BasicParser<CharT>::skipEmptyLines() {
|
void BasicParser<CharT>::skipEmptyLines() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t initpos = pos;
|
||||||
skipWhitespace();
|
skipWhitespace();
|
||||||
pos = linestart;
|
pos = std::max<size_t>(initpos, linestart);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT>
|
template<typename CharT>
|
||||||
|
|||||||
@ -38,7 +38,7 @@ static dv::value perform_literal(std::string_view literal) {
|
|||||||
literal == "false" || literal == "False") {
|
literal == "false" || literal == "False") {
|
||||||
return literal[0] == 't';
|
return literal[0] == 't';
|
||||||
}
|
}
|
||||||
if (literal == "null" || literal == "Null") {
|
if (literal == "null" || literal == "Null" || literal == "~") {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::string(literal);
|
return std::string(literal);
|
||||||
@ -204,8 +204,9 @@ dv::value Parser::parseFullValue(int indent) {
|
|||||||
skipEmptyLines();
|
skipEmptyLines();
|
||||||
int init_pos = pos;
|
int init_pos = pos;
|
||||||
int next_indent = countIndent();
|
int next_indent = countIndent();
|
||||||
if (next_indent < indent) {
|
if (next_indent <= indent) {
|
||||||
throw error("indentation error");
|
pos = init_pos;
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (source[pos] == '-') {
|
if (source[pos] == '-') {
|
||||||
pos = init_pos;
|
pos = init_pos;
|
||||||
@ -269,6 +270,10 @@ dv::value Parser::parseArray(int indent) {
|
|||||||
dv::value object = dv::object();
|
dv::value object = dv::object();
|
||||||
object[std::string(name)] = parseFullValue(next_indent);
|
object[std::string(name)] = parseFullValue(next_indent);
|
||||||
skipEmptyLines();
|
skipEmptyLines();
|
||||||
|
if (!hasNext()) {
|
||||||
|
list.add(std::move(object));
|
||||||
|
break;
|
||||||
|
}
|
||||||
next_indent = countIndent();
|
next_indent = countIndent();
|
||||||
if (next_indent > indent) {
|
if (next_indent > indent) {
|
||||||
pos = linestart;
|
pos = linestart;
|
||||||
|
|||||||
@ -661,7 +661,7 @@ int TextBox::calcIndexAt(int x, int y) const {
|
|||||||
line = std::min(line, label->getLinesNumber() - 1);
|
line = std::min(line, label->getLinesNumber() - 1);
|
||||||
size_t lineLength = getLineLength(line);
|
size_t lineLength = getLineLength(line);
|
||||||
uint offset = 0;
|
uint offset = 0;
|
||||||
while (lcoord.x + rawTextCache.metrics.calcWidth(labelText, offset) < x &&
|
while (lcoord.x + rawTextCache.metrics.calcWidth(labelText, 0, offset) < x &&
|
||||||
offset < lineLength - 1) {
|
offset < lineLength - 1) {
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,19 +8,17 @@
|
|||||||
#include "elements/Button.hpp"
|
#include "elements/Button.hpp"
|
||||||
#include "elements/Canvas.hpp"
|
#include "elements/Canvas.hpp"
|
||||||
#include "elements/CheckBox.hpp"
|
#include "elements/CheckBox.hpp"
|
||||||
#include "elements/TextBox.hpp"
|
|
||||||
#include "elements/SplitBox.hpp"
|
|
||||||
#include "elements/TrackBar.hpp"
|
|
||||||
#include "elements/SelectBox.hpp"
|
|
||||||
#include "elements/Image.hpp"
|
#include "elements/Image.hpp"
|
||||||
#include "elements/InlineFrame.hpp"
|
#include "elements/InlineFrame.hpp"
|
||||||
#include "elements/InputBindBox.hpp"
|
#include "elements/InputBindBox.hpp"
|
||||||
#include "elements/InventoryView.hpp"
|
#include "elements/InventoryView.hpp"
|
||||||
#include "elements/Menu.hpp"
|
#include "elements/Menu.hpp"
|
||||||
|
#include "elements/ModelViewer.hpp"
|
||||||
#include "elements/Panel.hpp"
|
#include "elements/Panel.hpp"
|
||||||
|
#include "elements/SelectBox.hpp"
|
||||||
|
#include "elements/SplitBox.hpp"
|
||||||
#include "elements/TextBox.hpp"
|
#include "elements/TextBox.hpp"
|
||||||
#include "elements/TrackBar.hpp"
|
#include "elements/TrackBar.hpp"
|
||||||
#include "elements/ModelViewer.hpp"
|
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "frontend/locale.hpp"
|
#include "frontend/locale.hpp"
|
||||||
#include "frontend/menu.hpp"
|
#include "frontend/menu.hpp"
|
||||||
@ -197,7 +195,10 @@ static void read_uinode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void read_container_impl(
|
static void read_container_impl(
|
||||||
UiXmlReader& reader, const xml::xmlelement& element, Container& container
|
UiXmlReader& reader,
|
||||||
|
const xml::xmlelement& element,
|
||||||
|
Container& container,
|
||||||
|
bool subnodes
|
||||||
) {
|
) {
|
||||||
read_uinode(reader, element, container);
|
read_uinode(reader, element, container);
|
||||||
|
|
||||||
@ -207,6 +208,9 @@ static void read_container_impl(
|
|||||||
if (element.has("scroll-step")) {
|
if (element.has("scroll-step")) {
|
||||||
container.setScrollStep(element.attr("scroll-step").asInt());
|
container.setScrollStep(element.attr("scroll-step").asInt());
|
||||||
}
|
}
|
||||||
|
if (!subnodes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto& sub : element.getElements()) {
|
for (auto& sub : element.getElements()) {
|
||||||
if (sub->isText()) continue;
|
if (sub->isText()) continue;
|
||||||
auto subnode = reader.readUINode(*sub);
|
auto subnode = reader.readUINode(*sub);
|
||||||
@ -219,7 +223,7 @@ static void read_container_impl(
|
|||||||
void UiXmlReader::readUINode(
|
void UiXmlReader::readUINode(
|
||||||
UiXmlReader& reader, const xml::xmlelement& element, Container& container
|
UiXmlReader& reader, const xml::xmlelement& element, Container& container
|
||||||
) {
|
) {
|
||||||
read_container_impl(reader, element, container);
|
read_container_impl(reader, element, container, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiXmlReader::readUINode(
|
void UiXmlReader::readUINode(
|
||||||
@ -229,11 +233,9 @@ void UiXmlReader::readUINode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void read_base_panel_impl(
|
static void read_base_panel_impl(
|
||||||
UiXmlReader& reader,
|
UiXmlReader& reader, const xml::xmlelement& element, BasePanel& panel
|
||||||
const xml::xmlelement& element,
|
|
||||||
BasePanel& panel
|
|
||||||
) {
|
) {
|
||||||
read_uinode(reader, element, panel);
|
read_container_impl(reader, element, panel, false);
|
||||||
|
|
||||||
if (element.has("padding")) {
|
if (element.has("padding")) {
|
||||||
glm::vec4 padding = element.attr("padding").asVec4();
|
glm::vec4 padding = element.attr("padding").asVec4();
|
||||||
@ -348,7 +350,7 @@ static std::shared_ptr<UINode> read_container(
|
|||||||
UiXmlReader& reader, const xml::xmlelement& element
|
UiXmlReader& reader, const xml::xmlelement& element
|
||||||
) {
|
) {
|
||||||
auto container = std::make_shared<Container>(reader.getGUI(), glm::vec2());
|
auto container = std::make_shared<Container>(reader.getGUI(), glm::vec2());
|
||||||
read_container_impl(reader, element, *container);
|
read_container_impl(reader, element, *container, true);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,8 +367,7 @@ static std::shared_ptr<UINode> read_split_box(
|
|||||||
);
|
);
|
||||||
read_base_panel_impl(reader, element, *splitBox);
|
read_base_panel_impl(reader, element, *splitBox);
|
||||||
for (auto& sub : element.getElements()) {
|
for (auto& sub : element.getElements()) {
|
||||||
if (sub->isText())
|
if (sub->isText()) continue;
|
||||||
continue;
|
|
||||||
auto subnode = reader.readUINode(*sub);
|
auto subnode = reader.readUINode(*sub);
|
||||||
if (subnode) {
|
if (subnode) {
|
||||||
splitBox->add(subnode);
|
splitBox->add(subnode);
|
||||||
@ -379,15 +380,15 @@ static std::shared_ptr<UINode> read_model_viewer(
|
|||||||
UiXmlReader& reader, const xml::xmlelement& element
|
UiXmlReader& reader, const xml::xmlelement& element
|
||||||
) {
|
) {
|
||||||
auto model = element.attr("src", "").getText();
|
auto model = element.attr("src", "").getText();
|
||||||
auto viewer = std::make_shared<ModelViewer>(
|
auto viewer =
|
||||||
reader.getGUI(), glm::vec2(), model
|
std::make_shared<ModelViewer>(reader.getGUI(), glm::vec2(), model);
|
||||||
);
|
read_container_impl(reader, element, *viewer, true);
|
||||||
read_container_impl(reader, element, *viewer);
|
|
||||||
if (element.has("center")) {
|
if (element.has("center")) {
|
||||||
viewer->setCenter(element.attr("center").asVec3());
|
viewer->setCenter(element.attr("center").asVec3());
|
||||||
}
|
}
|
||||||
if (element.has("cam-rotation")) {
|
if (element.has("cam-rotation")) {
|
||||||
viewer->setRotation(glm::radians(element.attr("cam-rotation").asVec3()));
|
viewer->setRotation(glm::radians(element.attr("cam-rotation").asVec3())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return viewer;
|
return viewer;
|
||||||
}
|
}
|
||||||
@ -450,7 +451,8 @@ static std::shared_ptr<UINode> read_select(
|
|||||||
}
|
}
|
||||||
auto value = elem->attr("value").getText();
|
auto value = elem->attr("value").getText();
|
||||||
auto text = parse_inner_text(*elem, reader.getContext());
|
auto text = parse_inner_text(*elem, reader.getContext());
|
||||||
options.push_back(SelectBox::Option {std::move(value), std::move(text)});
|
options.push_back(SelectBox::Option {std::move(value), std::move(text)}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.has("selected")) {
|
if (element.has("selected")) {
|
||||||
@ -485,10 +487,9 @@ static std::shared_ptr<UINode> read_select(
|
|||||||
element.attr("onselect").getText(),
|
element.attr("onselect").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()
|
||||||
);
|
);
|
||||||
selectBox->listenChange(
|
selectBox->listenChange([callback = std::move(callback)](
|
||||||
[callback=std::move(callback)](GUI&, const std::string& value) {
|
GUI&, const std::string& value
|
||||||
callback(value);
|
) { callback(value); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
read_panel_impl(reader, element, *selectBox, false);
|
read_panel_impl(reader, element, *selectBox, false);
|
||||||
return selectBox;
|
return selectBox;
|
||||||
@ -539,7 +540,7 @@ static std::shared_ptr<UINode> read_text_box(
|
|||||||
);
|
);
|
||||||
textbox->setHint(hint);
|
textbox->setHint(hint);
|
||||||
|
|
||||||
read_container_impl(reader, element, *textbox);
|
read_container_impl(reader, element, *textbox, true);
|
||||||
if (element.has("padding")) {
|
if (element.has("padding")) {
|
||||||
glm::vec4 padding = element.attr("padding").asVec4();
|
glm::vec4 padding = element.attr("padding").asVec4();
|
||||||
textbox->setPadding(padding);
|
textbox->setPadding(padding);
|
||||||
@ -839,7 +840,7 @@ static std::shared_ptr<UINode> read_page_box(
|
|||||||
auto& gui = reader.getGUI();
|
auto& gui = reader.getGUI();
|
||||||
auto menu = std::make_shared<Menu>(gui);
|
auto menu = std::make_shared<Menu>(gui);
|
||||||
menu->setPageLoader(gui.getMenu()->getPageLoader());
|
menu->setPageLoader(gui.getMenu()->getPageLoader());
|
||||||
read_container_impl(reader, element, *menu);
|
read_container_impl(reader, element, *menu, true);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
@ -849,14 +850,15 @@ static std::shared_ptr<UINode> read_iframe(
|
|||||||
) {
|
) {
|
||||||
auto& gui = reader.getGUI();
|
auto& gui = reader.getGUI();
|
||||||
auto iframe = std::make_shared<InlineFrame>(gui);
|
auto iframe = std::make_shared<InlineFrame>(gui);
|
||||||
read_container_impl(reader, element, *iframe);
|
read_container_impl(reader, element, *iframe, true);
|
||||||
|
|
||||||
std::string src = element.attr("src", "").getText();
|
std::string src = element.attr("src", "").getText();
|
||||||
iframe->setSrc(src);
|
iframe->setSrc(src);
|
||||||
return iframe;
|
return iframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
UiXmlReader::UiXmlReader(gui::GUI& gui, scriptenv&& env) : gui(gui), env(std::move(env)) {
|
UiXmlReader::UiXmlReader(gui::GUI& gui, scriptenv&& env)
|
||||||
|
: gui(gui), env(std::move(env)) {
|
||||||
contextStack.emplace("");
|
contextStack.emplace("");
|
||||||
add("image", read_image);
|
add("image", read_image);
|
||||||
add("canvas", read_canvas);
|
add("canvas", read_canvas);
|
||||||
|
|||||||
@ -137,7 +137,7 @@ static int l_unpack(lua::State* L) {
|
|||||||
for (size_t i = 0; format[i]; i++) {
|
for (size_t i = 0; format[i]; i++) {
|
||||||
switch (format[i]) {
|
switch (format[i]) {
|
||||||
case 'b':
|
case 'b':
|
||||||
lua::pushinteger(L, reader.get());
|
lua::pushinteger(L, static_cast<int8_t>(reader.get()));
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
lua::pushinteger(L, reader.get() & 0xFF);
|
lua::pushinteger(L, reader.get() & 0xFF);
|
||||||
|
|||||||
@ -44,7 +44,7 @@ static int l_create_fragment(lua::State* L) {
|
|||||||
|
|
||||||
static int l_load_fragment(lua::State* L) {
|
static int l_load_fragment(lua::State* L) {
|
||||||
dv::value map;
|
dv::value map;
|
||||||
if (!lua::isstring(L, 1)) {
|
if (lua::isstring(L, 1)) {
|
||||||
io::path path = lua::require_string(L, 1);
|
io::path path = lua::require_string(L, 1);
|
||||||
if (!io::exists(path)) {
|
if (!io::exists(path)) {
|
||||||
throw std::runtime_error("file "+path.string()+" does not exist");
|
throw std::runtime_error("file "+path.string()+" does not exist");
|
||||||
|
|||||||
@ -181,7 +181,6 @@ std::unique_ptr<Process> scripting::start_coroutine(const io::path& script) {
|
|||||||
lua::pushstring(L, pack.id);
|
lua::pushstring(L, pack.id);
|
||||||
lua::setfield(L, "PACK_ID");
|
lua::setfield(L, "PACK_ID");
|
||||||
|
|
||||||
lua::dump_stack(L);
|
|
||||||
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
||||||
lua::createtable(L, 0, 0);
|
lua::createtable(L, 0, 0);
|
||||||
lua::setglobal(L, "__vc__pack_envs");
|
lua::setglobal(L, "__vc__pack_envs");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user