Skip to content

Commit

Permalink
Merge pull request #50 from Z0rb14n/master
Browse files Browse the repository at this point in the history
Add Inventories of Mannequins, Hat Racks
  • Loading branch information
jasoncoon authored Jun 3, 2024
2 parents a7799ff + 176dc90 commit 21cb1b5
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 18 deletions.
96 changes: 96 additions & 0 deletions resources/js/WorldLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function readWorldFile(reader, world) {
readChests(reader, world);
readSigns(reader, world);
readNpcs(reader, world);
readTileEntities(reader, world);

self.postMessage({
'status': "Done.",
Expand Down Expand Up @@ -699,6 +700,101 @@ function readNpcs(reader, world) {
});
}

function readTileEntity(reader) {
let tileType = reader.readUint8();
if (tileType < 0 || tileType > 7) {
return null;
}
let tileEntity = {};
tileEntity.type = tileType;
tileEntity.id = reader.readInt32();
tileEntity.position = {x:reader.readInt16(), y:reader.readInt16()};
switch (tileType) {
case 0: // target dummy
reader.readInt16();
break;
case 1: // item frame
case 4: // weapon rack
case 6: // plate
tileEntity.item = {}
tileEntity.item.id = reader.readInt16();
tileEntity.item.prefixId = reader.readUint8();
tileEntity.item.count = reader.readInt16();
break;
case 2: // logic sensor
tileEntity.logicCheckType = reader.readUint8();
tileEntity.on = reader.readUint8() > 0;
break;
case 3: // (wo)mannequin
tileEntity.items = Array(8)
tileEntity.dyes = Array(8);
let itemBitmask = reader.readUint8();
let dyeBitmask = reader.readUint8();
for (let i = 0; i < 8; i++) {
tileEntity.items[i] = {
id: 0
};
if (((itemBitmask >> i) & 1) === 1) {
tileEntity.items[i].id = reader.readInt16();
tileEntity.items[i].prefixId = reader.readUint8();
tileEntity.items[i].count = reader.readInt16();
}
}
for (let j = 0; j < 8; j++) {
tileEntity.dyes[j] = {
id: 0
};
if (((dyeBitmask >> j) & 1) === 1) {
tileEntity.dyes[j].id = reader.readInt16();
tileEntity.dyes[j].prefixId = reader.readUint8();
tileEntity.dyes[j].count = reader.readInt16();
}
}
break;
case 5: // hat rack
tileEntity.items = Array(2)
tileEntity.dyes = Array(2);
let bitmask = reader.readUint8();
for (let i = 0; i < 2; i++) {
tileEntity.items[i] = {
id: 0
};
if (((bitmask >> i) & 1) === 1) {
tileEntity.items[i].id = reader.readInt16();
tileEntity.items[i].prefixId = reader.readUint8();
tileEntity.items[i].count = reader.readInt16();
}
}
for (let j = 0; j < 2; j++) {
tileEntity.dyes[j] = {
id: 0
};
if (((bitmask >> (j+2)) & 1) === 1) {
tileEntity.dyes[j].id = reader.readInt16();
tileEntity.dyes[j].prefixId = reader.readUint8();
tileEntity.dyes[j].count = reader.readInt16();
}
}
break;
case 7: // pylon
break;
}
return tileEntity;
}

function readTileEntities(reader, world) {
/** @type{Map<{x:int,y:int}, any>}*/
let byPosition = new Map();
let count = reader.readInt32();
for (let i = 0; i < count; i++) {
let tileEntity = readTileEntity(reader);
byPosition.set(tileEntity.position, tileEntity);
}
self.postMessage({
'tileEntities': byPosition,
});
}

function readString(reader) {
var stringLength = 0;
var stringLengthParsed = false;
Expand Down
118 changes: 104 additions & 14 deletions resources/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,31 @@ function isTileMatch(tile, selectedInfos, x, y) {
}
}
}

// check if the tile entity contains it
let tileEntity = tile.tileEntity;
if (tileEntity && info.isItem) {
switch (tileEntity.type) {
case 1: // item frame
case 4: // weapon rack
case 6: // plate
if (info.Id == tileEntity.item.id) {
return true;
}
break;
case 3: // (wo)mannequin
case 5: // hat rack
for (let i = 0; i < tileEntity.items.length; i++) {
if (info.Id == tileEntity.items[i].id) {
return true;
}
if (info.Id == tileEntity.dyes[i].id) {
return true;
}
}
break;
}
}
}

return false;
Expand Down Expand Up @@ -586,6 +611,23 @@ function getMousePos(canvas, evt) {
return mousePos;
}

function getItemText(item) {
let prefix = "";

if(item.prefixId > 0 && item.prefixId < settings.ItemPrefix.length)
prefix = settings.ItemPrefix[item.prefixId].Name;

let itemName = item.id;
for(let itemIndex = 0; itemIndex < settings.Items.length; itemIndex++) {
let itemSettings = settings.Items[itemIndex];
if(Number(itemSettings.Id) === item.id) {
itemName = itemSettings.Name;
break;
}
}
return `${prefix} ${itemName} (${item.count})`;
}

