diff --git a/assets/fonts/Roboto_Mono/OFL.txt b/assets/fonts/Roboto_Mono/OFL.txt new file mode 100644 index 0000000..38d9750 --- /dev/null +++ b/assets/fonts/Roboto_Mono/OFL.txt @@ -0,0 +1,91 @@ +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/Roboto_Mono/font.ttf b/assets/fonts/Roboto_Mono/font.ttf new file mode 100644 index 0000000..3806bfb Binary files /dev/null and b/assets/fonts/Roboto_Mono/font.ttf differ diff --git a/assets/fonts/WDXL_Lubrifont_TC/OFL.txt b/assets/fonts/WDXL_Lubrifont_TC/OFL.txt new file mode 100644 index 0000000..2294d5d --- /dev/null +++ b/assets/fonts/WDXL_Lubrifont_TC/OFL.txt @@ -0,0 +1,94 @@ +Copyright 2025 The WDXL Lubrifont Project Authors (https://github.com/NightFurySL2001/WD-XL-font) +Copyright 2018-2020 The ZCOOL QingKe HuangYou Project Authors (https://www.github.com/googlefonts/zcool-qingke-huangyou) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/WDXL_Lubrifont_TC/font.ttf b/assets/fonts/WDXL_Lubrifont_TC/font.ttf new file mode 100644 index 0000000..a98f355 Binary files /dev/null and b/assets/fonts/WDXL_Lubrifont_TC/font.ttf differ diff --git a/lib/simple_ui/level/bar.lua b/lib/simple_ui/level/bar.lua index aa3d723..b91701e 100644 --- a/lib/simple_ui/level/bar.lua +++ b/lib/simple_ui/level/bar.lua @@ -57,6 +57,8 @@ function barElement:draw() love.graphics.setColor(1, 1, 1) --- текст поверх if self.drawText then + local font = Tree.fonts:getDefaultTheme():getVariant("small") + love.graphics.setFont(font) love.graphics.printf(tostring(self.value) .. "/" .. tostring(self.maxValue), self.bounds.x, self.bounds.y, self.bounds.width, "center") end diff --git a/lib/simple_ui/level/end_turn.lua b/lib/simple_ui/level/end_turn.lua index 53c506c..e1cb679 100644 --- a/lib/simple_ui/level/end_turn.lua +++ b/lib/simple_ui/level/end_turn.lua @@ -22,8 +22,8 @@ function endTurnButton:update(dt) end function endTurnButton:layout() - local font = love.graphics.newFont(16) - self.text = love.graphics.newText(font, "end_turn") + local font = Tree.fonts:getDefaultTheme():getVariant("headline") + self.text = love.graphics.newText(font, "Завершить ход") self.bounds.width = self.text:getWidth() + 32 self.bounds.height = self.text:getHeight() + 16 end diff --git a/lib/tree.lua b/lib/tree.lua index 3d47546..a023fdc 100644 --- a/lib/tree.lua +++ b/lib/tree.lua @@ -6,6 +6,7 @@ Tree = { assets = (require "lib.utils.asset_bundle"):load() } +Tree.fonts = (require "lib.utils.font_manager"):load("WDXL_Lubrifont_TC"):loadTheme("Roboto_Mono") -- дефолтный шрифт Tree.panning = require "lib/panning" Tree.controls = require "lib.controls" Tree.level = (require "lib.level.level").new("procedural", "flower_plains") -- для теста у нас только один уровень, который сразу же загружен diff --git a/lib/utils/asset_bundle.lua b/lib/utils/asset_bundle.lua index da4692a..b8e355b 100644 --- a/lib/utils/asset_bundle.lua +++ b/lib/utils/asset_bundle.lua @@ -51,7 +51,7 @@ function AssetBundle.loadFile(path) elseif (ext == "lua") then return require(string.gsub(path, ".lua", "")) end - return nil + return filedata end function AssetBundle.cutExtension(filename) diff --git a/lib/utils/font_manager.lua b/lib/utils/font_manager.lua new file mode 100644 index 0000000..0bec070 --- /dev/null +++ b/lib/utils/font_manager.lua @@ -0,0 +1,94 @@ +--- @alias FontVariant "smallest" | "small" | "medium" | "large" | "headline" + +--- @class TextTheme +--- @field private _sizes {[FontVariant]: integer} +local theme = { + _sizes = { + smallest = 10, + small = 12, + medium = 14, + large = 16, + headline = 20, + } +} +theme.__index = theme + +--- @param loader fun(size: integer): love.Font? +function theme.new(loader) + local t = {} + for tag, size in pairs(theme._sizes) do + local f = loader(size) + if not f then return nil end + t[tag] = f + end + + return setmetatable(t, theme) +end + +--- @param variant FontVariant +--- @return love.Font +function theme:getVariant(variant) + return self[variant] +end + +---------------------------------------------------------- + +--- A singleton to handle fonts +--- @class FontManager +--- @field private _themes table +--- @field defaultTheme string? +local FontManager = { + _themes = {} +} + +--- @param name string +--- @param size integer +function FontManager.newFont(name, size) + local err = function() + print("[FontManager]: font " .. name .. " not found!") + end + local fontDir = Tree.assets.files.fonts[name] + if not fontDir then return err() end + local font = fontDir.font + if not font then return err() end + return love.graphics.newFont(font, size) +end + +--- @param name string +--- @return FontManager +function FontManager:loadTheme(name) + self._themes[name] = theme.new( + function(size) + return self.newFont(name, size) + end + ) + return self +end + +--- @param name string +--- @return TextTheme? +function FontManager:getTheme(name) + return self._themes[name] +end + +--- @return TextTheme +function FontManager:getDefaultTheme() + return self._themes[self.defaultTheme] +end + +--- initial setup +--- @param defaultFontName string +function FontManager:load(defaultFontName) + local t = self:loadTheme(defaultFontName):getTheme(defaultFontName) + if not t then + print("[FontManager]: default font " .. defaultFontName .. " is missing") + return self + end + self.defaultTheme = defaultFontName + + local f = t:getVariant("medium") + love.graphics.setFont(f) + return self +end + +return FontManager diff --git a/main.lua b/main.lua index 3b2629c..bd2a7a8 100644 --- a/main.lua +++ b/main.lua @@ -64,6 +64,7 @@ function love.draw() testLayout:draw() love.graphics.setColor(1, 1, 1) + love.graphics.setFont(Tree.fonts:getTheme("Roboto_Mono"):getVariant("medium")) local stats = "fps: " .. love.timer.getFPS() .. " lt: " .. lt .. " dt: " .. dt .. " mem: " .. string.format("%.2f MB", collectgarbage("count") / 1000)