Skip to content

Commit

Permalink
Update after PR, remove line spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Oct 5, 2022
1 parent 0ba7351 commit af62632
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Style is lua table with parameters. The default style is the following:
```lua
default = {
font_height = 28,
line_spacing = 8,
spacing = 1,
scale = 1,
waving = false,
Expand All @@ -66,7 +65,6 @@ These parameters *must* be present in your default or source style.
- `shaking` in pixels, the amount to shake every symbol the style applies to.

## Other Parameters:
- `line_spacing` in pixels, additional distance between new lines
- `can_skip` if false, printer.instant_appear is disabled while text with this style appears
- `sound` string. Name of the sound played when a symbol appears. TO-DO: Need to rewrite printer.play_sound function.
- `waving` set true to enable waving symbol effect
Expand Down Expand Up @@ -213,10 +211,10 @@ Use in the gui `final()` function to correct final printer component.
Insality

## Contributors
rocamocha
rocamocha

# Changelog
- \[9-20-22\] Improved functionality of creating new lines and added optional style parameter `line_spacing`. Updated documentation, converted passive voice to active voice where possible. (rocamocha)
- \[9-20-22\] Improved functionality of creating new lines. Updated documentation, converted passive voice to active voice where possible. (rocamocha)

# License
My code is under MIT license
Expand Down
10 changes: 6 additions & 4 deletions example/printer_example.gui
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ nodes {
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 0.0
alpha: 1.0
overridden_fields: 30
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
Expand Down Expand Up @@ -158,9 +159,9 @@ nodes {
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
Expand All @@ -172,6 +173,7 @@ nodes {
outline_alpha: 1.0
shadow_alpha: 1.0
overridden_fields: 10
overridden_fields: 16
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
Expand Down
2 changes: 1 addition & 1 deletion example/styles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ return {

slow_appear = {
speed = 0.08,
appear = 0.15,
appear = 0.2,
color = "#FFFFFF"
},

Expand Down
47 changes: 23 additions & 24 deletions printer/printer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ local colors = require("printer.colors")
local utf8 = require("printer.utf8string")
local custom_regex = require("printer.regex")

local HASH_PRINT_DONE = hash("print_done")
local COLOR_INVISIBLE = vmath.vector4(1, 1, 1, 0)

local contains = function(t, value)
for i = 1, #t do
if t[i] == value then
Expand All @@ -54,14 +57,14 @@ local contains = function(t, value)
end

local split = function(inputstr, sep)
sep = sep or "%s"
local t = {}
local i = 1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
sep = sep or "%s"
local t = {}
local i = 1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end

local M = {}
Expand All @@ -72,7 +75,6 @@ local styles = {
default = {
font_height = 28,
spacing = 1, -- pixels between letters
line_spacing = 8,
scale = 1, -- scale of character
waving = false, -- if true - do waving by sinus
color = "#FFFFFF",
Expand Down Expand Up @@ -105,11 +107,11 @@ end
local function get_style(self, name)
if name == "/" or name == "default" or name == nil then
if self.default_style == "default" then
self.last_style = styles.default
self.last_style = styles.default
return styles.default
else
name = self.default_style
self.last_style = styles[name]
self.last_style = styles[name]
end
end

Expand All @@ -118,7 +120,7 @@ local function get_style(self, name)
style[k] = v
end

for k, v in pairs(self.last_style) do
for k, v in pairs(self.last_style) do
style[k] = v
end

Expand All @@ -130,7 +132,7 @@ local function get_style(self, name)
print("[Printer]: No style name " .. name)
end

self.last_style = style
self.last_style = style
return style
end

Expand Down Expand Up @@ -210,12 +212,9 @@ local function update_letter_pos(self, node_data)

if not self.prev_node or is_new_row then
-- first symbol
local row_index = (self.current_row-1)
pos.x = -self.parent_size.x * 0.5
pos.y = self.parent_size.y - ((self.current_row-1) * style.font_height) - style.font_height
if is_new_row then
local line_spacing = style.line_spacing or style.font_height * 0.5
pos.y = pos.y - line_spacing * (self.current_row-1)
end
pos.y = self.parent_size.y * 0.5 - (row_index * style.font_height) - style.font_height * 0.5
else
local prev_pos = gui.get_position(self.prev_node.node)
local prev_size = get_letter_size(self.prev_node)
Expand All @@ -235,7 +234,6 @@ local function set_word_pos(self, word)
end


local invisible = vmath.vector4(1, 1, 1, 0)
local function get_symbol(self, text, stylename)
local is_icon = false
local node
Expand All @@ -254,7 +252,7 @@ local function get_symbol(self, text, stylename)
local node_data = {node = node, style = get_style(self, stylename), text = text, is_icon = is_icon}
gui.set_enabled(node, true)
gui.set_parent(node, self.node_parent)
gui.set_color(node, invisible)
gui.set_color(node, COLOR_INVISIBLE)
table.insert(self.current_letters, node_data)

return node_data
Expand Down Expand Up @@ -367,7 +365,7 @@ local function appear_node(self, node_data, is_instant)
color.w = 1
gui.animate(node, gui.PROP_COLOR, color, gui.EASING_OUTSINE, style.appear)
else
color.w = 1
color.w = 1
gui.set_color(node, color)
end

Expand Down Expand Up @@ -417,7 +415,7 @@ local function print_next(self)
end
else
self.is_print = false
msg.post('.', hash('print_done'))
msg.post('.', HASH_PRINT_DONE)
end
end

Expand Down Expand Up @@ -458,6 +456,7 @@ function M.fadeout(self)
end
end


function M.instant_appear(self)
local current_letter = self.current_letters[self.current_index]

Expand All @@ -482,7 +481,7 @@ function M.print(self, str, source)
self.new_row = false
self.stylename = source_styles[source] or "default"
self.default_style = self.stylename
self.last_style = styles[self.default_style]
self.last_style = styles[self.default_style]
self.prev_node = false
clear_prev_text(self)
self.string = str
Expand Down Expand Up @@ -556,4 +555,4 @@ function M.add_word_style(word, style)
end


return M
return M

0 comments on commit af62632

Please sign in to comment.