knowing me I would name units things like, minion_type1, minion_type2, minion_type3, flying_minion, etc ... lol ^-^ and buildings evil_lab, minion_constructor, adv_minion_constructor. lol
I had some spare time tonight and decided to make the list of unit names for the Stargate unit names theme. I haven't decided if I want to use the system we were discussing above or just make a separate json shadowing mod to implement this yet though.
There's a few issues in the current patch: The close button has been moved in the game files so we currently only see a small box (it's moved to 'ui/main/shared/img/close_btn.png') The original names are shown briefly before the altered names, every time you hover over the icon in the build bar Selecting a unit shows the original name The first bullet point is an easy fix, don't know about the other two but I'm sure you have more of an idea.
Thanks for reporting that! The other two points are side effects of the hackish way this mod works. Since I can't do on-the-fly shadowing or intercept unit json reads I basicly have to watch the UI with a timer and replace the name when it pops up. I'm hoping to be able to improve that once the API gets more options but I can't really do anything else for now.
Why not just hook into the function that sets the values for the popup? Eg, this the function that sets the build bar details (in live_game.js): Code: handlers.unit_data = function (payload) { var id; var element; var sicon; model.itemDetails = {}; for (id in payload.data) { element = payload.data[id]; sicon = (element.sicon_override) ? element.sicon_override : id.substring(id.search(start), id.search(end)); model.itemDetails[id] = new UnitDetailModel(element.name, element.description, element.cost, sicon); } // nuke hack // the projectiles are not magically added to the unit_list, so the display details aren't sent to the ui model.itemDetails['/pa/units/land/nuke_launcher/nuke_launcher_ammo.json'] = new UnitDetailModel('nuke', 'LR-96 -Pacifier- Missile', 32400); model.itemDetails['/pa/units/land/anti_nuke_launcher/anti_nuke_launcher_ammo.json'] = new UnitDetailModel('anti nuke', 'SR-24 -Shield- Missile Defense', 17280); }; Specifically, the important part is: Code: model.itemDetails[id] = new UnitDetailModel(element.name, element.description, element.cost, sicon); That's the name, description and cost shown on the build hover bar; change these here and they'll only ever display your custom names.
Sweet, thanks! I wrote this mod when I still couldn't make heads or tails of live_game.js so I ended up using a looped replace. Now that I'm better I should be able to get that fixed. Update coming sometime next weekend hopefully.
and done. I ended up having to shadow live_game.js but it works great now! Thanks a ton for pointing that out to me. I also shadowed live_game_world_popup.js so it will also display the custom names in the hover over unit popup in the bottom-right corner now.
Check out this: https://forums.uberent.com/threads/rel-stargate-unit-names-63475.58651/ It's time to get started on those other themes...
It's somewhat dangerous to shadow game files like that, since that means your mod is likely to break PA itself every time a patch is released. I think it's not necessary either. Can't you do something like this? Code: var oldhandlerunit_data = handlers.unit_data; handlers.unit_data = function (payload) { for (id in payload.data) { //<custom unit names code> var name = payload.data[id].name; for (index = 0; index < model.LUnitNames.RulesArray.length; ++index) { var RealName = model.LUnitNames.RulesArray[index].split(" > ")[0]; var NewName = model.LUnitNames.RulesArray[index].split(" > ")[1]; payload.data[id].name = name.replace(new RegExp(RealName, "g"), NewName); } //</custom unit names code> } oldhandlerunit_data(payload); } (UNTESTED) So basically you alter the payload to have the custom names already and let the native PA code handle the rest. This will likely survive patches. And you need to do something similar for handlers.hover in live_game_world_popup.js of course.
I tried that originally but it causes a very strange error and no matter what I tried I couldn't get it to work. I don't remember the exact error off the top of my head but I could test it again and post it if you want.
If you're game could I post a version of it that uses function replacement and you could take a look at it? I'd prefer not to have to use shadowing but I'm honestly stumped on this.
Here's the version to test. If it works you should see a lot of "Thanks DeathByDenim!"s without any error messages following them in the logs of world hover.html and the live game.html. Thanks for your help!
Ok, I think I got it. The code in Renamer.js you posted already worked for live_game.js itself, but you were still shadowing live_game.js itself as well. I've split Renamer.js into two files. One for live_game.js and one for live_game_world_popup.js. I've also removed the shadowing of course. It works for me. I was able to make the Dox appear as Banana. It seems Doxes don't generate alerts though, so I haven't worked on that part. Maybe it's automatic? Probably not.
Ok, so I had some time today to play around with this and your code helps a lot! Thanks. It has an issue with replacing the names in the build bar popups though since the payload is actually read-only. I rewrote the function though and it works fine now. I also had to change the live_game_world_popup code so it included the replacement for the name of the unit it is building or attacking. Thanks again and update incoming!