| 1 | export class Store{ |
| 2 | static namespace = "THREEJS-PATH-EDITOR"; |
| 3 | |
| 4 | constructor(){ |
| 5 | this.udoArr = []; |
| 6 | } |
| 7 | |
| 8 | udo(){ |
| 9 | const data = this.udoArr.pop(); |
| 10 | if (data){ |
| 11 | localStorage.setItem(Store.namespace, data ); |
| 12 | return true; |
| 13 | } |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | write( config, nodes ) { |
| 18 | const serializedData = localStorage.getItem( Store.namespace ); |
| 19 | const data = serializedData ? JSON.parse(serializedData) : {}; |
| 20 | const config1 = {}; |
| 21 | for (const [key, value] of Object.entries(config)) { |
| 22 | if (typeof value != "function" ) config1[key] = value; |
| 23 | } |
| 24 | this.udoArr.push( JSON.stringify(data) ); |
| 25 | if (this.udoArr.length>6) this.udoArr.shift(); |
| 26 | const path = { config: config1, nodes }; |
| 27 | data[config.name] = path; |
| 28 | data['activePath'] = config.name; |
| 29 | localStorage.setItem(Store.namespace, JSON.stringify(data)); |
| 30 | } |
| 31 | |
| 32 | read( key ) { |
| 33 | const serializedData = localStorage.getItem( Store.namespace ); |
| 34 | const data = JSON.parse(serializedData); |
| 35 | return data ? data[key] : undefined; |
| 36 | } |
| 37 | |
| 38 | delete( key ){ |
| 39 | const serializedData = localStorage.getItem( Store.namespace ); |
| 40 | const data = JSON.parse(serializedData); |
| 41 | delete data[key]; |
| 42 | localStorage.setItem(Store.namespace, JSON.stringify(data)); |
| 43 | } |
| 44 | |
| 45 | getPathNames(){ |
| 46 | const names = []; |
| 47 | const serializedData = localStorage.getItem( Store.namespace ); |
| 48 | if (serializedData==null) return ['Path1']; |
| 49 | const data = JSON.parse(serializedData); |
| 50 | for (const [key, value] of Object.entries(data)) { |
| 51 | if (key != 'activePath' && key != 'tips') names.push( key ); |
| 52 | } |
| 53 | return names; |
| 54 | } |
| 55 | |
| 56 | copy(){ |
| 57 | let name = this.read( 'activePath' ); |
| 58 | if (name){ |
| 59 | const path = this.read( name ); |
| 60 | if (path){ |
nothing calls this directly
no outgoing calls
no test coverage detected