[.js] How to target a $.widget()?

I’m trying to set a new value to the settlementRadius field in the map.js. How can I do that?

$.widget( "stonehearth.stonehearthMap", {
   options: {
      // callbacks
      hover: null,
      cellSize: 12,
      settlementRadius: 19,
      click: function(cellX, cellY) {
         console.log('Selected cell: ' + cellX + ', ' + cellY);
      }
   },
   ...

Er…
Waiting for the next build, I guess. We moved it to constants.json :disappointed_relieved:

Here:

"game_creation": {
         "num_starting_citizens": 5,
         "settlement_radius": 19
      },
1 Like

That helps a lot with changing it to a new but constant value, like the current giant_map mod does. (Having it in the constants.json helps to avoid overriding the js)

What I’m trying now is adding options to the map selection screen to chose the desired map size (small, normal, large). The ui is done, but I need to change that value according to the option selected.

2 Likes

I’m not sure how the $.widget() works, but here’s a link I found: Widget Factory | jQuery UI
If you check selectSettlement.js, it creates a widget of that type with id #map, passing some values:

self.$('#map').stonehearthMap({
            mapGrid: e.map,
            mapInfo: e.map_info,

            click: function(cellX, cellY) {
               self._chooseLocation(cellX, cellY);
            },

            hover: function(cellX, cellY) {
               var map = $('#map').stonehearthMap('getMap');
               var cell = map[cellY] && map[cellY][cellX];
               if (cell) {
                  self._updateScroll(cell);
               }
            }
         });

It’s possible that you can retrieve #map instead and try to get the options.settlementRadius from there somehow. (Not sure, since I’m not familiar with this).

I discovered that in the end I was kinda doing it right. The problem was the values I was passing to it. For some reason, when trying to use jquery methods the values were not updating, but using pure javascript worked fine.

1 Like