Page 1 of 2

[Solved] Procedural meters generation?

Posted: July 21st, 2018, 11:10 am
by MetalTxus
Greetings.

I have the following piece of code:

Code: Select all

[Game01]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover01#
LeftMouseUpAction = ["#gameTarget01#"]
X = 0
Y = 0

[Game02]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover02#
LeftMouseUpAction = ["#gameTarget02#"]
X = (1 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(1 / #colCount#) * #coverHeight#)

[Game03]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover03#
LeftMouseUpAction = ["#gameTarget03#"]
X = (2 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(2 / #colCount#) * #coverHeight#)

[Game04]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover04#
LeftMouseUpAction = ["#gameTarget04#"]
X = (3 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(3 / #colCount#) * #coverHeight#)

[Game05]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover05#
LeftMouseUpAction = ["#gameTarget05#"]
X = (4 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(4 / #colCount#) * #coverHeight#)

[Game06]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover06#
LeftMouseUpAction = ["#gameTarget06#"]
X = (5 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(5 / #colCount#) * #coverHeight#)

[Game07]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover07#
LeftMouseUpAction = ["#gameTarget07#"]
X = (6 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(6 / #colCount#) * #coverHeight#)

[Game08]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover08#
LeftMouseUpAction = ["#gameTarget08#"]
X = (7 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(7 / #colCount#) * #coverHeight#)

[Game09]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover09#
LeftMouseUpAction = ["#gameTarget09#"]
X = (8 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(8 / #colCount#) * #coverHeight#)

[Game10]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover10#
LeftMouseUpAction = ["#gameTarget10#"]
X = (9 % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(9 / #colCount#) * #coverHeight#)
...and I was wondering if there was a way to procedurally generate these, as it's currently quite tedious to mantain.

The generation inside a loop should be as easy as:

Code: Select all

[Game${index + 1}]
Meter = Image
MeterStyle = GameCover
ImageName = #gameCover${index + 1}#
LeftMouseUpAction = ["#gameTarget${index + 1}#"]
X = (${index} % #colCount# = 0 ? #coverPositionCompensationHack# : #coverWidth#)r
Y = (Floor(${index} / #colCount#) * #coverHeight#)
...but even though I've read there's looping it only seems to work with measures and not meters themselves. Is there no way to achieve this?

Re: Procedural meters generation?

Posted: July 21st, 2018, 11:24 am
by jsmorley
Not in any practical way. Rainmeter is not a procedural language, and meters are created when the skin is read on load or refresh.

Re: Procedural meters generation?

Posted: July 21st, 2018, 11:28 am
by balala
EDIT: Sorry jsmorley, it seems I again was not atentive enough.
MetalTxus wrote:...but even though I've read there's looping it only seems to work with measures and not meters themselves. Is there no way to achieve this?
I'm not sure what are you thinking to, but first of all, you have to keep in mind that Rainmeter is not a programming language. For a such task you probably would need a proper programming language, such as C or eventually lua. Probably can be written a lua script to generate such a code, but I'm not sure at all that it worth.

Re: Procedural meters generation?

Posted: July 21st, 2018, 12:04 pm
by kyriakos876
You can have a lua script that creates new meters or deletes specific ones, but if you don't want to delete or create meters more than once, it's not worth it going through it. But still, it will just do the work for you of writing the code. Like, it will actually write in the .ini file one by one the meters, or delete them. I, so far, use this only to create a skin in the beginning, like a launcher, that has the same code all around with only the icons changing and the "on mouse click" commands. I do intend on advancing this code but it takes too much time as I'm not fluent on lua. But yea, as Jsmorley said,

"Not in any practical way"

Re: Procedural meters generation?

Posted: July 21st, 2018, 6:06 pm
by SilverAzide
MetalTxus wrote:Greetings.

I have the following piece of code:
...and I was wondering if there was a way to procedurally generate these, as it's currently quite tedious to mantain.

The generation inside a loop should be as easy as:
...but even though I've read there's looping it only seems to work with measures and not meters themselves. Is there no way to achieve this?
Everything that JSMorley and balala says above is true. BUT... You can do it with Lua code, and I will warn you it is NOT trivial. The trick is to create your skin with all the meters you need in advance. The meters will contain the absolute minimal code, like this:

Code: Select all

[Game1]
Meter=Image

[Game2]
Meter=Image
When the skin launches you'd fire a Lua script function that would loop through all your meters and populate them with the necessary settings, as in your example.

The perfect example of this is LuaCalendar. This skin is just an empty shell of 40+ meters, but with a (mind-boggling) set of Lua functions that configures, populates, and positions all the meters on the fly. Your skin would not require anything nearly as complex as what LuaCalendar is doing, but the logic is the same.

Re: Procedural meters generation?

Posted: July 21st, 2018, 6:14 pm
by balala
SilverAzide wrote:The perfect example of this is LuaCalendar. This skin is just an empty shell of 40+ meters, but with a (mind-boggling) set of Lua functions that configures, populates, and positions all the meters on the fly. Your skin would not require anything nearly as complex as what LuaCalendar is doing, but the logic is the same.
I didn't study the code of the LuaCalendar or its .lua code, but I have a question: has a such approach any advantage? Because once populated I'd say the code never changes and has not to be repopulated. Or I am wrong somewhere?

Re: Procedural meters generation?

Posted: July 21st, 2018, 6:26 pm
by SilverAzide
balala wrote:I didn't study the code of the LuaCalendar or its .lua code, but I have a question: has a such approach any advantage? Because once populated I'd say the code never changes and has not to be repopulated. Or I am wrong somewhere?
Well, for LuaCalendar, using Lua is really the only reasonable approach because as you cycle through the months you need to reconfigure the entire skin on the fly. But for the OPs issue, the main benefit he'd get from Lua is the ability to loop through all the meters as he appears to want to do. Unlike LuaCalendar, he'd only need to do this just one time when the skin starts up. It's also much easier to set all the meter properties with Lua in a loop... you could do it with a whole bunch of plain old Rainmeter measures and lots and lots of !SetOption bangs, but that is MUCH too impractical as you and JSMorley noted.

Re: Procedural meters generation?

Posted: July 21st, 2018, 7:11 pm
by balala
SilverAzide wrote:Well, for LuaCalendar, using Lua is really the only reasonable approach because as you cycle through the months you need to reconfigure the entire skin on the fly.
No, it's not the only. Native Rainmeter code can handle this. I wrote a such calendar, here it is: https://forum.rainmeter.net/viewtopic.php?p=124162#p124162 (obviously I'm talking about the Calendar skin of this package, if you're interested).
Especially that if I'm not wrong (again, I didn't study the code of the LuaCalendar) using a such continuous rewrite of the meters requires a continuous refresh of the skin, every time you're switching to the next (or previous) month. And, at least in my conception, this is an extremely big disadvantage (if I am right).
SilverAzide wrote:But for the OPs issue, the main benefit he'd get from Lua is the ability to loop through all the meters as he appears to want to do. Unlike LuaCalendar, he'd only need to do this just one time when the skin starts up. It's also much easier to set all the meter properties with Lua in a loop... you could do it with a whole bunch of plain old Rainmeter measures and lots and lots of !SetOption bangs, but that is MUCH too impractical as you and JSMorley noted.
Again, if only once have to go through the creation of the meters, I'm not sure at all it worth to work with a lua code, which can create the needed meters. Instead of writing a such lua code, he could write the Rainmeter meters themselves.

Re: Procedural meters generation?

Posted: July 21st, 2018, 9:22 pm
by SilverAzide
balala wrote:Especially that if I'm not wrong (again, I didn't study the code of the LuaCalendar) using a such continuous rewrite of the meters requires a continuous refresh of the skin, every time you're switching to the next (or previous) month. And, at least in my conception, this is an extremely big disadvantage (if I am right).

Again, if only once have to go through the creation of the meters, I'm not sure at all it worth to work with a lua code, which can create the needed meters. Instead of writing a such lua code, he could write the Rainmeter meters themselves.
Not correct, sorry, LuaCalendar does not do that. Obviously you can do things in Rainmeter natively, but for what the original poster wanted -- a procedural approach to configuring a series of similar meters -- Lua would be a reasonable choice.

Re: Procedural meters generation?

Posted: July 21st, 2018, 9:36 pm
by balala
SilverAzide wrote:Not correct, sorry, LuaCalendar does not do that.
As I said, I didn't study the code. Nor the code of the skin itself, nor the lua code. Sorry if I was mistaken.
SilverAzide wrote:Obviously you can do things in Rainmeter natively, but for what the original poster wanted -- a procedural approach to configuring a series of similar meters -- Lua would be a reasonable choice.
What any of us consider a simpler solution, depends on a lot of things. However I still think that writing a lua code to to use it for creation of a set of meters (especially if the lua code is ran only once and the appropriate meters are created only once), doesn't worth. For me it definitely wouldn't.