Don't Starve Together

Don't Starve Together

Celestial Tools
 This topic has been pinned, so it's probably important
ADM  [developer] 28 Apr, 2023 @ 5:44pm
Moonlens Compatibility Tutorial
Introduction
2 of the new structures introduced in this mod can revolutionize base building in the sense of optimizing storage rooms : The Moon Chest and the Lens Beacon !

These buildings make use of Moonlenses and are used together to operate in larger range... and the more Moonlens types you have, the more space there is.

Don't Starve has 6 pretty gems that can be socketed in the Cratered Moonrock, and while this is not something we tend to see much, mods can totally add their own gems and create a new Moonlens from them
(along all the cool stuff you can consider doing with them, ofc).

So this topic aims at explaining what is required for modders to make their Moonlens fully compatible with the chests and beacons... and you'll see it's very easy.
There's even templates for you to use if needed.

What is there to do ?
Most of the stuff is actually handled by Celestial Tools as long as your Moonlens is done finely, it will be capable of unlocking Moon Chests with its 9 new slots, both by dropping it or within the Lens Beacon without you having to do anything extra.

What won't be working however is the rendering of the gem on both the chests and beacons, because we don't know how they should look like without your help, yikes... but this only results in less cool visuals while it can still be used, just so you know.

All that is needed to do is creating 2 extra anim files per Moonlens, name them accordingly to both your gem / moonlens prefab(s) and our method to grab them, and load them, nothing else.

Basics and links
Let's get started by looking how this compatibility was done with a gem from another mod we made : Cherry Forest, who has custom gems that show on both buildings of Celestial Tools.

The gem and moonlens prefabs are named "cherrygem" and "cherrymooneye" accordingly to how it is done for vanilla ones ("redgem", "redmooneye", etc...), this conformity is important for us to detect vanilla + modded ones, create the chest gem rooms and display them.
So obviously replace any mention of 'cherry' you come across in the following steps / files with your gem(s) pretty name(s).

Download at this link[drive.google.com] an exported-like folder that contains the two Spriter files needed per gem with the images used to rename, replace and test later.

If needed, here is another link[drive.google.com] for the script of the modded lens(es) used in the tutorial, it is no different than vanilla lenses, but for the most we are here assuming your items are already created in a working mod project, alright ?

I'm also linking[drive.google.com] the modded Moonlens Spriter project of the cherrygem if it can be helpful. This is for reference and can be done the way you like it.
But as a bonus I added all the vanilla lens's gem images + the chest keyholes we made if they can be helpful to draw your own gems for what matters here.

Lens Beacon compatibility
Starting with the first and easiest one, the one for the Lens Beacon :
'moonglassbeacon_gem_cherry.scml'

This one requires one image under the object folder 'gem_cherry'
For this one you should be using the exact same gem image your Moonlens uses, so yeah, practical !

Replace the image, changes the image, folder and project names to the right ones.
And don't forget to open the .scml file with any text editor to replace the object 3 'gem_cherry' mentions here too :
<folder id="0" name="gem_cherry"> <file id="0" name="gem_cherry/gem_cherry-0.png" width="74" height="74" pivot_x="0.485983" pivot_y="0.527594"/> </folder>
With that done and saved, you should also go directly in the Spriter project to override the save (File > Save Project As [same .scml file]) in order to replace the image size data, you can also adjust the pivot if needed but this is usually centered as already presented.

Moon Chest compatibility
Now the Moon Chest :
'moonglasschest_gem_cherry.scml'

Here we will need a specific image since the gem visible in the keyhole is quite small and has a special cratered moonrock around it, this is the only image you need to create, do make use of the 'keyhole_cherry' image for scale or the ones available in the third link and you will probably manage to make a fancy keyhole by yourself !

Afterward, repeat the renaming process like you did with the beacon, within the .scml too BUT you won't need to open and save the project with Spriter because the image size will be the same, in fact, if you save it you will reset the first keyhole object id to 0 while it should be 16 which, if not fixed afterward can cause the gem to not show.
Better skip this...

Finishing Up
One last thing you might need to add, is to set a name for the chest room color. This can be added to the 'STRINGS.MOONGLASSCHEST_COLOUR' string table, unless yours is already part of the 'STRINGS.UI.COLOUR' one. The first character has to be uppercase, like so :
STRINGS.MOONGLASSCHEST_COLOUR.Cherry = "Cherry"
With this, characters can describe better the current chest room, but it would work without too.

And you're actually done, well, just run the autocompiller, then find those two .zip files in the anim folder, open them, and delete in both the anim.bin files, we're adding new assets to our builds here, not anims !

What's left is load the assets which can be done in your modmain.lua or wherever your mod Assets is located, add them within it with the correct name :
Assets = { Asset("ANIM", "anim/moonglassbeacon_gem_cherry.zip"), Asset("ANIM", "anim/moonglasschest_gem_cherry.zip"), }

Yup, this time that's actually it, nothing else to do if to update or publish the mod after you've tested it. You can definitively let us know if you added gems and that visual compatibility in your mod because... well that's more chest space for us coming from cool mods right ? : )
Last edited by ADM; 6 Apr, 2024 @ 11:13am