reply starting to work
I can't seem to break it, though I'm sleepy and don't have a good grasp of the big picture.
This commit is contained in:
parent
6a465257af
commit
2697d5eb7f
|
@ -29,11 +29,17 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
end
|
||||
local button = on_button(x,y)
|
||||
if button then
|
||||
local n, id = new_comment(button.name, button.depth)
|
||||
local parent = find_node(Global_state.thread, button.name)
|
||||
assert(parent)
|
||||
table.insert(parent.metadata.replies, id)
|
||||
save_metadata(parent)
|
||||
local item_index = find_comment_index(button.name)
|
||||
table.insert(Global_state.thread.data,
|
||||
button.item_index+1,
|
||||
new_comment(button.name, button.depth))
|
||||
item_index+1,
|
||||
n)
|
||||
A()
|
||||
end
|
||||
-- pan surface
|
||||
Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
load_subtree = function(filename, out, depth)
|
||||
load_subtree = function(id, out, depth)
|
||||
-- load a file and recursively all replies to it
|
||||
-- print('load_subtree', filename)
|
||||
local item = initialize_item(filename, depth)
|
||||
-- print('load_subtree', id)
|
||||
local item = initialize_item(id, depth)
|
||||
-- every item renders to a row consisting of two
|
||||
-- columns: padding and 'item stuff'
|
||||
local row = cols(Inter_comment_spacing)
|
||||
|
@ -12,9 +12,9 @@ load_subtree = function(filename, out, depth)
|
|||
table.insert(row.data, item_stuff)
|
||||
table.insert(item_stuff.data, item)
|
||||
table.insert(item_stuff.data,
|
||||
reply_button(filename, #out, depth))
|
||||
reply_button(id, depth))
|
||||
for i,reply_id in ipairs(item.metadata.replies) do
|
||||
local reply = load_subtree(reply_id, out, depth+1)
|
||||
end
|
||||
return item
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
initialize_item = function(filename, depth)
|
||||
local result = {filename=full_path(filename)}
|
||||
initialize_item = function(id, depth)
|
||||
local result = {
|
||||
type='text',
|
||||
id=id, filename=full_path(id),
|
||||
width=Width, depth=depth,
|
||||
metadata=load_metadata(id),
|
||||
border=Border_color,
|
||||
}
|
||||
load_from_disk(result)
|
||||
-- massage schema slightly; this isn't an editor state
|
||||
result.data = result.lines
|
||||
result.lines = nil
|
||||
-- more fields
|
||||
result.type = 'text'
|
||||
result.width = Width
|
||||
result.depth = depth
|
||||
result.metadata = load_metadata(filename)
|
||||
result.border = Border_color
|
||||
return result
|
||||
end
|
|
@ -1,18 +1,23 @@
|
|||
new_comment = function(parent_id, depth)
|
||||
local id = next_comment_id(parent_id)
|
||||
print('creating', id)
|
||||
local comment = {
|
||||
type='text',
|
||||
filename=full_path(next_comment(parent_id)),
|
||||
id=id,
|
||||
filename=full_path(id),
|
||||
data={{data=''}},
|
||||
width=Width,
|
||||
depth=depth+1,
|
||||
metadata={replies={}},
|
||||
border=Border_color,
|
||||
}
|
||||
save_metadata(comment)
|
||||
local result = cols(20)
|
||||
table.insert(result.data, indent(depth+1))
|
||||
local item_stuff = rows()
|
||||
table.insert(result.data, item_stuff)
|
||||
table.insert(item_stuff.data, comment)
|
||||
table.insert(item_stuff.data, reply_button(comment.filename, 0, depth+1))
|
||||
return result
|
||||
end
|
||||
table.insert(item_stuff.data,
|
||||
reply_button(comment.id, depth+1))
|
||||
return result, id
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
reply_button = function(filename, index, depth)
|
||||
reply_button = function(filename, depth)
|
||||
return {
|
||||
type='text', data={{data='reply'}},
|
||||
button=true, margin=20,
|
||||
name=filename, item_index=index,
|
||||
name=filename,
|
||||
depth=depth,
|
||||
bg=Reply_button_color,
|
||||
border=Reply_button_border_color,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
find_node = function(node, id)
|
||||
if node.type == 'text' and not node.button then
|
||||
if node.id == id then
|
||||
return node
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
if node.type == 'rows' or node.type == 'cols' then
|
||||
for _,child in ipairs(node.data) do
|
||||
local t = find_node(child, id)
|
||||
if t then return t end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
next_comment = function(id)
|
||||
next_comment_id = function(id)
|
||||
local num_replies = #load_metadata(id).replies
|
||||
local corename = id:gsub('%.md$', '')
|
||||
return ('%s-%d.md'):format(corename, num_replies)
|
|
@ -0,0 +1,6 @@
|
|||
save_metadata = function(node)
|
||||
--print('saving metadata for', node.id)
|
||||
local mfile = metadata_file(node.id)
|
||||
local mpath = save_dir_path(mfile)
|
||||
love.filesystem.write(mpath, json.encode(node.metadata))
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
find_comment_index = function(id)
|
||||
assert(Global_state.thread.type == 'rows')
|
||||
for i,row in ipairs(Global_state.thread.data) do
|
||||
assert(row.type == 'cols')
|
||||
assert(#row.data == 2)
|
||||
assert(row.data[2].type == 'rows')
|
||||
if row.data[2].data[1].id == id then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue