Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure #16

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Custom/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
</div>
</div>
<div id="directions">
<button type="button" class="collapsible" id="docsButton" style="width:100%;height:100%;" title="Click for help" onclick="window.open('https://didsr.github.io/WebXR-tools/Custom/doc/','_blank')"><i class="fa-solid fa-circle-info">V1.0</i></button>
<button type="button" class="collapsible" id="docsButton" style="width:100%;height:100%;" title="Click for help" onclick="window.open('https://didsr.github.io/WebXR-tools/Custom/doc/','_blank')"><i class="fa-solid fa-circle-info"></i></button>
<br>
<br>
<button id="consoleButton" onclick="toggleConsole()">Toggle Console</button>
Expand Down Expand Up @@ -447,7 +447,6 @@
<script src="utils/entity/selectEntity.js" type="text/javascript"></script>

<!--extra -->
<script src="utils/extra/clipboard.js" type="text/javascript"></script>
<script src="utils/extra/consoleDump.js" type="text/javascript"></script>
<script src="utils/extra/hexToRgb.js" type="text/javascript"></script>
<script src="utils/extra/vrEventHandler.js" type="text/javascript"></script>
Expand All @@ -467,6 +466,7 @@
<script src="utils/scene/displayNext.js" type="text/javascript"></script>
<script src="utils/scene/rename.js" type="text/javascript"></script>
<script src="utils/scene/resetScene.js" type="text/javascript"></script>
<script src="utils/scene/clipboard.js" type="text/javascript"></script>

