Skip to content

Commit

Permalink
implement portraits: beavers and goblins
Browse files Browse the repository at this point in the history
  • Loading branch information
ineveraskedforthis committed Jan 9, 2024
1 parent 7ac8c7a commit dec61e5
Show file tree
Hide file tree
Showing 41 changed files with 161 additions and 13 deletions.
53 changes: 53 additions & 0 deletions sote/engine/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,59 @@ function ui.image(image, rect, rotation)
)
end

local temp_quad = love.graphics.newQuad(0, 0, 256, 256, 256, 256)

--- Draws a part of UI image at x/y coordinates and with a given width and height
---@param image love.Image
---@param rect Rect
---@param rotation number?
function ui.image_ith(image, i, rect, rotation)
if rotation == nil then
rotation = 0
end

local x = rect.x
local y = rect.y
local width = rect.width
local height = rect.height
-- Pull data
local image_width = image:getWidth()
local image_height = image:getHeight()
local dims_x, dims_y = love.graphics.getDimensions()

local quads = image_width / image_height
if (i > 0) and (i < 1) then
i = math.floor(i * quads)
end
temp_quad:setViewport(image_height * i, 0, image_height, image_height, image_width, image_height)

image_width = image_height

-- Calculate "scaling" factor for width and height
local fill_x = width / reference_width
local fill_y = height / reference_height
local target_x = image_width / dims_x
local target_y = image_height / dims_y
local scale_x = fill_x / target_x
local scale_y = fill_y / target_y

-- Calculate "proper" x and y positions
local position_fraction_x = x / reference_width
local position_fraction_y = y / reference_height

-- Adjust them for drawing offset
position_fraction_x = position_fraction_x + fill_x / 2
position_fraction_y = position_fraction_y + fill_y / 2

love.graphics.draw(
image, temp_quad,
dims_x * position_fraction_x, dims_y * position_fraction_y,
rotation,
scale_x, scale_y,
image_width / 2, image_height / 2
)
end

---@alias VerticalAlignMode "up" | "center" | "down"
--- Draws text at x/y coordinates in a given width/height quad.
--- Texts first line will be centered vertically.
Expand Down
6 changes: 6 additions & 0 deletions sote/game/entities/pop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
---@field leader_of table<Realm, Realm>
---@field rank CHARACTER_RANK?
---@field former_pop boolean
---@field dna number[]

local rtab = {}

