[REL] Custom Unit Names [64498]

Discussion in 'Mod Discussions' started by LavaSnake, January 30, 2014.

  1. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    version 1.1: Fixes mod conflict with cola_colin's AlertsManager.
  2. Antiglow

    Antiglow Well-Known Member

    Messages:
    342
    Likes Received:
    319
    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
    LavaSnake likes this.
  3. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
  4. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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.
    cptconundrum likes this.
  5. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    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.
  6. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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.
  7. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    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.
    LavaSnake likes this.
  8. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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.
    emraldis and Raevn like this.
  9. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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.
  10. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Check out this: https://forums.uberent.com/threads/rel-stargate-unit-names-63475.58651/
    It's time to get started on those other themes...
  11. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,327
    Likes Received:
    2,125
    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.
  12. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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.
  13. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,327
    Likes Received:
    2,125
    Oh, that's too bad. Oh well, it was just a thought. :)
  14. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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.
  15. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,327
    Likes Received:
    2,125
    Sure, no problem. I can take a look. And probably many others that read this thread as well. :)
  16. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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!

    Attached Files:

    Last edited: April 11, 2014
  17. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,327
    Likes Received:
    2,125
    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. :)

    Attached Files:

  18. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Thanks! I'll look into that and hopefully put out a shadow-less update soon.
  19. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    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!
    Last edited: April 19, 2014
  20. tristanlorius

    tristanlorius New Member

    Messages:
    28
    Likes Received:
    10
    arm suck huge B*115 Core forever, i think this needs to be a mod

Share This Page