Skip to content

Commit

Permalink
Fix: Duplicate one time function calls after new line
Browse files Browse the repository at this point in the history
This will fix the issue reported that will cause duplicate one time functions in text-boxes that print one set of characters at a time.
  • Loading branch information
sysl-dev committed Aug 3, 2024
1 parent 1f903fc commit 6c9b950
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
15 changes: 12 additions & 3 deletions example/library/slog-text.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local m = {
debug = false,
_NAME = 'SYSL-Text',
_VERSION = '2.1',
_VERSION = '2.2',
_DESCRIPTION = 'Fancy Text System',
_URL = 'https://github.com/SystemLogoff',
_LICENSE = [[
Expand Down Expand Up @@ -450,6 +450,7 @@ function M:send(text, wrap_num, show_all)
"audio",
"waitforinput",
"scroll",
"function", -- If you're using instant text, have your function calls outside of the textbox.
} -- HACK: Some commands are not allowed when showing all the text at once.
for i = 1, #self.table_string do
for x = 1, #banned_commands do
Expand All @@ -476,6 +477,15 @@ function M:send(text, wrap_num, show_all)
end
end

------------------------------------------------------------------------------
--Remove Empty
------------------------------------------------------------------------------

for i = #self.table_string, 1, -1 do
if self.table_string[i] == "" then
table.remove(self.table_string, i)
end
end
------------------------------------------------------------------------------
-- Calculates width and height, no matter what display mode the text is set to.
-- Note, some special commands will throw this off, such as cursor drawing
Expand Down Expand Up @@ -683,8 +693,7 @@ function M:update(dt)
-----------------------------------------------------------------------------
-- Skip waiting for rendering when it's a command.
-----------------------------------------------------------------------------
if self.table_string[self.current_character] and
self.table_string[self.current_character]:match("%" .. special_character[1]) then
if self.table_string[self.current_character] and self.table_string[self.current_character]:match("%" .. special_character[1]) and self.table_string[self.current_character] ~= (special_character[1] .. "newline" .. special_character[2]) then
self.current_character = self.current_character + 1
end

Expand Down
36 changes: 29 additions & 7 deletions example/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Icon = require("library.slog-icon");
-- SLog Text Library
Text = require("library.slog-text")

--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
--[[------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------]]--
-- Config - Advanced Scripting
--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
-- Enable Advanced Scripting with the [function=lua code] command.
Expand Down Expand Up @@ -138,8 +138,8 @@ Text.configure.add_text_sound(Audio.text.neue, 0.2)
-- There are nicer ways to do this, but it works as an example.
--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
example = {
display_mode = 10,
maxmodes = 10,
display_mode = 11,
maxmodes = 11,
long_text_block = require('longtext'),
ex5_textboxsize = 64,
bop = true,
Expand Down Expand Up @@ -179,8 +179,11 @@ example8box:send("[function=example.bop=true]Did you hear about the [color=#FF00
example9box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue_small, character_sound = true, print_speed = 0.04, sound_every = 2, sound_number = 4})
example9box:send("Hello! Welcome to the world of Pocket Creatures![waitforinput][scroll][newline]My name is Professor Tree![newline][waitforinput][scroll][scroll]And you are?", 150, false)
example10box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.monogram_extended_custom, character_sound = false, keep_space_on_line_break=true, modify_character_width_table = {["j"] = -1, }})
local sp_test_string = "[shake][[]color=red][/shake]"
example10box:send("Special Sheep Polution Test, Bahhh:\n\nij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij\n\na a a a a a a a a a a a a a a a a a a a a a a a a\n\nI've dropped so many letters oh no!\nOjan Pjan Ajan Testj Characterj oj mh wj ikj applej orangej colaj Martijn..\n" .. sp_test_string, 540, true)
local sp_test_string = "[shake][[]color=red]Wow it's characters[[]/color][/shake]"
example10box:send("Special Sheep Polution Test, Bahhh:\n\nij ij ij ij ij ij ij ij ij ij ij ij ij ij ij [color=#ff0000]ij ij ij ij ij[/color] ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ijfart [rainbow]\n\na a a a a a a[/rainbow] a a a a a a a a a a a a a a a a a a [function=print('tes1t')]\n[function=print('te2st')] \nI've dropped so many letters oh no!\nOjan Pjan Ajan Testj Characterj oj mh wj ikj applej orangej colaj Martijn..\n" .. sp_test_string, 540, true)
example11box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.monogram_extended_custom, character_sound = false, keep_space_on_line_break=true, modify_character_width_table = {["j"] = -1, }})
example11box:send("Special Sheep Polution Test, Bahhh:\n\nij ij ij ij ij ij ij ij[function=print('test1')] ij ij ij ij ij ij ij [color=#ff0000]ij ij ij ij ij[/color] ij ij ij [function=print('test2')]ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ij ijfart[backspace=4] [rainbow]\n\na a a a a a a[/rainbow] a a a a a a a a a a a a a a a a a a [function=print('tes1t')]\n [function=print('te2st')] \nThis is for Function is executed twice when placed exactly after where the text is wrapped #10 " , 540, false)

end

--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
Expand Down Expand Up @@ -283,7 +286,7 @@ example_text = "Catching Monsters Style Textbox / C to continue text"
love.graphics.draw(images.bg)

Frame.draw("utp", 320/2 - 150/2 - 4, 180 - 40, example9box.get.width + 8, 2 * 17)
local bop = 1

love.graphics.setScissor( 320/2 - 150/2, 180 - 40 + 4, example9box.get.width, 2 * 17 )
example9box:draw(320/2 - 150/2, 180 - 40 + 4)
love.graphics.setScissor()
Expand All @@ -301,7 +304,7 @@ end

if example.display_mode == 10 then
Screen.start()
example_text = "Center Style Textbox"
example_text = "BugFix Textbox"

love.graphics.draw(images.bg)
Screen.stop()
Expand All @@ -311,6 +314,20 @@ if example.display_mode == 10 then
example10box:draw(0,0)
end



if example.display_mode == 11 then
Screen.start()
example_text = "BugFix2 Textbox"

love.graphics.draw(images.bg)
Screen.stop()
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill",0,0,540, 540)
love.graphics.setColor(1,1,1,1)
example11box:draw(0,0)
end

-- Draw Information Bar At the Bottom
love.graphics.setColor(0.95,0.95,0.95,1)
love.graphics.rectangle("fill", 0, 180*4 - 25, 320*4, 40)
Expand Down Expand Up @@ -357,12 +374,17 @@ function love.update(dt)
if example.display_mode == 10 then
example10box:update(dt)
end
if example.display_mode == 11 then
example11box:update(dt)
end
end

--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
-- Hacky mess per example
--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
function love.keypressed( key, scancode, isrepeat )
if key == "f3" then print(table.concat(example11box.table_string)) end
if key == "f2" then print(table.concat(example11box.table_string, "|")) end
if key == "space" then example.display_mode = example.display_mode + 1 end
if example.display_mode > example.maxmodes then example.display_mode = 1 end
if example.display_mode == 1 then
Expand Down

0 comments on commit 6c9b950

Please sign in to comment.