Browse Source

Experiments configs. Config merger, inheritance-like system

rigwild 1 year ago
parent
commit
0ee586f1e8

+ 2 - 0
config.messagesId.js

@@ -1,3 +1,5 @@
+'use strict'
+
 // List of IDs for messages sent using WebSockets
 
 // Message IDs for experiments events

+ 10 - 0
src/functions.js

@@ -57,3 +57,13 @@ export const shuffleArray = array => {
   }
   return array
 }
+
+/**
+ * Build a configuration file by merging the default config with the asked scene.
+ * The asked scene config will overwrite the default config.
+ * @param {Object} defaultConfig The default configuration object
+ * @param {Object} scenesConfig The scenes specific configuration
+ * @returns {Function} A function that will return the scene configuration
+ */
+export const buildConfig = (defaultConfig = {}, scenesConfig = {}) =>
+  sceneName => Object.assign(defaultConfig, scenesConfig[sceneName])

+ 25 - 0
src/mixins/ExperimentBaseExtracts/config.js

@@ -0,0 +1,25 @@
+import { buildConfig } from './utils'
+
+// This will apply to all the scenes
+export const defaultConfig = {
+  showHoverBorder: false,
+  extractConfig: {
+    x: 4,
+    y: 4
+  },
+  lockConfig: true
+}
+
+// This will overwrite the config for the given scene
+export const scenesConfig = {
+  bathroom: {
+    showHoverBorder: false,
+    extractConfig: {
+      x: 4,
+      y: 4
+    },
+    lockConfig: true
+  }
+}
+
+export default buildConfig(defaultConfig, scenesConfig)

src/views/Experiments/NoReference.vue → src/views/Experiments/NoReference/index.vue


+ 31 - 0
src/views/Experiments/WithReference/config.js

@@ -0,0 +1,31 @@
+import { buildConfig } from './utils'
+import {
+  defaultConfig as mixinDefaultConfig,
+  scenesConfig as mixinScenesConfig
+} from '@/mixins/ExperimentBaseExtracts'
+
+// This will apply to all the scenes
+export const defaultConfig = {
+  ...mixinDefaultConfig,
+  showHoverBorder: false,
+  extractConfig: {
+    x: 4,
+    y: 4
+  },
+  lockConfig: true
+}
+
+// This will overwrite the config for the given scene
+export const scenesConfig = {
+  ...mixinScenesConfig,
+  bathroom: {
+    showHoverBorder: false,
+    extractConfig: {
+      x: 4,
+      y: 4
+    },
+    lockConfig: true
+  }
+}
+
+export default buildConfig(defaultConfig, scenesConfig)

+ 1 - 0
src/views/Experiments/WithReference.vue

@@ -91,6 +91,7 @@ import ExperimentBaseExtracts from '@/mixins/ExperimentBaseExtracts'
 import { API_ROUTES } from '@/functions'
 import Loader from '@/components/Loader.vue'
 import ExtractConfiguration from '@/components/ExperimentsComponents/ExtractConfiguration.vue'
+import getSceneConfig from './config'
 
 export default {
   name: 'ExperimentWithReference',