update editor & rename 'model' property to 'src'
This commit is contained in:
parent
4333d9ab06
commit
4ff42b94c3
@ -8,47 +8,49 @@
|
|||||||
</panel>
|
</panel>
|
||||||
</splitbox>
|
</splitbox>
|
||||||
<splitbox id="editorContainer" split-pos="0.8">
|
<splitbox id="editorContainer" split-pos="0.8">
|
||||||
<container color="#00000080"
|
<splitbox id="codePanel" orientation="horizontal">
|
||||||
onclick="document.editor.focused = true document.editor.caret = -1">
|
<container color="#00000080" cursor="text"
|
||||||
<container size-func="-1,30" color="#00000020">
|
onclick="document.editor.focused = true document.editor.caret = -1">
|
||||||
<image id="lockIcon" src="gui/lock" tooltip="@Read only"
|
<container size-func="-1,30" color="#00000020">
|
||||||
interactive="true" onclick="unlock_access()"
|
<image id="lockIcon" src="gui/lock" tooltip="@Read only"
|
||||||
color="#FFFFFF80" size="16" pos="4,6"
|
interactive="true" onclick="unlock_access()"
|
||||||
hover-color="#1080FF"></image>
|
color="#FFFFFF80" size="16" pos="4,6"
|
||||||
<panel orientation="horizontal" gravity="top-right"
|
hover-color="#1080FF"></image>
|
||||||
size="60,16" padding="8" interval="8" color="0">
|
<panel orientation="horizontal" gravity="top-right"
|
||||||
<image id="saveIcon" src="gui/save" tooltip="@Save"
|
size="60,16" padding="8" interval="8" color="0">
|
||||||
enabled="false" interactive="true"
|
<image id="saveIcon" src="gui/save" tooltip="@Save"
|
||||||
hover-color="#1080FF"
|
enabled="false" interactive="true"
|
||||||
onclick="save_current_file()"
|
hover-color="#1080FF"
|
||||||
color="#FFFFFF80" size="16"></image>
|
onclick="save_current_file()"
|
||||||
<image id="infoIcon" src="gui/info" tooltip="@editor.info.tooltip"
|
color="#FFFFFF80" size="16"></image>
|
||||||
enabled="true" interactive="true"
|
<image id="infoIcon" src="gui/info" tooltip="@editor.info.tooltip"
|
||||||
color="#FFFFFF80" size="16"></image>
|
enabled="true" interactive="true"
|
||||||
<image id="syncIcon" src="gui/play" tooltip="@Run"
|
color="#FFFFFF80" size="16"></image>
|
||||||
enabled="true" interactive="true"
|
<image id="syncIcon" src="gui/play" tooltip="@Run"
|
||||||
hover-color="#1080FF"
|
enabled="true" interactive="true"
|
||||||
onclick="run_current_file()"
|
hover-color="#1080FF"
|
||||||
color="#FFFFFF80" size="16"></image>
|
onclick="run_current_file()"
|
||||||
</panel>
|
color="#FFFFFF80" size="16"></image>
|
||||||
<label id="title" pos="26,8"></label>
|
</panel>
|
||||||
|
<label id="title" pos="26,8"></label>
|
||||||
|
</container>
|
||||||
|
<textbox
|
||||||
|
id='editor'
|
||||||
|
pos='0,30'
|
||||||
|
color='0'
|
||||||
|
autoresize='true'
|
||||||
|
margin='0'
|
||||||
|
padding='5'
|
||||||
|
multiline='true'
|
||||||
|
line-numbers='true'
|
||||||
|
oncontrolkey='on_control_combination'
|
||||||
|
size-func="-1,40"
|
||||||
|
text-wrap='false'
|
||||||
|
scroll-step='50'
|
||||||
|
></textbox>
|
||||||
</container>
|
</container>
|
||||||
<textbox
|
<modelviewer id="modelviewer" visible="false" center="0.5,0.5,0.5" cam-rotation="45,-45,0"/>
|
||||||
id='editor'
|
</splitbox>
|
||||||
pos='0,30'
|
|
||||||
color='0'
|
|
||||||
autoresize='true'
|
|
||||||
margin='0'
|
|
||||||
padding='5'
|
|
||||||
multiline='true'
|
|
||||||
line-numbers='true'
|
|
||||||
oncontrolkey='on_control_combination'
|
|
||||||
size-func="-1,40"
|
|
||||||
text-wrap='false'
|
|
||||||
scroll-step='50'
|
|
||||||
></textbox>
|
|
||||||
<modelviewer size="480" model="stairs" center="0.5,0.5,0.5" cam-rotation="45,-45,0" gravity="top-right"/>
|
|
||||||
</container>
|
|
||||||
<splitbox orientation="horizontal" split-pos="0.4">
|
<splitbox orientation="horizontal" split-pos="0.4">
|
||||||
<panel id="traceback" padding="4" color="#000000A0">
|
<panel id="traceback" padding="4" color="#000000A0">
|
||||||
</panel>
|
</panel>
|
||||||
|
|||||||
@ -104,10 +104,29 @@ function unlock_access()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function reload_model(filename, name)
|
||||||
|
assets.parse_model("xml", document.editor.text, name)
|
||||||
|
end
|
||||||
|
|
||||||
function run_current_file()
|
function run_current_file()
|
||||||
if not current_file.filename then
|
if not current_file.filename then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local info = registry.get_info(current_file.filename)
|
||||||
|
local script_type = info and info.type or "file"
|
||||||
|
local unit = info and info.unit
|
||||||
|
|
||||||
|
if script_type == "model" then
|
||||||
|
print(current_file.filename)
|
||||||
|
clear_output()
|
||||||
|
local _, err = pcall(reload_model, current_file.filename, unit)
|
||||||
|
if err then
|
||||||
|
document.output:paste(string.format("\n[#FF0000]%s[#FFFFFF]", err))
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local chunk, err = loadstring(document.editor.text, current_file.filename)
|
local chunk, err = loadstring(document.editor.text, current_file.filename)
|
||||||
clear_output()
|
clear_output()
|
||||||
if not chunk then
|
if not chunk then
|
||||||
@ -119,9 +138,7 @@ function run_current_file()
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local info = registry.get_info(current_file.filename)
|
|
||||||
local script_type = info and info.type or "file"
|
|
||||||
local unit = info and info.unit
|
|
||||||
save_current_file()
|
save_current_file()
|
||||||
|
|
||||||
local func = function()
|
local func = function()
|
||||||
@ -191,6 +208,7 @@ events.on("core:open_traceback", function(traceback_b64)
|
|||||||
tb_list.size = srcsize
|
tb_list.size = srcsize
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--- Save the current file in the code editor if has writeable path.
|
||||||
function save_current_file()
|
function save_current_file()
|
||||||
if not current_file.mutable then
|
if not current_file.mutable then
|
||||||
return
|
return
|
||||||
@ -202,7 +220,22 @@ function save_current_file()
|
|||||||
document.editor.edited = false
|
document.editor.edited = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Open a file in the code editor.
|
||||||
|
--- @param filename string - the path to the file to open.
|
||||||
|
--- @param line integer - the line number to focus on (optional).
|
||||||
|
--- @param mutable string - writeable file path (optional).
|
||||||
function open_file_in_editor(filename, line, mutable)
|
function open_file_in_editor(filename, line, mutable)
|
||||||
|
debug.log("opening file " .. string.escape(filename) .. " in editor")
|
||||||
|
|
||||||
|
local ext = file.ext(filename)
|
||||||
|
if ext == "xml" or ext == "vcm" then
|
||||||
|
document.modelviewer.src = file.stem(filename)
|
||||||
|
document.modelviewer.visible = true
|
||||||
|
else
|
||||||
|
document.modelviewer.visible = false
|
||||||
|
end
|
||||||
|
document.codePanel:refresh()
|
||||||
|
|
||||||
local editor = document.editor
|
local editor = document.editor
|
||||||
local source = file.read(filename):gsub('\t', ' ')
|
local source = file.read(filename):gsub('\t', ' ')
|
||||||
editor.scroll = 0
|
editor.scroll = 0
|
||||||
@ -225,7 +258,7 @@ end
|
|||||||
function on_open(mode)
|
function on_open(mode)
|
||||||
registry = require "core:internal/scripts_registry"
|
registry = require "core:internal/scripts_registry"
|
||||||
|
|
||||||
document.editorContainer:setInterval(200, refresh_file_title)
|
document.codePanel:setInterval(200, refresh_file_title)
|
||||||
|
|
||||||
clear_traceback()
|
clear_traceback()
|
||||||
clear_output()
|
clear_output()
|
||||||
|
|||||||
@ -22,8 +22,7 @@
|
|||||||
markup="md"
|
markup="md"
|
||||||
></textbox>
|
></textbox>
|
||||||
</container>
|
</container>
|
||||||
<iframe id="editorRoot" pos="0,30" size-func="-1,gui.get_viewport()[2]-30"
|
<iframe id="editorRoot" pos="0,30" size-func="-1,gui.get_viewport()[2]-30">
|
||||||
src="core:code_editor">
|
|
||||||
</iframe>
|
</iframe>
|
||||||
<textbox id='prompt'
|
<textbox id='prompt'
|
||||||
consumer='submit'
|
consumer='submit'
|
||||||
|
|||||||
@ -104,8 +104,10 @@ function set_mode(mode)
|
|||||||
|
|
||||||
if mode == 'debug' then
|
if mode == 'debug' then
|
||||||
document.root.color = {16, 18, 20, 220}
|
document.root.color = {16, 18, 20, 220}
|
||||||
|
document.editorRoot.src = "core:code_editor"
|
||||||
else
|
else
|
||||||
document.root.color = {0, 0, 0, 128}
|
document.root.color = {0, 0, 0, 128}
|
||||||
|
document.editorRoot.src = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
document.prompt.visible = show_prompt
|
document.prompt.visible = show_prompt
|
||||||
|
|||||||
@ -372,7 +372,7 @@ static std::shared_ptr<UINode> read_split_box(
|
|||||||
static std::shared_ptr<UINode> read_model_viewer(
|
static std::shared_ptr<UINode> read_model_viewer(
|
||||||
UiXmlReader& reader, const xml::xmlelement& element
|
UiXmlReader& reader, const xml::xmlelement& element
|
||||||
) {
|
) {
|
||||||
auto model = element.attr("model", "").getText();
|
auto model = element.attr("src", "").getText();
|
||||||
auto viewer = std::make_shared<ModelViewer>(
|
auto viewer = std::make_shared<ModelViewer>(
|
||||||
reader.getGUI(), glm::vec2(), model
|
reader.getGUI(), glm::vec2(), model
|
||||||
);
|
);
|
||||||
|
|||||||
@ -192,6 +192,9 @@ std::string EnginePaths::createWriteableDevice(const std::string& name) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (name == "core") {
|
||||||
|
folder = "res:";
|
||||||
|
}
|
||||||
if (folder.emptyOrInvalid()) {
|
if (folder.emptyOrInvalid()) {
|
||||||
throw std::runtime_error("pack not found");
|
throw std::runtime_error("pack not found");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user