Fix Box shape recall
This commit is contained in:
parent
6c60821469
commit
e136603d81
3 changed files with 56 additions and 21 deletions
|
|
@ -45,7 +45,9 @@ function deleteClonesFor(username) {
|
|||
if (!isReady) return;
|
||||
EntityViewer.queryOctree();
|
||||
Script.setTimeout(function () {
|
||||
var ids = Entities.findEntitiesByType("Shape", SCAN_CENTER, SCAN_RADIUS);
|
||||
// Use untyped findEntities to avoid type-specific visibility issues
|
||||
// (Box entities are not always returned by findEntitiesByType)
|
||||
var ids = Entities.findEntities(SCAN_CENTER, SCAN_RADIUS);
|
||||
var deleted = 0;
|
||||
ids.forEach(function (id) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
var SHAPE_TYPE = {
|
||||
tetrahedron: "Tetrahedron",
|
||||
hexahedron: "Cube",
|
||||
hexahedron: "Box",
|
||||
octahedron: "Octahedron",
|
||||
dodecahedron: "Dodecahedron",
|
||||
icosahedron: "Icosahedron",
|
||||
|
|
@ -92,7 +92,9 @@
|
|||
}
|
||||
|
||||
function countLiveClones(username, shapeId) {
|
||||
var results = Entities.findEntitiesByType("Shape", MyAvatar.position, 100);
|
||||
// Scan both Shape and Box — hexahedron/cube uses the Box entity type
|
||||
var results = Entities.findEntitiesByType("Shape", MyAvatar.position, 100)
|
||||
.concat(Entities.findEntitiesByType("Box", MyAvatar.position, 100));
|
||||
var count = 0;
|
||||
results.forEach(function (id) {
|
||||
try {
|
||||
|
|
@ -110,9 +112,11 @@
|
|||
var spawnPos = Vec3.sum(shelfProps.position,
|
||||
Vec3.multiplyQbyV(shelfProps.rotation, SPAWN_OFFSET));
|
||||
|
||||
var shapeType = SHAPE_TYPE[_shapeId] || "Sphere";
|
||||
var entityType = (shapeType === "Box") ? "Box" : "Shape";
|
||||
Entities.addEntity({
|
||||
type: "Shape",
|
||||
shape: SHAPE_TYPE[_shapeId] || "Sphere",
|
||||
type: entityType,
|
||||
shape: shapeType,
|
||||
name: "manifold_" + _shapeId + "_" + _username,
|
||||
position: spawnPos,
|
||||
dimensions: { x: 0.25, y: 0.25, z: 0.25 },
|
||||
|
|
@ -177,7 +181,7 @@
|
|||
|
||||
// Mouse
|
||||
this.clickDownOnEntity = function () { onClickDown(); };
|
||||
this.clickUpOnEntity = function () { _busy = false; };
|
||||
this.clickReleaseOnEntity = function () { _busy = false; };
|
||||
|
||||
// Controller — near (<0.3m) and far (>0.3m)
|
||||
// Requires "Triggerable" checkbox enabled on the entity.
|
||||
|
|
|
|||
|
|
@ -537,18 +537,34 @@
|
|||
btn.disabled = true;
|
||||
btn.classList.add("loading");
|
||||
|
||||
fetch(API_BASE + "/purchase", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + state.token,
|
||||
},
|
||||
body: JSON.stringify({ shape: shapeId }),
|
||||
})
|
||||
function doPurchase(token) {
|
||||
return fetch(API_BASE + "/purchase", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ shape: shapeId }),
|
||||
});
|
||||
}
|
||||
|
||||
doPurchase(state.token)
|
||||
.then(function(r) {
|
||||
if (r.status === 401) {
|
||||
return refreshSession().then(function(newToken) {
|
||||
return doPurchase(newToken);
|
||||
});
|
||||
}
|
||||
if (!r.ok) return r.text().then(function(t) { throw new Error(t.trim()); });
|
||||
return r.json();
|
||||
})
|
||||
.then(function(r) {
|
||||
// after potential retry, r may still be a Response not yet parsed
|
||||
if (r && typeof r.json === "function") {
|
||||
return r.json();
|
||||
}
|
||||
return r;
|
||||
})
|
||||
.then(function(d) {
|
||||
btn.classList.remove("loading");
|
||||
btn.classList.add("success");
|
||||
|
|
@ -583,13 +599,26 @@
|
|||
btn.disabled = true;
|
||||
btn.textContent = "recalling...";
|
||||
|
||||
fetch(API_BASE + "/recall", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + state.token,
|
||||
},
|
||||
body: JSON.stringify({ username: state.username }),
|
||||
function doRecall(token) {
|
||||
return fetch(API_BASE + "/recall", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ username: state.username }),
|
||||
});
|
||||
}
|
||||
|
||||
doRecall(state.token)
|
||||
.then(function(r) {
|
||||
if (r.status === 401) {
|
||||
// Token expired — refresh and retry once
|
||||
return refreshSession().then(function(newToken) {
|
||||
return doRecall(newToken);
|
||||
});
|
||||
}
|
||||
return r;
|
||||
})
|
||||
.then(function(r) {
|
||||
btn.classList.add("ok");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue