Commit 555049fb47984d5b7206892dc72b11ee0faf436e

Authored by DarkGod
1 parent 078f397d

Chat files now support dynamic dialog entries

... ... @@ -72,6 +72,7 @@ function _M:init(name, npc, player, data)
72 72 self:loadChatFormat(filepath)
73 73 end
74 74 end
  75 + self._loadchat = loadchat
75 76 loadchat(name, true)
76 77
77 78 self:triggerHook{"Chat:load", data=data}
... ... @@ -93,7 +94,9 @@ end
93 94 function _M:setFunctionEnv(fct)
94 95 local env = setmetatable({
95 96 self = self,
  97 + cur_chat = self,
96 98 chat_env = self.chat_env,
  99 + loadChatFile = function(file) return self._loadchat(file, false) end,
97 100 newChat = function(c) self:addChat(c) end,
98 101 }, {__index=_G})
99 102 setfenv(fct, env)
... ... @@ -137,7 +140,7 @@ function _M:chatFormatActions(nodes, answer, node, stop_at)
137 140 end
138 141
139 142 ---------------------------------------------------------------------------
140   - if node.name == "chat" or node.name == "entry-selector" then
  143 + if node.name == "chat" or node.name == "entry-selector" or node.name == "dynamic" then
141 144 answer.jump = node.data.chatid
142 145 ---------------------------------------------------------------------------
143 146 elseif node.name == "lua-code" then
... ... @@ -371,6 +374,15 @@ function _M:loadChatFormat(filepath)
371 374 auto = auto,
372 375 answers = answers,
373 376 }
  377 + elseif node.name == "dynamic" then
  378 + local auto, err = loadstring(node.data.code)
  379 + if not auto and err then error("[Chat] chatFormatActions ERROR: "..err) end
  380 + self:setFunctionEnv(auto)
  381 + local text, answers = auto()
  382 + self:addChat{ id = node.data.chatid,
  383 + text = text,
  384 + answers = answers,
  385 + }
374 386 end
375 387 end
376 388 self.default_id = "welcome"
... ...