Taking Questions about Mixintos and Overrides

I don’t think so. It seems that mixintos are inverted too.

1 Like

Fudge =(
I was afraid you’d say something to that effect.


EDITTOAVOIDDOUPLEPOST:
Ok, I’ve got a stupid question. Is is possible to mixinto html files? If so how?
I’m pretty sure the answer is no.

I’d like to add the weaver into the start menu. Before, I replaced the whole thing in stonehearth.smod, but if there is a better way, I’d rather do that.

Now to try and figure out how to get this to work for a new place-able table. . . .

Running into all kinds of confusing problems tonight :fearful:

Well, I’m currently writing a tool that would check references to aliases/files automatically to make sure everything’s up-to-date. In theory it could also figure out which aliases are not used at all, or duplicated, all that stuff.

However, that is confusing to code.

2 Likes

You and me both >.<;
Though adding a table doesn’t seem too difficult, should be the same as adding a bed, which I’ve done.


On a side note, it seems like both sheep and weaver’s workbenches can’t be modded in, so I’m having to downgrade =[

Sheeps can be spawned using rp_spawn_stuff, so it’s definitely possible. However, the code to shear sheeps isn’t available. Even if you spawn sheep (by enabling scenarios you might have a chance I think, but that’s more guessing than knowing), you couldn’t do anything with them.

I wonder if it’s possible to change one of the sizes of trees to allow it to drop wool as a resource instead of wood. (just a suggestion)[quote=“chimeforest, post:45, topic:5229”]
should be the same as adding a bed, which I’ve done.
[/quote]
TEACH ME YOUR POWERS ALMIGHTY CHIMEFOREST!
-bows deeply;
xD

1 Like

If you want to be really cruel, I guess you could use the chopping AI as a template for a shearing action. You would have to do it yourself, but it’s not impossible to do.

1 Like

Well, yes, sheep can also be crafted by the carpenter, but without the shearing, there’s really no point =/
Before the update they were shear-able, I guess there are in the middle of updating the code for it.

I should have worded my reply differently, sorry.

I suppose weavers might be able to be modded in again… but that’s currently above my level/more effort than I’m willing to put into it since it’ll probably be added pretty soon anyway.

@Avairian, hmm… “wool trees”, lol. or maybe cotton bushes?since I technically don’t need “wool” but "fiber"
Right now I have wool as a crafting recipe for the carpenter, as a temporary hot fix.

Either woks. Hahaha
Just got the game to start with my latest table attempt. Lets see how she goes. . .

Edit

After carpenter finishes the table

Invalid path /nihonjin/entities/furniture/bamboo_table/bamboo_table_proxy.json

:frowning:

Edit 2.0

I love this new debugger :heart:

4 Likes

But we don’t need to change the loading process really. If we can make some code execute right after all of the mods are loaded then it might be possible. The only question is what is the difference between load_json and load_manifest. My ideas only work if the manifests are stored in the lua half. [quote=“RepeatPan, post:23, topic:5229”]
Give me a break, I just forgot three quotes.
[/quote]
I missed one of them so I thought 4 were missing meaning that { "tools" : [ "category : Tools" ], "weapons" : [ "category : Weapons" ] } looked like it might have been what you meant.

1 Like

Hmpf. I see where you are going with this. Because the definition of an alias does not load the JSON immediately, it could be intercepted by lua by calling load_json, modifying the table and therefore the cache…

However, again, while you might be able to fool calls to radiant.resources.load_json this way, you won’t be able to fool the engine. The cache is entirely lua sided and lua is invoked as soon as all manifests are parsed. So not only is it too late, it also won’t work for C components.

So just make sure your lua code is called first, you manage to do that with rp don’t you? Because that’s possibly the hardest bit. The problem is that there is the radiant.resources.load_manifest that uses a different engine call and doesn’t seem to cache. You’d have to figure out what it’s actually doing differently. Even in the absolute worst case scenario of being completely incapable of modifying in loaded manifests we can still fake if we’re willing to disregard anything resembling common sense, decency, compatibility or sanity within the code. Just rewrite the modded files and restart the game with os.execute or something.

No. RP is, by design, invoked as soon as all mods are loaded (minus all RP mods of course), which includes SH. Although SH has likely done nothing at this point, it has still run to some extent.

However, your plan seems to work - although in a very, very limited way.

radiant.resources.load_json('/stonehearth/entities/professions/carpenter/recipes').craftable_recipes[1].category = "Stuff & Things"

As long as this is executed before a carpenter is built (which is the original time this is executed), everything is fine - the changes will carry over without a problem.

There’s a few issues.

  • You need to do this before the game accesses it. In our case, likely, we want to do the magic after all mods have mixinto’d and before it is accessed. We can assume that mixintos happen before any lua is executed and/or transparent when attempting to load a file.
  • The cache is stupid. foo/bar and foo/bar/bar.json are two different entries. It’s necessary to patch both. This will, in some cases, yield an exception that needs to be dealt with. Not a big issue, just a bit untidy.
  • This is still all after manifests were loaded. Even if it wasn’t, the manifests are dealt with by the engine, not lua.
  • When dealing with all these jsons, it is necessary to use absolute paths. Aliases and relative paths have all gone at this point. I suppose since RP is scanning all manifests, I might as well offer some sort of reverse-lookup that transforms paths into aliases (if possible).

Never. Not just is this a good example of “What not to do with os.execute”, it’s also neither very stable (popen is going away sooner or later, rather sooner I’d expect) nor guaranteed to work.

So, yes. Using this method, we could actually perform some magic on certain, selected things. The recipe lists would be one example, where we could merge entries.

local recipes = radiant.resources.load_json('/stonehearth/entities/professions/carpenter/recipes')

local categories = {}
for i, value in pairs(recipes.craftable_recipes) do
	local cat = categories[value.category]
	
	-- Category already exists
	if cat then
		for _, recipe in pairs(value.recipes) do
			table.insert(cat.recipes, recipe)
		end
	else
		categories[value.category] = value
	end
end

recipes.craftable_recipes = {}
for k, v in pairs(categories) do
	table.insert(recipes.craftable_recipes, v)
end

This example script (which doesn’t require RP - a server_init_script entry is enough) would fix multiple categories by merging them by name. If your mixin has as category “Construction & Furnishings”, it will appear here - in the original category that was defined by SH. Or the other way around; either way, it’s just one category - not two with the same name.

This is just one of the things possible - you could define the order, have the categories themselves sorted and more. So, yes, it’s possible - but the cases in which this magic is possible are very, very limited. Basically to anywhere that uses load_json of some sort and not the engine itself.

load_manifest simply returns the manifest of said mod (load_manifest("rp_test")), not much more that I’m aware of. I remember vaguely that there was a difference, I think something about file() being parsed or something like that, I can’t recall. There was a reason I’ve switched in RP from load_json to load_manifest, but it might just have been convenience.

I just wanted to know if we could use the overrides and mixintos functions for a part of the UI for example use overrides on the start_menu.html and start_menu.js to add a new workshop for a profession.

start_menu.html is a decoy. Currently there is no official way to add stuff to the start menu, although RP provides a JS function (rp.addToStartMenu) that allows you to add (and to some extent modify) stuff to the menu. Checkout rp_spawn_stuff and rp_click_and_gone for examples. I can give you the JSON for a workshop if you want me to - it’s actually not difficult to add stuff to existing menus.


On-topic: As I’ve found out with @Avairian, a failing overwrite will cause all other overwrites to fail silently. The log message stating that it is “ignored” isn’t quite true, it’s actually aborting the overriding process it seems (i.e. ignores entries below the offender).

One more reason to have Jofferson. Have a sneak peek.

Woohooo I’m helpful! :smile:

1 Like

well, i was all set to unleash my guide, aptly titled Steve’s Super Simple Mixins and Overrides Guide, or SSSMOG… however, after confirming that my simple concept was working, i found a scenario that i havent been able to explain yet…

so, let me just post what works, and then get into the confusing part:


create your mod folder


1) locate your mods folder (in this case, in the Steam directory)

  • C:\Program Files (x86)\Steam\SteamApps\common\Stonehearth\mods

2) create a new folder for your mod (in my example, i’m adding new journal entries, so i’ve added the “journals” folder)

  • C:\Program Files (x86)\Steam\SteamApps\common\Stonehearth\mods\journals

