| 1078 | } |
| 1079 | |
| 1080 | function recallSavedValue(gui, controller) { |
| 1081 | // Find the topmost GUI, that's where remembered objects live. |
| 1082 | const root = gui.getRoot(); |
| 1083 | |
| 1084 | // Does the object we're controlling match anything we've been told to |
| 1085 | // remember? |
| 1086 | const matchedIndex = root.__rememberedObjects.indexOf(controller.object); |
| 1087 | |
| 1088 | // Why yes, it does! |
| 1089 | if (matchedIndex !== -1) { |
| 1090 | // Let me fetch a map of controllers for thcommon.isObject. |
| 1091 | let controllerMap = root.__rememberedObjectIndecesToControllers[matchedIndex]; |
| 1092 | |
| 1093 | // Ohp, I believe this is the first controller we've created for this |
| 1094 | // object. Lets make the map fresh. |
| 1095 | if (controllerMap === undefined) { |
| 1096 | controllerMap = {}; |
| 1097 | root.__rememberedObjectIndecesToControllers[matchedIndex] = |
| 1098 | controllerMap; |
| 1099 | } |
| 1100 | |
| 1101 | // Keep track of this controller |
| 1102 | controllerMap[controller.property] = controller; |
| 1103 | |
| 1104 | // Okay, now have we saved any values for this controller? |
| 1105 | if (root.load && root.load.remembered) { |
| 1106 | const presetMap = root.load.remembered; |
| 1107 | |
| 1108 | // Which preset are we trying to load? |
| 1109 | let preset; |
| 1110 | |
| 1111 | if (presetMap[gui.preset]) { |
| 1112 | preset = presetMap[gui.preset]; |
| 1113 | } else if (presetMap[DEFAULT_DEFAULT_PRESET_NAME]) { |
| 1114 | // Uhh, you can have the default instead? |
| 1115 | preset = presetMap[DEFAULT_DEFAULT_PRESET_NAME]; |
| 1116 | } else { |
| 1117 | // Nada. |
| 1118 | return; |
| 1119 | } |
| 1120 | |
| 1121 | // Did the loaded object remember thcommon.isObject? && Did we remember this particular property? |
| 1122 | if (preset[matchedIndex] && preset[matchedIndex][controller.property] !== undefined) { |
| 1123 | // We did remember something for this guy ... |
| 1124 | const value = preset[matchedIndex][controller.property]; |
| 1125 | |
| 1126 | // And that's what it is. |
| 1127 | controller.initialValue = value; |
| 1128 | controller.setValue(value); |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | function add(gui, object, property, params) { |
| 1135 | if (object[property] === undefined) { |