Skip to content

Commit

Permalink
integrate smelter hud
Browse files Browse the repository at this point in the history
  • Loading branch information
KirbyPaint committed Feb 18, 2021
1 parent ddcfc64 commit 2ba132e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"perlin-simplex": "0.0.3",
"popper.js": "^1.16.1"
}
}
}
7 changes: 7 additions & 0 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ body>div>div:hover {
box-shadow: inset 2px 1px 20px 1px rgba(0, 0, 0, 0.288);
background-color: #ffe77aff;
border: 1px solid black;
display: none;

/* positioning */
position: fixed;
bottom: 50%;
left: 50%;
margin-left: -150px;
}
#smelter-container > * {
color: white;
Expand Down
18 changes: 9 additions & 9 deletions src/js/machines.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ export class Refuel {

// SMELTER EVENT // PLEASE USE WITH ID SMELTER OBJECT INV

const interactiveWindow = (id, s, invObj) => {
s.smelt(id, invObj)
}

document.getElementById("smelter-container").addEventListener("click", (event) => {
const {id} = event.target;
interactiveWindow(id, smelter, inv)
console.log(inv);
});
// const interactiveWindow = (id, s, invObj) => {
// s.smelt(id, invObj);
// };

// document.getElementById("smelter-container").addEventListener("click", (event) => {
// const {id} = event.target;
// interactiveWindow(id, smelter, inv)
// console.log(inv);
// });
67 changes: 45 additions & 22 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function renderText(character) {
$("#playerTree").text(character.inventory.tree);
}

// function lastKnown() {
// return [character.last_x, character.last_y];
// }

$(document).ready(function () {
for (let i = 0; i < 200; i++) {
let divinput = `<div>`;
Expand Down Expand Up @@ -134,6 +138,18 @@ $(document).ready(function () {
}
}, true);

document.getElementById("smelter-container").addEventListener("click", (event) => {
const {id} = event.target;
let smelter = gameworld.world[character.last_x][character.last_y].machine;
let inv = character;
interactiveWindow(id, smelter, inv);
console.log(inv);
});

const interactiveWindow = (id, s, invObj) => {
s.smelt(id, invObj);
};

window.addEventListener("click", function () {
const clicked = event.target;
const currentID = clicked.id || "No ID!";
Expand All @@ -153,12 +169,19 @@ $(document).ready(function () {
} else if (character.toolType === "Hand") {

let thisMachine = gameworld.world[mouse_x][mouse_y].machine;
if (thisMachine != undefined) {
if (thisMachine != undefined && thisMachine.name !== "Smelter") {
thisMachine.withdrawal(character);
if (thisMachine.on == false) {
gameworld.removeMachine(mouse_y, mouse_x); // YES THESE DO NEED TO BE y, x
gameworld.renderChunk(mouse_x, mouse_y, "player hand");
}
} else if (thisMachine.name === "Smelter") {
// Code for the smelter click event
$("#smelter-container").show();
console.log("display UI");
character.last_x = mouse_x;
character.last_y = mouse_y;
// Code for the smelter click event
}

} else if (character.toolType === "Miner") {
Expand Down Expand Up @@ -219,27 +242,27 @@ $(document).ready(function () {
// const player_y = parseInt(character.location_y);
// const mouse_x = parseInt(coords[0]);
// const mouse_y = parseInt(coords[1]);
// if (character.validClick(player_x, player_y, mouse_x, mouse_y)) {
// if (character.toolType === "Hand") {
// if (character.checkInventory("coal") >= 50) {
// let placementResponse = gameworld.addMachine(mouse_x, mouse_y, 50, character.checkInventory("coal"), "Smelter");
// if (placementResponse === "occupied") {
// let thisMachine = gameworld.world[mouse_x][mouse_y].machine;
// thisMachine.withdrawal(character);
// } else if (placementResponse === "success") {
// const machine = new Smelter(mouse_x, mouse_y);
// gameworld.world[mouse_x][mouse_y].machine = machine;
// character.inventory.coal -= 50;
// } else if (placementResponse === "not enough") {
// alert("need more coal to create smelting machine");
// }
// } else {
// alert("need more coal to create smelting machine");
// }
// }
// gameworld.renderChunk(mouse_x, mouse_y, "player hand");
// renderText(character);
// }
// if (character.validClick(player_x, player_y, mouse_x, mouse_y)) {
// if (character.toolType === "Hand") {
// if (character.checkInventory("coal") >= 50) {
// let placementResponse = gameworld.addMachine(mouse_x, mouse_y, 50, character.checkInventory("coal"), "Smelter");
// if (placementResponse === "occupied") {
// let thisMachine = gameworld.world[mouse_x][mouse_y].machine;
// thisMachine.withdrawal(character);
// } else if (placementResponse === "success") {
// const machine = new Smelter(mouse_x, mouse_y);
// gameworld.world[mouse_x][mouse_y].machine = machine;
// character.inventory.coal -= 50;
// } else if (placementResponse === "not enough") {
// alert("need more coal to create smelting machine");
// }
// } else {
// alert("need more coal to create smelting machine");
// }
// }
// gameworld.renderChunk(mouse_x, mouse_y, "player hand");
// renderText(character);
// }
// });

window.addEventListener("mousemove", function (event) { // Get ID of div
Expand Down
8 changes: 5 additions & 3 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default class Player {
this.credits = 0;
this.location_x = x;
this.location_y = y;
this.last_x = 0;
this.lasy_y = 0;
}

addInventory(key, amount) {
Expand Down Expand Up @@ -88,10 +90,10 @@ export default class Player {
// Displays tool material and type as string
// Only use for displays, not functionality.
checkTool() {
if (this.toolType === "Hand") {
return this.toolType;
} else {
if (this.toolType === "Axe" || this.toolType === "Pickaxe") {
return this.toolMaterial + " " + this.toolType;
} else {
return this.toolType;
}
}

Expand Down

0 comments on commit 2ba132e

Please sign in to comment.