Expand Down Expand Up @@ -90,6 +91,11 @@ function rtab.POP:new(race, faith, culture, female, age, home, location, charact
r.dead = false
r.former_pop = false

r.dna = {}
for i = 1, 20 do
table.insert(r.dna, love.math.random())
end

setmetatable(r, rtab.POP)

return r
Expand Down
5 changes: 5 additions & 0 deletions sote/game/entities/realm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ end
---@field realm_id number
---@field name string
---@field budget Budget
---@field tax_target number
---@field tax_collected_this_year number
---@field r number
---@field g number
---@field b number
Expand Down Expand Up @@ -151,6 +153,9 @@ function realm.Realm:new()
o.tributaries = {}
o.paying_tribute_to = {}

o.tax_target = 0
o.tax_collected_this_year = 0

o.provinces = {}
o.bought = {}
o.sold = {}
Expand Down
23 changes: 23 additions & 0 deletions sote/game/raws/race-loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function ll.load()
g = 0.4,
b = 0.3,
icon = 'beaver.png',
portrait_description = {
folder = "beaver",
layers = {"cloth_behind.png", "base.png", "over_1.png", "over_2.png", "ear.png", "cloth.png"},
layers_groups = {
cloth = {"cloth_behind.png", "cloth.png"}
}
},
description = 'high beavers',
males_per_hundred_females = 108,
child_age = 4,
Expand Down Expand Up @@ -89,6 +96,14 @@ function ll.load()
g = 0.5,
b = 0.1,
icon = 'woman-elf-face.png',
portrait_description = {
folder = "null_middle",
layers = {"hair_behind.png", "base.png", "neck.png", "cheeks.png",
"chin.png", "ear.png", "eyes.png", "nose.png", "mouth.png", "hair.png", "clothes.png", "beard.png"},
layers_groups = {
hair = {"hair_behind.png", "hair.png"}
}
},
description = 'elves',
males_per_hundred_females = 100,
child_age = 5,
Expand Down Expand Up @@ -233,6 +248,14 @@ function ll.load()
g = 0.7,
b = 0.1,
icon = 'goblin.png',
portrait_description = {
folder = "goblin",
layers = {"04.png", "05.png", "055.png", "06.png", "07.png", "08.png", "09.png", "10.png", "11.png"},
layers_groups = {
ear = {"04.png", "07.png"},
hair = {"055.png", "10.png"}
}
},
description = 'goblin',
males_per_hundred_females = 102,
child_age = 1,
Expand Down
6 changes: 6 additions & 0 deletions sote/game/raws/race.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
local JOBTYPE = require "game.raws.job_types"

---@class PortraitDescription
---@field folder string
---@field layers string[]
---@field layers_groups string[][]

---@class Race
---@field name string
---@field icon string
---@field portrait_description nil|PortraitDescription
---@field description string
---@field r number
---@field g number
Expand Down
24 changes: 24 additions & 0 deletions sote/game/scenes/asset-loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ function asl.load_assets()
end
coroutine.yield()

asl.message = "Loading portraits..."
print(asl.message)

---@type table<string, love.Image>
ASSETS.portraits = {}
local fs = love.filesystem.getDirectoryItems("portraits")
for _, folder in pairs(fs) do
print(folder)
ASSETS.portraits[folder] = {}
local folder_content = love.filesystem.getDirectoryItems("portraits/" .. folder)
for _, image_name in pairs(folder_content) do
local c = love.graphics.newImage("portraits/" .. folder .. "/" .. image_name)
ASSETS.portraits[folder][image_name] = c
print("portraits/" .. folder .. "/" .. image_name)
-- Make sure to yield every now and then so that we don't hang the core!
yield_counter = yield_counter + 1
if yield_counter == 25 then
yield_counter = 0
coroutine.yield()
end
end
end
coroutine.yield()

ASSETS.all_done = true
end

Expand Down
39 changes: 35 additions & 4 deletions sote/game/scenes/game/widgets/portrait.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,42 @@ return function(rect, character)
ui.style.panel_outline = {r = 255 / 255, g = 215 / 255, b = 0 / 255, a = 1}
end

-- TODO: maybe we should draw background images related to current position
local old_inside = ui.style["panel_inside"]
ui.style["panel_inside"] = {r = 0 / 255, g = 20 / 255, b = 10 / 255, a = 0.3}
ui.panel(rect, 2, false)
ui.style["panel_inside"] = old_inside

love.graphics.setLineWidth( 4 )
ui.panel(rect)
love.graphics.setLineWidth( 1 )

ui.style.panel_outline = style
if character.race.portrait_description then
---@type number[]
local dna_per_layer = {}
---@type table<string, number>
local layer_to_index = {}
for i, layer in ipairs(character.race.portrait_description.layers) do
table.insert(dna_per_layer, character.dna[i])
layer_to_index[layer] = i
end

for i, layers_group in pairs(character.race.portrait_description.layers_groups) do
for j, layer in ipairs(layers_group) do
dna_per_layer[layer_to_index[layer]] = dna_per_layer[layer_to_index[layers_group[1]]]
end
end

assert(ASSETS.portraits[character.race.portrait_description.folder] ~= nil, character.race.portrait_description.folder .. " WAS NOT LOADED")

ui.image(ASSETS.get_icon(character.race.icon), rect)
for i, layer in ipairs(character.race.portrait_description.layers) do
assert(ASSETS.portraits[character.race.portrait_description.folder][layer] ~= nil, layer .. " WAS NOT LOADED")
assert(dna_per_layer[i] ~= nil, i)
ui.image_ith(ASSETS.portraits[character.race.portrait_description.folder][layer], dna_per_layer[i], rect)
end
else
ui.image(ASSETS.icons[character.race.icon], rect)
end

ui.panel(rect, 2, true, false)
love.graphics.setLineWidth( 1 )
ui.style.panel_outline = style
end
18 changes: 9 additions & 9 deletions sote/game/world-gen/province-gen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ function pro.run()
print('creating river-like provinces')
local riverlike_prov_count = math.floor(prov_count / 8)
for _ = 1, riverlike_prov_count do
if _ % 100 == 0 then
print(_ / riverlike_prov_count * 100)
end
-- if _ % 100 == 0 then
-- print(_ / riverlike_prov_count * 100)
-- end
-- Get a random soil rich tile with no province assigned to it
local tile = WORLD:random_tile()
local failsafe = 0
Expand All @@ -288,9 +288,9 @@ function pro.run()
print('creating coastal provinces')
local coastal_count = math.floor(prov_count / 5)
for _ = 1, coastal_count do
if _ % 100 == 0 then
print(_ / coastal_count * 100)
end
-- if _ % 100 == 0 then
-- print(_ / coastal_count * 100)
-- end

-- Get a random coastal tile with no province assigned to it
local tile = WORLD:random_tile()
Expand All @@ -314,9 +314,9 @@ function pro.run()

print('create rest of provinces')
for _ = 1, prov_count - coastal_count - riverlike_prov_count do
if _ % 100 == 0 then
print(_ / (prov_count - coastal_count - riverlike_prov_count) * 100)
end
-- if _ % 100 == 0 then
-- print(_ / (prov_count - coastal_count - riverlike_prov_count) * 100)
-- end
-- Get a random land tile with no province assigned to it
local tile = WORLD:random_tile()
local failsafe = 0
Expand Down
Binary file added sote/portraits/beaver/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/beaver/cloth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/beaver/cloth_behind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/beaver/ear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/beaver/over_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/beaver/over_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/055.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/goblin_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/beard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/beard_behind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/cheeks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/chin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/clothes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/clothes_behind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/clothes_infront.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sote/portraits/null_middle/ear.png
Binary file added sote/portraits/null_middle/eyes.png
Binary file added sote/portraits/null_middle/hair.png
Binary file added sote/portraits/null_middle/hair_behind.png
Binary file added sote/portraits/null_middle/mouth.png
Binary file added sote/portraits/null_middle/neck.png
Binary file added sote/portraits/null_middle/nose.png
Binary file added sote/portraits/null_middle/template.png

0 comments on commit dec61e5

Please sign in to comment.