Skip to content

Commit

Permalink
'options' arg for Text:registerCommand, fixed reaction text wrapping …
Browse files Browse the repository at this point in the history
…strangely
  • Loading branch information
SylviBlossom committed Apr 20, 2022
1 parent 0a6d559 commit c0e0af8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/engine/game/common/smallfacetext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function SmallFaceText:init(text, face, x, y, actor)
self:addChild(self.sprite)
end

self.text = Text("", 40+70, 10)
self.text = Text("", 40+70, 10, nil, nil, nil, nil, false)
self.text.font_size = 16
self.text.inherit_color = true
self.text:setText(text)
Expand Down
8 changes: 4 additions & 4 deletions src/engine/game/common/textbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ function Textbox:init(x, y, width, height, default_font, default_font_size, batt
self.reactions = {}
self.reaction_instances = {}

self.text:registerCommand("face", function(text, node)
self.text:registerCommand("face", function(text, node, dry)
if self.actor and self.actor:getPortraitPath() then
self.face.path = self.actor:getPortraitPath()
end
self:setFace(node.arguments[1], tonumber(node.arguments[2]), tonumber(node.arguments[3]))
end)
self.text:registerCommand("facec", function(text, node)
self.text:registerCommand("facec", function(text, node, dry)
self.face.path = "face"
local ox, oy = tonumber(node.arguments[2]), tonumber(node.arguments[3])
if self.actor then
Expand All @@ -102,13 +102,13 @@ function Textbox:init(x, y, width, height, default_font, default_font_size, batt
self:setFace(node.arguments[1], ox, oy)
end)

self.text:registerCommand("react", function(text, node)
self.text:registerCommand("react", function(text, node, dry)
local react_data = tonumber(node.arguments[1]) and self.reactions[tonumber(node.arguments[1])] or self.reactions[node.arguments[1]]
local reaction = SmallFaceText(react_data.text, react_data.face, react_data.x, react_data.y, react_data.actor)
reaction.layer = 0.1 + (#self.reaction_instances) * 0.01
self:addChild(reaction)
table.insert(self.reaction_instances, reaction)
end, false)
end, {instant = false})

self.advance_callback = nil
end
Expand Down
4 changes: 2 additions & 2 deletions src/engine/game/shop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function Shop:postInit()
self.dialogue_text = DialogueText(nil, 30, 53 + 219)
self.dialogue_text.line_offset = 8

self.dialogue_text:registerCommand("emote", emoteCommand, true)
self.dialogue_text:registerCommand("emote", emoteCommand)

self.dialogue_text:setLayer(SHOP_LAYERS["dialogue"])
self:addChild(self.dialogue_text)
Expand All @@ -217,7 +217,7 @@ function Shop:postInit()
self.right_text = DialogueText("", 30 + 420, 53 + 209)
self.right_text.line_offset = 8

self.right_text:registerCommand("emote", emoteCommand, true)
self.right_text:registerCommand("emote", emoteCommand)

self.right_text:setLayer(SHOP_LAYERS["dialogue"])
self:addChild(self.right_text)
Expand Down
11 changes: 6 additions & 5 deletions src/engine/objects/dialoguetext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ function DialogueText:isModifier(command)
return Utils.containsValue(DialogueText.COMMANDS, command) or super:isModifier(self, command)
end

function DialogueText:registerCommand(command, func, instant)
super:registerCommand(self, command, func)
self.custom_command_wait[command] = (instant == false)
function DialogueText:registerCommand(command, func, options)
options = options or {}
super:registerCommand(self, command, func, options)
self.custom_command_wait[command] = options["instant"] ~= false
end

function DialogueText:processCustomCommand(node)
local result = super:processCustomCommand(self, node)
function DialogueText:processCustomCommand(node, dry)
local result = super:processCustomCommand(self, node, dry)
if self.custom_command_wait[node.command] then
self.state.typed_characters = self.state.typed_characters + 1
end
Expand Down
8 changes: 6 additions & 2 deletions src/engine/objects/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Text:init(text, x, y, w, h, font, style, autowrap)
self.nodes_to_draw = {}

self.custom_commands = {}
self.custom_command_dry = {}

self.font = font or "main"
self.font_size = nil
Expand Down Expand Up @@ -373,12 +374,15 @@ function Text:processModifier(node, dry)
end
end

function Text:registerCommand(command, func)
function Text:registerCommand(command, func, options)
self.custom_commands[command] = func
self.custom_command_dry[command] = options and options["dry"] or false
end

function Text:processCustomCommand(node, dry)
return self.custom_commands[node.command](self, node, dry)
if not dry or self.custom_command_dry[node.command] then
return self.custom_commands[node.command](self, node, dry)
end
end

function Text:drawChar(node, state, use_color)
Expand Down

0 comments on commit c0e0af8

Please sign in to comment.