<commit_before>import VueAsyncData from 'vue-async-data'
import VueLocalStorage from 'vue-localstorage'

Vue.use(VueAsyncData)
Vue.use(VueLocalStorage)

import Easel from './easel'
import ImageLoader from './image-loader'

import './commands'
import './directives'
import './ctrl'

export default class App extends Vue {

	constructor() {
		super({
			el: 'body',
			data: {
				effects: [],
				currentEffect: '',
				params: {},
				ui: {
				}
			},
			localStorage: {
				currentEffect: {type: String, default: 'polar-perlin'},
				currentParams: {type: Object, default: {}}
			}
		})

		this.easel = new Easel()
		this.changeEffect = this.changeEffect.bind(this)

		this._loadEffects = this._loadEffects.bind(this)
		this._loadEffects()

		window.Commands.execute('load-source', './assets/default.jpg')

		window.Commands.on('reload-effects', this._loadEffects)
	}

	_loadEffects() {
		$.getJSON('./assets/effects.json', (data) => {
			this.effectsData = data

			let effectsList = _.map(this.effectsData, (e, key) => { return{label: e.label, value: key}})
			this.$set('effects', effectsList)

			this.currentEffect = this.$localStorage.get('currentEffect')
			console.log('load effect')
			this.changeEffect()


			// let defaultParams = this.effectsData[this.currentEffect].params
			// let savedParams = this.$localStorage.get('currentParams')

			// this.$set('params', _.merge(defaultParams, savedParams))
		})
	}

	updateUniforms() {
		for (let key in this.uniforms) {
			this.uniforms[key].value = this.params[key].value
		}
		this.$localStorage.set('currentParams', this.params)
		this.easel.updateUniforms(this.uniforms)
	}

	changeEffect() {
		console.log('change effect:', this.currentEffect)

		let effect = this.effectsData[this.currentEffect]

		this.$set('params', effect.params)
		this.$localStorage.set('currentEffect', this.currentEffect)

		let uniforms = {}

		for (let key in this.params) {
			let p = this.params[key]
			let type, value

			if (p.type.search(/range|offset|angle|random/) != -1) {
				type = 'f'
				value = p.value
			} else if (p.type.search(/hanni|range2d|offset2d/) != -1) {
				type = 'v2'
				value = new THREE.Vector2(p.value.x, p.value.y)
			}

			uniforms[key] = {type, value}
		}

		this.uniforms = uniforms

		this.easel.changeEffect(effect.fragmentShader, uniforms)
	}

	// events
	onClickLoad() {
		window.Commands.loadImage('load-source')
	}

	onClickSave() {
		window.Commands.execute('save-canvas')
	}

	onClickReset() {
		window.Commands.execute('reset-canvas')
	}

}
<commit_msg>Load each params properly<commit_after>import VueLocalStorage from 'vue-localstorage'

Vue.use(VueLocalStorage)

import Easel from './easel'

import './commands'
import './ctrl'

export default class App extends Vue {

	constructor() {
		super({
			el: 'body',
			data: {
				effects: [],
				currentEffect: '',
				params: {},
				ui: {
				}
			},
			localStorage: {
				currentEffect: {type: String, default: 'polar-perlin'},
				currentParams: {type: Object, default: {}}
			}
		})

		this.easel = new Easel()
		this.changeEffect = this.changeEffect.bind(this)

		this._loadEffects = this._loadEffects.bind(this)
		this._loadEffects()

		window.Commands.execute('load-source', './assets/default.jpg')

		window.Commands.on('reload-effects', this._loadEffects)
	}

	_loadEffects() {
		$.getJSON('./assets/effects.json', (data) => {
			this.effectsData = data

			let effectsList = _.map(this.effectsData, (e, key) => { return{label: e.label, value: key}})
			this.$set('effects', effectsList)

			this.currentEffect = this.$localStorage.get('currentEffect')
			console.log('load effect')
			this.changeEffect()

			let defaultParams = this.effectsData[this.currentEffect].params
			let savedParams = this.$localStorage.get('currentParams')

			let params = {}

			for (let key in defaultParams) {
				params[key] = defaultParams[key]
				if (key in savedParams && defaultParams[key].type == savedParams[key].type) {
					params[key].value = savedParams[key].value
				}
			}

			this.$set('params', params)
		})
	}

	updateUniforms() {
		for (let key in this.uniforms) {
			this.uniforms[key].value = this.params[key].value
		}
		this.$localStorage.set('currentParams', this.params)
		this.easel.updateUniforms(this.uniforms)
	}

	changeEffect() {
		console.log('change effect:', this.currentEffect)

		let effect = this.effectsData[this.currentEffect]

		this.$set('params', effect.params)
		this.$localStorage.set('currentEffect', this.currentEffect)

		let uniforms = {}

		for (let key in this.params) {
			let p = this.params[key]
			let type, value

			if (p.type.search(/slider|offset|angle|random/) != -1) {
				type = 'f'
				value = p.value
			} else if (p.type.search(/slider2d|offset2d/) != -1) {
				type = 'v2'
				value = new THREE.Vector2(p.value.x, p.value.y)
			}

			uniforms[key] = {type, value}
		}

		this.uniforms = uniforms

		this.easel.changeEffect(effect.fragmentShader, uniforms)
	}

	// events
	onClickLoad() {
		window.Commands.loadImage('load-source')
	}

	onClickSave() {
		window.Commands.execute('save-canvas')
	}

	onClickReset() {
		window.Commands.execute('reset-canvas')
	}

}

{'fraction_non_alphanumeric': 0.15855786005039738, 'fraction_numerical': 0.0023260321767784456, 'mean_word_length': 3.6236559139784945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5844887', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1729, 'n_words': 322}