Config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. var Config = function ( name ) {
  5. var storage = {
  6. 'autosave': true,
  7. 'theme': 'css/light.css',
  8. 'project/title': '',
  9. 'project/editable': false,
  10. 'project/renderer': 'WebGLRenderer',
  11. 'project/renderer/antialias': true,
  12. 'project/renderer/gammaInput': false,
  13. 'project/renderer/gammaOutput': false,
  14. 'project/renderer/shadows': true,
  15. 'project/vr': false,
  16. 'settings/history': false,
  17. 'controls/translate': 'w',
  18. 'controls/rotate': 'e',
  19. 'controls/scale': 'r'
  20. };
  21. if ( window.localStorage[ name ] === undefined ) {
  22. window.localStorage[ name ] = JSON.stringify( storage );
  23. } else {
  24. var data = JSON.parse( window.localStorage[ name ] );
  25. for ( var key in data ) {
  26. storage[ key ] = data[ key ];
  27. }
  28. }
  29. return {
  30. getKey: function ( key ) {
  31. return storage[ key ];
  32. },
  33. setKey: function () { // key, value, key, value ...
  34. for ( var i = 0, l = arguments.length; i < l; i += 2 ) {
  35. storage[ arguments[ i ] ] = arguments[ i + 1 ];
  36. }
  37. window.localStorage[ name ] = JSON.stringify( storage );
  38. console.log( '[' + /\d\d\:\d\d\:\d\d/.exec( new Date() )[ 0 ] + ']', 'Saved config to LocalStorage.' );
  39. },
  40. clear: function () {
  41. delete window.localStorage[ name ];
  42. }
  43. };
  44. };