c1_lua/lua/app/userdata/chapter/chapter_data.lua
2023-04-07 20:50:11 +08:00

62 lines
1.4 KiB
Lua

local ChapterData = class("ChapterData", BaseData)
local MIN_CHAPTER_ID = 1
function ChapterData:ctor()
self.data.chapterId = MIN_CHAPTER_ID
self.data.maxChapterId = 0
self.data.isDirty = false
end
function ChapterData:clear()
self.data.chapterId = MIN_CHAPTER_ID
self.data.maxChapterId = 0
end
function ChapterData:init(data)
self.data.chapterId = data and data.chapterId or MIN_CHAPTER_ID
self.data.maxChapterId = data and data.maxChapterId or self.data.chapterId - 1
end
function ChapterData:getChapterId()
return self.data.chapterId
end
function ChapterData:setChapterId(chapterId)
self.data.chapterId = chapterId
end
function ChapterData:goNextChapter()
local chapterInfo = self:getChapterCfg()[self.data.chapterId]
if chapterInfo == nil then
return false
end
local chapterId = chapterInfo.next_chapter
if chapterId == nil then
return false
end
self.data.chapterId = chapterId
return true
end
function ChapterData:goLastChapter()
local chapterInfo = self:getChapterCfg()[self.data.chapterId]
if chapterInfo == nil then
return false
end
local chapterId = chapterInfo.before_chapter
if chapterId == nil then
return false
end
self.data.chapterId = chapterId
return true
end
function ChapterData:getChapterCfg()
if self.chapterCfg == nil then
self.chapterCfg = ConfigManager:getConfig("chapter")
end
return self.chapterCfg
end
return ChapterData