Log in

View Full Version : Adding Image to A Map



SieferSeesSomething
December 25th, 2023, 06:03
Hello everyone, I've been looking into how to make extensions for the first time. It's my Christmas present to myself. I'm still at the beginning, looking at various tutorials, but most of them are outdated at this point, so I've also been relying on unpacking Core RPG and looking at API documents but there's a lot, so I may need some help.

First question, is it possible to add an image to another image programmatically through a Lua extension? Would I use the addLayer method for it that I see here (https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/2165473281/Image), and add an image layer that points to an icon resource or something like that? Or would it require something like creating a windowclass with an icon image without a frame?

Example uses would be adding random decorations to a map, or making other sorts of indicators on the map besides the arrow, square, and circle.

LordEntrails
December 25th, 2023, 22:32
The current CoreRPG capability that I'm aware of that does this is around the blood splats/death indicators when an NPC is removed from the CT. So yes, its achievable :) There is a Death Indicators extension that you might find that does a similar thing, but the code you are looking for might be more apparent. Death Indicator Ex v4.5 extension for 5e Fantasy Grounds Unity (https://www.fantasygrounds.com/forums/showthread.php?59203-Death-Indicator-Ex-v4-5-extension-for-5e-Fantasy-Grounds-Unity)

Be aware, make sure you are adding them as layers/images and not tokens. Tokens impact visibility calculations and performance (the extension originally had this problem, but I think SR has since resolved it.)

SieferSeesSomething
December 25th, 2023, 22:49
Yes, thanks! I was hoping someone would respond with some extensions that did something similar I can look at, but I realized I forgot to ask.

Appreciate the direction! And happy holidays!

SieferSeesSomething
December 31st, 2023, 07:08
Hope everyone had a good Christmas and is ready for New Year's!

I've been experimenting with some image adding using the direction of the death indicators functionality Lord Entrails pointed me towards, both the Core RPG version and the 5e extension above, but I have run into a few issues I hope someone can help me. Specifically, I can't really figure out what the "asset" parameter is for the addLayer parameters. I keep getting errors when throwing my own images in there from the same place I put other images (an icon entry in my extension.xml file in the base node pointing to an image in my graphics folder). I can't really figure out what is put in there or how. For CoreRPG, I found the general place its put it in in the manager_image_deathmarker.lua file in the getSetMap() where the sAsset variable here seems to be the key.


function getSetMap()
local tSetMap = { };
for _,nodeSet in ipairs(DB.getChildList("settings.imagedeathmarkerset")) do
local sName = DB.getValue(nodeSet, "name", "");
local tSetData = {};
for _,nodeAsset in ipairs(DB.getChildList(nodeSet, "assets")) do
local sAsset = DB.getValue(nodeAsset, "value", "");
if sAsset ~= "" then
table.insert(tSetData, sAsset);
end
end
local sTint = DB.getValue(nodeSet, "tint", "");
if (sTint ~= "") then
tSetData.tint = sTint;
end
tSetMap[sName] = tSetData;
end
return tSetMap;
end

But kind of stuck here. Not really sure what's happening in all those lines. Looks like it's related to some db entry in <settings><imagedeathmarkerset>, but I can't find that entry in any db.xml files in the test projects I've been working with or anywhere in my Find in Files search, let alone anything related to assets in those files at all. I tried throwing a Debug.console line into this file to see if it can help show me what's happening:


local x,y = token.getPosition();
local nGridScale = TokenManager.getTokenSpace(token);
Debug.console("manager_image_deathmarker.lua sAsset", sAsset); --I added this line here
Image.addLayerPaintStamp(sPath, nLayerID, { asset=sAsset, w=nGridScale, h=nGridScale, x=x, y=y, color=sTint });

But even when I successfully got death markers to appear by killing enemies then removing them from the combat tracker, nothing would pop up in the console log. Any suggestions on why the console log isn't popping up (in practice 4e and 5e games I tried)? Or with using an image I have as an asset for the Image.addLayer or Image.addLayerPaintStamp functions? Is the relevant database node being created and deleted so fast that I can't see it, or am I on the completely wrong track?

Thanks and have a Happy New Year!

Trenloe
December 31st, 2023, 10:05
[QUOTE=SieferSeesSomething;704951]...nothing would pop up in the console log. Any suggestions on why the console log isn't popping up[.../QUOTE]
The console window only "pops up" (opens by itself) if there is an error. Just writing debug to the console won't automatically open it. You can open the console by using the /console chat command but you may find it easier to open the console.log file from the FG app data directory.

For your first question - sAsset is a FG filepath to a valid graphics file, it isn't an FG icon resource. For example, looking in the database of a test campaign:


<imagedeathmarkerset>
<id-00001>
<assets>
<id-00001>
<value type="string">images/Death Markers/blood/blood_01.png@SmiteWorks Assets</value>
</id-00001>

In this example, the sAsset value is: images/Death Markers/blood/blood_01.png@SmiteWorks Assets - this is the images/Death Markers/blood/blood_01.png file within the SmiteWorks Assets module (SmiteWorks Assets.mod in the <FG app data>\modules directory).

Hope this helps.

SieferSeesSomething
January 1st, 2024, 02:33
Oh ya, sorry I phrased that wrong. I was able to make the console log pop up easily enough, it's just that the specific message wouldn't appear within it.

For the sAsset field example you gave, that was very helpful to understanding what's happening there, thanks! One more question: How would I use that with an extension I'm making instead of putting the graphic in a separate module? Putting images/testimage.png both in the extensions images folder and adding it as an asset to the test campaign I'm using both didn't work. When I put in "images/Death Markers/blood/blood_01.png@SmiteWorks Assets", it does work. Does it only work if i put a graphic in a separate module? Feels like it would make it difficult to ship it all together in a single extension zip, for example.

Thanks for the help! I feel like I'm getting close!

Zacchaeus
January 1st, 2024, 09:37
I don't know the answer you are looking for but there are many extensions which also have accompanying modules. If your extension was on the forge then any files associated with the extension would also get downloaded for anyone subscribed to it. Extensions aren't limited to just the extension file.

Trenloe
January 1st, 2024, 15:27
One more question: How would I use that with an extension I'm making instead of putting the graphic in a separate module? Putting images/testimage.png both in the extensions images folder and adding it as an asset to the test campaign I'm using both didn't work. When I put in "images/Death Markers/blood/blood_01.png@SmiteWorks Assets", it does work. Does it only work if i put a graphic in a separate module? Feels like it would make it difficult to ship it all together in a single extension zip, for example.
The graphics files need to be accessible via the FG filesystem - so this is local files (global and campaign based), and in modules (.mod files). So you will need two files - a .ext extension and a .mod module. However, the module file doesn't have to be activated - FG can access the files directly as if it's a filesystem.

SieferSeesSomething
January 3rd, 2024, 04:21
Thanks everyone! I made a module file and it seems to be working! Slowly, but surely I'm getting it lol.