Merge pull request #527 from MihailRis/vcm-format
new simple text 3d models format
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
language = "VCM"
|
||||
extensions = ["vcm"]
|
||||
line-comment-start = "#"
|
||||
@@ -0,0 +1,4 @@
|
||||
language = "XML"
|
||||
extensions = ["xml"]
|
||||
multiline-comment-start = "<!--"
|
||||
multiline-comment-end = "-->"
|
||||
+43
-46
@@ -1,12 +1,6 @@
|
||||
<splitbox id="editorRoot" orientation="horizontal" split-pos="0.3">
|
||||
<splitbox split-pos="0.75">
|
||||
<panel interval="2" color="0" padding="2">
|
||||
<textbox pos="2" padding="4,0,4,0" sub-consumer="filter_files" hint="@Filter"></textbox>
|
||||
<panel id="filesList" color="#00000030" interval="6" padding="4"
|
||||
size-func="-1,-45" pos="2,38">
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
</panel>
|
||||
<iframe src="core:files_panel"></iframe>
|
||||
<panel id="problemsLog"
|
||||
color="#00000030"
|
||||
padding="5,15,5,15">
|
||||
@@ -14,46 +8,49 @@
|
||||
</panel>
|
||||
</splitbox>
|
||||
<splitbox id="editorContainer" split-pos="0.8">
|
||||
<container color="#00000080"
|
||||
onclick="document.editor.focused = true document.editor.caret = -1">
|
||||
<container size-func="-1,30" color="#00000020">
|
||||
<image id="lockIcon" src="gui/lock" tooltip="@Read only"
|
||||
interactive="true" onclick="unlock_access()"
|
||||
color="#FFFFFF80" size="16" pos="4,6"
|
||||
hover-color="#1080FF"></image>
|
||||
<panel orientation="horizontal" gravity="top-right"
|
||||
size="60,16" padding="8" interval="8" color="0">
|
||||
<image id="saveIcon" src="gui/save" tooltip="@Save"
|
||||
enabled="false" interactive="true"
|
||||
hover-color="#1080FF"
|
||||
onclick="save_current_file()"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
<image id="infoIcon" src="gui/info" tooltip="@editor.info.tooltip"
|
||||
enabled="true" interactive="true"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
<image id="syncIcon" src="gui/play" tooltip="@Run"
|
||||
enabled="true" interactive="true"
|
||||
hover-color="#1080FF"
|
||||
onclick="run_current_file()"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
</panel>
|
||||
<label id="title" pos="26,8"></label>
|
||||
<splitbox id="codePanel" orientation="horizontal">
|
||||
<container color="#00000080" cursor="text"
|
||||
onclick="document.editor.focused = true document.editor.caret = -1">
|
||||
<container size-func="-1,30" color="#00000020">
|
||||
<image id="lockIcon" src="gui/lock" tooltip="@Read only"
|
||||
interactive="true" onclick="unlock_access()"
|
||||
color="#FFFFFF80" size="16" pos="4,6"
|
||||
hover-color="#1080FF"></image>
|
||||
<panel orientation="horizontal" gravity="top-right"
|
||||
size="60,16" padding="8" interval="8" color="0">
|
||||
<image id="saveIcon" src="gui/save" tooltip="@Save"
|
||||
enabled="false" interactive="true"
|
||||
hover-color="#1080FF"
|
||||
onclick="save_current_file()"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
<image id="infoIcon" src="gui/info" tooltip="@editor.info.tooltip"
|
||||
enabled="true" interactive="true"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
<image id="syncIcon" src="gui/play" tooltip="@Run"
|
||||
enabled="true" interactive="true"
|
||||
hover-color="#1080FF"
|
||||
onclick="run_current_file()"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
</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>
|
||||
<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>
|
||||
<modelviewer id="modelviewer" visible="false" center="0.5,0.5,0.5" cam-rotation="45,-45,0"/>
|
||||
</splitbox>
|
||||
<splitbox orientation="horizontal" split-pos="0.4">
|
||||
<panel id="traceback" padding="4" color="#000000A0">
|
||||
</panel>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
local writeables = {}
|
||||
local registry
|
||||
local filenames
|
||||
|
||||
local current_file = {
|
||||
filename = "",
|
||||
@@ -49,6 +48,10 @@ events.on("core:error", function (msg, traceback)
|
||||
table.insert(errors_all, full)
|
||||
end)
|
||||
|
||||
events.on("core:open_in_editor", function(filename, linenum)
|
||||
open_file_in_editor(filename, linenum)
|
||||
end)
|
||||
|
||||
local function find_mutable(filename)
|
||||
local packid = file.prefix(filename)
|
||||
if packid == "core" then
|
||||
@@ -80,16 +83,6 @@ local function refresh_file_title()
|
||||
..(edited and ' *' or '')
|
||||
end
|
||||
|
||||
function filter_files(text)
|
||||
local filtered = {}
|
||||
for _, filename in ipairs(filenames) do
|
||||
if filename:find(text) then
|
||||
table.insert(filtered, filename)
|
||||
end
|
||||
end
|
||||
build_files_list(filtered, text)
|
||||
end
|
||||
|
||||
function on_control_combination(keycode)
|
||||
if keycode == input.keycode("s") then
|
||||
save_current_file()
|
||||
@@ -111,10 +104,29 @@ function unlock_access()
|
||||
)
|
||||
end
|
||||
|
||||
local function reload_model(filename, name)
|
||||
assets.parse_model("xml", document.editor.text, name)
|
||||
end
|
||||
|
||||
function run_current_file()
|
||||
if not current_file.filename then
|
||||
return
|
||||
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)
|
||||
clear_output()
|
||||
if not chunk then
|
||||
@@ -126,9 +138,7 @@ function run_current_file()
|
||||
)
|
||||
return
|
||||
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()
|
||||
|
||||
local func = function()
|
||||
@@ -198,6 +208,7 @@ events.on("core:open_traceback", function(traceback_b64)
|
||||
tb_list.size = srcsize
|
||||
end)
|
||||
|
||||
--- Save the current file in the code editor if has writeable path.
|
||||
function save_current_file()
|
||||
if not current_file.mutable then
|
||||
return
|
||||
@@ -209,7 +220,22 @@ function save_current_file()
|
||||
document.editor.edited = false
|
||||
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)
|
||||
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 source = file.read(filename):gsub('\t', ' ')
|
||||
editor.scroll = 0
|
||||
@@ -229,43 +255,11 @@ function open_file_in_editor(filename, line, mutable)
|
||||
document.saveIcon.enabled = current_file.modified
|
||||
end
|
||||
|
||||
function build_files_list(filenames, selected)
|
||||
local files_list = document.filesList
|
||||
files_list.scroll = 0
|
||||
files_list:clear()
|
||||
|
||||
for _, actual_filename in ipairs(filenames) do
|
||||
local filename = actual_filename
|
||||
if selected then
|
||||
filename = filename:gsub(selected, "**"..selected.."**")
|
||||
end
|
||||
local parent = file.parent(filename)
|
||||
local info = registry.get_info(actual_filename)
|
||||
local icon = "file"
|
||||
if info then
|
||||
icon = info.type == "component" and "entity" or info.type
|
||||
end
|
||||
files_list:add(gui.template("script_file", {
|
||||
path = parent .. (parent[#parent] == ':' and '' or '/'),
|
||||
name = file.name(filename),
|
||||
icon = icon,
|
||||
unit = info and info.unit or '',
|
||||
filename = actual_filename
|
||||
}))
|
||||
end
|
||||
end
|
||||
|
||||
function on_open(mode)
|
||||
registry = require "core:internal/scripts_registry"
|
||||
|
||||
local files_list = document.filesList
|
||||
|
||||
document.editorContainer:setInterval(200, refresh_file_title)
|
||||
document.codePanel:setInterval(200, refresh_file_title)
|
||||
|
||||
clear_traceback()
|
||||
clear_output()
|
||||
|
||||
filenames = registry.filenames
|
||||
table.sort(filenames)
|
||||
build_files_list(filenames)
|
||||
end
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
markup="md"
|
||||
></textbox>
|
||||
</container>
|
||||
<iframe id="editorRoot" pos="0,30" size-func="-1,gui.get_viewport()[2]-30"
|
||||
src="core:code_editor">
|
||||
<iframe id="editorRoot" pos="0,30" size-func="-1,gui.get_viewport()[2]-30">
|
||||
</iframe>
|
||||
<textbox id='prompt'
|
||||
consumer='submit'
|
||||
|
||||
@@ -104,8 +104,10 @@ function set_mode(mode)
|
||||
|
||||
if mode == 'debug' then
|
||||
document.root.color = {16, 18, 20, 220}
|
||||
document.editorRoot.src = "core:code_editor"
|
||||
else
|
||||
document.root.color = {0, 0, 0, 128}
|
||||
document.editorRoot.src = ""
|
||||
end
|
||||
|
||||
document.prompt.visible = show_prompt
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<panel interval="2" color="0" padding="2">
|
||||
<textbox pos="2" padding="4,0,4,0" sub-consumer="filter_files" hint="@Filter"></textbox>
|
||||
<panel id="filesList" color="#00000030" interval="6" padding="4"
|
||||
size-func="-1,-45" pos="2,38">
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
</panel>
|
||||
@@ -0,0 +1,54 @@
|
||||
local registry
|
||||
local filenames
|
||||
|
||||
function filter_files(text)
|
||||
local pattern_safe = text:pattern_safe();
|
||||
local filtered = {}
|
||||
for _, filename in ipairs(filenames) do
|
||||
if filename:find(pattern_safe) then
|
||||
table.insert(filtered, filename)
|
||||
end
|
||||
end
|
||||
build_files_list(filtered, pattern_safe)
|
||||
end
|
||||
|
||||
function open_file_in_editor(filename, linenum)
|
||||
events.emit("core:open_in_editor", filename, linenum)
|
||||
end
|
||||
|
||||
function build_files_list(filenames, highlighted_part)
|
||||
local files_list = document.filesList
|
||||
files_list.scroll = 0
|
||||
files_list:clear()
|
||||
|
||||
for _, actual_filename in ipairs(filenames) do
|
||||
local filename = actual_filename
|
||||
if highlighted_part then
|
||||
filename = filename:gsub(highlighted_part, "**"..highlighted_part.."**")
|
||||
end
|
||||
local parent = file.parent(filename)
|
||||
local info = registry.get_info(actual_filename)
|
||||
local icon = "file"
|
||||
if info then
|
||||
icon = info.type == "component" and "entity" or info.type
|
||||
end
|
||||
files_list:add(gui.template("script_file", {
|
||||
path = parent .. (parent[#parent] == ':' and '' or '/'),
|
||||
name = file.name(filename),
|
||||
icon = icon,
|
||||
unit = info and info.unit or '',
|
||||
filename = actual_filename,
|
||||
open_func = "open_file_in_editor",
|
||||
}))
|
||||
end
|
||||
end
|
||||
|
||||
function on_open(mode)
|
||||
registry = require "core:internal/scripts_registry"
|
||||
|
||||
local files_list = document.filesList
|
||||
|
||||
filenames = registry.filenames
|
||||
table.sort(filenames)
|
||||
build_files_list(filenames)
|
||||
end
|
||||
@@ -3,7 +3,7 @@
|
||||
<label hover-color='#30A0FF'
|
||||
pos="20,2"
|
||||
interactive="true"
|
||||
onclick='open_file_in_editor("%{filename}")'
|
||||
onclick='%{open_func}("%{filename}")'
|
||||
markup='md'
|
||||
tooltip='%{unit}'
|
||||
sizefunc="-1,-1">
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@box from (0,0,0) to (1,0.5,1) delete (top,south)
|
||||
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,south)
|
||||
@rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2"
|
||||
@rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1"
|
||||
@@ -1,6 +1,6 @@
|
||||
local export = {
|
||||
filenames = {},
|
||||
classification = {}
|
||||
registry = {}
|
||||
}
|
||||
|
||||
local function collect_components(dirname, dest)
|
||||
@@ -9,7 +9,7 @@ local function collect_components(dirname, dest)
|
||||
for i, filename in ipairs(files) do
|
||||
if file.ext(filename) == "lua" then
|
||||
table.insert(dest, filename)
|
||||
export.classification[filename] = {
|
||||
export.registry[filename] = {
|
||||
type="component",
|
||||
unit=file.prefix(filename)..":"..file.stem(filename)
|
||||
}
|
||||
@@ -33,13 +33,13 @@ local function collect_scripts(dirname, dest, ismodule)
|
||||
end
|
||||
end
|
||||
|
||||
local function load_scripts_list()
|
||||
local packs = pack.get_installed()
|
||||
local function load_scripts_list(packs)
|
||||
local registry = export.registry
|
||||
for _, packid in ipairs(packs) do
|
||||
collect_scripts(packid..":modules", export.filenames, true)
|
||||
end
|
||||
for _, filename in ipairs(export.filenames) do
|
||||
export.classification[filename] = {
|
||||
registry[filename] = {
|
||||
type="module",
|
||||
unit=file.join(file.parent(file.prefix(filename)..":"..
|
||||
filename:sub(filename:find("/")+1)),
|
||||
@@ -51,27 +51,39 @@ local function load_scripts_list()
|
||||
end
|
||||
end
|
||||
|
||||
function export.build_classification()
|
||||
local classification = {}
|
||||
local function load_models_list(packs)
|
||||
local registry = export.registry
|
||||
for _, filename in ipairs(file.list("models")) do
|
||||
local ext = file.ext(filename)
|
||||
if ext == "xml" or ext == "vcm" then
|
||||
registry[filename] = {type="model", unit=file.stem(filename)}
|
||||
table.insert(export.filenames, filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function export.build_registry()
|
||||
local registry = {}
|
||||
for id, props in pairs(block.properties) do
|
||||
classification[props["script-file"]] = {type="block", unit=block.name(id)}
|
||||
registry[props["script-file"]] = {type="block", unit=block.name(id)}
|
||||
end
|
||||
for id, props in pairs(item.properties) do
|
||||
classification[props["script-file"]] = {type="item", unit=item.name(id)}
|
||||
registry[props["script-file"]] = {type="item", unit=item.name(id)}
|
||||
end
|
||||
local packs = pack.get_installed()
|
||||
for _, packid in ipairs(packs) do
|
||||
classification[packid..":scripts/world.lua"] = {type="world", unit=packid}
|
||||
classification[packid..":scripts/hud.lua"] = {type="hud", unit=packid}
|
||||
registry[packid..":scripts/world.lua"] = {type="world", unit=packid}
|
||||
registry[packid..":scripts/hud.lua"] = {type="hud", unit=packid}
|
||||
end
|
||||
export.classification = classification
|
||||
export.registry = registry
|
||||
export.filenames = {}
|
||||
|
||||
load_scripts_list()
|
||||
load_scripts_list(packs)
|
||||
load_models_list(packs)
|
||||
end
|
||||
|
||||
function export.get_info(filename)
|
||||
return export.classification[filename]
|
||||
return export.registry[filename]
|
||||
end
|
||||
|
||||
return export
|
||||
|
||||
@@ -63,4 +63,4 @@ cache_names(block)
|
||||
cache_names(item)
|
||||
|
||||
local scripts_registry = require "core:internal/scripts_registry"
|
||||
scripts_registry.build_classification()
|
||||
scripts_registry.build_registry()
|
||||
|
||||
@@ -523,9 +523,6 @@ function time.post_runnable(runnable)
|
||||
table.insert(__post_runnables, runnable)
|
||||
end
|
||||
|
||||
assets = {}
|
||||
assets.load_texture = core.__load_texture
|
||||
|
||||
-- --------- Deprecated functions ------ --
|
||||
local function wrap_deprecated(func, name, alternatives)
|
||||
return function (...)
|
||||
|
||||
Reference in New Issue
Block a user