#Item Piles Splittermond Currencies
1 messages ยท Page 1 of 1 (latest)
I see. Man I work in IT, but discord makes me feel old ๐
Haha ๐
In any case, I've been noodling on the problem
So in the getItemPrices, I've thought this up:
if (typeof overallCost === "string" && isNaN(Number(overallCost))) {
const parts = overallCost.matchAll(/((\w*)(?=.)([1-9]+\d*)(?=.)(\w*))+/g);
overallCost = 0;
if (parts.length === 1 && !parts[0][1] && !parts[0][3]) {
overallCost = Number(parts[0][2]);
} else {
for (const part of parts) {
const currency = currencyList.find(curr => {
const abbr = curr.abbreviation.toLowerCase();
return abbr.includes(part[1]) || abbr.includes(part[3]);
});
if (!currency) continue;
overallCost += currency.exchangeRate * Number(part[2]);
}
}
}
Yeah, I am really sorry for this ๐ I wish I could help you more
In essence, I use regex to detect like 10gp 50sp 25cp
which then adds up each relative currency value to figure out the total
so that the rest of the code can take it from there
Sorry if I take some time to understand that, I'm really new to JS.
But we are still talking about issue #176 and not the new one (#200) I created, yes? Just to be sure.
Yeah the old one
Okay, so basically, the problem is string parsing
We need to take 1L 50T and somehow translate it into raw numbers so that Item Piles can handle it
Since L and T are both used in the currency settings, we can split the cost up into individual parts, and figure out what each part means
In this case 1L and 50T
if we look for numbers and text, we can deduct that 1L is 1 Lunare and 50T is 50 Telare
Meaning the cost of this item is 150 Telare total
Get my drift? ๐
Did you mix it up or did I understand it wrong?
I assumed the way I created it, it was 1S = 100L = 10000T. Is it the other way around?
Ah sorry
Substitute Solare with Lunare in my examples
1L 50T = 150T yes
I've never used the system FYI, hence my confusion
I did write something like this to get merchants working in Splittermond: https://bitbucket.org/rpgframework-cloud/splittermond-fvtt/pull-requests/88
No one has ๐ Literally 70% of the issues in the system are from me
Cool, lol
Well, with my implementation, I think it should be safe to then put Lunare as primary currency, with 100, 1, and 0.01 as the exchanges, respectively
Then I'd have to use floats to represent the basePrice. As I already said I am new to JS and wanted to make sure I have exact values and therefore used integers. I don't know what it's called, but I guess you know what I am talking about, when using float to do simple maths and ending up with something like 2.00000000000003 or something like that.
Is it safe/wise/easy to just use a float instead?
You don't, though
๐ great
So, if you continue to use your prices with parts
Like 10L 50T
Item piles will figure out how to represent that on its own side
I made it better, I'll show you with comments
Ok, right now prices are stored in splittermond as a string. It'd normally be something like 10L 50T. I then added the basePrice, which just converts it to a single number. So you say it should already work with the string?
That's what I'm describing what I'm doing
This is what I'm putting into item piles directly
Are you currently implementing it or is it already implemented?
Am currently
Here, with comments:
// Get all the parts, split by number, remove empty strings, and spaces at the start/end of each part
const parts = overallCost.split(/([1-9]+\d*)/g)
.filter(Boolean)
.map(part => part.trim());
// If there's only one part (one number), use that to determine the cost
overallCost = 0;
if (parts.length === 1) {
overallCost = Number(parts[0]);
} else {
// Otherwise, go through each part
for (let i = 0; i < parts.length; i++) {
// If the current part is not a number, then the next part is the cost
const cost = isNaN(Number(parts[i])) ? parts[i + 1] : Number(parts[i]);
// If the current part is not a number, then it is the currency shorthand
const potentialCurrency = (isNaN(Number(parts[i])) ? parts[i] : parts[i + 1]).toLowerCase();
// Try to find the currency in the currency list setup
const currency = currencyList.find(curr => {
const abbr = curr.abbreviation.toLowerCase();
return abbr.includes(potentialCurrency) || curr.name.toLowerCase().startsWith(potentialCurrency);
});
// If we didn't find it, give up
if (!currency) continue;
// Otherwise add it to the overall fractional cost
overallCost += currency.exchangeRate * Number(cost);
}
}
currencyList being the merchant's (or entire system's) currency setup
Does any of that make sense? ๐
So even crazy people who do like L1 50 T can be handled
because it finds that L is not a number, so the next part must be a number
so, 1 tolare*
the next part is a number so the next one after that must be a string, so 50 Lunare
you get the gist
AAA
i'm so confused with the currencies sometimes
but you get the principle
I'll go try this out in splittermond now I think
Yes, I do. If I understand it correctly, we did exactly the same thing
Indeed we did
Mine just assumes people may be crazy
Which... is definitely a certainty
Are you sure? It's german only. Maybe I can help you
I'll just quickly create a merchant and see myself ๐
Then I'll send you a beta version to test out
Great
Neat.
There isn't really a base currency
Does it have to be though? I'd prefer the smalles one. Does it have any technical reason to be?
Not really, not in this instance I suppose
Telare are pretty much used all the time still. It's not like DnD where you run around and do everything with Gold
We only ever had more than 1 Solare two times
I am not even sure there is anything in the rulebook, that's more than 50L ๐
Haha okay then
Well besides magically crafted Items, but I am getting off topic^^
Telare it is
Try installing this directly in the foundry client ๐
https://raw.githubusercontent.com/fantasycalendar/FoundryVTT-ItemPiles/next/module.json
It's the beta version
I'm looking into your issue now
While we are at it. Can you replace the Lunare Icon with icons/commodities/currency/coins-assorted-mix-silver.webp ? Some update changed the Icon
Sure can do
I'll also improve the handling of having the smallest currency being the primary one, I was basing most of my logic around the 5e system of gold being primary, and being split
Didn't work for me:
It's working, it's just always defaulting to the smallest currency
This will fix it
Like if you buy it from the merchant
With a person who has Lunare
It'll use lunare to pay for it
Ah yes. Good thing that's working. I thought it would also convert the price of 5000T to 50L in the merchants window^^
Nah :p it's just displaying the "easiest" way to show it, because Telare is the primary currency
so it doesn't think it has to show higher currencies
I'll make it show higher ones if it can
Now I see why it could be good to use Lunare as a base currency. hm...
Yeah
It's like using dimes instead of dollars
So by using dollars as a primary one, dimes becomes a thing it tries to avoid
Yeah it's a bit more complicated in splittermond unfortunately ๐ Most daily use items are <1L. Torches, Oils, Food. Only weapons and armor are more most of the time
Try setting Lunare as primary, with 100, 1, 0.01
If something costs 50T it will show that
and use that
Is it too complicated to convert it back to the currencies in the most sensible way?
Nope, I can do it at the snap of a finger
It's all configured here
The next time you update, it'll just ask if you want to update, and it'll work
Oh it already does when using lunare as the primary:
Yeah, so it works like you expect? ๐
I'd recommend the exchange rates of 100, 1, and 0.01 in any case
I'd go for 1, 0.01, 0.0001 to have it exactly as i imagined it
I don't get that
It's the same thing
that is just how much the primary currency is multiplied
100, 1, 0.01:
I see
That makes sense, thank you
Putting more priority on Solare
Convert to it if you can
Otherwise use Lunare, lastly Telare
I getcha
Does it really put more priority on it? It only uses it if it is indeed at least 1S
It would never use it otherwise
Indeed
this looks best right now imho
The only thing that putting Solare as primary is that if you put just a simple "50" on an item price, it'll default to 50S
Was a bit hard to understand everything when I wasn't sure how to get it running ๐
You might want to put it on Telare, if that doesn't break anything
well as my physics teacher always said "50 what? apples? bananas?"
I think it's good like that. Will you set it as the splittermond defaults?
Indeed
Thanks for walking me through it!
I think it might fix your other bug too
Can you test?
It does
awesome
What exactly did fix it? The new way of calculating the base price from the price-string or the new exchange rates or the new primary?
I think you forgot to reenable the german translation with 2.3.0.
And yeah I think both of those contributed
Ok, thank you again, then. It's already late here, so I will head to bed. The next time I have some annyoing issue, it will be easier to figure out ๐
Oh I just remembered, there is a new item type in splittermond. npcattack.
This would be the new filter:
spell,strength,weakness,mastery,species,culture,ancestry,education,resource,npcfeature,moonsign,language,culturelore,statuseffect,spelleffect,npcattack
Okayo, added
Thanks