bug fix in JSON serialization

This commit is contained in:
2025-11-08 20:33:49 +02:00
parent f5a08a9702
commit 5c5c45938b
7 changed files with 21 additions and 4 deletions
@@ -36,6 +36,7 @@ const tl = 4;
class MazeQuizGame { class MazeQuizGame {
constructor(engine, data) { constructor(engine, data) {
data.noPhysics = true;
return new Promise(async (resolve, reject)=>{ return new Promise(async (resolve, reject)=>{
let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions; let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions;
let def = this.generate(questions); let def = this.generate(questions);
@@ -41,7 +41,6 @@ export default {
props:['modelValue'], props:['modelValue'],
mounted(){ mounted(){
this.modelValue.questions ??= []; this.modelValue.questions ??= [];
this.modelValue.noPhysics = true;
}, },
methods:{ methods:{
addQuestion(){ addQuestion(){
@@ -10,6 +10,7 @@ import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js'
class Particles { class Particles {
constructor(engine, data) { constructor(engine, data) {
data.noPhysics = true;
const { x, y, count, w, h } = data; const { x, y, count, w, h } = data;
let positions = Particles.positions(count, w, h); let positions = Particles.positions(count, w, h);
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
@@ -43,7 +43,6 @@ export default {
this.modelValue.count = 1000; this.modelValue.count = 1000;
this.modelValue.w = 50; this.modelValue.w = 50;
this.modelValue.h = 50; this.modelValue.h = 50;
this.modelValue.noPhysics = true;
} }
} }
} }
+14
View File
@@ -60,6 +60,20 @@ export default {
.sort((a, b) => a.sort - b.sort).map(({ value }) => value) .sort((a, b) => a.sort - b.sort).map(({ value }) => value)
}, },
deepMerge(target, source, transformFn) {
Object.entries(source).forEach(([key, value]) => {
if (transformFn){
value = transformFn(key, value)
}
if (value && typeof value === 'object' && !Array.isArray(value)) {
this.deepMerge(target[key] = target[key] || {}, value, transformFn);
return;
}
target[key] = value;
});
return target;
},
drawOnCanvas(svg, width, height){ drawOnCanvas(svg, width, height){
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
let url = URL.createObjectURL(new Blob([svg],{ type:"image/svg+xml;charset=utf-8" })); let url = URL.createObjectURL(new Blob([svg],{ type:"image/svg+xml;charset=utf-8" }));
+1
View File
@@ -62,6 +62,7 @@ export default {
async save(params) { async save(params) {
this.loading = true; this.loading = true;
try { try {
console.log('saving', this.object)
let result = await this.$api.game.save(this.object); let result = await this.$api.game.save(this.object);
//Object.assign(this.object, result.data.object); //Object.assign(this.object, result.data.object);
this.object.id = result.data.object.id; this.object.id = result.data.object.id;
+4 -2
View File
@@ -1,13 +1,15 @@
import axios from 'axios'; import axios from 'axios';
import Utils from '@/lib/Utils';
const $ax = axios.create({ const $ax = axios.create({
baseURL: '/api/', baseURL: '/api/',
transformRequest: [ transformRequest: [
(data, headers)=>{ (data, headers)=>{
if (data && !(data instanceof FormData)){ if (data && !(data instanceof FormData)){
data = JSON.stringify(data, (k, v)=>{ data = Utils.deepMerge({}, data, (k, v)=>{
return k.startsWith('__') ? undefined : v; return k.startsWith('__') ? undefined : v;
}); })
data = JSON.stringify(data);
headers['Content-Type'] = 'application/json;charset=utf-8'; headers['Content-Type'] = 'application/json;charset=utf-8';
} }
return data; return data;