massive UwU fixes & updates
when login lasd sids is logged out, added cache for images they are being save to local storage when loaded, added reload for dragging elements when resizing the window or zooming the page, updated logging function, added local and cloud saving, loading for project, updated project preview image saving, updated object loading, updated sid cleaning. i did it all in one day OWO. thats it Uwu
This commit is contained in:
BIN
public/img/shadow-energy.gif
Normal file
BIN
public/img/shadow-energy.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 435 KiB |
@ -7,11 +7,6 @@ function get_from_uuid(callback){
|
||||
// console.log("good");
|
||||
callback(res["body"])
|
||||
}
|
||||
else if (res["out"] == bad){
|
||||
if (res["body"] == "expired"){
|
||||
logout(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -19,37 +14,40 @@ function log_by_sid() {
|
||||
// const uuid = $.cookie("uuid");
|
||||
// const sid = $.cookie("sid");
|
||||
// console.log("log");
|
||||
if($.cookie('uuid') == null && $.cookie('sid') == null){
|
||||
if($.cookie('sid') == null){
|
||||
// get_sid(location.hostname);
|
||||
get_sid();
|
||||
}else if ($.cookie('sid') != null && $.cookie('uuid') != null){
|
||||
$.post( "/sid_log")
|
||||
.done(function( res ) {
|
||||
console.log("ping");
|
||||
if(res["out"] == "good"){
|
||||
goto(res["url"]);
|
||||
}
|
||||
else if (res["out"] == "bad"){
|
||||
clear_ck(false);
|
||||
}
|
||||
})}
|
||||
}
|
||||
// else if ($.cookie('sid') != null && $.cookie('uuid') != null){
|
||||
// $.post( "/sid_log")
|
||||
// .done(function( res ) {
|
||||
// console.log("ping");
|
||||
// if(res["out"] == "good"){
|
||||
// goto(res["url"]);
|
||||
// }
|
||||
// else if (res["out"] == "bad"){
|
||||
// clear_ck(false);
|
||||
// }
|
||||
// })}
|
||||
}
|
||||
|
||||
function clear_ck(redirect = true){
|
||||
let uuid = $.cookie("uuid");
|
||||
let sid = $.cookie("sid");
|
||||
$.removeCookie("uuid");
|
||||
$.removeCookie('sid');
|
||||
console.log("sid");
|
||||
$.post( "/clear_sid")
|
||||
.done(function( res ) {
|
||||
console.log("sid");
|
||||
$.cookie("uuid",null);
|
||||
$.cookie("sid",null);
|
||||
$.removeCookie("uuid");
|
||||
$.removeCookie('sid');
|
||||
console.log("clear");
|
||||
get_sid();
|
||||
if(res["out"] == "good"){
|
||||
if (redirect) goto("/login");
|
||||
}
|
||||
})
|
||||
setTimeout(()=>{
|
||||
$.post( "/clear_sid",{uuid:uuid,sid:sid})
|
||||
.done(function( res ) {
|
||||
console.log("sid");
|
||||
if(res["out"] == "good"){
|
||||
// get_sid();
|
||||
if (redirect) goto("/login");
|
||||
}
|
||||
console.log("clear");
|
||||
})
|
||||
},100)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,12 +1,7 @@
|
||||
window.dragMoveListener = dragMoveListener;
|
||||
let root = document.getElementById("drags");
|
||||
let objs = { height:"2",width:"4"};
|
||||
|
||||
function get_count(clas){
|
||||
if (objs[clas] == null) objs[clas] = {};
|
||||
let count = Object.keys(objs[clas]).length;
|
||||
return count;
|
||||
}
|
||||
let objs_store = {};
|
||||
|
||||
function create(clas,x,y,body,id,size){
|
||||
let main_clas = clas.split(" ")[0];
|
||||
@ -18,20 +13,39 @@ function create(clas,x,y,body,id,size){
|
||||
clas.forEach(cl => {
|
||||
obj.classList.add(cl);
|
||||
});
|
||||
load_obj(main_clas,"`img`,`name`,`description`,`width`,`height`",(db_data)=>{
|
||||
if (db_data == null) {
|
||||
delete objs[main_clas][id];
|
||||
save(()=>{
|
||||
goto("/proj/"+proj_name);
|
||||
});
|
||||
get_obj(main_clas,(db_data)=>{
|
||||
if ($.cookie("cache") == "true"){
|
||||
if (localStorage.getItem(`${main_clas}`) == null){
|
||||
load_obj(main_clas,"`img`",(odata)=>{
|
||||
localStorage.setItem(main_clas,odata["img"]);
|
||||
make(odata["img"]);
|
||||
})
|
||||
}
|
||||
else{
|
||||
make(localStorage.getItem(main_clas))
|
||||
}
|
||||
}
|
||||
else if (db_data != null){
|
||||
obj.src = db_data["img"];
|
||||
obj.title = `${db_data["name"]}\n${db_data["description"]}\nwidth:${db_data["width"]}см height:${db_data["height"]}см`;
|
||||
// drag.transform = `translate(${drag.getAttribute("data-y")}px, ${drag.getAttribute("data-y")}px) scale(${db_data["width"] * 2} ${db_data["height"] * 2})`;
|
||||
if(size){
|
||||
obj.style.width = `${db_data["width"] * 2}px`;
|
||||
obj.style.height = `${db_data["height"] * 2}px`;
|
||||
else{
|
||||
load_obj(main_clas,"`img`",(odata)=>{
|
||||
localStorage.setItem(main_clas,odata["img"]);
|
||||
make(odata["img"]);
|
||||
})
|
||||
}
|
||||
function make(img){
|
||||
if (db_data == null) {
|
||||
delete objs[main_clas][id];
|
||||
save(()=>{
|
||||
goto("/proj/"+proj_name);
|
||||
});
|
||||
}
|
||||
else if (db_data != null){
|
||||
obj.src = img;
|
||||
obj.title = `${db_data["name"]}\n${db_data["description"]}\nwidth:${db_data["width"]}см height:${db_data["height"]}см`;
|
||||
// drag.transform = `translate(${drag.getAttribute("data-y")}px, ${drag.getAttribute("data-y")}px) scale(${db_data["width"] * 2} ${db_data["height"] * 2})`;
|
||||
if(size){
|
||||
obj.style.width = `${db_data["width"] * 2}px`;
|
||||
obj.style.height = `${db_data["height"] * 2}px`;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -40,6 +54,12 @@ function create(clas,x,y,body,id,size){
|
||||
set_pos(obj,x,y);
|
||||
}
|
||||
|
||||
function resize_drags(){
|
||||
document.getElementById('drags').style.left = $('.dropzone')[0].getBoundingClientRect().x;
|
||||
document.getElementById('drags').style.width = $('.dropzone')[0].style.width;
|
||||
drag_start();
|
||||
}
|
||||
|
||||
function wall_size_change(type,value){
|
||||
let wall = document.getElementsByClassName("wall")[0];
|
||||
let scroll;
|
||||
@ -47,7 +67,7 @@ function wall_size_change(type,value){
|
||||
if (value == null) scroll = document.getElementById("wall_width").value;
|
||||
else scroll = value;
|
||||
// document.getElementById("wall_width_value").innerHTML = (Math.ceil((parseFloat(scroll)+0.1)*10)/ 10);
|
||||
document.getElementById("wall_width_value").innerHTML = scroll;
|
||||
document.getElementById("wall_width_value").innerHTML = `${scroll}м`;
|
||||
|
||||
// console.log(scroll);
|
||||
wall.style.width = `${scroll * 200}px`;
|
||||
@ -57,7 +77,7 @@ function wall_size_change(type,value){
|
||||
if (value == null) scroll = document.getElementById("wall_height").value;
|
||||
else scroll = value;
|
||||
// document.getElementById("wall_height_value").innerHTML = (Math.ceil((parseFloat(scroll)+0.1)*10)/ 10);
|
||||
document.getElementById("wall_height_value").innerHTML = scroll;
|
||||
document.getElementById("wall_height_value").innerHTML = `${scroll}м`;
|
||||
|
||||
// console.log(scroll);
|
||||
wall.style.height = `${scroll * 200}px`;
|
||||
@ -65,7 +85,7 @@ function wall_size_change(type,value){
|
||||
}
|
||||
}
|
||||
|
||||
function load_local(objss){
|
||||
function load(objss){
|
||||
// objs = JSON.parse($.cookie("objs"));
|
||||
// console.log(objs);
|
||||
objs = objss;
|
||||
@ -92,7 +112,9 @@ function load_local(objss){
|
||||
drag_start();
|
||||
}
|
||||
|
||||
function load_proj(){
|
||||
function load_proj_cloud(){
|
||||
document.getElementById("drags").innerHTML = "";
|
||||
document.getElementById("top_panel_center").innerText = `loading ${proj_name} from cloud`;
|
||||
$.post( "/load_proj",{name:proj_name})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
@ -100,7 +122,8 @@ function load_proj(){
|
||||
// console.log(JSON.parse(`'${res["body"]}'`));
|
||||
// console.log(JSON.parse(res["body"]));
|
||||
// $.cookie("objs",res["body"]);
|
||||
load_local(JSON.parse(res["body"]));
|
||||
load(JSON.parse(res["body"]));
|
||||
document.getElementById("top_panel_center").innerText = `${proj_name} (cloud)`;
|
||||
}
|
||||
else if(res["out"] == "bad proj"){
|
||||
console.log("bad");
|
||||
@ -111,12 +134,28 @@ function load_proj(){
|
||||
})
|
||||
}
|
||||
|
||||
function load_proj_local(){
|
||||
// document.getElementById("top_panel_center").innerText = `loading ${proj_name} from local storage`;
|
||||
if(localStorage.getItem(proj_name) == null){
|
||||
save_local()
|
||||
}
|
||||
document.getElementById("top_panel_center").innerText = `${proj_name} (local)`;
|
||||
document.getElementById("drags").innerHTML = "";
|
||||
load(JSON.parse(localStorage.getItem(proj_name)));
|
||||
}
|
||||
|
||||
function save_local(){
|
||||
// console.log(objs);
|
||||
localStorage.setItem(proj_name,JSON.stringify(objs));
|
||||
}
|
||||
|
||||
function save(callback){
|
||||
// console.log(objs);
|
||||
html2canvas(document.querySelector("body"),{height: 500, width:(window.innerWidth /1.65),x:(window.innerWidth / 5), y:250}).then(canvas => {
|
||||
html2canvas(document.querySelector("body"),{height: document.getElementById("wall").style.height.split("p")[0], width:document.getElementById("wall").style.width.split("p")[0], y:document.getElementById("wall").getBoundingClientRect().top,x:document.getElementById("wall").getBoundingClientRect().left}).then(canvas => {
|
||||
let scr = "";
|
||||
console.log(canvas.toDataURL().length);
|
||||
if (canvas.toDataURL().length < 120000) scr = canvas.toDataURL()
|
||||
scr = canvas.toDataURL();
|
||||
// if (canvas.toDataURL().length < 120000) scr = canvas.toDataURL()
|
||||
// console.log(scr);
|
||||
$.post( "/save_proj", {proj:JSON.stringify(objs),name:proj_name,img:scr})
|
||||
.done(function( res ) {
|
||||
@ -134,11 +173,25 @@ function load_objs(callback){
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
res["body"].forEach(element => {
|
||||
objs_store[`${element["name"]}`] = {description:element["description"],height:element["height"],width:element["width"],id:element["id"],name:element["name"]}
|
||||
});
|
||||
callback(res["body"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function get_obj(clas,callback){
|
||||
if(objs_store != null && objs_store[clas] != null){
|
||||
callback(objs_store[clas]);
|
||||
}
|
||||
else{
|
||||
load_objs(()=>{
|
||||
callback(objs_store[clas]);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function load_obj(name,key,callback){
|
||||
$.post( "/get_obj",{name:name,key:key})
|
||||
.done(function( res ) {
|
||||
@ -233,11 +286,11 @@ interact('.createzone').dropzone({
|
||||
var drag = event.relatedTarget;
|
||||
var zone = event.target;
|
||||
if(drag.classList[1] == "spawn" && drag.classList[0] == zone.classList[0]){
|
||||
load_obj(drag.classList[0],"`height`, `width`",(db_data)=>{
|
||||
get_obj(drag.classList[0],(db_data)=>{
|
||||
// drag.transform = `translate(${drag.getAttribute("data-y")}px, ${drag.getAttribute("data-y")}px) scale(${db_data["width"] * 2} ${db_data["height"] * 2})`;
|
||||
drag.style.width = `${db_data["width"] * 2}px`;
|
||||
drag.style.height = `${db_data["height"] * 2}px`;
|
||||
console.log(db_data);
|
||||
// console.log(db_data);
|
||||
})
|
||||
let x = zone.getBoundingClientRect().left - document.getElementById("drags").getBoundingClientRect().left;
|
||||
let y = zone.getBoundingClientRect().top - document.getElementById("drags").getBoundingClientRect().top;
|
||||
@ -251,6 +304,10 @@ interact('.createzone').dropzone({
|
||||
})
|
||||
|
||||
function drag_start() {
|
||||
let spawns = document.getElementsByClassName("spawn");
|
||||
Object.entries(spawns).forEach(([key, spawn]) => {
|
||||
spawn.parentElement.removeChild(spawn);
|
||||
});
|
||||
let zones = document.getElementsByClassName("createzone");
|
||||
Object.entries(zones).forEach(([key, zone]) => {
|
||||
let x = zone.getBoundingClientRect().left - document.getElementById("drags").getBoundingClientRect().left;
|
||||
|
Reference in New Issue
Block a user