<!-- shareable link -->
<script src="utils/shareableLink/export.js" type="text/javascript"></script>
Expand Down
21 changes: 16 additions & 5 deletions Custom/utils/localStorage/addPackage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Adds packages to local storage.
Returns true on success and throws an error on failure.
*/
function manageLocalStorage(key, value){
function manageLocalStorage(key, value, ver){

let textures = {}

Expand All @@ -28,7 +28,12 @@
// compress the package content
value = LZString.compressToBase64(JSON.stringify(value))

let arr = [value,textures,version]
let arr;
if(ver){
arr = [value, textures, ver]
} else {
arr = [value,textures,version]
}

// get the contents of localStorage
let localScenes = JSON.parse(localStorage.getItem('packages'))
Expand Down Expand Up @@ -144,8 +149,9 @@ async function changeUrl(){
// get the desired package from localStorage
let key = Object.keys(localArr[recentPackages.selectedIndex])[0]

let currVer = localArr[recentPackages.selectedIndex][key].length < 3 ? version : localArr[recentPackages.selectedIndex][key][2];

if(localArr[recentPackages.selectedIndex][key][2] < version){
if(currVer < version){
alert('Package is out of date. You might need to remake it.')
}

Expand Down Expand Up @@ -224,8 +230,13 @@ async function changeUrl(){
}
}

changePackage(); // invoke the function to change packages to the selected option
}
names[packageSelect.value] = {}
Object.keys(scenes[packageSelect.value]).forEach(currName =>{
if(currName.split('(').length > 1){
currName = currName.split(' (')[0]
}
names[packageSelect.value][currName] = names[packageSelect.value][currName] ? names[packageSelect.value][currName] + 1 : 1;
});

// condensed function to get size of a string
function ByteSize(str){
Expand Down
3 changes: 3 additions & 0 deletions Custom/utils/package/renamePackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function renamePackage(){

scenes[packageName] = currPackage
delete scenes[packageSelect.value]

names[packageName] = names[oldName];
delete names[oldName]
packageSelect.options[packageSelect.selectedIndex].value = packageName
packageSelect.options[packageSelect.selectedIndex].text = packageName

Expand Down
17 changes: 16 additions & 1 deletion Custom/utils/scene/addRemoveScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function addPattern(){
}

currName = ''
if(Object.keys(names[packageSelect.value]).indexOf(patternName) == -1){
if(!names[packageSelect.value][patternName]){
names[packageSelect.value][patternName] = 1
currName = patternName
} else {
Expand Down Expand Up @@ -75,11 +75,26 @@ function removePattern(){
i++;
}
children = []
let childrenNames = []
revertChanges()
indices.forEach(ind => {
delete scenes[packageSelect.value][patternList.children[ind].id]
childrenNames.push(patternList.children[ind].id)
children.push(patternList.children[ind])
})

childrenNames.sort((a,b) => { a.localeCompare(b) }).reverse()

console.log(childrenNames)
childrenNames.forEach((name) => {
if(name.split('(').length > 1 &&
Number(name.split('(')[1].split(')')[0]) == names[packageSelect.value][name.split(' (')[0]]-1){
names[packageSelect.value][name.split(' (')[0]] = names[packageSelect.value][name.split(' (')[0]]-1;
} else if(names[packageSelect.value][name] == 1){
delete names[packageSelect.value][name]
}
})

children.forEach(child =>{
patternList.removeChild(child)
})
Expand Down
76 changes: 76 additions & 0 deletions Custom/utils/scene/clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Handles code related to copying, cutting, and pasting */

// copies a pattern or group of patterns
let clipboard;
function copyPattern(){
if(isNaN(parseInt(patternList.getAttribute('selectedIndex')))){
alert('No pattern selected')
return
}
let i = 0;
indices = []
while(i < patternList.children.length){
if(patternList.children[i].style.background == 'rgb(243, 152, 20)'){
indices.push(i)
}
i++;
}
clipboard = {}
indices.forEach(ind => {
clipboard[patternList.children[ind].id] = scenes[packageSelect.value][patternList.children[ind].id]
})
}

// pastes a pattern or group of patterns
function pastePattern(){
if(clipboard == null){
return;
}

Object.keys(clipboard).forEach(name =>{
currName = name.split(' (')[0];
if(names[packageSelect.value][currName]){
currName = currName + ' ('+names[packageSelect.value][currName]+')'
names[packageSelect.value][name.split(' (')[0]] = names[packageSelect.value][name.split(' (')[0]] + 1

} else {
names[packageSelect.value][currName] = 1
}

scenes[packageSelect.value][currName] = clipboard[name]
let textContent = currName;
if(currName.length > 20){
textContent = currName.substring(0,20)+"..."
}

var toggle_button = '<li id="'+currName+'">'+textContent+'</li>';

$('#items-list').append(toggle_button)

item = document.getElementById(currName)
$(item).prop('draggable', true)
item.addEventListener('dragstart', dragStart)
item.addEventListener('drop', dropped)
item.addEventListener('dragenter', cancelDefault)
item.addEventListener('dragover', cancelDefault)
item.addEventListener('click',selectPattern)
})
patternList.scrollTo({
top: 1000000000,
left: 0,
behavior: "smooth",
});

}

// cuts a pattern or group of patterns
function cutPattern(){
if(isNaN(parseInt(patternList.getAttribute('selectedIndex')))){
alert('No pattern selected')
return
}
keysPressed["ctrl"] = false;
keysPressed["x"] = false;
copyPattern()
removePattern()
}
14 changes: 11 additions & 3 deletions Custom/utils/scene/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ function renamePattern(){
oldName = patternList.children[parseInt(patternList.getAttribute('selectedIndex'))].id
currScene = scenes[packageSelect.value][oldName]
currName = ''
if(Object.keys(names).indexOf(patternName) == -1){
if(!names[packageSelect.value][patternName]){
names[patternName] = 1
currName = patternName
} else {
names[patternName] = names[patternName] + 1
currName = patternName+''+names[patternName]
currName = patternName+''+names[packageSelect.value][patternName]
names[packageSelect.value][patternName] = names[packageSelect.value][patternName] + 1

}

if(names[packageSelect.value][oldName] == 1){
delete names[packageSelect.value][oldName]
} else if(oldName.split('(').length > 1 &&
Number(oldName.split('(')[1].split(')')[0]) == names[packageSelect.value][oldName.split(' (')[0]]-1){
names[packageSelect.value][oldName.split(' (')[0]] = names[packageSelect.value][oldName.split(' (')[0]]-1;
}
scenes[packageSelect.value][currName] = currScene
delete scenes[packageSelect.value][oldName]

Expand Down
14 changes: 11 additions & 3 deletions Custom/utils/shareableLink/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ async function pastebinFetch(url,onload){
return false;
}

let currVer = fileContent['version'] ? fileContent['version'] : 1.0
let currVer = !Number.isNaN(fileContent['version']) ? fileContent['version'] : 1.0

if(currVer < version){
alert('Package is out of date. You might need to remake it.')
}
Expand Down Expand Up @@ -217,14 +218,14 @@ async function pastebinFetch(url,onload){
// handle local storage updates
if(url.split("https://didsr.pythonanywhere.com/webxrtools/get?id=").length > 1){
// if link came from pastebin, then only save pastebin id
let out = manageLocalStorage(fileContent['filename'] + " ("+url.split("https://didsr.pythonanywhere.com/webxrtools/get?id=")[1]+")", fileContent['scenes'])
let out = manageLocalStorage(fileContent['filename'] + " ("+url.split("https://didsr.pythonanywhere.com/webxrtools/get?id=")[1]+")", fileContent['scenes'], currVer)
if(out == false){
return false;
}
packages[fileContent['filename']] = url.split("https://didsr.pythonanywhere.com/webxrtools/get?id=")[1]// save id in packages
} else {
// if link is not from pastebin, save entire link address
let out = manageLocalStorage(fileContent['filename'] + " ("+encodeURIComponent(decodeURIComponent(url))+")", fileContent['scenes'])
let out = manageLocalStorage(fileContent['filename'] + " ("+encodeURIComponent(decodeURIComponent(url))+")", fileContent['scenes'], currVer)
if(out == false){
return false;
}
Expand Down Expand Up @@ -277,6 +278,13 @@ async function pastebinFetch(url,onload){
packageSelect.options.add(new Option(fileContent['filename'],fileContent['filename']))
packageSelect.value = fileContent['filename']

names[packageSelect.value] = {}
Object.keys(scenes[packageSelect.value]).forEach(currName =>{
if(currName.split('(').length > 1){
currName = currName.split(' (')[0]
}
names[packageSelect.value][currName] = names[packageSelect.value][currName] ? names[packageSelect.value][currName] + 1 : 1;
});
changePackage() // invokes the function change packages to the uploaded one
return true; // returns success
}
Binary file added Images/controllerFigure.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading