close #42 (serializable import/export of elements)

This commit is contained in:
Paul Liverman III 2016-10-30 23:40:40 -07:00
parent bb2cbba024
commit 77ba978d7e
14 changed files with 112 additions and 14 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/bitser"]
path = lib/bitser
url = https://github.com/gvx/bitser

View File

@ -343,7 +343,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-10-30 22:18:17 </i> <i style="float:right;">Last updated 2016-10-30 23:39:49 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View File

@ -79,7 +79,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-10-30 22:18:17 </i> <i style="float:right;">Last updated 2016-10-30 23:39:49 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View File

@ -490,7 +490,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-10-30 22:18:17 </i> <i style="float:right;">Last updated 2016-10-30 23:39:49 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View File

@ -71,7 +71,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-10-30 22:18:17 </i> <i style="float:right;">Last updated 2016-10-30 23:39:49 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View File

@ -148,7 +148,15 @@ element.parent\focusChild element
table.insert element.parent, element.parent\removeChild(element),</td> table.insert element.parent, element.parent\removeChild(element),</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#printElementTree-todo4">printElementTree-todo4</a></td> <td class="name" nowrap><a href="#textinput-todo4">textinput-todo4</a></td>
<td class="summary">doc me</td>
</tr>
<tr>
<td class="name" nowrap><a href="#textinput-todo4-todo5">textinput-todo4-todo5</a></td>
<td class="summary">doc me</td>
</tr>
<tr>
<td class="name" nowrap><a href="#printElementTree-todo6">printElementTree-todo6</a></td>
<td class="summary">Correct this once elements are reimplemented if it needs correction.</td> <td class="summary">Correct this once elements are reimplemented if it needs correction.</td>
</tr> </tr>
</table> </table>
@ -645,8 +653,36 @@ table.insert element.parent, element.parent\removeChild(element),
</dd> </dd>
<dt> <dt>
<a name = "printElementTree-todo4"></a> <a name = "textinput-todo4"></a>
<strong>printElementTree-todo4</strong> <strong>textinput-todo4</strong>
</dt>
<dd>
doc me
</dd>
<dt>
<a name = "textinput-todo4-todo5"></a>
<strong>textinput-todo4-todo5</strong>
</dt>
<dd>
doc me
</dd>
<dt>
<a name = "printElementTree-todo6"></a>
<strong>printElementTree-todo6</strong>
</dt> </dt>
<dd> <dd>
Correct this once elements are reimplemented if it needs correction. Correct this once elements are reimplemented if it needs correction.
@ -665,7 +701,7 @@ table.insert element.parent, element.parent\removeChild(element),
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-10-30 22:18:17 </i> <i style="float:right;">Last updated 2016-10-30 23:39:49 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View File

@ -125,7 +125,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-10-30 22:18:17 </i> <i style="float:right;">Last updated 2016-10-30 23:39:49 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View File

@ -74,6 +74,9 @@ do
if self.data.draw == nil then if self.data.draw == nil then
self.data.draw = true self.data.draw = true
end end
if not (self.data.type) then
self.data.type = "element"
end
self.child = { } self.child = { }
end, end,
__base = _base_0, __base = _base_0,

View File

@ -22,6 +22,7 @@ class element
@data.h = 0 unless @data.h @data.h = 0 unless @data.h
@data.update = false if @data.update == nil @data.update = false if @data.update == nil
@data.draw = true if @data.draw == nil @data.draw = true if @data.draw == nil
@data.type = "element" unless @data.type
@child = {} @child = {}

View File

@ -14,7 +14,10 @@ do
data = { } data = { }
end end
self.parent, self.data = parent, data self.parent, self.data = parent, data
return _class_0.__parent.__init(self, self.parent, self.data) _class_0.__parent.__init(self, self.parent, self.data)
if self.data.type == "element" then
self.data.type = "window"
end
end, end,
__base = _base_0, __base = _base_0,
__name = "window", __name = "window",

View File

@ -10,6 +10,8 @@ class window extends element
new: (@parent, @data={}) => new: (@parent, @data={}) =>
super @parent, @data super @parent, @data
@data.type = "window" if @data.type == "element"
--- @todo if data, do stuff about it --- @todo if data, do stuff about it
setSize: => setSize: =>

View File

