Development Questions - GDT.fire

I am attempting to add a R&D research item to the game without using UltimateLib. Better yet, I would like to hijack one of the in-game researches and then add to it, but even though I have successfully hijacked many other methods, I just cannot seem to hijack a R&D researchable.

Any pointers?

I’d like to recall I did that once so it should be plausible. I’m gonna try and see if I can remember how I did it and I’ll get back to you :slight_smile:

2 Likes

The SpartanLib add an option to a R&D research

Instead of making thread after thread about different coding questions I have, I’ll just add to this one.

What is the best way to make a custom Javascript/jQuery template, similar to the ones for GDT.addEvent and GDT.addResearchItem, in GDT? I tried using various libraries like Handlebars, but I’m having some trouble implementing it without errors.

Not quite sure what you mean, GDT.addEvent and GDT.addResearchItem are just plain javascript functions.

Here’s an example of creating a simular function:

var Example= {};
(function () {
Example.myCustomFunction = function(){
    //Do something
}

I apologize for any confusion I may have engendered. When adding a research item in GDT, there is a template to follow:
> GDT.addResearchItem(

    {
        id: "Swift Loading",
        name: "Swift loading".localize(),
        v: 4,
        canResearch: function (company) {
            return LevelCalculator.getMissionLevel('Level Design') > 5 //The 'Level Design' level has to 6 or higher
        },
        category: "Level Design",
        categoryDisplayName: "Level Design".localize()
    });

I wish to know how to create my own template with custom “members,” which are the id, name, category, etc. UltimateLib gave the ability to add items to the R&D Lab by creating it’s own template for people to use. I would like to create my own as well.

Basically, I am just asking how to create my own template for my own function in GDT:

myMethod(
{
id: “some ID”,
foo: “pineapple”
})

Well the “template” you are referring to is just you creating an object with all the properties you define in it.
After that it’s the function you pass this object to which uses this data in any way it wishes, I’m not that good at explaining things hope you kinda understand.

Here’s an example:

var Example = {};
(function () {
    var itemList = [];

  Example.AddCustomItem = function(item){
        if(item.id == "MultiPlatformOptimized"){
          //do something
      }
      //do something.. example:
      alert("added item: " + item.name);
      itemList.push(item);
  }


  var runCode = function(){
      Example.AddCustomItem({
            id : "MultiPlatformOptimized",
            name : "Multi-Platform optimized",
            category: "Level Design"
        });
  }
  runCode();
}

Is there a way to make it so the “template” modifies an HTML element based on what is entered in the Example.AddCustomItem function?

Yeah you can do something like this:

https://jsfiddle.net/rf9219wj/5/

var Example = {};
(function () {
    var itemList = [];

  Example.AddCustomItem = function(item){
      //do something.. example:
      var div = $("body");
            div.append('<div id="example div">Id: ' + item.id + '</br>' 
                                                                   + 'Name: ' + item.name + '</br>'
                                     + 'Category: ' + item.category + '</br>'
                                                                         + '</div>');
      itemList.push(item);
  }


  var runCode = function(){
      Example.AddCustomItem({
            id : "MultiPlatformOptimized",
            name : "Multi-Platform optimized",
            category: "Level Design"
        });
  }
  runCode();
})();
1 Like

Thank you so much! I feel so stupid for not being able to do what seems so easy now that you’ve explained it. :stuck_out_tongue:

You’re welcome,
Glad I could help :smiley:

The key thing to adding / modifying the UI is not adding the elements to the DOM it’s making them visible when you want them to be visible. For example the code now will add a new div to the body, but that div will always be there even on the startup screen ect…

You’ll need to add components that are invisible to start with something like css: display:none, after that you’ll need to hook a function that will make your div visible. For example cheatmod adds an invisible div containing the cheat menu to the body on start up. Then I hook the GDT context menu and add my cheatbutton, when that button is pressed the cheatmenu div is put to visible.

Yeah, I’ve been using a mixture of .hide() and .show() and .toggle() after I append it once.

What are you working on if you don’t mind me asking?

It’s far from done. Addtionally, I started with practically no JS knowledge (I have been teaching myself since the beginning), so don’t be startled by incredibly bad JS coding.


That link in the thread is also old. I have changed a lot of the code since I moved over to Atom.

Looks cool, I did a bit of AI for competitorMod fun stuf.

If its something you can Decrypt the code for the UltimateLib, this can bring the new life.

So I have come across another thing that is beyond my substandard jQ and JS knowledge. I do not wish to give away what I am working, so I will try to provide a sufficient example.

My template looks like this:

var exampleTemplate = function() {
  example.AddNew({
    foo1: 'Hello!',
    fooThing: 'John Smith',
    fooDate: '1/2/3'
  });
}
exampleTemplate();

Basically, I am attempting to add something like the below piece of code to my template:

trigger: function() {
  GameManager.company.currentLevel == 1;
}

How would one push or “trigger” exampleTemplate(); based on what is entered into the trigger:

I have tried elsewhere to do something like:

if (foo.trigger && foo.trigger()) {
   // Here I push foo                
}

Any ideas?

if (foo.trigger && foo.trigger()) {
   // Here I push foo                
}

looks fine (if it’s in the addNew method.

try replacing the trigger method:

trigger: function() {
  return GameManager.company.currentLevel == 1;
}

Does anyone know how to implement save-specific data? Specifically, how can I save whether or not a div is shown through save-specific data. I’ve messed around with DataStore, and it just doesn’t seem to work for me.

In a mod I am creating, various divs are appended (I show/hide all the main divs). I need to make it so that a div that is appended in one save wouldn’t be available in separate save or new game.

GDT.getDataStore(“modname”).data is used to save save-specific data. However, from what I understand, you’re trying to save data which you want to recall in other saves, in which case you’re better off using GDT.getDataStore(“modname”).settings.