Giter Site home page Giter Site logo

Comments (11)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
I thought I was having this problem, but the problem when the object being 
saved controls are part of a folder eg:

    obj = { test: 0};
    gui.add(obj, "test");
    gui.remember(obj); // works ok on save

    obj = { test: 0};
    var folder = gui.addFolder("folder");
    folder.add(obj, "test");
    gui.remember(obj); // fails on save

Original comment by [email protected] on 4 Jul 2012 at 8:12

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
[deleted comment]

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
I have this problem in Chrome Version 25.0.1364.160 Built on Ubuntu 12.04, 
running on LinuxMint 13 (25.0.1364.160-0ubuntu0.12.04.1)


This can be seen by clicking the Save button in Dat.gui, on the page
here: http://codepen.io/lingo/full/KuDse

Original comment by [email protected] on 5 May 2013 at 6:54

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
I have this issue as well, with or without folders.
Uncaught TypeError: Cannot read property 'forEach' of undefined
dat.gui.js:110

Windows 7 64bit
Chrome and firefox.

Strangely, the workshop demo works fine.

Original comment by [email protected] on 9 Aug 2013 at 11:07

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
Sorry guys,

Just to clarify what works and what doesn't since I just discovered a quirky 
behaviour.
On the workshop demo, everything except local storage works properly.
On my own project, local storage doesn't work either, and to make matters 
worse, it throws the TypeError when I try to access the preset settings (gear 
icon), Save, or New. But if I hit Revert, the preset settings, Save and New now 
work! Local storage still doesn't work, but atleast I can grab the JSON from 
the preset settings popup and paste it into a document.

I verified this behaviour on http://codepen.io/lingo/full/KuDse
I thought a quickfix would be to run gui.revert() or gui.revert(gui) after you 
initialize your gui but it does nothing.

Cheers,

Tom

Original comment by [email protected] on 9 Aug 2013 at 11:25

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
One more update!
Apparently gui.revert() DOES work as long as you use load some JSON upon 
instantiation.


    var gui = new dat.GUI({
        load: presetJSON
    });

    gui.remember(sceneProperties);
    gui.revert();

So there you have it. As long as you manually hit the Revert button the first 
time you use the GUI to generate your initial JSON, and then using the 
load:JSON and gui.revert() trick, it works.

Original comment by [email protected] on 9 Aug 2013 at 11:52

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
SAME ISSUE!
can anyone provide a working example of presets?

Original comment by [email protected] on 6 Dec 2013 at 5:31

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
I got it to stop bitching like this....
gui = new dat.GUI({
        load: {
            "preset": "Default",
            "closed": false,
            "remembered": {
                "Default": {}
            },
            "folders": {}
        }
    });
    gui.revert(); // stop it bitching
    gui.save(); // enable revert on Defaults
... no need to create presets first, just use the above.  If it saves to 
localStorage then it will ignore the load: value, so seems to be safe enough.

Thanks  [email protected]

Original comment by [email protected] on 5 Jan 2014 at 1:14

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
Guys, I just spent an hour hunting through the code and I figured it out. I 
have no idea who wrote this stuff, but it's some absurd spaghetti at parts.


***

TypeError / forEach Problem: If your controllers array is not initialized, 
you'll get the forEach error. Make sure you call remember() right after you 
instantiate the GUI object.

    var obj = { foo: 'bar' };
    var gui = new dat.GUI();
    gui.remember(obj);

I wanted to fix this bug anyway, so around Line 109 I add the following tests 
for obj existence:

    if (!obj) return;

    if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) { 

***

LocalStorage Problem: saveToLocalStorage() is a private function for GUI and 
curiously wrapped in a block where only the getters and setters are defined.

The issue is that block is separate from the main method definitions! Thus, 
besides the getters and setters, the rest of GUI's common methods cannot call 
saveToLocalStorage(). To make matters more weird, it is never called manually. 
The function is only bound to a DOM event on window for when the tab closes... 
who the hell wrote this?

Fuck, well I tracked this down too. Around Line 1676 add:

    var saveToLocalStorage;

Then expose the private save function around Line 1930:

    saveToLocalStorage = function () {
      if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true') {
        localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
      }
    }

    this.saveToLocalStorageIfPossible = saveToLocalStorage;


FINALLY add calls to saveToLocalStorageIfPossible() in GUI's save() and 
saveAs() methods (Line 2226):

    save: function() {

          if (!this.load.remembered) {
            this.load.remembered = {};
          }

          this.load.remembered[this.preset] = getCurrentPreset(this);
          markPresetModified(this, false);          

          this.saveToLocalStorageIfPossible();
        },

After it all, you'll get LocalStorage + presets working just fine.

Attached is the patched file. Good god, I can't believe how much time I just 
spent on that.






Original comment by [email protected] on 23 Jan 2014 at 7:04

Attachments:

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
Nice work! Frankly, I still use this library but only for its GUI. The 
saving/loading I now do manually with JSON and  a mongoDB; not as simple, but 
has the advantage of collaborative presets.

Original comment by [email protected] on 23 Jan 2014 at 2:58

from dat-gui.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
Fixed this and merged it to a maintained github-hosted fork of dat.gui 

https://github.com/dataarts/dat.gui/commit/f36a8273a1162559a24b9d574aeb7c5112342
9ea

Original comment by [email protected] on 23 Jan 2014 at 11:24

from dat-gui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.