Compare commits
68 Commits
feature/fl
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 781a09a947 | |||
| 9e7a787d83 | |||
| d41f9fb542 | |||
| 80ae1e0a68 | |||
| 1602d3b5ac | |||
| 1f97bffe2e | |||
| 8b24793e82 | |||
| c7a41676c2 | |||
| aac6e5e8f4 | |||
| 3d125f5cbc | |||
| 1397e48e84 | |||
| b75dca12cb | |||
| 4f7dc9ab14 | |||
| efe98e8210 | |||
| 5bc51c976e | |||
| 652098fea1 | |||
| 46a71ceb0b | |||
| 90f3a82ce5 | |||
| b4b9eea27e | |||
| ec18710047 | |||
| 5c464bc9ee | |||
| 53c83bf1a1 | |||
| d8a89ec24b | |||
| d587c93222 | |||
| 4cdd9f17ba | |||
| 1514ad12ca | |||
| 52027c8693 | |||
| 3ef6cfcfaf | |||
| 7242ad44ed | |||
| 46a52c31df | |||
| 8bd9ae275b | |||
| 51075bafbb | |||
| 3015971692 | |||
| 9b5488ce0c | |||
| a5e5ade8d7 | |||
| 24131f277c | |||
| 0934028955 | |||
| 9d11941fe9 | |||
| 8e58b8a532 | |||
| 83e743e1cd | |||
| b89719abed | |||
| 3d6124d2ed | |||
| 09fb7e80ae | |||
| 885fabe24e | |||
| 4629cde5d4 | |||
| b77c07eef0 | |||
| 7526e3064f | |||
| 4b14d7252e | |||
| 2b4dc56c88 | |||
| 947ac12c35 | |||
| eecf24c471 | |||
| a9f8816c8e | |||
| be386be601 | |||
| 8cbaf643ab | |||
| 77f5a2abdc | |||
| f59f32bd70 | |||
| 94cd2e7ee9 | |||
| 7c5314b7c8 | |||
| d2599f8764 | |||
| 351fdda60c | |||
| e3d9cafdd3 | |||
| 8292a20ae0 | |||
| c54e489b58 | |||
| a4b29af579 | |||
| f3d74440ce | |||
| 9b10557435 | |||
| aa4c5185d3 | |||
| 8cb6e62845 |
BIN
assets/audio/sounds/meow.ogg
(Stored with Git LFS)
Normal file
BIN
assets/audio/sounds/meow.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -9,5 +9,6 @@ Tree.behaviors.positioned = require "character.behaviors.positioned"
|
|||||||
Tree.behaviors.tiled = require "character.behaviors.tiled"
|
Tree.behaviors.tiled = require "character.behaviors.tiled"
|
||||||
Tree.behaviors.cursor = require "character.behaviors.cursor"
|
Tree.behaviors.cursor = require "character.behaviors.cursor"
|
||||||
Tree.behaviors.ai = require "lib.character.behaviors.ai"
|
Tree.behaviors.ai = require "lib.character.behaviors.ai"
|
||||||
|
Tree.behaviors.effects = require "lib.character.behaviors.effects"
|
||||||
|
|
||||||
--- @alias voidCallback fun(): nil
|
--- @alias voidCallback fun(): nil
|
||||||
|
|||||||
187
lib/character/behaviors/effects.lua
Normal file
187
lib/character/behaviors/effects.lua
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
local task = require "lib.utils.task"
|
||||||
|
local efb = require "lib.effectbook"
|
||||||
|
local book = efb.book
|
||||||
|
|
||||||
|
--- ===========ЛОГИКА ЭФФЕКТОВ И ЧТО С ЭТИМ ЕДЯТ===========
|
||||||
|
--- читать здесь: https://docs.google.com/document/d/1Hxa5dOLaeRpLQOs5H-oIDDuLLhKbDw40lR9d62Zb4Tg/edit?usp=sharing
|
||||||
|
--- и здесь: https://docs.google.com/document/d/1jvhuM3mxqYSQTEM8m-WL-uUSie9QRsZOCCUEiw9ZqzM/edit?tab=t.0
|
||||||
|
|
||||||
|
--- behavior thats holds all effects that we applied
|
||||||
|
--- @class EffectsBehavior : Behavior
|
||||||
|
--- @field effectsPriority EffectTag[] хранит эффекты в порядке их применения
|
||||||
|
--- @field effectsProperties table<EffectTag, { stacks: integer, intensity: integer }> хранит характеристики эффектов
|
||||||
|
local behavior = {}
|
||||||
|
behavior.__index = behavior
|
||||||
|
behavior.id = "effects"
|
||||||
|
|
||||||
|
--- @return EffectsBehavior
|
||||||
|
function behavior.new()
|
||||||
|
return setmetatable({
|
||||||
|
effectsPriority = {},
|
||||||
|
effectsProperties = {},
|
||||||
|
}, behavior)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- проверяет, можно ли наложить эффект и при наложении его применяет
|
||||||
|
--- @param effect EffectTag
|
||||||
|
--- @param stacks integer
|
||||||
|
--- @param intensity integer
|
||||||
|
function behavior:addEffect(effect, stacks, intensity)
|
||||||
|
local task1, birthStatement = book[effect]:beforeBirth(self.owner, intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
if not birthStatement then return end
|
||||||
|
|
||||||
|
-- проверка на сумму, и её применение
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
if efb.sums[effect] then
|
||||||
|
if efb.sums[effect][ef] then
|
||||||
|
if not efb.sums[effect][ef](self.owner, effect, ef) then return end
|
||||||
|
end
|
||||||
|
elseif efb.sums[ef] then
|
||||||
|
if efb.sums[ef][effect] then
|
||||||
|
if not efb.sums[ef][effect](self.owner, ef, effect) then return end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
book[effect]:onBirth(self.owner, stacks, intensity)
|
||||||
|
|
||||||
|
local task3 = book[effect]:afterBirth(self.owner, intensity)
|
||||||
|
if task3 then
|
||||||
|
task3(function()
|
||||||
|
print("[Effects]: мы применили эффект!!")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Удаляет один эффект по порядку
|
||||||
|
--- @param effect EffectTag
|
||||||
|
function behavior:deleteEffect(effect)
|
||||||
|
self.effectsProperties[effect] = nil
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
if ef == effect then
|
||||||
|
table.remove(self.effectsPriority, i)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- О ДААА ЭТА ФУНКЦИЯ МЕНЯЕТ СОСТОЯНИЕ О ДАААААА О ДАААААААААА
|
||||||
|
--- @param effect EffectTag
|
||||||
|
--- @param amount integer
|
||||||
|
function behavior:deleteStacks(effect, amount)
|
||||||
|
print("[Effects]: удаляем стаки!!")
|
||||||
|
self.effectsProperties[effect].stacks = self.effectsProperties[effect].stacks -
|
||||||
|
amount -- !!!!!!!!!!!!!!!! <<<<< 21+ only
|
||||||
|
if self.effectsProperties[effect].stacks <= 0 then
|
||||||
|
print("[Effects]:", effect, "ДОЛЖЕН БЫТЬ СТЁРТ")
|
||||||
|
self:deleteEffect(effect)
|
||||||
|
print("[Effects]:", effect, "СТЁРТ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должна вызываться перед смертью персонажа;
|
||||||
|
---
|
||||||
|
--- возвращает, убивать ли персонажа
|
||||||
|
--- @return boolean
|
||||||
|
function behavior:beforeDeath()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1, deathStatement = book[ef]:beforeDeath(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
if deathStatement == false then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должна вызываться после смерти персонажа (может ли такая ситуация возникнуть вообще?)
|
||||||
|
function behavior:afterDeath()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1 = book[ef]:afterDeath(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должен вызываться в начале хода
|
||||||
|
---
|
||||||
|
--- возвращает, может ли персонаж сделать ход?
|
||||||
|
--- @return boolean
|
||||||
|
function behavior:beforeTurn()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1, turnStatement = book[ef]:beforeTurn(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
if turnStatement == false then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должен вызываться в конце хода
|
||||||
|
function behavior:afterTurn()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1 = book[ef]:afterTurn(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должен вызываться перед кастом спелла
|
||||||
|
---
|
||||||
|
--- возвращает, может ли персонаж скастовать спелл?
|
||||||
|
--- @return boolean
|
||||||
|
function behavior:beforeCast()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1, castStatement = book[ef]:beforeCast(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
if castStatement == false then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должен вызываться после каста спелла
|
||||||
|
function behavior:afterCast()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1 = book[ef]:afterCast(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должен вызываться перед получением урона
|
||||||
|
---
|
||||||
|
--- возвращает получаемый урон
|
||||||
|
--- @return integer
|
||||||
|
function behavior:beforeDamage(damage)
|
||||||
|
local totalDamage = damage
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1
|
||||||
|
task1, totalDamage = book[ef]:beforeDamage(self.owner, self.effectsProperties[ef].intensity,
|
||||||
|
totalDamage or damage)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return totalDamage or damage
|
||||||
|
end
|
||||||
|
|
||||||
|
--- должен вызываться после получения урона
|
||||||
|
function behavior:afterDamage()
|
||||||
|
for i, ef in ipairs(self.effectsPriority) do
|
||||||
|
local task1 = book[ef]:afterDamage(self.owner, self.effectsProperties[ef].intensity)
|
||||||
|
if task1 then
|
||||||
|
task1(function() end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return behavior
|
||||||
@ -20,6 +20,9 @@ function behavior.new(spellbook)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function behavior:endCast()
|
function behavior:endCast()
|
||||||
|
self.owner:try(Tree.behaviors.effects, function(effects)
|
||||||
|
effects:afterCast()
|
||||||
|
end)
|
||||||
self.state = "idle"
|
self.state = "idle"
|
||||||
self.cast = nil
|
self.cast = nil
|
||||||
Tree.level.turnOrder:reorder()
|
Tree.level.turnOrder:reorder()
|
||||||
|
|||||||
@ -6,10 +6,27 @@
|
|||||||
--- @field initiative integer
|
--- @field initiative integer
|
||||||
--- @field class Class
|
--- @field class Class
|
||||||
--- @field isInTurnOrder boolean
|
--- @field isInTurnOrder boolean
|
||||||
|
--- @field amIAlive boolean
|
||||||
local behavior = {}
|
local behavior = {}
|
||||||
behavior.__index = behavior
|
behavior.__index = behavior
|
||||||
behavior.id = "stats"
|
behavior.id = "stats"
|
||||||
|
|
||||||
|
--- план прост, если что-то не так, то мы просто убиваем бехавиор (по крайней мере так должно было быть, но пиаш мне запретил :sob:)
|
||||||
|
function behavior:checkStats()
|
||||||
|
-- if self.hp <= 0 then behavior:die() end
|
||||||
|
if self.hp <= 0 then
|
||||||
|
self.amIAlive = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param damage integer
|
||||||
|
function behavior:dealDamage(damage)
|
||||||
|
local effects = self.owner:has(Tree.behaviors.effects)
|
||||||
|
if effects then damage = effects:beforeDamage(damage) end
|
||||||
|
self.hp = self.hp - damage
|
||||||
|
self:checkStats()
|
||||||
|
end
|
||||||
|
|
||||||
--- @param hp? integer
|
--- @param hp? integer
|
||||||
--- @param mana? integer
|
--- @param mana? integer
|
||||||
--- @param initiative? integer
|
--- @param initiative? integer
|
||||||
@ -22,6 +39,7 @@ function behavior.new(hp, mana, initiative, class, isInTurnOrder)
|
|||||||
initiative = initiative or 10,
|
initiative = initiative or 10,
|
||||||
class = class or "dev_warrior",
|
class = class or "dev_warrior",
|
||||||
isInTurnOrder = isInTurnOrder or true,
|
isInTurnOrder = isInTurnOrder or true,
|
||||||
|
amIAlive = true
|
||||||
}, behavior)
|
}, behavior)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
123
lib/effectbook.lua
Normal file
123
lib/effectbook.lua
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
local task = require "lib.utils.task"
|
||||||
|
local effect = require "lib.spell.effect"
|
||||||
|
local easing = require "lib.utils.easing"
|
||||||
|
|
||||||
|
--- некое уникальное строковое значение
|
||||||
|
--- @alias EffectTag string
|
||||||
|
|
||||||
|
--- Кровотечение.
|
||||||
|
---
|
||||||
|
--- Наносит `intensity` урона перед началом каждого хода.
|
||||||
|
local bleeding = effect.new({
|
||||||
|
tag = "bleeding"
|
||||||
|
})
|
||||||
|
|
||||||
|
function bleeding:afterBirth(owner, intensity)
|
||||||
|
local light = require "lib/character/character".spawn("Bleeding Light Effect")
|
||||||
|
light:addBehavior {
|
||||||
|
Tree.behaviors.light.new { color = Vec3 { 1, 0., 0. }, intensity = 4 },
|
||||||
|
Tree.behaviors.positioned.new(owner:has(Tree.behaviors.positioned).position + Vec3 { 0.5, 0.5 }),
|
||||||
|
}
|
||||||
|
|
||||||
|
return task.wait({ task.chain(task.tween(light:has(Tree.behaviors.light) --[[@as LightBehavior]],
|
||||||
|
{ intensity = 1, color = Vec3 { 0, 0., 0. } }, 800, easing.easeInCubic), function()
|
||||||
|
light:die()
|
||||||
|
return task.fromValue()
|
||||||
|
end) })
|
||||||
|
end
|
||||||
|
|
||||||
|
function bleeding:beforeTurn(owner, intensity)
|
||||||
|
local stats = owner:has(Tree.behaviors.stats)
|
||||||
|
local sprite = owner:has(Tree.behaviors.sprite)
|
||||||
|
if not stats or not sprite then return end
|
||||||
|
stats:dealDamage(intensity)
|
||||||
|
return task.wait({ sprite:animate("hurt") }), true
|
||||||
|
end
|
||||||
|
|
||||||
|
function bleeding:afterTurn(owner, intensity)
|
||||||
|
local behavior = owner:has(Tree.behaviors.effects)
|
||||||
|
if not behavior then
|
||||||
|
print('[EffectBook]: yo man what the hell wheres your behavior how thats possible please stop thats not normal')
|
||||||
|
else
|
||||||
|
behavior:deleteStacks("bleeding", 1)
|
||||||
|
end
|
||||||
|
return task.wait {}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- meow
|
||||||
|
function bleeding:afterCast(owner, intensity)
|
||||||
|
Tree.audio:play(Tree.assets.files.audio.sounds.meow)
|
||||||
|
return task.wait {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function bleeding:beforeCast(owner, intensity)
|
||||||
|
Tree.audio:play(Tree.assets.files.audio.sounds.meow)
|
||||||
|
return task.wait {}, true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Отвращение к смерти.
|
||||||
|
---
|
||||||
|
--- Спасает от смертельного урона, оставляя одно очко здоровья. Персонаж не может ходить до тех пор, пока эффект не сработает.
|
||||||
|
local aversionToDeath = effect.new {
|
||||||
|
tag = "aversionToDeath"
|
||||||
|
}
|
||||||
|
|
||||||
|
function aversionToDeath:beforeDamage(owner, intensity, damage)
|
||||||
|
local stats = owner:has(Tree.behaviors.stats)
|
||||||
|
local effects = owner:has(Tree.behaviors.effects)
|
||||||
|
if not stats or not effects then return end
|
||||||
|
if stats.hp <= damage then
|
||||||
|
effects:deleteStacks("aversionToDeath", 1)
|
||||||
|
-- тут должен быть какой-нибудь классный спецэффект, но я не умею в шейдеры
|
||||||
|
return task.wait({}), stats.hp - 1
|
||||||
|
end
|
||||||
|
return task.wait {}, damage
|
||||||
|
end
|
||||||
|
|
||||||
|
function aversionToDeath:beforeTurn(owner, intensity)
|
||||||
|
local sprite = owner:has(Tree.behaviors.sprite)
|
||||||
|
if not sprite then
|
||||||
|
return task.wait {}, false
|
||||||
|
end
|
||||||
|
return task.wait {
|
||||||
|
sprite:animate("hurt")
|
||||||
|
}, false
|
||||||
|
end
|
||||||
|
|
||||||
|
----------------- Effectbook & Sum -----------------
|
||||||
|
|
||||||
|
--- @alias EffectSumFunc fun(owner: Character, effect1: EffectTag, effect2: EffectTag): boolean
|
||||||
|
|
||||||
|
--- Принимает таблицу, в ключах которых тэги эффектов, которые мы хотим просуммировать, и в значениях которых функция,
|
||||||
|
--- возвращающая булево значение: применять ли эффект после суммирования.
|
||||||
|
--- @type table<EffectTag, table<EffectTag, EffectSumFunc>>
|
||||||
|
local sums = {}
|
||||||
|
|
||||||
|
--- Сумма кровотечения и отвращения к смерти, (в целях разработки) удаляет оба эффекта, не позволяя дальше применять эффект
|
||||||
|
sums.bleeding = {
|
||||||
|
aversionToDeath = function(owner, effect1, effect2)
|
||||||
|
print("[EffectBook]: применяем сумму, удаляем оба эффекта")
|
||||||
|
local behaviorEffect = owner:has(Tree.behaviors.effects)
|
||||||
|
if not behaviorEffect then
|
||||||
|
print(
|
||||||
|
"[EffectBook]: yo man what the hell wheres your behavior how thats possible please stop thats not normal")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
behaviorEffect:deleteEffect(effect1)
|
||||||
|
behaviorEffect:deleteEffect(effect2)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
--- @class EffectBook
|
||||||
|
--- @field sums table<EffectTag, table<EffectTag, EffectSumFunc>>
|
||||||
|
--- @field book table<EffectTag, Effect>
|
||||||
|
local effectbook = {
|
||||||
|
sums = sums,
|
||||||
|
book = {
|
||||||
|
bleeding = bleeding,
|
||||||
|
aversionToDeath = aversionToDeath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return effectbook
|
||||||
@ -1,8 +1,6 @@
|
|||||||
local utils = require "lib.utils.utils"
|
local utils = require "lib.utils.utils"
|
||||||
local pQueue = require "lib.utils.priority_queue"
|
|
||||||
--- @class CharacterGrid : Grid
|
--- @class CharacterGrid : Grid
|
||||||
--- @field __grid {string: Id|nil}
|
--- @field __grid {string: Id|nil}
|
||||||
--- @field yOrderQueue PriorityQueue<Character> очередь отрисовки сверху вниз
|
|
||||||
local grid = setmetatable({}, require "lib.level.grid.base")
|
local grid = setmetatable({}, require "lib.level.grid.base")
|
||||||
grid.__index = grid
|
grid.__index = grid
|
||||||
|
|
||||||
@ -29,22 +27,13 @@ function grid:add(id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param a Character
|
|
||||||
--- @param b Character
|
|
||||||
local function drawCmp(a, b)
|
|
||||||
--- @TODO: это захардкожено, надо разделить поведения
|
|
||||||
return a:has(Tree.behaviors.positioned).position.y < b:has(Tree.behaviors.positioned).position.y
|
|
||||||
end
|
|
||||||
|
|
||||||
--- fills the grid with the actual data
|
--- fills the grid with the actual data
|
||||||
---
|
---
|
||||||
--- should be called as early as possible during every tick
|
--- should be called as early as possible during every tick
|
||||||
function grid:reload()
|
function grid:reload()
|
||||||
self:reset()
|
self:reset()
|
||||||
self.yOrderQueue = pQueue.new(drawCmp)
|
|
||||||
utils.each(Tree.level.characters, function(c)
|
utils.each(Tree.level.characters, function(c)
|
||||||
self:add(c.id)
|
self:add(c.id)
|
||||||
self.yOrderQueue:insert(c)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,15 @@ function turnOrder:next()
|
|||||||
char:try(Tree.behaviors.positioned, function(positioned)
|
char:try(Tree.behaviors.positioned, function(positioned)
|
||||||
Tree.level.camera:animateTo(positioned.position, 1500, easing.easeInOutCubic)(
|
Tree.level.camera:animateTo(positioned.position, 1500, easing.easeInOutCubic)(
|
||||||
function()
|
function()
|
||||||
|
-- проверяем, позволяют ли эффекты нам сходить
|
||||||
|
if char:try(Tree.behaviors.effects, function(effects)
|
||||||
|
-- print("[TurnOrder]: ну мы пытаемся применить эффект к", char.id)
|
||||||
|
return effects:beforeTurn()
|
||||||
|
end) == false then
|
||||||
|
self:next()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if char:has(Tree.behaviors.ai) then
|
if char:has(Tree.behaviors.ai) then
|
||||||
char:has(Tree.behaviors.ai):makeTurn()(
|
char:has(Tree.behaviors.ai):makeTurn()(
|
||||||
function()
|
function()
|
||||||
@ -69,6 +78,9 @@ function turnOrder:endRound()
|
|||||||
char:try(Tree.behaviors.spellcaster, function(spellcaster)
|
char:try(Tree.behaviors.spellcaster, function(spellcaster)
|
||||||
spellcaster:processCooldowns()
|
spellcaster:processCooldowns()
|
||||||
end)
|
end)
|
||||||
|
char:try(Tree.behaviors.effects, function(effects)
|
||||||
|
effects:afterTurn()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.actedQueue, self.pendingQueue = self.pendingQueue, self.actedQueue
|
self.actedQueue, self.pendingQueue = self.pendingQueue, self.actedQueue
|
||||||
|
|||||||
@ -1,77 +0,0 @@
|
|||||||
--- Объект, который отвечает за работу с элементами интерфейса одного экрана
|
|
||||||
--- @class UIBuilder
|
|
||||||
--- @field private _cache UIElement[]
|
|
||||||
--- @field elementTree UIElement
|
|
||||||
local builder = {}
|
|
||||||
builder.__index = builder
|
|
||||||
|
|
||||||
--- @return UIBuilder
|
|
||||||
local function new(from)
|
|
||||||
from._cache = {}
|
|
||||||
|
|
||||||
setmetatable(from, builder)
|
|
||||||
return from
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @param element? UIElement
|
|
||||||
--- @private
|
|
||||||
function builder:_get(element)
|
|
||||||
if not element then return nil end
|
|
||||||
|
|
||||||
local key = builder:_makeKey(element)
|
|
||||||
if not key then return element end
|
|
||||||
|
|
||||||
local cached = self._cache[key]
|
|
||||||
if cached then return cached end
|
|
||||||
|
|
||||||
self._cache[key] = element
|
|
||||||
return element
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @param element UIElement
|
|
||||||
--- @private
|
|
||||||
function builder:_makeKey(element)
|
|
||||||
if not element.key then return nil end
|
|
||||||
if type(element.key) == "string" then return element.key end
|
|
||||||
element.key = element.type .. "<" .. tostring(element.key) .. ">"
|
|
||||||
return element.key
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @private
|
|
||||||
function builder:build_step(cur)
|
|
||||||
if not cur then return end
|
|
||||||
if cur.build then
|
|
||||||
cur.child = self:_get(cur:build())
|
|
||||||
cur.child.parent = cur
|
|
||||||
self:build_step(cur.child)
|
|
||||||
elseif cur.children then
|
|
||||||
for _, child in ipairs(cur.children) do
|
|
||||||
self:build_step(self:_get(child))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
cur.child = self:_get(cur.child)
|
|
||||||
self:build_step(cur.child)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Этот метод раскрывает всех отложенных (через build) детей в дереве и хитро их кэширует, чтобы не перестраивались постоянно
|
|
||||||
---
|
|
||||||
--- Благодаря этому можно каждый раз создавать новые элементы в верстке, а получать старые :)
|
|
||||||
function builder:build()
|
|
||||||
local root = self:_get(self.elementTree)
|
|
||||||
self:build_step(root)
|
|
||||||
end
|
|
||||||
|
|
||||||
function builder:layout()
|
|
||||||
self.elementTree:layout()
|
|
||||||
end
|
|
||||||
|
|
||||||
function builder:update(dt)
|
|
||||||
self.elementTree:update(dt)
|
|
||||||
end
|
|
||||||
|
|
||||||
function builder:draw()
|
|
||||||
self.elementTree:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
return new
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
--- @class Constraints
|
|
||||||
--- @field minWidth number
|
|
||||||
--- @field maxWidth number
|
|
||||||
--- @field minHeight number
|
|
||||||
--- @field maxHeight number
|
|
||||||
local constraints = {
|
|
||||||
minWidth = 0,
|
|
||||||
maxWidth = math.huge,
|
|
||||||
minHeight = 0,
|
|
||||||
maxHeight = math.huge
|
|
||||||
}
|
|
||||||
|
|
||||||
constraints.__index = constraints
|
|
||||||
|
|
||||||
--- @param from {minWidth: number?, maxWidth: number?, minHeight: number?, maxHeight: number?}
|
|
||||||
--- @return Constraints
|
|
||||||
local function new(from)
|
|
||||||
return setmetatable(from, constraints)
|
|
||||||
end
|
|
||||||
|
|
||||||
return new
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
local Constraints = require "lib.simple_ui.core.constraints"
|
|
||||||
local Vec3 = require "lib.utils.vec3"
|
|
||||||
|
|
||||||
--- @class UIElement
|
|
||||||
--- @field type string
|
|
||||||
--- @field key? any Must be convertible to string
|
|
||||||
--- @field parent? UIElement
|
|
||||||
--- @field constraints Constraints
|
|
||||||
--- @field offset Vec3 Положение левого верхнего угла элемента в экранных координатах {x, y}. Устанавливается родительским элементом.
|
|
||||||
--- @field size Vec3 Размеры элемента в экранных координатах {x, y}
|
|
||||||
--- @field build? fun(self): UIElement?
|
|
||||||
local element = {}
|
|
||||||
element.__index = element
|
|
||||||
element.type = "Element"
|
|
||||||
element.constraints = Constraints {}
|
|
||||||
element.offset = Vec3 {}
|
|
||||||
element.size = Vec3 {}
|
|
||||||
|
|
||||||
--- "Constraints go down. Sizes go up. Parent sets position."
|
|
||||||
---
|
|
||||||
--- Karl Marx, probably.
|
|
||||||
function element:layout() end
|
|
||||||
|
|
||||||
function element:update(dt) end
|
|
||||||
|
|
||||||
function element:draw() end
|
|
||||||
|
|
||||||
--- @param values {[string]: any}
|
|
||||||
--- @return UIElement
|
|
||||||
function element:new(values)
|
|
||||||
return setmetatable(values, self)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Рекурсивно обходит дерево элементов вверх, начиная с первого родителя.
|
|
||||||
---
|
|
||||||
--- К каждому посещенному элементу применяет функцию visitor.
|
|
||||||
---
|
|
||||||
--- Обход заканчивается, если visitor возвращает false, или если родители кончились.
|
|
||||||
--- @param visitor fun(element: UIElement): boolean
|
|
||||||
function element:traverseUp(visitor)
|
|
||||||
if not self.parent then return end
|
|
||||||
if not visitor(self.parent) then return end
|
|
||||||
return self.parent:traverseUp(visitor)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
local Element = require "lib.simple_ui.core.element"
|
|
||||||
|
|
||||||
--- @class MultiChildElement : UIElement
|
|
||||||
--- @field children UIElement[]
|
|
||||||
local element = setmetatable({}, require "lib.simple_ui.core.element")
|
|
||||||
element.__index = element
|
|
||||||
element.children = {}
|
|
||||||
|
|
||||||
function element:update(dt)
|
|
||||||
for _, child in ipairs(self.children) do
|
|
||||||
child:update(dt)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function element:draw()
|
|
||||||
for _, child in ipairs(self.children) do
|
|
||||||
child:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @TODO: сделать дебажный метод для отрисовки границ
|
|
||||||
love.graphics.setColor(1, 0, 0)
|
|
||||||
love.graphics.line(self.offset.x, self.offset.y, self.offset.x + self.size.x, self.offset.y)
|
|
||||||
love.graphics.line(self.offset.x, self.offset.y, self.offset.x, self.offset.y + self.size.y)
|
|
||||||
love.graphics.line(self.offset.x + self.size.x, self.offset.y, self.offset.x + self.size.x,
|
|
||||||
self.offset.y + self.size.y)
|
|
||||||
love.graphics.line(self.offset.x, self.offset.y + self.size.y, self.offset.x + self.size.x,
|
|
||||||
self.offset.y + self.size.y)
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @generic T : MultiChildElement
|
|
||||||
--- @param values {children: UIElement[]?, [string]: any}
|
|
||||||
--- @return T
|
|
||||||
function element:new(values)
|
|
||||||
for _, child in ipairs(values.children or {}) do
|
|
||||||
child.parent = values
|
|
||||||
end
|
|
||||||
return Element.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
local Element = require "lib.simple_ui.core.element"
|
|
||||||
|
|
||||||
--- @class SingleChildElement : UIElement
|
|
||||||
--- @field child? UIElement
|
|
||||||
local element = setmetatable({}, require "lib.simple_ui.core.element")
|
|
||||||
element.__index = element
|
|
||||||
|
|
||||||
function element:layout()
|
|
||||||
if not self.child then return end
|
|
||||||
self.child.constraints = self.constraints
|
|
||||||
self.child:layout()
|
|
||||||
self.child.offset = self.offset:copy()
|
|
||||||
end
|
|
||||||
|
|
||||||
function element:update(dt)
|
|
||||||
if self.child then self.child:update(dt) end
|
|
||||||
end
|
|
||||||
|
|
||||||
function element:draw()
|
|
||||||
if self.child then self.child:draw() end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @generic T : SingleChildElement
|
|
||||||
--- @param self T
|
|
||||||
--- @param values {child: UIElement?, [string]: any}
|
|
||||||
--- @return T
|
|
||||||
function element:new(values)
|
|
||||||
if values.child then values.child.parent = values end
|
|
||||||
return Element.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
--- @alias Axis "horizontal" | "vertical"
|
|
||||||
--- @alias MainAxisSize "max" | "min"
|
|
||||||
--- @alias MainAxisAlignment "start" | "center" | "end"
|
|
||||||
109
lib/simple_ui/element.lua
Normal file
109
lib/simple_ui/element.lua
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
local Rect = require "lib.simple_ui.rect"
|
||||||
|
|
||||||
|
local function makeGradientMesh(w, h, topColor, bottomColor)
|
||||||
|
local vertices = {
|
||||||
|
{ 0, 0, 0, 0, topColor[1], topColor[2], topColor[3], topColor[4] }, -- левый верх
|
||||||
|
{ w, 0, 1, 0, topColor[1], topColor[2], topColor[3], topColor[4] }, -- правый верх
|
||||||
|
{ w, h, 1, 1, bottomColor[1], bottomColor[2], bottomColor[3], bottomColor[4] }, -- правый низ
|
||||||
|
{ 0, h, 0, 1, bottomColor[1], bottomColor[2], bottomColor[3], bottomColor[4] }, -- левый низ
|
||||||
|
}
|
||||||
|
local mesh = love.graphics.newMesh(vertices, "fan", "static")
|
||||||
|
return mesh
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @class UIElement
|
||||||
|
--- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в экранных координатах
|
||||||
|
--- @field overlayGradientMesh love.Mesh Общий градиент поверх элемента (интерполированный меш)
|
||||||
|
local uiElement = {}
|
||||||
|
uiElement.bounds = Rect {}
|
||||||
|
uiElement.overlayGradientMesh = makeGradientMesh(1, 1, { 0, 0, 0, 0 }, { 0, 0, 0, 0.4 });
|
||||||
|
uiElement.__index = uiElement
|
||||||
|
|
||||||
|
function uiElement:update(dt) end
|
||||||
|
|
||||||
|
function uiElement:draw() end
|
||||||
|
|
||||||
|
function uiElement:hitTest(screenX, screenY)
|
||||||
|
return self.bounds:hasPoint(screenX, screenY)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @generic T : UIElement
|
||||||
|
--- @param values table
|
||||||
|
--- @param self T
|
||||||
|
--- @return T
|
||||||
|
function uiElement.new(self, values)
|
||||||
|
values.bounds = values.bounds or Rect {}
|
||||||
|
values.overlayGradientMesh = values.overlayGradientMesh or uiElement.overlayGradientMesh;
|
||||||
|
return setmetatable(values, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Рисует границу вокруг элемента (с псевдо-затенением)
|
||||||
|
--- @param type "outer" | "inner"
|
||||||
|
--- @param width? number
|
||||||
|
function uiElement:drawBorder(type, width)
|
||||||
|
local w = width or 4
|
||||||
|
love.graphics.setLineWidth(w)
|
||||||
|
|
||||||
|
if type == "inner" then
|
||||||
|
love.graphics.setColor(0.2, 0.2, 0.2)
|
||||||
|
love.graphics.line({
|
||||||
|
self.bounds.x, self.bounds.y + self.bounds.height,
|
||||||
|
self.bounds.x, self.bounds.y,
|
||||||
|
self.bounds.x + self.bounds.width, self.bounds.y,
|
||||||
|
})
|
||||||
|
|
||||||
|
love.graphics.setColor(0.3, 0.3, 0.3)
|
||||||
|
love.graphics.line({
|
||||||
|
self.bounds.x + self.bounds.width, self.bounds.y,
|
||||||
|
self.bounds.x + self.bounds.width, self.bounds.y + self.bounds.height,
|
||||||
|
self.bounds.x, self.bounds.y + self.bounds.height,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
love.graphics.setColor(0.3, 0.3, 0.3)
|
||||||
|
-- love.graphics.line({
|
||||||
|
-- self.bounds.x, self.bounds.y + self.bounds.height,
|
||||||
|
-- self.bounds.x, self.bounds.y,
|
||||||
|
-- self.bounds.x + self.bounds.width, self.bounds.y,
|
||||||
|
-- })
|
||||||
|
love.graphics.line({
|
||||||
|
self.bounds.x, self.bounds.y + self.bounds.height - w,
|
||||||
|
self.bounds.x, self.bounds.y + w,
|
||||||
|
})
|
||||||
|
|
||||||
|
love.graphics.line({
|
||||||
|
self.bounds.x + w, self.bounds.y,
|
||||||
|
self.bounds.x + self.bounds.width - w, self.bounds.y,
|
||||||
|
})
|
||||||
|
|
||||||
|
love.graphics.setColor(0.2, 0.2, 0.2)
|
||||||
|
-- love.graphics.line({
|
||||||
|
-- self.bounds.x + self.bounds.width, self.bounds.y,
|
||||||
|
-- self.bounds.x + self.bounds.width, self.bounds.y + self.bounds.height,
|
||||||
|
-- self.bounds.x, self.bounds.y + self.bounds.height,
|
||||||
|
-- })
|
||||||
|
|
||||||
|
love.graphics.line({
|
||||||
|
self.bounds.x + self.bounds.width, self.bounds.y + w,
|
||||||
|
self.bounds.x + self.bounds.width, self.bounds.y + self.bounds.height - w,
|
||||||
|
})
|
||||||
|
|
||||||
|
love.graphics.line({
|
||||||
|
self.bounds.x + self.bounds.width - w, self.bounds.y + self.bounds.height,
|
||||||
|
self.bounds.x + w, self.bounds.y + self.bounds.height,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- рисует градиент поверх элемента
|
||||||
|
function uiElement:drawGradientOverlay()
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(self.bounds.x, self.bounds.y)
|
||||||
|
love.graphics.scale(self.bounds.width, self.bounds.height)
|
||||||
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
love.graphics.draw(self.overlayGradientMesh)
|
||||||
|
love.graphics.pop()
|
||||||
|
end
|
||||||
|
|
||||||
|
return uiElement
|
||||||
@ -1,28 +0,0 @@
|
|||||||
local Constraints = require "lib.simple_ui.core.constraints"
|
|
||||||
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
||||||
|
|
||||||
--- @class Center : SingleChildElement
|
|
||||||
local element = setmetatable({}, SingleChildElement)
|
|
||||||
element.__index = element
|
|
||||||
element.__type = "Center"
|
|
||||||
|
|
||||||
function element:layout()
|
|
||||||
self.size = Vec3 { self.constraints.maxWidth, self.constraints.maxHeight }
|
|
||||||
|
|
||||||
if not self.child then return end
|
|
||||||
self.child.constraints = Constraints(self.constraints)
|
|
||||||
self.child:layout()
|
|
||||||
|
|
||||||
self.child.offset = Vec3 {
|
|
||||||
self.offset.x + (self.size.x - self.child.size.x) / 2,
|
|
||||||
self.offset.y + (self.size.y - self.child.size.y) / 2,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @return Center
|
|
||||||
--- @param values {child: UIElement?}
|
|
||||||
function element:new(values)
|
|
||||||
return SingleChildElement.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
local Constraints = require "lib.simple_ui.core.constraints"
|
|
||||||
local MultiChildElement = require "lib.simple_ui.core.multi_child_element"
|
|
||||||
|
|
||||||
--- @class Flex : MultiChildElement
|
|
||||||
--- @field direction Axis
|
|
||||||
--- @field mainAxisSize MainAxisSize
|
|
||||||
--- @field mainAxisAlignment MainAxisAlignment
|
|
||||||
local element = setmetatable({}, require "lib.simple_ui.core.multi_child_element")
|
|
||||||
element.__index = element
|
|
||||||
element.type = "Flex"
|
|
||||||
element.direction = "horizontal"
|
|
||||||
element.mainAxisSize = "max"
|
|
||||||
element.mainAxisAlignment = "start"
|
|
||||||
|
|
||||||
function element:layout()
|
|
||||||
local mainAxisSize = 0
|
|
||||||
local crossAxisSize = 0
|
|
||||||
if self.direction == "horizontal" then
|
|
||||||
for _, child in ipairs(self.children) do
|
|
||||||
child.constraints = Constraints { maxHeight = self.constraints.maxHeight }
|
|
||||||
child:layout()
|
|
||||||
if child.size.y > crossAxisSize then crossAxisSize = child.size.y end
|
|
||||||
mainAxisSize = mainAxisSize + child.size.x
|
|
||||||
end
|
|
||||||
|
|
||||||
local start = 0
|
|
||||||
if self.mainAxisAlignment == "center" then
|
|
||||||
start = self.constraints.maxWidth / 2 - mainAxisSize / 2
|
|
||||||
elseif self.mainAxisAlignment == "end" then
|
|
||||||
start = self.constraints.maxWidth - mainAxisSize
|
|
||||||
end
|
|
||||||
local shift = 0
|
|
||||||
for _, child in ipairs(self.children) do
|
|
||||||
child.offset = Vec3 { self.offset.x + start + shift, self.offset.y }
|
|
||||||
shift = shift + child.size.x
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.mainAxisSize == "max" then
|
|
||||||
self.size = Vec3 { self.constraints.maxWidth, crossAxisSize }
|
|
||||||
else
|
|
||||||
self.size = Vec3 { mainAxisSize, crossAxisSize }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for _, child in ipairs(self.children) do
|
|
||||||
child.constraints = Constraints { maxWidth = self.constraints.maxWidth }
|
|
||||||
child:layout()
|
|
||||||
if child.size.x > crossAxisSize then crossAxisSize = child.size.x end
|
|
||||||
mainAxisSize = mainAxisSize + child.size.y
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local start = 0
|
|
||||||
if self.mainAxisAlignment == "center" then
|
|
||||||
start = self.constraints.maxHeight / 2 - mainAxisSize / 2
|
|
||||||
elseif self.mainAxisAlignment == "end" then
|
|
||||||
start = self.constraints.maxHeight - mainAxisSize
|
|
||||||
end
|
|
||||||
local shift = 0
|
|
||||||
for _, child in ipairs(self.children) do
|
|
||||||
child.offset = Vec3 { self.offset.x, self.offset.y + start + shift }
|
|
||||||
shift = shift + child.size.y
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.mainAxisSize == "max" then
|
|
||||||
self.size = Vec3 { crossAxisSize, self.constraints.maxHeight }
|
|
||||||
else
|
|
||||||
self.size = Vec3 { crossAxisSize, mainAxisSize }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @param values {direction: Axis?, mainAxisSize: MainAxisSize?, mainAxisAlignment: MainAxisAlignment?, children: UIElement[]?}
|
|
||||||
--- @return Flex
|
|
||||||
function element:new(values)
|
|
||||||
return MultiChildElement.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
local Constraints = require "lib.simple_ui.core.constraints"
|
|
||||||
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
||||||
|
|
||||||
--- @class Padding : SingleChildElement
|
|
||||||
--- @field left number
|
|
||||||
--- @field right number
|
|
||||||
--- @field top number
|
|
||||||
--- @field bottom number
|
|
||||||
local element = setmetatable({}, SingleChildElement)
|
|
||||||
element.__index = element
|
|
||||||
element.type = "Padding"
|
|
||||||
element.left = 0
|
|
||||||
element.right = 0
|
|
||||||
element.top = 0
|
|
||||||
element.bottom = 0
|
|
||||||
|
|
||||||
--- "When passing layout constraints to its child, padding shrinks the constraints by the given padding, causing the child to layout at a smaller size.
|
|
||||||
--- Padding then sizes itself to its child's size, inflated by the padding, effectively creating empty space around the child."
|
|
||||||
---
|
|
||||||
--- as in https://api.flutter.dev/flutter/widgets/Padding-class.html
|
|
||||||
function element:layout()
|
|
||||||
if not self.child then return end
|
|
||||||
local c = Constraints(self.constraints)
|
|
||||||
c.maxWidth = c.maxWidth - self.left - self.right
|
|
||||||
c.maxHeight = c.maxHeight - self.top - self.bottom
|
|
||||||
c.maxWidth = c.maxWidth > 0 and c.maxWidth or 0
|
|
||||||
c.maxHeight = c.maxHeight > 0 and c.maxHeight or 0
|
|
||||||
self.child.constraints = c
|
|
||||||
|
|
||||||
self.child:layout()
|
|
||||||
self.size = Vec3 { self.child.size.x + self.left + self.right, self.child.size.y + self.top + self.bottom }
|
|
||||||
self.child.offset = self.offset + Vec3 { self.left, self.top }
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @return Padding
|
|
||||||
--- @param values {left: number?, top: number?, right: number?, bottom: number?, child: UIElement?}
|
|
||||||
function element:new(values)
|
|
||||||
return SingleChildElement.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
local Constraints = require "lib.simple_ui.core.constraints"
|
|
||||||
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
||||||
|
|
||||||
--- @class Placeholder : SingleChildElement
|
|
||||||
local element = setmetatable({}, SingleChildElement)
|
|
||||||
element.__index = element
|
|
||||||
element.type = "Placeholder"
|
|
||||||
|
|
||||||
function element:layout()
|
|
||||||
self.size = Vec3 { self.constraints.maxWidth, self.constraints.maxHeight }
|
|
||||||
|
|
||||||
if not self.child then return end
|
|
||||||
self.child.constraints = Constraints(self.constraints)
|
|
||||||
self.child:layout()
|
|
||||||
self.child.offset = self.offset:copy()
|
|
||||||
end
|
|
||||||
|
|
||||||
function element:draw()
|
|
||||||
love.graphics.rectangle("line", self.offset.x, self.offset.y, self.size.x, self.size.y)
|
|
||||||
love.graphics.line(self.offset.x, self.offset.y, self.offset.x + self.size.x, self.offset.y + self.size.y)
|
|
||||||
love.graphics.line(self.offset.x, self.offset.y + self.size.y, self.offset.x + self.size.x, self.offset.y)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @return Placeholder
|
|
||||||
--- @param values {child: UIElement?}
|
|
||||||
function element:new(values)
|
|
||||||
return SingleChildElement.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
local Constraints = require "lib.simple_ui.core.constraints"
|
|
||||||
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
||||||
|
|
||||||
--- @class ScreenArea : SingleChildElement
|
|
||||||
local element = setmetatable({}, SingleChildElement)
|
|
||||||
element.__index = element
|
|
||||||
element.type = "ScreenArea"
|
|
||||||
|
|
||||||
function element:layout()
|
|
||||||
local screenW, screenH = love.graphics.getWidth(), love.graphics.getHeight()
|
|
||||||
self.constraints = Constraints {
|
|
||||||
maxWidth = screenW,
|
|
||||||
maxHeight = screenH
|
|
||||||
}
|
|
||||||
self.size = Vec3 { screenW, screenH }
|
|
||||||
|
|
||||||
if not self.child then return end
|
|
||||||
self.child.constraints = Constraints {
|
|
||||||
maxWidth = screenW,
|
|
||||||
maxHeight = screenH,
|
|
||||||
}
|
|
||||||
self.child:layout()
|
|
||||||
self.child.offset = Vec3 {}
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @return ScreenArea
|
|
||||||
--- @param values {child: UIElement?}
|
|
||||||
function element:new(values)
|
|
||||||
return SingleChildElement.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
||||||
|
|
||||||
--- @class SizedBox : SingleChildElement
|
|
||||||
local element = setmetatable({}, require "lib.simple_ui.core.single_child_element")
|
|
||||||
local Constraints = require("lib.simple_ui.core.constraints")
|
|
||||||
element.type = "SizedBox"
|
|
||||||
element.__index = element
|
|
||||||
element.width = 0
|
|
||||||
element.height = 0
|
|
||||||
|
|
||||||
function element:layout()
|
|
||||||
self.size = Vec3 { self.width, self.height }
|
|
||||||
|
|
||||||
if not self.child then return end
|
|
||||||
self.child.constraints = Constraints {
|
|
||||||
maxWidth = self.width,
|
|
||||||
maxHeight = self.height,
|
|
||||||
}
|
|
||||||
self.child:layout()
|
|
||||||
self.child.offset = self.offset:copy()
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @return SizedBox
|
|
||||||
--- @param values {width: number?, height: number?, child: UIElement?}
|
|
||||||
function element:new(values)
|
|
||||||
return SingleChildElement.new(self, values)
|
|
||||||
end
|
|
||||||
|
|
||||||
return element
|
|
||||||
71
lib/simple_ui/level/bar.lua
Normal file
71
lib/simple_ui/level/bar.lua
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
local Element = require "lib.simple_ui.element"
|
||||||
|
|
||||||
|
|
||||||
|
--- @class BarElement : UIElement
|
||||||
|
--- @field getter fun() : number
|
||||||
|
--- @field value number
|
||||||
|
--- @field maxValue number
|
||||||
|
--- @field color Color
|
||||||
|
--- @field useDividers boolean
|
||||||
|
--- @field drawText boolean
|
||||||
|
local barElement = setmetatable({}, Element)
|
||||||
|
barElement.__index = barElement
|
||||||
|
barElement.useDividers = false
|
||||||
|
barElement.drawText = false
|
||||||
|
|
||||||
|
function barElement:update(dt)
|
||||||
|
local val = self.getter()
|
||||||
|
self.value = val < 0 and 0 or val > self.maxValue and self.maxValue or val
|
||||||
|
end
|
||||||
|
|
||||||
|
function barElement:draw()
|
||||||
|
local valueWidth = self.bounds.width * self.value / self.maxValue
|
||||||
|
local emptyWidth = self.bounds.width - valueWidth
|
||||||
|
|
||||||
|
--- шум
|
||||||
|
love.graphics.setShader(Tree.assets.files.shaders.soft_uniform_noise)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
love.graphics.setShader()
|
||||||
|
|
||||||
|
--- закраска пустой части
|
||||||
|
love.graphics.setColor(0.05, 0.05, 0.05)
|
||||||
|
love.graphics.setBlendMode("multiply", "premultiplied")
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x + valueWidth, self.bounds.y, emptyWidth,
|
||||||
|
self.bounds.height)
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
|
--- закраска значимой части её цветом
|
||||||
|
love.graphics.setColor(self.color.r, self.color.g, self.color.b)
|
||||||
|
love.graphics.setBlendMode("multiply", "premultiplied")
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, valueWidth,
|
||||||
|
self.bounds.height)
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
|
--- мерки
|
||||||
|
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255)
|
||||||
|
if self.useDividers then
|
||||||
|
local count = self.maxValue - 1
|
||||||
|
local measureWidth = self.bounds.width / self.maxValue
|
||||||
|
|
||||||
|
for i = 1, count, 1 do
|
||||||
|
love.graphics.line(self.bounds.x + i * measureWidth, self.bounds.y, self.bounds.x + i * measureWidth,
|
||||||
|
self.bounds.y + self.bounds.height)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
--- текст поверх
|
||||||
|
if self.drawText then
|
||||||
|
local font = Tree.fonts:getDefaultTheme():getVariant("small")
|
||||||
|
local t = love.graphics.newText(font, tostring(self.value) .. "/" .. tostring(self.maxValue))
|
||||||
|
love.graphics.draw(t, math.floor(self.bounds.x + self.bounds.width / 2 - t:getWidth() / 2),
|
||||||
|
math.floor(self.bounds.y + self.bounds.height / 2 - t:getHeight() / 2))
|
||||||
|
end
|
||||||
|
|
||||||
|
self:drawBorder("inner")
|
||||||
|
|
||||||
|
self:drawGradientOverlay()
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(values) return barElement:new(values) end
|
||||||
86
lib/simple_ui/level/bottom_bars.lua
Normal file
86
lib/simple_ui/level/bottom_bars.lua
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
local Element = require "lib.simple_ui.element"
|
||||||
|
local Rect = require "lib.simple_ui.rect"
|
||||||
|
local Color = require "lib.simple_ui.color"
|
||||||
|
local Bar = require "lib.simple_ui.level.bar"
|
||||||
|
|
||||||
|
--- @class BottomBars : UIElement
|
||||||
|
--- @field hpBar BarElement
|
||||||
|
--- @field manaBar BarElement
|
||||||
|
local bottomBars = setmetatable({}, Element)
|
||||||
|
bottomBars.__index = bottomBars;
|
||||||
|
|
||||||
|
--- @param cid Id
|
||||||
|
function bottomBars.new(cid)
|
||||||
|
local t = setmetatable({}, bottomBars)
|
||||||
|
|
||||||
|
t.hpBar =
|
||||||
|
Bar {
|
||||||
|
getter = function()
|
||||||
|
local char = Tree.level.characters[cid]
|
||||||
|
return char:try(Tree.behaviors.stats, function(stats)
|
||||||
|
return stats.hp or 0
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
color = Color { r = 130 / 255, g = 8 / 255, b = 8 / 255 },
|
||||||
|
drawText = true,
|
||||||
|
maxValue = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
t.manaBar =
|
||||||
|
Bar {
|
||||||
|
getter = function()
|
||||||
|
local char = Tree.level.characters[cid]
|
||||||
|
return char:try(Tree.behaviors.stats, function(stats)
|
||||||
|
return stats.mana or 0
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
color = Color { r = 51 / 255, g = 105 / 255, b = 30 / 255 },
|
||||||
|
useDividers = true,
|
||||||
|
maxValue = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
function bottomBars:update(dt)
|
||||||
|
local height = 16
|
||||||
|
local margin = 2
|
||||||
|
|
||||||
|
self.bounds.height = height
|
||||||
|
self.bounds.y = self.bounds.y - height
|
||||||
|
|
||||||
|
self.hpBar.bounds = Rect {
|
||||||
|
width = -2 * margin + self.bounds.width / 2,
|
||||||
|
height = height - margin,
|
||||||
|
x = self.bounds.x + margin,
|
||||||
|
y = self.bounds.y + margin
|
||||||
|
}
|
||||||
|
|
||||||
|
self.manaBar.bounds = Rect {
|
||||||
|
width = -2 * margin + self.bounds.width / 2,
|
||||||
|
height = height - margin,
|
||||||
|
x = self.bounds.x + margin + self.bounds.width / 2,
|
||||||
|
y = self.bounds.y + margin
|
||||||
|
}
|
||||||
|
|
||||||
|
self.hpBar:update(dt)
|
||||||
|
self.manaBar:update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function bottomBars:draw()
|
||||||
|
-- шум
|
||||||
|
love.graphics.setShader(Tree.assets.files.shaders.soft_uniform_noise)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
love.graphics.setShader()
|
||||||
|
|
||||||
|
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255)
|
||||||
|
love.graphics.setBlendMode("multiply", "premultiplied")
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
|
self.hpBar:draw()
|
||||||
|
self.manaBar:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
return bottomBars.new
|
||||||
108
lib/simple_ui/level/cpanel.lua
Normal file
108
lib/simple_ui/level/cpanel.lua
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
local task = require "lib.utils.task"
|
||||||
|
local easing = require "lib.utils.easing"
|
||||||
|
local Element = require "lib.simple_ui.element"
|
||||||
|
local Rect = require "lib.simple_ui.rect"
|
||||||
|
local SkillRow = require "lib.simple_ui.level.skill_row"
|
||||||
|
local Bars = require "lib.simple_ui.level.bottom_bars"
|
||||||
|
local EndTurnButton = require "lib.simple_ui.level.end_turn"
|
||||||
|
|
||||||
|
--- @class CharacterPanel : UIElement
|
||||||
|
--- @field animationTask Task
|
||||||
|
--- @field alpha number
|
||||||
|
--- @field state "show" | "idle" | "hide"
|
||||||
|
--- @field skillRow SkillRow
|
||||||
|
--- @field bars BottomBars
|
||||||
|
--- @field endTurnButton EndTurnButton
|
||||||
|
local characterPanel = setmetatable({}, Element)
|
||||||
|
characterPanel.__index = characterPanel
|
||||||
|
|
||||||
|
function characterPanel.new(characterId)
|
||||||
|
local t = {}
|
||||||
|
t.state = "show"
|
||||||
|
t.skillRow = SkillRow(characterId)
|
||||||
|
t.bars = Bars(characterId)
|
||||||
|
t.endTurnButton = EndTurnButton {}
|
||||||
|
t.alpha = 0 -- starts hidden/animating
|
||||||
|
return setmetatable(t, characterPanel)
|
||||||
|
end
|
||||||
|
|
||||||
|
function characterPanel:show()
|
||||||
|
self.state = "show"
|
||||||
|
self.animationTask = task.tween(self, { alpha = 1 }, 300, easing.easeOutCubic)
|
||||||
|
self.animationTask(function() self.state = "idle" end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function characterPanel:hide()
|
||||||
|
self.state = "hide"
|
||||||
|
self.animationTask = task.tween(self, { alpha = 0 }, 300, easing.easeOutCubic)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type love.Canvas
|
||||||
|
local characterPanelCanvas;
|
||||||
|
|
||||||
|
function characterPanel:update(dt)
|
||||||
|
-- Tasks update automatically via task.update(dt) in main.lua
|
||||||
|
self.skillRow:update(dt)
|
||||||
|
self.bars.bounds = Rect {
|
||||||
|
width = self.skillRow.bounds.width,
|
||||||
|
x = self.skillRow.bounds.x,
|
||||||
|
y = self.skillRow.bounds.y
|
||||||
|
}
|
||||||
|
self.bars:update(dt)
|
||||||
|
|
||||||
|
self.bounds = Rect {
|
||||||
|
x = self.bars.bounds.x,
|
||||||
|
y = self.bars.bounds.y,
|
||||||
|
width = self.bars.bounds.width,
|
||||||
|
height = self.bars.bounds.height + self.skillRow.bounds.height
|
||||||
|
}
|
||||||
|
|
||||||
|
self.endTurnButton:layout()
|
||||||
|
self.endTurnButton.bounds.x = self.bounds.x + self.bounds.width + 32
|
||||||
|
self.endTurnButton.bounds.y = self.bounds.y + self.bounds.height / 2 - self.endTurnButton.bounds.height / 2
|
||||||
|
|
||||||
|
self.endTurnButton:update(dt)
|
||||||
|
|
||||||
|
if not characterPanelCanvas then
|
||||||
|
characterPanelCanvas = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- анимация появления
|
||||||
|
local revealShader = Tree.assets.files.shaders.reveal
|
||||||
|
revealShader:send("t", self.alpha)
|
||||||
|
end
|
||||||
|
|
||||||
|
function characterPanel:draw()
|
||||||
|
self.skillRow:draw()
|
||||||
|
|
||||||
|
--- @TODO: переписать этот ужас с жонглированием координатами, а то слишком хардкод (skillRow рисуется относительно нуля и не закрывает канвас)
|
||||||
|
love.graphics.push()
|
||||||
|
local canvas = love.graphics.getCanvas()
|
||||||
|
love.graphics.translate(0, self.bars.bounds.height)
|
||||||
|
love.graphics.setCanvas(characterPanelCanvas)
|
||||||
|
love.graphics.clear()
|
||||||
|
love.graphics.draw(canvas)
|
||||||
|
love.graphics.pop()
|
||||||
|
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(-self.bounds.x, -self.bounds.y)
|
||||||
|
self.bars:draw()
|
||||||
|
self:drawBorder("outer")
|
||||||
|
love.graphics.pop()
|
||||||
|
|
||||||
|
--- рисуем текстуру шейдером появления
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
love.graphics.setShader(Tree.assets.files.shaders.reveal)
|
||||||
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
|
||||||
|
self.endTurnButton:draw()
|
||||||
|
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(self.bounds.x, self.bounds.y)
|
||||||
|
love.graphics.draw(characterPanelCanvas)
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
love.graphics.pop()
|
||||||
|
love.graphics.setShader()
|
||||||
|
end
|
||||||
|
|
||||||
|
return characterPanel.new
|
||||||
53
lib/simple_ui/level/end_turn.lua
Normal file
53
lib/simple_ui/level/end_turn.lua
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
local Element = require "lib.simple_ui.element"
|
||||||
|
local task = require "lib.utils.task"
|
||||||
|
local easing = require "lib.utils.easing"
|
||||||
|
|
||||||
|
--- @class EndTurnButton : UIElement
|
||||||
|
--- @field hovered boolean
|
||||||
|
--- @field onClick function?
|
||||||
|
local endTurnButton = setmetatable({}, Element)
|
||||||
|
endTurnButton.__index = endTurnButton
|
||||||
|
|
||||||
|
function endTurnButton:update(dt)
|
||||||
|
local mx, my = love.mouse.getPosition()
|
||||||
|
if self:hitTest(mx, my) then
|
||||||
|
self.hovered = true
|
||||||
|
if Tree.controls:isJustPressed("select") then
|
||||||
|
if self.onClick then self.onClick() end
|
||||||
|
Tree.controls:consume("select")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.hovered = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function endTurnButton:layout()
|
||||||
|
local font = Tree.fonts:getDefaultTheme():getVariant("large")
|
||||||
|
self.text = love.graphics.newText(font, "Завершить ход")
|
||||||
|
self.bounds.width = self.text:getWidth() + 32
|
||||||
|
self.bounds.height = self.text:getHeight() + 16
|
||||||
|
end
|
||||||
|
|
||||||
|
function endTurnButton:draw()
|
||||||
|
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255, 0.9)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
|
||||||
|
if self.hovered then
|
||||||
|
love.graphics.setColor(0.1, 0.1, 0.1)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(0.95, 0.95, 0.95)
|
||||||
|
love.graphics.draw(self.text, self.bounds.x + 16, self.bounds.y + 8)
|
||||||
|
|
||||||
|
self:drawBorder("outer")
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function endTurnButton:onClick()
|
||||||
|
Tree.level.turnOrder:next()
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(values)
|
||||||
|
return endTurnButton:new(values)
|
||||||
|
end
|
||||||
23
lib/simple_ui/level/layout.lua
Normal file
23
lib/simple_ui/level/layout.lua
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
local CPanel = require "lib.simple_ui.level.cpanel"
|
||||||
|
|
||||||
|
local build
|
||||||
|
|
||||||
|
local layout = {}
|
||||||
|
function layout:update(dt)
|
||||||
|
if self.characterPanel then self.characterPanel:update(dt) end
|
||||||
|
|
||||||
|
local cid = Tree.level.selector:selected()
|
||||||
|
if cid then
|
||||||
|
self.characterPanel = CPanel(cid)
|
||||||
|
self.characterPanel:show()
|
||||||
|
self.characterPanel:update(dt)
|
||||||
|
elseif Tree.level.selector:deselected() then
|
||||||
|
self.characterPanel:hide()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function layout:draw()
|
||||||
|
if self.characterPanel then self.characterPanel:draw() end
|
||||||
|
end
|
||||||
|
|
||||||
|
return layout
|
||||||
2
lib/simple_ui/level/scale.lua
Normal file
2
lib/simple_ui/level/scale.lua
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
local UI_SCALE = 0.75 -- выдуманное значение для dependency injection, надо подбирать так, чтобы UI_SCALE * 64 было целым числом
|
||||||
|
return UI_SCALE
|
||||||
213
lib/simple_ui/level/skill_row.lua
Normal file
213
lib/simple_ui/level/skill_row.lua
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
local icons = require("lib.utils.sprite_atlas").load(Tree.assets.files.dev_icons)
|
||||||
|
local Element = require "lib.simple_ui.element"
|
||||||
|
local Rect = require "lib.simple_ui.rect"
|
||||||
|
|
||||||
|
local UI_SCALE = require "lib.simple_ui.level.scale"
|
||||||
|
|
||||||
|
--- @class SkillButton : UIElement
|
||||||
|
--- @field hovered boolean
|
||||||
|
--- @field selected boolean
|
||||||
|
--- @field onClick function?
|
||||||
|
--- @field getCooldown function?
|
||||||
|
--- @field icon? string
|
||||||
|
local skillButton = setmetatable({}, Element)
|
||||||
|
skillButton.__index = skillButton
|
||||||
|
|
||||||
|
function skillButton:update(dt)
|
||||||
|
if not self.icon then return end
|
||||||
|
local mx, my = love.mouse.getPosition()
|
||||||
|
if self:hitTest(mx, my) then
|
||||||
|
self.hovered = true
|
||||||
|
if Tree.controls:isJustPressed("select") then
|
||||||
|
local cd = self.getCooldown and self.getCooldown() or 0
|
||||||
|
if cd == 0 then
|
||||||
|
if self.onClick then self.onClick() end
|
||||||
|
end
|
||||||
|
|
||||||
|
Tree.controls:consume("select")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.hovered = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function skillButton:draw()
|
||||||
|
love.graphics.setLineWidth(2)
|
||||||
|
|
||||||
|
local cd = self.getCooldown and self.getCooldown() or 0
|
||||||
|
|
||||||
|
if not self.icon then
|
||||||
|
love.graphics.setColor(0.05, 0.05, 0.05)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
self:drawBorder("inner")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local quad = icons:pickQuad(self.icon)
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(self.bounds.x, self.bounds.y)
|
||||||
|
love.graphics.scale(self.bounds.width / icons.tileSize, self.bounds.height / icons.tileSize)
|
||||||
|
love.graphics.draw(icons.atlas, quad)
|
||||||
|
love.graphics.pop()
|
||||||
|
|
||||||
|
self:drawBorder("inner")
|
||||||
|
|
||||||
|
if self.selected then
|
||||||
|
love.graphics.setColor(0.3, 1, 0.3, 0.5)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
elseif self.hovered then
|
||||||
|
love.graphics.setColor(0.7, 1, 0.7, 0.5)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if cd > 0 then
|
||||||
|
love.graphics.setColor(0, 0, 0, 0.5)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
|
||||||
|
local font = Tree.fonts:getDefaultTheme():getVariant("headline")
|
||||||
|
love.graphics.setColor(0, 0, 0)
|
||||||
|
local t = love.graphics.newText(font, tostring(cd))
|
||||||
|
love.graphics.draw(t, math.floor(self.bounds.x + 2 + self.bounds.width / 2 - t:getWidth() / 2),
|
||||||
|
math.floor(self.bounds.y + 2 + self.bounds.height / 2 - t:getHeight() / 2))
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
love.graphics.draw(t, math.floor(self.bounds.x + self.bounds.width / 2 - t:getWidth() / 2),
|
||||||
|
math.floor(self.bounds.y + self.bounds.height / 2 - t:getHeight() / 2))
|
||||||
|
else
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--- @class SkillRow : UIElement
|
||||||
|
--- @field characterId Id
|
||||||
|
--- @field selected SkillButton?
|
||||||
|
--- @field children SkillButton[]
|
||||||
|
local skillRow = setmetatable({}, Element)
|
||||||
|
skillRow.__index = skillRow
|
||||||
|
|
||||||
|
--- @param characterId Id
|
||||||
|
--- @return SkillRow
|
||||||
|
function skillRow.new(characterId)
|
||||||
|
local t = {
|
||||||
|
characterId = characterId,
|
||||||
|
children = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
setmetatable(t, skillRow)
|
||||||
|
|
||||||
|
local char = Tree.level.characters[characterId]
|
||||||
|
char:try(Tree.behaviors.spellcaster, function(behavior)
|
||||||
|
for i, spell in ipairs(behavior.spellbook) do
|
||||||
|
local skb = skillButton:new { icon = spell.tag }
|
||||||
|
skb.onClick = function()
|
||||||
|
skb.selected = not skb.selected
|
||||||
|
if t.selected then t.selected.selected = false end
|
||||||
|
t.selected = skb
|
||||||
|
|
||||||
|
if not behavior.cast then
|
||||||
|
behavior.cast = behavior.spellbook[i]
|
||||||
|
behavior.state = "casting"
|
||||||
|
behavior.spellbook[i]:onSelected(char)
|
||||||
|
else
|
||||||
|
behavior.state = "idle"
|
||||||
|
behavior.cast = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
skb.getCooldown = function()
|
||||||
|
return behavior.cooldowns[spell.tag] or 0
|
||||||
|
end
|
||||||
|
t.children[i] = skb
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
for i = #t.children + 1, 7, 1 do
|
||||||
|
t.children[i] = skillButton:new {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type love.Canvas
|
||||||
|
local c;
|
||||||
|
|
||||||
|
function skillRow:update(dt)
|
||||||
|
local iconSize = math.floor(64 * UI_SCALE)
|
||||||
|
local screenW, screenH = love.graphics.getDimensions()
|
||||||
|
local padding, margin = 8, 4
|
||||||
|
local count = #self.children -- слоты под скиллы
|
||||||
|
|
||||||
|
self.bounds = Rect {
|
||||||
|
width = iconSize * count + (count + 1) * margin,
|
||||||
|
height = iconSize + 2 * margin,
|
||||||
|
}
|
||||||
|
self.bounds.y = screenH - self.bounds.height - padding -- отступ снизу
|
||||||
|
self.bounds.x = screenW / 2 - self.bounds.width / 2
|
||||||
|
|
||||||
|
for i, skb in ipairs(self.children) do
|
||||||
|
skb.bounds = Rect { x = self.bounds.x + margin + (i - 1) * (iconSize + margin), -- друг за другом, включая первый отступ от границы
|
||||||
|
y = self.bounds.y + margin, height = iconSize, width = iconSize }
|
||||||
|
skb:update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not c then
|
||||||
|
c = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function skillRow:draw()
|
||||||
|
love.graphics.setCanvas({ c, stencil = true })
|
||||||
|
love.graphics.clear()
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
|
||||||
|
do
|
||||||
|
--- рисуем в локальных координатах текстурки
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(-self.bounds.x, -self.bounds.y)
|
||||||
|
|
||||||
|
-- сначала иконки скиллов
|
||||||
|
for _, skb in ipairs(self.children) do
|
||||||
|
skb:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- маска для вырезов под иконки
|
||||||
|
love.graphics.setShader(Tree.assets.files.shaders.alpha_mask)
|
||||||
|
love.graphics.stencil(function()
|
||||||
|
local mask = Tree.assets.files.masks.rrect32
|
||||||
|
local maskSize = mask:getWidth()
|
||||||
|
for _, skb in ipairs(self.children) do
|
||||||
|
love.graphics.draw(mask, skb.bounds.x, skb.bounds.y, 0,
|
||||||
|
skb.bounds.width / maskSize, skb.bounds.height / maskSize)
|
||||||
|
end
|
||||||
|
end, "replace", 1)
|
||||||
|
love.graphics.setShader()
|
||||||
|
|
||||||
|
|
||||||
|
-- дальше рисуем панель, перекрывая иконки
|
||||||
|
love.graphics.setStencilTest("less", 1)
|
||||||
|
-- шум
|
||||||
|
love.graphics.setShader(Tree.assets.files.shaders.soft_uniform_noise)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
love.graphics.setShader()
|
||||||
|
|
||||||
|
-- фон
|
||||||
|
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255)
|
||||||
|
love.graphics.setBlendMode("multiply", "premultiplied")
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
|
||||||
|
love.graphics.setStencilTest()
|
||||||
|
|
||||||
|
--затенение
|
||||||
|
self:drawGradientOverlay()
|
||||||
|
love.graphics.pop()
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return skillRow.new
|
||||||
@ -1,88 +0,0 @@
|
|||||||
local ScreenArea = require "lib.simple_ui.elements.screen_area"
|
|
||||||
local Placeholder = require "lib.simple_ui.elements.placeholder"
|
|
||||||
local Padding = require "lib.simple_ui.elements.padding"
|
|
||||||
local Builder = require "lib.simple_ui.core.builder"
|
|
||||||
local Flex = require "lib.simple_ui.elements.flex"
|
|
||||||
local SizedBox = require "lib.simple_ui.elements.sized_box"
|
|
||||||
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
||||||
|
|
||||||
|
|
||||||
local MyWidget = setmetatable({}, SingleChildElement)
|
|
||||||
MyWidget.__index = MyWidget
|
|
||||||
|
|
||||||
local Canary = setmetatable({}, SingleChildElement)
|
|
||||||
Canary.__index = Canary
|
|
||||||
|
|
||||||
local reported = false
|
|
||||||
function Canary:build()
|
|
||||||
if not reported then
|
|
||||||
self:traverseUp(function(element)
|
|
||||||
print(element.type)
|
|
||||||
return true
|
|
||||||
end)
|
|
||||||
reported = true
|
|
||||||
end
|
|
||||||
|
|
||||||
return Placeholder:new {}
|
|
||||||
end
|
|
||||||
|
|
||||||
--- comment
|
|
||||||
--- @return Flex
|
|
||||||
function MyWidget:build()
|
|
||||||
return Flex:new {
|
|
||||||
key = "my_flex",
|
|
||||||
direction = "vertical",
|
|
||||||
mainAxisSize = "max",
|
|
||||||
children = {
|
|
||||||
Padding:new {
|
|
||||||
top = 8,
|
|
||||||
child = Flex:new {
|
|
||||||
key = "inner_flex",
|
|
||||||
mainAxisAlignment = "start",
|
|
||||||
mainAxisSize = "min",
|
|
||||||
children = {
|
|
||||||
SizedBox:new {
|
|
||||||
width = 100,
|
|
||||||
height = 100,
|
|
||||||
child = Placeholder:new {}
|
|
||||||
},
|
|
||||||
SizedBox:new {
|
|
||||||
width = 150,
|
|
||||||
height = 200,
|
|
||||||
child = Placeholder:new {}
|
|
||||||
},
|
|
||||||
SizedBox:new {
|
|
||||||
width = 100,
|
|
||||||
height = 100,
|
|
||||||
child = Canary:new {}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Flex:new {
|
|
||||||
key = "inner_flex2",
|
|
||||||
mainAxisAlignment = "center",
|
|
||||||
children = {
|
|
||||||
SizedBox:new {
|
|
||||||
width = 100,
|
|
||||||
height = 100,
|
|
||||||
child = Placeholder:new {}
|
|
||||||
},
|
|
||||||
|
|
||||||
SizedBox:new {
|
|
||||||
width = 100,
|
|
||||||
height = 100,
|
|
||||||
child = Placeholder:new {}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
return Builder {
|
|
||||||
elementTree = ScreenArea:new {
|
|
||||||
child = MyWidget:new {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -18,7 +18,7 @@ function rect.new(table)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function rect:hasPoint(x, y)
|
function rect:hasPoint(x, y)
|
||||||
return x >= self.x and x < self.width and y >= self.y and y < self.height
|
return x >= self.x and x < self.x + self.width and y >= self.y and y < self.y + self.height
|
||||||
end
|
end
|
||||||
|
|
||||||
return rect.new
|
return rect.new
|
||||||
169
lib/spell/effect.lua
Normal file
169
lib/spell/effect.lua
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
local utils = require "lib.utils.utils"
|
||||||
|
local taskUtils = require "lib.utils.task"
|
||||||
|
|
||||||
|
--- Некоторое свойство, что можно наложить на персонажа. Позволяет реализовать такие вещи как DOT'ы
|
||||||
|
--- и вообще, что душа поживает.
|
||||||
|
---
|
||||||
|
--- У каждого эффекта есть тэг и функции триггеры (например, `beforeTurn`, что срабатывает перед началом хода персонажа и так далее).
|
||||||
|
--- Каждая функция триггер делится на два типа, `before...` и `after...`. Каждая из них возвращает `task`, для того чтобы
|
||||||
|
--- проиграть анимацию, например. Функции типа `before...` также возвращают по мимо таска некоторое значение, зависящее от
|
||||||
|
--- конкретной функции.
|
||||||
|
--- @class Effect
|
||||||
|
--- @field tag string
|
||||||
|
local effect = {}
|
||||||
|
effect.__index = effect
|
||||||
|
|
||||||
|
--- Предполагается, что в каждую функцию будет передаваться `Character` (владелец эффекта) и параметр `intensity`, который отвечает за силу эффекта
|
||||||
|
--- @alias EffectFunc fun(owner: Character, intensity: integer): Task<nil>, nil бред конечно, но иначе всё в жёлтом
|
||||||
|
--- @alias EffectStatementFunc fun(owner: Character, intensity: integer): Task<nil>, boolean
|
||||||
|
--- @alias EffectDamageFunc fun(owner: Character, intensity: integer, damage: integer): Task<nil>, integer
|
||||||
|
--- @alias EffectRegenFunc fun(owner: Character, intensity: integer, amountHp: integer): Task<nil>, integer
|
||||||
|
--- @alias EffectData { tag: string }
|
||||||
|
|
||||||
|
--- Срабатывает перед применением эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает, а можно ли применить эффект?
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>, boolean
|
||||||
|
function effect:beforeBirth(owner, intensity) return taskUtils.fromValue(), true end
|
||||||
|
|
||||||
|
--- Срабатывает после применения эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterBirth(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Срабатывает перед смертью владельца эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает, умирает ли персонаж?
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>, boolean
|
||||||
|
function effect:beforeDeath(owner, intensity) return taskUtils.fromValue(), true end
|
||||||
|
|
||||||
|
--- Срабатывает после смерти владельца эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterDeath(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Срабатывает перед ходом владельца эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает, будет ли персонаж ходить?
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>, boolean
|
||||||
|
function effect:beforeTurn(owner, intensity) return taskUtils.fromValue(), true end
|
||||||
|
|
||||||
|
--- Срабатывает после хода владельца эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterTurn(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Срабатывает перед кастом заклинания владельцем эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает, произойдёт ли каст?
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>, boolean
|
||||||
|
function effect:beforeCast(owner, intensity) return taskUtils.fromValue(), true end
|
||||||
|
|
||||||
|
--- Срабатывает после каста заклинания владельцем эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterCast(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Срабатывает перед нанесением урона владельцем эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает урон, который собираются нанести
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @param damage integer
|
||||||
|
--- @return Task<nil>, integer
|
||||||
|
function effect:beforeAttack(owner, intensity, damage) return taskUtils.fromValue(), damage end
|
||||||
|
|
||||||
|
--- Срабатывает после нанесения урона владельцем эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterAttack(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Срабатывает перед получением урона владельцем эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает урон, который должны получить
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @param damage integer
|
||||||
|
--- @return Task<nil>, integer
|
||||||
|
function effect:beforeDamage(owner, intensity, damage) return taskUtils.fromValue(), damage end
|
||||||
|
|
||||||
|
--- Срабатывает после получения урона владельцем эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterDamage(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Срабатывает перед регенерацией здоровья владельцем эффекта
|
||||||
|
---
|
||||||
|
--- Возвращает количество здоровья, которое должно быть восстановлено
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @param amountHp integer кол-во хп для регена
|
||||||
|
--- @return Task<nil>, integer
|
||||||
|
function effect:beforeRegeneration(owner, intensity, amountHp) return taskUtils.fromValue(), amountHp end
|
||||||
|
|
||||||
|
--- Срабатывает после регенерации здоровья владельцем эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param intensity integer
|
||||||
|
--- @return Task<nil>
|
||||||
|
function effect:afterRegeneration(owner, intensity) return taskUtils.fromValue() end
|
||||||
|
|
||||||
|
--- Функция, что задаёт правила присвоения эффекта
|
||||||
|
--- @param owner Character
|
||||||
|
--- @param stacks integer
|
||||||
|
--- @param intensity integer
|
||||||
|
function effect:onBirth(owner, stacks, intensity)
|
||||||
|
local effects = owner:has(Tree.behaviors.effects)
|
||||||
|
if not effects then return end
|
||||||
|
-- проверяем на наличие такого же эффекта
|
||||||
|
if effects.effectsProperties[self.tag] then
|
||||||
|
local i = 1
|
||||||
|
while i < #effects.effectsPriority and effects.effectsPriority[i] ~= self.tag do
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
local ef = table.remove(effects.effectsPriority, i)
|
||||||
|
effects.effectsPriority[#effects.effectsPriority + 1] = ef
|
||||||
|
else
|
||||||
|
effects.effectsPriority[#effects.effectsPriority + 1] = self.tag
|
||||||
|
end
|
||||||
|
effects.effectsProperties[self.tag] = {
|
||||||
|
stacks = stacks,
|
||||||
|
intensity = intensity
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function effect:update(dt) end
|
||||||
|
|
||||||
|
function effect:draw() end
|
||||||
|
|
||||||
|
--- дип сравнение эффектов
|
||||||
|
--- @param other Effect
|
||||||
|
--- @return boolean
|
||||||
|
function effect:__eq(other)
|
||||||
|
return utils.deepComparison(self, other)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param data EffectData
|
||||||
|
--- @return Effect
|
||||||
|
local function new(data)
|
||||||
|
local newEffect = setmetatable({
|
||||||
|
tag = data.tag,
|
||||||
|
}, effect)
|
||||||
|
|
||||||
|
return newEffect
|
||||||
|
end
|
||||||
|
|
||||||
|
return { new = new }
|
||||||
@ -123,6 +123,13 @@ function spell.new(data)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- проверка на возможность каста
|
||||||
|
if not caster:try(Tree.behaviors.effects, function(effects)
|
||||||
|
return effects:beforeCast()
|
||||||
|
end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
caster:try(Tree.behaviors.stats, function(stats)
|
caster:try(Tree.behaviors.stats, function(stats)
|
||||||
stats.mana = stats.mana - self.baseCost
|
stats.mana = stats.mana - self.baseCost
|
||||||
end)
|
end)
|
||||||
@ -130,6 +137,8 @@ function spell.new(data)
|
|||||||
caster:try(Tree.behaviors.spellcaster, function(spellcaster)
|
caster:try(Tree.behaviors.spellcaster, function(spellcaster)
|
||||||
spellcaster.cooldowns[self.tag] = self.baseCooldown
|
spellcaster.cooldowns[self.tag] = self.baseCooldown
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
return data.onCast(caster, target)
|
return data.onCast(caster, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,8 @@ local regenerateMana = spell.new {
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local sprite = caster:has(Tree.behaviors.sprite)
|
local sprite = caster:has(Tree.behaviors.sprite)
|
||||||
if not sprite then return end
|
local effects = caster:has(Tree.behaviors.effects)
|
||||||
|
if not sprite or not effects then return end -- и тут возможно на эффекты проверять не стоит
|
||||||
print(caster.id, "has regenerated mana and gained initiative")
|
print(caster.id, "has regenerated mana and gained initiative")
|
||||||
|
|
||||||
local light = require "lib/character/character".spawn("Light Effect")
|
local light = require "lib/character/character".spawn("Light Effect")
|
||||||
@ -67,7 +68,8 @@ local regenerateMana = spell.new {
|
|||||||
light:die()
|
light:die()
|
||||||
return task.fromValue()
|
return task.fromValue()
|
||||||
end),
|
end),
|
||||||
sprite:animate("hurt")
|
sprite:animate("hurt"),
|
||||||
|
effects:addEffect("aversionToDeath", 1, 1),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@ -86,9 +88,10 @@ local attack = spell.new {
|
|||||||
stats.hp = stats.hp - 4
|
stats.hp = stats.hp - 4
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local targetEffects = targetCharacter:has(Tree.behaviors.effects)
|
||||||
local sprite = caster:has(Tree.behaviors.sprite)
|
local sprite = caster:has(Tree.behaviors.sprite)
|
||||||
local targetSprite = targetCharacter:has(Tree.behaviors.sprite)
|
local targetSprite = targetCharacter:has(Tree.behaviors.sprite)
|
||||||
if not sprite or not targetSprite then return end
|
if not sprite or not targetSprite or not targetEffects then return end -- проверять на эффект может и не стоит
|
||||||
|
|
||||||
caster:try(Tree.behaviors.positioned, function(b) b:lookAt(target) end)
|
caster:try(Tree.behaviors.positioned, function(b) b:lookAt(target) end)
|
||||||
|
|
||||||
@ -111,7 +114,8 @@ local attack = spell.new {
|
|||||||
light:die()
|
light:die()
|
||||||
return task.fromValue()
|
return task.fromValue()
|
||||||
end),
|
end),
|
||||||
targetSprite:animate("hurt")
|
targetSprite:animate("hurt"),
|
||||||
|
targetEffects:addEffect("bleeding", 3, 3)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
),
|
),
|
||||||
|
|||||||
@ -74,4 +74,19 @@ function P.lerp(from, to, t)
|
|||||||
return from + (to - from) * t
|
return from + (to - from) * t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Compares two tables by their fields
|
||||||
|
--- @param t1 table
|
||||||
|
--- @param t2 table
|
||||||
|
--- @return boolean
|
||||||
|
function P.deepComparison(t1, t2)
|
||||||
|
for k, v in pairs(t1) do
|
||||||
|
if type(v) == "table" and type(t2[k]) == "table" then
|
||||||
|
if not P.deepComparison(v, t2[k]) then return false end
|
||||||
|
elseif t2[k] ~= v then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return P
|
return P
|
||||||
|
|||||||
66
main.lua
66
main.lua
@ -12,19 +12,20 @@ end
|
|||||||
function love.load()
|
function love.load()
|
||||||
love.window.setMode(1280, 720, { resizable = true, msaa = 4, vsync = true })
|
love.window.setMode(1280, 720, { resizable = true, msaa = 4, vsync = true })
|
||||||
require "lib/tree" -- важно это сделать после настройки окна
|
require "lib/tree" -- важно это сделать после настройки окна
|
||||||
testLayout = require "lib.simple_ui.level.test"
|
testLayout = require "lib.simple_ui.level.layout"
|
||||||
|
|
||||||
local chars = {
|
local chars = {
|
||||||
character.spawn("Foodor")
|
-- character.spawn("Foodor")
|
||||||
:addBehavior {
|
-- :addBehavior {
|
||||||
Tree.behaviors.residentsleeper.new(),
|
-- Tree.behaviors.residentsleeper.new(),
|
||||||
Tree.behaviors.stats.new(nil, nil, 1),
|
-- Tree.behaviors.stats.new(nil, nil, 1),
|
||||||
Tree.behaviors.positioned.new(Vec3 { 1, 1 }),
|
-- Tree.behaviors.positioned.new(Vec3 { 3, 3 }),
|
||||||
Tree.behaviors.tiled.new(),
|
-- Tree.behaviors.tiled.new(),
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
-- Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||||
Tree.behaviors.shadowcaster.new(),
|
-- Tree.behaviors.shadowcaster.new(),
|
||||||
Tree.behaviors.spellcaster.new()
|
-- Tree.behaviors.spellcaster.new(),
|
||||||
},
|
-- Tree.behaviors.effects.new()
|
||||||
|
-- },
|
||||||
character.spawn("Foodor")
|
character.spawn("Foodor")
|
||||||
:addBehavior {
|
:addBehavior {
|
||||||
Tree.behaviors.residentsleeper.new(),
|
Tree.behaviors.residentsleeper.new(),
|
||||||
@ -33,7 +34,8 @@ function love.load()
|
|||||||
Tree.behaviors.tiled.new(),
|
Tree.behaviors.tiled.new(),
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||||
Tree.behaviors.shadowcaster.new(),
|
Tree.behaviors.shadowcaster.new(),
|
||||||
Tree.behaviors.spellcaster.new()
|
Tree.behaviors.spellcaster.new(),
|
||||||
|
Tree.behaviors.effects.new()
|
||||||
},
|
},
|
||||||
character.spawn("Foodor")
|
character.spawn("Foodor")
|
||||||
:addBehavior {
|
:addBehavior {
|
||||||
@ -43,19 +45,33 @@ function love.load()
|
|||||||
Tree.behaviors.tiled.new(),
|
Tree.behaviors.tiled.new(),
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||||
Tree.behaviors.shadowcaster.new(),
|
Tree.behaviors.shadowcaster.new(),
|
||||||
Tree.behaviors.spellcaster.new()
|
|
||||||
},
|
|
||||||
character.spawn("BOAR")
|
|
||||||
:addBehavior {
|
|
||||||
Tree.behaviors.residentsleeper.new(),
|
|
||||||
Tree.behaviors.stats.new(nil, nil, 2),
|
|
||||||
Tree.behaviors.positioned.new(Vec3 { 5, 5 }),
|
|
||||||
Tree.behaviors.tiled.new(),
|
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.boar),
|
|
||||||
Tree.behaviors.shadowcaster.new(),
|
|
||||||
Tree.behaviors.spellcaster.new(),
|
Tree.behaviors.spellcaster.new(),
|
||||||
Tree.behaviors.ai.new("dev_warrior")
|
Tree.behaviors.effects.new()
|
||||||
},
|
},
|
||||||
|
-- character.spawn("Baris")
|
||||||
|
-- :addBehavior {
|
||||||
|
-- Tree.behaviors.residentsleeper.new(),
|
||||||
|
-- Tree.behaviors.stats.new(nil, nil, 2),
|
||||||
|
-- Tree.behaviors.positioned.new(Vec3 { 5, 5 }),
|
||||||
|
-- Tree.behaviors.tiled.new(),
|
||||||
|
-- Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||||
|
-- Tree.behaviors.shadowcaster.new(),
|
||||||
|
-- Tree.behaviors.spellcaster.new(),
|
||||||
|
-- Tree.behaviors.ai.new(),
|
||||||
|
-- Tree.behaviors.effects.new()
|
||||||
|
-- },
|
||||||
|
-- character.spawn("BOAR")
|
||||||
|
-- :addBehavior {
|
||||||
|
-- Tree.behaviors.residentsleeper.new(),
|
||||||
|
-- Tree.behaviors.stats.new(nil, nil, 2),
|
||||||
|
-- Tree.behaviors.positioned.new(Vec3 { 7, 7 }),
|
||||||
|
-- Tree.behaviors.tiled.new(),
|
||||||
|
-- Tree.behaviors.sprite.new(Tree.assets.files.sprites.boar),
|
||||||
|
-- Tree.behaviors.shadowcaster.new(),
|
||||||
|
-- Tree.behaviors.spellcaster.new(),
|
||||||
|
-- Tree.behaviors.ai.new(),
|
||||||
|
-- Tree.behaviors.effects.new()
|
||||||
|
-- },
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, _ in pairs(chars) do
|
for id, _ in pairs(chars) do
|
||||||
@ -83,11 +99,7 @@ function love.update(dt)
|
|||||||
require('lib.utils.task').update(dt)
|
require('lib.utils.task').update(dt)
|
||||||
Tree.controls:poll()
|
Tree.controls:poll()
|
||||||
Tree.level.camera:update(dt) -- сначала логика камеры, потому что на нее завязан UI
|
Tree.level.camera:update(dt) -- сначала логика камеры, потому что на нее завязан UI
|
||||||
|
|
||||||
testLayout:build()
|
|
||||||
testLayout:layout()
|
|
||||||
testLayout:update(dt) -- потом UI, потому что нужно перехватить жесты и не пустить их дальше
|
testLayout:update(dt) -- потом UI, потому что нужно перехватить жесты и не пустить их дальше
|
||||||
|
|
||||||
Tree.panning:update(dt)
|
Tree.panning:update(dt)
|
||||||
Tree.level:update(dt)
|
Tree.level:update(dt)
|
||||||
Tree.audio:update(dt)
|
Tree.audio:update(dt)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user