DT: RCUI and Hotloading Mods

Hey Everyone, it’s been another busy week for Team Stonehearth! Our first cut at Alpha 13 is now on the Steam Unstable branch, and it includes the potter, clay buildings, bugfixes, and the hearthling therapist. Your bug reports, especially regarding the hearthling therapist, have already helped Albert find one long-running AI issue, so please keep those coming! In the meantime, the rest of us continue to jam on Rayya’s Children, and the game features that will support them.

This week, I’d like to show you TWO things: the re-skinned Rayya’s Children UI, and the hot-loading mod feature that we’ve added to make it possible.

Rayya’s Children UI and Hot Loading Mods

One of the first things you’ll notice when you decide to play as Rayya’s Children is the new sand-and-clay UI that Tom built for them. Though the UI does not change their gameplay, we think it adds quite a bit to to the flavor and consistency of their kingdom.

The RCUI is built as a separate mod that overrides the assets in the existing mod. However, overrides wipe out the base materials, so if that were the extent of the feature, Rayya’s Children’s UI, if included, would always wipe out the default Ascendancy wood UI, even when you were playing the Ascendancy! How do we make sure that a mod is loaded only sometimes, and unloaded again when it’s no longer useful? Enter Yang’s feature: the ability to hot-load and unload mods at runtime, during the game.

Hot Loading Mods!

All mods in the mods folder are automatically loaded when the game starts. To exclude a mod, you can now add a deferred_load" : true value to your mod’s manifest.json:

   "info" : {
      "name" : "rayyas_children_ui",
      "deferred_load": true,
      "version" : 1

Note: please refresh the page if you can’t see the code snippets. I’ve changed the site’s CSS, so you’ll want the new version, not the cached version!

Later, in some lua code, (in this case, the client_init_script file that runs in the Rayya’s Children mod) you can call _radiant.res.load_mod("mod_name_here") to turn on a specific mod.

In this case, the Rayya’s Children mod (different from the Rayya’s Children UI mod, which is deferred load), specifies a client-side script to run as soon as the game loads:

   "info" : {
      "name" : "rayyas_children",
      "version" : 1
   "default_locale": "en",
   "client_init_script" : "file(rayyas_children_client)"

The rayyas_children_client.lua file listens for any changes to the player’s kingdom. If the kingdom is rayyas_children, it calls _radiant.res.load_mod("rayyas_children_ui") which loads the mod:

rayyas_children = {
   constants = require 'constants'
local player_service_trace = nil

local function check_override_ui(players, player_id)
   -- Load ui mod
   if not player_id then
      player_id = 'player_1' 
   local client_player = players[player_id]
   if client_player then
      if client_player.kingdom == "rayyas_children:kingdoms:rayyas_children" then
         -- hot load rayyas children ui mod

local function trace_player_service()
   _radiant.call('stonehearth:get_service', 'player')
         local player_service = r.result
         player_service_trace = player_service:trace('rayyas children ui change')

radiant.events.listen(rayyas_children, 'radiant:init', function()

return rayyas_children

To unload a mod, you can call _radiant.res.unload_mod("rayyas_children_ui").

If your mod is modifying game elements that have been cached by the game, you’ll need to force those elements to refresh. For example, to force the UI to refresh, if you change the UI, you must, from somwhere in javascript, call radiant.call('radiant:force_reload_browser');

Yang is still investigating how to force refresh on cached json and code files. However, qb models are not cached, and should reload fine right out of the box.

You can look for the new Rayya’s Children UI and the hot-loading mods feature in the next unstable release of Alpha 13!

Other News: Welcome Linda Cai!

This week, are also pleased to welcome Linda Cai to Team Radiant! Linda has a degree in Computer Science from UC Berkeley, and has also taken a number of art and animation classes. Though this is her first job out of school, she’s an avid Stonehearth fan, and impressed our socks off during her interview with a mountain of Stonehearth suggestions and a beautiful multithreaded C++ program that was easily superior to similar items written for us by applicants with years of industry experience. If you see Linda around the discourse, please say hi and make her feel welcome to our community.

And that’s it for this week! See you all during our regular Tuesday/Wednesday/Thursday livestreams and back here for next week’s Desktop Tuesday!