@ -29,6 +29,11 @@ local insert
insert = table.insert insert = table.insert
local inheritsFromElement local inheritsFromElement
inheritsFromElement = require(tostring(path) .. "/util").inheritsFromElement inheritsFromElement = require(tostring(path) .. "/util").inheritsFromElement
local dumps, loads
do
local _obj_0 = require(tostring(path) .. "/lib/bitser/bitser")
dumps, loads = _obj_0.dumps, _obj_0.loads
end
pop.elements = { } pop.elements = { }
pop.skins = { } pop.skins = { }
pop.extensions = { } pop.extensions = { }
@ -124,7 +129,6 @@ pop.create = function(element, parent, ...)
element = pop.elements[element](parent, ...) element = pop.elements[element](parent, ...)
insert(parent.child, element) insert(parent.child, element)
insert(parent.data.child, element.data) insert(parent.data.child, element.data)
element.parent = parent
element.data.parent = parent.data element.data.parent = parent.data
elseif parent == false then elseif parent == false then
element = pop.elements[element](false, ...) element = pop.elements[element](false, ...)
@ -134,7 +138,6 @@ pop.create = function(element, parent, ...)
element = pop.elements[element](pop.screen, parent, ...) element = pop.elements[element](pop.screen, parent, ...)
insert(pop.screen.child, element) insert(pop.screen.child, element)
insert(pop.screen.data.child, element.data) insert(pop.screen.data.child, element.data)
element.parent = pop.screen
element.data.parent = pop.screen.data element.data.parent = pop.screen.data
end end
return element return element
@ -252,6 +255,28 @@ pop.textinput = function(text)
end end
return false return false
end end
pop.import = function(data, parent)
if parent == nil then
parent = pop.screen
end
local element
if type(data) == "string" then
data = loads(data)
element = pop.create(data.type, parent, data)
else
element = pop.elements[data.type](parent, data)
insert(parent.child, element)
end
for i = 1, #data.child do
pop.import(data.child[i], element)
end
end
pop.export = function(element)
if element == nil then
element = pop.screen
end
return dumps(element.data)
end
pop.debugDraw = function(element) pop.debugDraw = function(element)
if element == nil then if element == nil then
element = pop.screen element = pop.screen

View File

@ -30,6 +30,7 @@ log "Require path detected: \"#{path}\""
import filesystem, graphics from love import filesystem, graphics from love
import insert from table import insert from table
import inheritsFromElement from require "#{path}/util" import inheritsFromElement from require "#{path}/util"
import dumps, loads from require "#{path}/lib/bitser/bitser"
--- @table pop --- @table pop
--- @tfield table elements All GUI classes are stored here. --- @tfield table elements All GUI classes are stored here.
@ -155,7 +156,7 @@ pop.create = (element, parent=pop.screen, ...) ->
element = pop.elements[element](parent, ...) element = pop.elements[element](parent, ...)
insert parent.child, element insert parent.child, element
insert parent.data.child, element.data insert parent.data.child, element.data
element.parent = parent --this should already have been set by the element, this is here as a precaution --element.parent = parent
element.data.parent = parent.data element.data.parent = parent.data
-- if explicitly no parent, just create the element -- if explicitly no parent, just create the element
elseif parent == false elseif parent == false
@ -167,7 +168,7 @@ pop.create = (element, parent=pop.screen, ...) ->
element = pop.elements[element](pop.screen, parent, ...) element = pop.elements[element](pop.screen, parent, ...)
insert pop.screen.child, element insert pop.screen.child, element
insert pop.screen.data.child, element.data insert pop.screen.data.child, element.data
element.parent = pop.screen --this should already have been set by the element, this is here as a precaution --element.parent = pop.screen
element.data.parent = pop.screen.data element.data.parent = pop.screen.data
return element return element
@ -369,6 +370,29 @@ pop.textinput = (text) ->
--- @todo doc me
pop.import = (data, parent=pop.screen) ->
local element
if type(data) == "string"
data = loads(data)
element = pop.create(data.type, parent, data)
else
element = pop.elements[data.type](parent, data)
insert parent.child, element
for i = 1, #data.child
pop.import data.child[i], element
--- @todo doc me
pop.export = (element=pop.screen) ->
return dumps(element.data)
--- Draws simple rectangle outlines to debug placement of elements. --- Draws simple rectangle outlines to debug placement of elements.
--- @function debugDraw --- @function debugDraw
--- @tparam Element element[opt] The element to draw (will draw its children as --- @tparam Element element[opt] The element to draw (will draw its children as

1
lib/bitser Submodule

@ -0,0 +1 @@
Subproject commit cf02122d221f5f7d3ebc898110f004cc6b658764