#Item Piles Splittermond Currencies

1 messages ยท Page 1 of 1 (latest)

surreal widget
#

@rare falcon Welcome! ๐Ÿ™‚

#

Aye, that's why I tagged you in the thread ๐Ÿ™‚

rare falcon
#

I see. Man I work in IT, but discord makes me feel old ๐Ÿ˜„

surreal widget
#

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]);
    }
  }
}
rare falcon
#

Yeah, I am really sorry for this ๐Ÿ˜„ I wish I could help you more

surreal widget
#

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

rare falcon
#

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.

surreal widget
#

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? ๐Ÿ™‚

rare falcon
#

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?

surreal widget
#

Ah sorry

rare falcon
#

Ok ok

surreal widget
#

Substitute Solare with Lunare in my examples

rare falcon
#

1L 50T = 150T yes

surreal widget
#

I've never used the system FYI, hence my confusion

rare falcon
rare falcon
surreal widget
#

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

rare falcon
#

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?

surreal widget
#

You don't, though

rare falcon
#

๐Ÿ˜„ great

surreal widget
#

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

rare falcon
#

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?

surreal widget
#

That's what I'm describing what I'm doing

surreal widget
rare falcon
#

Are you currently implementing it or is it already implemented?

surreal widget
#

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? ๐Ÿ™‚

rare falcon
#

Ah now I get it

#

Basically the same thing I did only way better and system agnostic

surreal widget
#

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

rare falcon
#

Yes, I do. If I understand it correctly, we did exactly the same thing

surreal widget
#

Indeed we did

#

Mine just assumes people may be crazy

#

Which... is definitely a certainty

rare falcon
surreal widget
#

I'll just quickly create a merchant and see myself ๐Ÿ™‚

#

Then I'll send you a beta version to test out

rare falcon
#

Great

surreal widget
rare falcon
surreal widget
#

lunare is the base currency, right?

#

Or is it actually Telare?

rare falcon
#

There isn't really a base currency

surreal widget
#

Ah okay

#

Well I'll make it lunare for item piles to have more wiggleroom

rare falcon
#

Does it have to be though? I'd prefer the smalles one. Does it have any technical reason to be?

surreal widget
#

Not really, not in this instance I suppose

rare falcon
#

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 ๐Ÿ˜„

surreal widget
#

Haha okay then

rare falcon
#

Well besides magically crafted Items, but I am getting off topic^^

surreal widget
#

Telare it is

surreal widget
#

It's the beta version

#

I'm looking into your issue now

rare falcon
#

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

surreal widget
#

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

rare falcon
#

Didn't work for me:

surreal widget
#

It's working, it's just always defaulting to the smallest currency

surreal widget
#

Like if you buy it from the merchant

#

With a person who has Lunare

#

It'll use lunare to pay for it

rare falcon
#

Ah yes. Good thing that's working. I thought it would also convert the price of 5000T to 50L in the merchants window^^

surreal widget
#

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

rare falcon
#

Now I see why it could be good to use Lunare as a base currency. hm...

surreal widget
#

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

rare falcon
#

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

surreal widget
#

Try setting Lunare as primary, with 100, 1, 0.01

#

If something costs 50T it will show that

#

and use that

rare falcon
#

Is it too complicated to convert it back to the currencies in the most sensible way?

surreal widget
#

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

rare falcon
#

Oh it already does when using lunare as the primary:

surreal widget
#

Yeah, so it works like you expect? ๐Ÿ™‚

#

I'd recommend the exchange rates of 100, 1, and 0.01 in any case

rare falcon
#

I'd go for 1, 0.01, 0.0001 to have it exactly as i imagined it

surreal widget
#

I don't get that

#

It's the same thing

#

that is just how much the primary currency is multiplied

rare falcon
#

100, 1, 0.01:

surreal widget
#

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

rare falcon
#

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

surreal widget
#

Indeed

rare falcon
#

this looks best right now imho

surreal widget
#

Nice, I'll use those

#

Does item piles make a bit more sense now? ๐Ÿ™‚

rare falcon
#

i don't know if it will break anything, though ๐Ÿ˜„

#

yeah, it's great, thanks

surreal widget
#

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

rare falcon
#

Was a bit hard to understand everything when I wasn't sure how to get it running ๐Ÿ˜„

surreal widget
#

You might want to put it on Telare, if that doesn't break anything

rare falcon
surreal widget
#

haha

#

fair

#

User error should be fixed on the user side

#

:p

rare falcon
#

I think it's good like that. Will you set it as the splittermond defaults?

surreal widget
#

Indeed

rare falcon
#

Great

#

thank you

surreal widget
#

Thanks for walking me through it!

#

I think it might fix your other bug too

#

Can you test?

rare falcon
#

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.

surreal widget
#

Huh, I did? I didn't touch any translation

#

Oh yeah

surreal widget
rare falcon
#

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

surreal widget
#

Okayo, added

rare falcon
#

Thanks