add your manifest.json file and mixintos folder


1) open notepad and paste in the following:

{
   "info" : {
      "name" : "Journals"
   },
   "mixintos" : {
      "stonehearth/data/personality/embarking.json" : [
         "file(/mixintos/embarking.json)"
      ]
   }
}
  • note: the two paths in the mixintos section… the first refers to the file you will be mixing “into”, while the second refers to the file you will be mixing “from”

2) navigate to the journals folder you just created, and save the file as manifest.json

3) while you are in the journals folder, create a new folder and call it mixintos


add your custom journal entries

1) open notepad and paste in the following:

{
   "activities" : [
      {
         "id" : "embarking",
         "trigger_policy" : [
            {
               "trigger_id" : "person_embarks",
               "probability" : 100
            }
         ],
         "text" : "On Arriving:",
         "type" : "random",
         "logs_by_personality" : {
            "belaguered_leader" : {
               "logs" : [
               "We've made a little contact with the Dwarves. Here's hoping he's not a big jerk."
               ]
            },
            "hopeless_optimist" : {
               "logs" : [
               "I'm sure they're working on getting us beds, right? It probably just takes time. I mean they can't be doing this to us on purpose...right?" 
               ]
            },
            "lovable_rogue" : {
               "logs" : [
               "One for the stockpile, and one for the black market! Who knew there was such a demand for illicit wooden chairs?"
               ]
            },
            "psychopathic_misanthrope" : {
               "logs" : [
               "A saw! They're giving me a saw! For making chairs, tables, doors and... I wonder if it can cut through bone..."
               ]
            },
            "insufferable_academic" : {
               "logs" : [
               "Hmph, I would be the only one here that knows how to use a saw."
               ]
            },
            "diligent_sweetheart" : {
               "logs" : [
               "I kind of feel bad about shearing all the poor sheep here, but their fluffy coats WERE starting to become a threat to my own cuteness level..."
               ]
            }
         }
      }
   ]
}

