Acharvak / Cookie-Clicker-Agronomicon

A mod for Cookie Clicker to help with the Gardening minigame
9 stars 3 forks source link

Error on add-on loading since V. 2.031 #1

Open Chorizorro opened 3 years ago

Chorizorro commented 3 years ago

The add-on throws a Javascript error on load. The add-on seems to still be fully functional, though.


Javascript error in console:

Uncaught TypeError: Cannot read property 'push' of undefined
    at initialize (Agronomicon.js:1455)
    at Agronomicon.js:1551
    at Agronomicon.js:1552

This is most likely caused by Game.customDraw not existing:

image

hyoretsu commented 3 years ago

Not most likely, there's no Game.customDraw or Game.customSave anymore so that's the source of the error.

TakGalaman commented 3 years ago

Anyone able to fix this?

hyoretsu commented 3 years ago

Anyone able to fix this?

Not that any of us have a fork or write access to this repository, but you just gotta move that stuff over to Game.registerHook('draw', () => {})

umnikos commented 2 years ago

Not that any of us have a fork or write access to this repository, but you just gotta move that stuff over to Game.registerHook('draw', () => {})

So I guess the following workaround will do?

Game.customDraw = {};
Game.customDraw.push = (function(f) {
    Game.registerHook('draw', f);
});
Game.customSave = {};
Game.customSave.push = (function(f) {
    Game.registerHook('save', f);
});

Edit: I assumed there's a "save" hook the same way there's a "draw" hook but apparently there isn't one, what is Game.customSave supposed to do?

hyoretsu commented 2 years ago

So I guess the following workaround will do?

Game.customDraw = {};
Game.customDraw.push = (function(f) {
    Game.registerHook('draw', f);
});
Game.customSave = {};
Game.customSave.push = (function(f) {
    Game.registerHook('save', f);
});

Edit: I assumed there's a "save" hook the same way there's a "draw" hook but apparently there isn't one, what is Game.customSave supposed to do?

You just gotta send the function to draw hook Game.registerHook('draw', drawCallback)

Game.customSave was probably the old way of saving mod data, before the new API was released last year. It's now included as a property in the object sent to Game.registerMod()

umnikos commented 2 years ago

Game.customSave was probably the old way of saving mod data, before the new API was released last year. It's now included as a property in the object sent to Game.registerMod()

I have no idea how Game.registerMod() is supposed to be used so I hacked a hook into the game:

// workaround for mod being unmaintained
Game.customDraw = {};
Game.customDraw.push = (function(f) {
    Game.registerHook('draw', f);
});
// yeaaah... I know...
Game.customSave = {};
Game.customSave.push = (function(f) {
    let old = Game.WriteSave;
    Game.WriteSave = (function(...t) {
        let r = old(...t);
        f();
        return r;
    }); 
});
hyoretsu commented 2 years ago

Game.customSave was probably the old way of saving mod data, before the new API was released last year. It's now included as a property in the object sent to Game.registerMod()

I have no idea how Game.registerMod() is supposed to be used so I hacked a hook into the game:

// workaround for mod being unmaintained
Game.customDraw = {};
Game.customDraw.push = (function(f) {
    Game.registerHook('draw', f);
});
// yeaaah... I know...
Game.customSave = {};
Game.customSave.push = (function(f) {
    let old = Game.WriteSave;
    Game.WriteSave = (function(t) {
        old(t);
        f();
    }); 
});

Yeah, problem: I suck at javascript. Solution:

That's harder than doing it the normal way. Literally just pass the function that was going to the old Game.customDraw to Game.registerHook

And you also shouldn't rewrite functions like that. This mod's save is already a workaround, so it saves independently from Cookie Clicker. (either left as is or adapted to new API, which isn't that hard)

Port of Darky's Achievement Package to new API.

To top it off, customDraw and customSave literally don't exist anymore, they're useless. The new mod API is the rule now.

umnikos commented 2 years ago

That's harder than doing it the normal way. Literally just pass the function that was going to the old Game.customDraw to Game.registerHook

We cannot do that without changing this repo's code and we cannot change the code without the repo's owner doing it for us. What I wrote is a (crappy) workaround to be inserted right before Game.LoadMod('https://acharvak.github.io/Cookie-Clicker-Agronomicon/Agronomicon.js').

The new mod API is the rule now.

Admittedly, I could figure out what Game.registerMod does exactly and see if I can pass it the already existing hooks in a more elegant way than what I just did, but the only API reference I could find is this and it can barely be called an API reference. Suggestions welcome!

hyoretsu commented 2 years ago

We cannot do that without changing this repo's code and we cannot change the code without the repo's owner doing it for us. What I wrote is a (crappy) workaround to be inserted right before Game.LoadMod('https://acharvak.github.io/Cookie-Clicker-Agronomicon/Agronomicon.js').

Anyone can just fork the repo and change the code. I don't think that workaround would do anything, especially since the game doesn't do anything to customSave or customDraw. Like, what's even calling the function(f)? You'd need the original function, at which point using Game.registerHook would still be easier.

Admittedly, I could figure out what Game.registerMod does exactly and see if I can pass it the already existing hooks in a more elegant way than what I just did, but the only API reference I could find is this and it can barely be called an API reference. Suggestions welcome!

Suggestion already sent, I literally ported a mod that's pretty similar to Agronomicon to the new mod API. It has the new way of doing it and you can access the original repo with the old way.

The best modding API docs we have are either the official one found in the game's source code (just search for "registermod") or Dashnet's Discord modding channel.