全站通知:
模块:Story
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:Story/doc创建
local p = {}
--"行车日志"页内容
function p.drivingLog(frame)
local data = mw.text.jsonDecode(mw.title.new("Module:Story/DrivingLog.json"):getContent())
local drivingLogDiv = mw.html.create("div"):addClass("driving-log")
for index = 1,#data do --遍历行车日志(启程/我将远航/黄金之梦/二重裂变...)
local logDiv = mw.html.create("div"):addClass("log")
local chapterTitle = data[index].title --章节标题,如"启程"
local stories = data[index].stories
for i = 1,#stories do --遍历章节(剧幕,开端,起始,考核...)
logDiv:wikitext(p.formatDrivingLog(stories[i],chapterTitle))
end
local h2 = mw.html.create("h2"):wikitext(chapterTitle)
drivingLogDiv:wikitext(tostring(h2),tostring(logDiv))
end
return tostring(drivingLogDiv)
end
--拼合"行车日志"页每个章节的div
function p.formatDrivingLog(logInfo,chapterTitle)
local chapterDiv = mw.html.create("div"):addClass("chapter") --章节外框
local review = mw.html.create("div"):addClass("review"):wikitext("[[行车日志/"..chapterTitle.."#"..logInfo.title.."|"..logInfo.title.."]]")
local desc = mw.html.create("div"):addClass("desc"):wikitext(logInfo.desc)
chapterDiv:wikitext(tostring(review),tostring(desc))
return tostring(chapterDiv)
end
------------------------------------------------------------------------------------------------------------------------
--行车日志子页内容
function p.drivingLogLog()
local title = mw.title.getCurrentTitle().subpageText
local chapter = mw.text.jsonDecode(mw.title.new("Module:Story/"..title..".json"):getContent())
local resultString = ""
for index = 1,#chapter do --遍历章节(剧幕,开端,起始,考核...)
local title = chapter[index].title
local chapterString = mw.html.create("h2"):attr("id",title):wikitext(title)
local chapterDiv = mw.html.create("div"):addClass("chapter") --章节外框
local list = chapter[index].list
if list~=nil then
for i = 1,#list do --遍历章节(剧幕,开端,起始,考核...)
local text = list[i]
local pos1 = text:find("::")
local pos2 = #text - text:reverse():find("::")
local npc --说话的人(莉薇娅)
if pos1<=1 then
npc=mw.html.create("span"):addClass("npc"):wikitext("旁白")
else
npc = mw.html.create("span"):addClass("npc"):wikitext(text:sub(1,pos1-1))
end
local text = mw.html.create("span"):addClass("text"):wikitext(text:sub(pos2+2,#text)) --对话内容(早上好,列车长。)
local talk = mw.html.create("div"):addClass("talk"):wikitext(tostring(npc),":",tostring(text))
chapterDiv:wikitext(tostring(talk))
end
end
resultString = resultString..tostring(chapterString)..tostring(chapterDiv)
end
return resultString
end
------------------------------------------------------------------------------------------------------------------------
--通用剧情
function p.formatStory(frame)
local title=frame.args[1] --如"红茶战争-主线"
local chapter = mw.text.jsonDecode(mw.title.new("Module:Story/"..title..".json"):getContent())
local result=mw.html.create("div"):addClass("story")
for index = 1,#chapter do --遍历章节(剧幕,开端,起始,考核...)
if index~=1 then
result:wikitext(tostring(mw.html.create("hr")))
end
local list = chapter[index]
for i = 1,#chapter[index] do
local text = list[i]
local pos1 = text:find("::")
local pos2 = #text - text:reverse():find("::")
local npc --说话的人(卡塔斯)
if pos1<=1 then
npc=mw.html.create("span"):addClass("npc"):wikitext("旁白")
else
npc = mw.html.create("span"):addClass("npc"):wikitext(text:sub(1,pos1-1))
end
local text = mw.html.create("span"):addClass("text"):wikitext(text:sub(pos2+2,#text)) --对话内容(深渊的帮凶,协助在这片大陆扩散不祥的香气的黑铁之主啊,束手就擒吧!)
local talk = mw.html.create("div"):addClass("talk"):wikitext(tostring(npc),":",tostring(text))
result:wikitext(tostring(talk))
end
end
return tostring(result)
end
return p