2) navigate to the mixintos folder inside the journals folder, and save the file as embarking.json

  • note: this is creating the file that is referenced from the manifest.json - file(/mixintos/embarking.json)

3) launch the game and enjoy your new journal entries!


ok, this is where im breaking it off, as i had quite a bit more mapped out, but my tests started to go a bit haywire…

i wanted to confirm that my mixintos werent overwriting the original embarking.json file entirely, so i stripped out all but one from the original, and confirmed that my new journal entries were showing up… success!

i then restored the original journal entries, and reloaded the game several times to make sure there was a blend of old and new journal entries… success!

however, i then started messing with the personality types and once again stripped out all the original journal entries (but one)… upon reload, i was still getting original journal entries (and not even the single entry that i left)…

i thought perhaps this was some off side effect of the new call to personality types in my manifest.json file, so i stripped that out… i was then left with my new custom embarking.json (with all new journal entries) and the original embarking.json (with only one entry)…

reload the game and im still getting original embarking journal entries… ?

im too tired now, but i’ll keep digging… suffice it to say that i now at least understand how mixintos are supposed to work (thanks @RepeatPan), and can confirm that original and new content can work together… i just need to figure out where these phantom entries are coming from! :smile:

1 Like

Disappointing guide, @SteveAdamo… Allow me to explain.

[Fatal] Duplicate keys are a no-go.

First, your manifest is kind of broken. Depending on how strict you want to be with JSON, it’s either not allowed to have two identical keys ("mixintos"), all but one are overwritten or it’s just accepting it. In our case, your second mixinto will be ignored - i.e. Stonehearth is reducing your manifest to one mixintos section.

[Info] The array can be omitted

Although it might make sense to show people that they can mixin multiple json files into one at the same time, this is kinda obsolete for this purpose. I guess it’s personal taste, but I would rather use a string.

[Spam] file() can deal with relative positions

This is very much taste now, but since the manifest is always at the root of a mod, it therefore can access the files with the relative file() operator, i.e. without /. This is probably just to improve readability of the manifest as well as trying to not confuse people (who might think that it’s relative… when it’s not).

My (corrected) version

{
	 "info" : {
			"name" : "Journals"
	 },
	 
	 "mixintos" : {
			"stonehearth/data/personality/personality_types.json" : "file(mixintos/personality_types.json)",
			"stonehearth/data/personality/embarking.json" : "file(mixintos/embarking.json)"
	 }
}

Untested and I haven’t checked your other JSONs either, but I’d recommend throwing them over at JSONLint - you would have seen that your manifest is behaving “odd”.

Okay thanks! I added a workshop in the previous version so I have the code to add a profession.
I just have to add my start_menu.html and start_menu.js in the stonhearth.smod so?
I hope they will allow us to overwrite this kind of files.