From 997dc5466d25684cc0a04f229c9612733c19182d Mon Sep 17 00:00:00 2001 From: N0rdye Date: Sat, 1 Jul 2023 17:12:37 +0500 Subject: [PATCH] trying to fix spawners --- public/lib/inter.js | 33 +++++++++++---------------------- views/admin.ejs | 16 +++++++++------- views/static/start.ejs | 3 ++- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/public/lib/inter.js b/public/lib/inter.js index f679a0d..a31425c 100644 --- a/public/lib/inter.js +++ b/public/lib/inter.js @@ -11,21 +11,14 @@ function get_count(clas){ function create(clas,x,y,body,id){ let main_clas = clas.split(" ")[0]; // if (body == null || body == "") body = "[]"; + let obj = document.createElement("img"); + obj.id = id; + obj.alt = id; + clas= clas.split(" "); + clas.forEach(cl => { + obj.classList.add(cl); + }); load_obj(main_clas,(db_data)=>{ - // let data = db_data; - // body = data["img"]; - // console.log(data["img"].toString()); - // console.log(db_data[0]); - // console.log(clas,x,y,body,parent); - // console.log(id); - // root.innerHTML += "
"+body+"
"; - // let img = document.createElement("img"); - let obj = document.createElement("img"); - obj.id = id; - clas= clas.split(" "); - clas.forEach(cl => { - obj.classList.add(cl); - }); if (db_data == null) { delete objs[main_clas][id]; save(()=>{ @@ -36,14 +29,10 @@ function create(clas,x,y,body,id){ obj.src = db_data["img"]; obj.title = `${db_data["name"]} \n ${db_data["description"]}`; } - // obj.innerHTML = body; - // parent.append(obj); - obj.setAttribute("max-width","100px"); - root.append(obj); - set_pos(obj,x,y); - // let obj_doc = document.getElementById(obj); - // console.log(obj_doc.classList); }) + obj.setAttribute("max-width","100px"); + root.append(obj); + set_pos(obj,x,y); } function wall_size_change(type,value){ @@ -96,13 +85,13 @@ function load_local(objss){ function load_proj(){ $.post( "/load_proj",{name:proj_name}) .done(function( res ) { + drag_start(); if(res["out"] == "good"){ // console.log("good"); // console.log(JSON.parse(`'${res["body"]}'`)); // console.log(JSON.parse(res["body"])); // $.cookie("objs",res["body"]); load_local(JSON.parse(res["body"])); - drag_start(); } else if(res["out"] == "bad proj"){ console.log("bad"); diff --git a/views/admin.ejs b/views/admin.ejs index 7c3d886..65c781b 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -59,15 +59,17 @@ let name = document.getElementById("nobj_name").value; let description = document.getElementById("nobj_description").value; var img = document.querySelector('img').src; + name = name.replace(" ","_"); if (img != "http://n0rsrv2:3002/admin"){ new_obj(name,img,0,0,description,(res)=>{ - if(res["out"] == "bad" && res["err"] == "name"){ - document.getElementById("obj_resp").innerHTML = "object already exist"; - } - else if(res["out"] == "good"){ - document.getElementById("obj_resp").innerHTML = "object created"; - } - }); + document.getElementById("obj_resp").innerHTML = "creating object"; + if(res["out"] == "bad" && res["err"] == "name"){ + document.getElementById("obj_resp").innerHTML = "object already exist"; + } + else if(res["out"] == "good"){ + document.getElementById("obj_resp").innerHTML = "object created"; + } + }); } else{ document.getElementById("obj_resp").innerHTML = "image not selected"; diff --git a/views/static/start.ejs b/views/static/start.ejs index d283907..5cb05a7 100644 --- a/views/static/start.ejs +++ b/views/static/start.ejs @@ -8,6 +8,7 @@ + <%= name %> @@ -17,7 +18,7 @@ margin: auto; padding-block: 20px; } - body{ + html{ background-color:aliceblue; }