Project creation, loading working in editor.
This commit is contained in:
parent
b22473acac
commit
6853e60ffc
91
editor/config/data-helper.lua
Normal file
91
editor/config/data-helper.lua
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
-- This is a script to help build the data files needed for a project
|
||||||
|
|
||||||
|
local dirtools = require("tools.vfs.dirtools")
|
||||||
|
local utils = require("utils")
|
||||||
|
local json = require("lua.json")
|
||||||
|
|
||||||
|
local tinsert = table.insert
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local data_helper = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Each world thats created we make a default proc to process for http server
|
||||||
|
local loadDefaultAssets = function(world)
|
||||||
|
|
||||||
|
-- Always start with an empty asset pool when creating a new world.
|
||||||
|
local assetpool = {}
|
||||||
|
|
||||||
|
-- Add a default env (simple plane)
|
||||||
|
|
||||||
|
-- Add the default skydome (so there is a decent bg)
|
||||||
|
|
||||||
|
-- Add some gizmos needed for editing and such (like xyz axis gizmo, bound cube gizmo etc)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Each world thats created we make a default proc to process for http server
|
||||||
|
local loadDefaultScenes = function(world)
|
||||||
|
|
||||||
|
return { { name = "Default", id = 0 } }
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Each world thats created we make a default proc to process for http server
|
||||||
|
local loadDefaultScripts = function(world)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ name = "global", id = 0, script = "engine.script.global", ref = "Global" },
|
||||||
|
{ name = "scene", id = 1, script = "engine.script.scene", ref = "Default" }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
data_helper.make_worlds = function( datapath, worlds )
|
||||||
|
local worlddata_path = dirtools.combine_path(datapath, "worlds")
|
||||||
|
dirtools.make_folder(worlddata_path)
|
||||||
|
|
||||||
|
local world_entries = {}
|
||||||
|
for i,world in ipairs(worlds) do
|
||||||
|
|
||||||
|
local data = world.data or {}
|
||||||
|
-- These are asset groups for the world
|
||||||
|
data.groups = { { id = 0, name = "default", tags = "default,all" } }
|
||||||
|
-- World assets. Some default assets are added automatically (mainly for editor)
|
||||||
|
data.assets = loadDefaultAssets(data)
|
||||||
|
data.scenes = loadDefaultScenes(data)
|
||||||
|
data.entities = {}
|
||||||
|
data.scripts = loadDefaultScripts(data)
|
||||||
|
|
||||||
|
world.data = data
|
||||||
|
|
||||||
|
-- save to data folder.
|
||||||
|
local world_filename = dirtools.combine_path(worlddata_path, world.name..".json")
|
||||||
|
local fh = io.open( world_filename, "w" )
|
||||||
|
if(fh) then
|
||||||
|
fh:write( json.encode( data ) )
|
||||||
|
fh:close()
|
||||||
|
tinsert(world_entries, { name = world.name, filename = world_filename })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return world_entries
|
||||||
|
end
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
data_helper.make_assets = function( datapath )
|
||||||
|
local worlddata_path = dirtools.combine_path(datapath, "assets")
|
||||||
|
dirtools.make_folder(worlddata_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return data_helper
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
@ -55,7 +55,6 @@ local function init()
|
|||||||
local proc = shell32.ShellExecuteA( hwnd, "open", cmd, nil, nil, 1)
|
local proc = shell32.ShellExecuteA( hwnd, "open", cmd, nil, nil, 1)
|
||||||
-- io.popen(cmd, "r")
|
-- io.popen(cmd, "r")
|
||||||
ffi.C.Sleep(500)
|
ffi.C.Sleep(500)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,8 @@ local ffi = require("ffi")
|
|||||||
|
|
||||||
local dirtools = require("tools.vfs.dirtools")
|
local dirtools = require("tools.vfs.dirtools")
|
||||||
local cfgmgr = require('editor.config-manager')
|
local cfgmgr = require('editor.config-manager')
|
||||||
|
local datahlp = require('editor.config.data-helper')
|
||||||
|
local tiny = require('engine.world.world-manager')
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -28,6 +30,7 @@ local projectmanager = {
|
|||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
projectmanager.init = function(self)
|
projectmanager.init = function(self)
|
||||||
|
|
||||||
cfgmgr.load()
|
cfgmgr.load()
|
||||||
self.recents = cfgmgr.recents
|
self.recents = cfgmgr.recents
|
||||||
end
|
end
|
||||||
@ -39,6 +42,9 @@ projectmanager.create = function(self, project)
|
|||||||
-- Check the path is valid first
|
-- Check the path is valid first
|
||||||
if(project) then
|
if(project) then
|
||||||
if(project.path and dirtools.is_folder(project.path)) then
|
if(project.path and dirtools.is_folder(project.path)) then
|
||||||
|
|
||||||
|
tiny.default = tiny.default or tiny.addWorld(tiny, "MasterWorld")
|
||||||
|
|
||||||
local clean_name = utils.cleanstring(project.name)
|
local clean_name = utils.cleanstring(project.name)
|
||||||
local project_path = dirtools.combine_path(project.path, clean_name)
|
local project_path = dirtools.combine_path(project.path, clean_name)
|
||||||
if(dirtools.make_folder(project_path)) then
|
if(dirtools.make_folder(project_path)) then
|
||||||
@ -54,17 +60,21 @@ projectmanager.create = function(self, project)
|
|||||||
local data_path = dirtools.combine_path(project_path, "data")
|
local data_path = dirtools.combine_path(project_path, "data")
|
||||||
dirtools.make_folder(data_path)
|
dirtools.make_folder(data_path)
|
||||||
|
|
||||||
|
-- Iterate default worlds and create datasets (assets, scripts etc) for them
|
||||||
|
local world_entries = datahlp.make_worlds(data_path, tiny.worlds)
|
||||||
|
|
||||||
local project_filename = dirtools.combine_path(project_path, "project.slp")
|
local project_filename = dirtools.combine_path(project_path, "project.slp")
|
||||||
self.current_project = {
|
self.current_project = {
|
||||||
filename = project_filename,
|
filename = project_filename,
|
||||||
name = clean_name,
|
name = clean_name,
|
||||||
paths = {
|
paths = {
|
||||||
project = project_path,
|
project = project_path,
|
||||||
assets = assets_path,
|
assets = assets_path,
|
||||||
config = config_path,
|
config = config_path,
|
||||||
build = build_path,
|
build = build_path,
|
||||||
cache = cache_path,
|
cache = cache_path,
|
||||||
data = data_path,
|
data = data_path,
|
||||||
|
worlds = world_entries,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,14 +101,33 @@ projectmanager.load = function(self, project)
|
|||||||
project_filename = dirtools.combine_path(project.path, project.projectfile)
|
project_filename = dirtools.combine_path(project.path, project.projectfile)
|
||||||
local fh = io.open(project_filename, "r")
|
local fh = io.open(project_filename, "r")
|
||||||
if(fh) then
|
if(fh) then
|
||||||
local data = fh:read( '*a' )
|
local data = fh:read( "*a" )
|
||||||
self.current_project = json.decode(data)
|
self.current_project = json.decode(data)
|
||||||
fh:close()
|
fh:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Load worlds
|
||||||
|
-- Clear worlds first!!
|
||||||
|
tiny.worlds = {}
|
||||||
|
for i,world_obj in ipairs(self.current_project.paths.worlds) do
|
||||||
|
local fh = io.open( world_obj.filename, "r")
|
||||||
|
if(fh) then
|
||||||
|
local data = fh:read("*a")
|
||||||
|
local jworld = json.decode(data)
|
||||||
|
local world = tiny.addWorld(tiny, world_obj.name)
|
||||||
|
utils.tmerge(world, jworld)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Consider making this a timed autosaver. Will see.
|
||||||
|
projectmanager.save = function(self, project)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ $(document).ready(function () {
|
|||||||
};
|
};
|
||||||
postData("/project/create", jdata, function(){ });
|
postData("/project/create", jdata, function(){ });
|
||||||
$("#modalProjectSelectConfirm").modal("hide");
|
$("#modalProjectSelectConfirm").modal("hide");
|
||||||
$("#modalProjectSelect").modal("toggle");
|
$("#modalProjectSelect").modal("hide");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -180,39 +180,6 @@ worldmanager.addAsset = function(self, assetFilename)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
|
||||||
-- Each world thats created we make a default proc to process for http server
|
|
||||||
worldmanager.loadDefaultAssets = function(self)
|
|
||||||
|
|
||||||
local thisworld = self.current_world
|
|
||||||
-- Always start with an empty asset pool when creating a new world.
|
|
||||||
local assetpool = {}
|
|
||||||
|
|
||||||
-- Add a default env (simple plane)
|
|
||||||
|
|
||||||
-- Add the default skydome (so there is a decent bg)
|
|
||||||
|
|
||||||
-- Add some gizmos needed for editing and such (like xyz axis gizmo, bound cube gizmo etc)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
|
||||||
-- Each world thats created we make a default proc to process for http server
|
|
||||||
worldmanager.loadDefaultScenes = function(self)
|
|
||||||
|
|
||||||
return { { name = "Default", id = 0 } }
|
|
||||||
end
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
|
||||||
-- Each world thats created we make a default proc to process for http server
|
|
||||||
worldmanager.loadDefaultScripts = function(self)
|
|
||||||
|
|
||||||
return {
|
|
||||||
{ name = "global", id = 0, script = "engine.script.global", ref = "Global" },
|
|
||||||
{ name = "scene", id = 1, script = "engine.script.scene", ref = "Default" }
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
-- Each world thats created we make a default proc to process for http server
|
-- Each world thats created we make a default proc to process for http server
|
||||||
worldmanager.addWorld = function(self, worldname)
|
worldmanager.addWorld = function(self, worldname)
|
||||||
@ -222,21 +189,14 @@ worldmanager.addWorld = function(self, worldname)
|
|||||||
return nil
|
return nil
|
||||||
else
|
else
|
||||||
self.current_world = tiny.world()
|
self.current_world = tiny.world()
|
||||||
self.current_world.name = worldname
|
self.current_world.name = worldname
|
||||||
-- These are asset groups for the world
|
|
||||||
self.current_world.groups = { { id = 0, name = "default", tags = "default,all" } }
|
|
||||||
-- World assets. Some default assets are added automatically (mainly for editor)
|
|
||||||
self.current_world.assets = worldmanager.loadDefaultAssets(self)
|
|
||||||
self.current_world.scenes = worldmanager.loadDefaultScenes(self)
|
|
||||||
self.current_world.entities = {}
|
|
||||||
self.current_world.scripts = worldmanager.loadDefaultScripts(self)
|
|
||||||
|
|
||||||
-- Add an updater for entities in the httpserver
|
-- Add an updater for entities in the httpserver
|
||||||
self:addSystem( worldname.."_Entities", { "name", "etype" }, tinysrv.entitySystemProc )
|
self:addSystem( worldname.."_Entities", { "name", "etype" }, tinysrv.entitySystemProc )
|
||||||
|
|
||||||
tinsert(self.worlds, self.current_world)
|
tinsert(self.worlds, self.current_world)
|
||||||
self.systems_lookup[worldname] = utils.tcount(self.worlds)
|
self.systems_lookup[worldname] = utils.tcount(self.worlds)
|
||||||
return utils.tcount(self.worlds)
|
return self.current_world, utils.tcount(self.worlds)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -298,10 +258,6 @@ end
|
|||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
worldmanager.default = worldmanager.default or worldmanager.addWorld(worldmanager, "MasterWorld")
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return worldmanager
|
return worldmanager
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
{"name":"Another Project","filename":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project\\project.slp","paths":{"config":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project\\config","build":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project\\build","project":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project","data":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project\\data","cache":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project\\cache","assets":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\Another Project\\assets"}}
|
|
||||||
1
projects/MegaProject/data/worlds/MasterWorld.json
Normal file
1
projects/MegaProject/data/worlds/MasterWorld.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"groups":[{"tags":"default,all","id":0,"name":"default"}],"scripts":[{"ref":"Global","script":"engine.script.global","id":0,"name":"global"},{"ref":"Default","script":"engine.script.scene","id":1,"name":"scene"}],"entities":[],"scenes":[{"id":0,"name":"Default"}]}
|
||||||
@ -1,12 +1 @@
|
|||||||
{
|
{"paths":{"config":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\config","worlds":[{"filename":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\data\\worlds\\MasterWorld.json","name":"MasterWorld"}],"data":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\data","assets":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\assets","project":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject","cache":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\cache","build":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\build"},"filename":"F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\project.slp","name":"MegaProject"}
|
||||||
"name": "MegaProject",
|
|
||||||
"filename": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\project.slp",
|
|
||||||
"paths": {
|
|
||||||
"config": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\config",
|
|
||||||
"build": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\build",
|
|
||||||
"project": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject",
|
|
||||||
"data": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\data",
|
|
||||||
"cache": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\cache",
|
|
||||||
"assets": "F:\\dev\\luajit\\Thunc\\sokol-luajit\\projects\\MegaProject\\assets"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user