panzoomContainer.addEventListener('mousemove', evt => {
if(!world)
return;
Expand Down Expand Up @@ -631,23 +673,32 @@ $("#panzoomContainer").on('panzoomend', function(evt, panzoom, matrix, changed)
text = `${text} - ${chest.name}`;

for(var i = 0; i < chest.items.length; i++) {
var item = chest.items[i];
var prefix = "";
let item = chest.items[i];
let itemText = getItemText(item);

if(item.prefixId > 0 && item.prefixId < settings.ItemPrefix.length)
prefix = settings.ItemPrefix[item.prefixId].Name;
$("#tileInfoList").append(`<li>${itemText}</li>`);
}
}

var itemName = item.id;
for(var itemIndex = 0; itemIndex < settings.Items.length; itemIndex++) {
var itemSettings = settings.Items[itemIndex];
if(itemSettings.Id == item.id) {
itemName = itemSettings.Name;
break;
let tileEntity = tile.tileEntity;
if (tileEntity) {
switch (tileEntity.type) {
case 3: // mannequin
case 5: // hat rack
let items = tileEntity.items;
let dyes = tileEntity.dyes;
let itemLength = items.length;
for (let i = 0; i < itemLength; i++) {
let item = items[i];
if (item.id > 0) {
$("#tileInfoList").append(`<li>${getItemText(item)}</li>`);
}
let dye = dyes[i];
if (dye.id > 0) {
$("#tileInfoList").append(`<li>${getItemText(dye)}</li>`);
}
}
}


$("#tileInfoList").append(`<li>${prefix} ${itemName} (${item.count})</li>`);
break;
}
}

Expand Down Expand Up @@ -745,6 +796,23 @@ function getTileText (tile) {
text = `${text} (${tile.Type}, ${tile.TextureU})`;
else
text = `${text} (${tile.Type})`;
if (tile.tileEntity) {
let tileEntity = tile.tileEntity;
switch (tileEntity.type) {
case 1: // item frame
case 4: // weapon rack
case 6: // plate
let item = tileEntity.item;
let itemText = getItemText(item);
text = `${text} - ${itemText}`;
break;
case 2: // logic sensor
let checkType = tile.info.CheckTypes[tileEntity.logicCheckType];
let on = tileEntity.on ? "On" : "Off";
text = `${text} - ${checkType}, ${on}`;
break;
}
}
}
else if (tile.WallType || tile.WallType === 0) {
if(tile.WallType < settings.Walls.length) {
Expand Down Expand Up @@ -862,6 +930,28 @@ function onWorldLoaderWorkerMessage(e) {
addNpcs(e.data.npcs);
}

if (e.data.tileEntities) {
for (const [pos, entity] of e.data.tileEntities.entries()) {
let idx = pos.x * world.height + pos.y;
let tile = world.tiles[idx];
if (tile) {
let size = tile.info.Size;
let sizeX = 1;
let sizeY = 1;
if (size) {
sizeX = size[0] - '0';
sizeY = size[2] - '0';
}
for (let x = 0; x < sizeX; x++) {
for (let y = 0; y < sizeY; y++) {
let idx = (pos.x+x) * world.height + pos.y+y;
world.tiles[idx].tileEntity = entity;
}
}
}
}
}

if(e.data.world) {
world = e.data.world;

Expand Down
33 changes: 29 additions & 4 deletions resources/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24484,7 +24484,20 @@ var settings = {
{ Id: "420", Name: "Logic Gate" },
{ Id: "421", Name: "Conveyor Belt Left" },
{ Id: "422", Name: "Conveyor Belt Right" },
{ Id: "423", Name: "Logic Sensor" },
{
Id: "423",
Name: "Logic Sensor",
CheckTypes: [
"None",
"Day",
"Night",
"PlayerAbove",
"Water",
"Lava",
"Honey",
"Liquid"
]
},
{ Id: "424", Name: "Wire Pipe" },
{ Id: "425", Name: "Announcement Box" },
{ Id: "426", Name: "Team Block Red" },
Expand Down Expand Up @@ -24634,12 +24647,24 @@ var settings = {
},
{ Id: "469", Name: "Crystal Table" },

{ Name: "Display Doll", Id: "470" },
{ Name: "Weapons Rack 2", Id: "471" },
{
Name: "Display Doll",
Size: "2,3",
Id: "470"
},
{
Name: "Weapons Rack 2",
Size: "3,3",
Id: "471"
},
{ Name: "Iron Brick", Id: "472" },
{ Name: "Lead Brick", Id: "473" },
{ Name: "Lesion Block", Id: "474" },
{ Name: "Hat Rack", Id: "475" },
{
Name: "Hat Rack",
Size: "3,4",
Id: "475"
},
{ Name: "Golf Cup", Id: "476" },
{ Name: "Mowed Golf Grass", Id: "477" },
{ Name: "Crimstone Brick", Id: "478" },
Expand Down

0 comments on commit 21cb1b5

Please sign in to comment.