[closed] Core [message] image height and width macros
Moderator: Forum Moderators
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[closed] Core [message] image height and width macros
Hi
https://github.com/wesnoth/wesnoth/blob ... age.cfg#L8
(from line 8 all the way to line 131)
Do you have an idea how that image size editing macro works(what it does, looks like an absolute mess to me)?
When I have an image how to get image_original_height and image_original_width from it?
How could I convert those WML macros to Lua functions?
Thanks ^^
https://github.com/wesnoth/wesnoth/blob ... age.cfg#L8
(from line 8 all the way to line 131)
Do you have an idea how that image size editing macro works(what it does, looks like an absolute mess to me)?
When I have an image how to get image_original_height and image_original_width from it?
How could I convert those WML macros to Lua functions?
Thanks ^^
Last edited by ZombieKnight on May 16th, 2024, 7:15 am, edited 1 time in total.
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
Re: Core [message] image height and width macros
First get rid of macros, run preprocessor on them. Then convert macroless WML to Lua, by wml.parse or manually as fits your situation better.
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Core [message] image height and width macros
What do you mean with run preprocesor""?
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
-
- Posts: 1288
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Core [message] image height and width macros
Probably something like:
Code: Select all
wesnoth -p units/Mario.cfg /tmp
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Core [message] image height and width macros
Jup, you were right (tho it took me a while to figure out what it does)
Now I have this:
...
This can be used to know images height and width
Any idea how to convert that code to Lua?
Do you know what language is that/ what is that?
Now I have this:
Code: Select all
h="(
if((image_original_width < 300) and (image_original_height < 300),
image_original_height,
((image_original_height * calculated_width) / 500)
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
mirror="(portrait_mirror)"
name="(portrait_image)"
w="(
if((image_original_width < 300) and (image_original_height < 300),
image_original_width,
((image_original_width * calculated_width) / 500)
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
x="(
if(image_original_width > 100,
0,
(calculated_width - image_width) / 2
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
y="(
if(image_original_height > 0,
(height - image_height),
height - ((calculated_width - image_height) / 2)
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
This can be used to know images height and width
filesystem.image_size
.Any idea how to convert that code to Lua?
Do you know what language is that/ what is that?
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
Re: Core [message] image height and width macros
Now that you have wml you can use wml.parse
Code: Select all
# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
[lua]
code=<<
x = wml.parse([[
h="(
if((image_original_width < 300) and (image_original_height < 300),
image_original_height,
((image_original_height * calculated_width) / 500)
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
mirror="(portrait_mirror)"
name="(portrait_image)"
w="(
if((image_original_width < 300) and (image_original_height < 300),
image_original_width,
((image_original_width * calculated_width) / 500)
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
x="(
if(image_original_width > 100,
0,
(calculated_width - image_width) / 2
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
y="(
if(image_original_height > 0,
(height - image_height),
height - ((calculated_width - image_height) / 2)
)
where calculated_width = ((
max(250, min(500, best_size))
where
best_size = (
if((best_width * aspect_ratio) > max_height,
floor(max_height / aspect_ratio),
best_width
)
where
best_width = (
if(gamemap_width > text_width_saturation,
gamemap_width - 675
,
gamemap_width / size_factor
)
where
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
size_factor = 3
),
aspect_ratio = (
if(image_original_width > 0,
as_decimal(image_original_height) / image_original_width,
0
)
),
max_height = (gamemap_height - 30)
)
))
)"
]])
>>
[/lua]
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Core [message] image height and width macros
Code: Select all
local image_original_width = ...
local image_original_height = ...
local portrait_mirror = ...
local portrait_image = ...
local x = wml.parse(...that code here )
...
...
T.foreground {
T.draw {
T.image {x}
}
}
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
Re: Core [message] image height and width macros
I cant tell if the wml you posted is expected inside [image]. By syntax it seems possible.
local image_original_width = ...
local image_original_height = ...
local portrait_mirror = ...
local portrait_image = ...
are not doing anything.
local image_original_width = ...
local image_original_height = ...
local portrait_mirror = ...
local portrait_image = ...
are not doing anything.
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Core [message] image height and width macros
yes, it's meant to use that in image...
What do you mean?
How to set image_original_width ... then?
What do you mean?
How to set image_original_width ... then?
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
Re: Core [message] image height and width macros
You need to use string concatenation then. Instead of
f((image_original_width < 300)
having f((]]..tostring(image_original_width)..[[ < 300)
for example.