Skip to content

Commit

Permalink
rework refiner screen & adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yrahcaz7 committed Jan 10, 2025
1 parent 0e2e47a commit 8279909
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 97 deletions.
69 changes: 19 additions & 50 deletions js/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,63 +340,35 @@ function selection() {
};
// deck selection from refiner
if (game.select[0] === S.REFINER) {
let len = game.deck.length;
let len = refinableDeck.length;
if (action === DIR.LEFT) {
do {
if (game.cardSelect[0] > 0) {
game.cardSelect[0]--;
} else if (game.cardSelect[1] > 0) {
game.cardSelect[0] = 5;
game.cardSelect[1]--;
} else {
break;
};
} while (game.deck[game.cardSelect[0] + (game.cardSelect[1] * 6)].level > 0);
if (game.cardSelect[0] > 0) {
game.cardSelect[0]--;
} else if (game.cardSelect[1] > 0) {
game.cardSelect[0] = 2;
game.cardSelect[1]--;
};
actionTimer = 1;
return;
} else if (action === DIR.RIGHT) {
do {
if (game.cardSelect[0] < 5 && (game.cardSelect[0] < (len - 1) % 6 || game.cardSelect[1] < Math.floor(len / 6))) {
game.cardSelect[0]++;
} else if (game.cardSelect[0] + (game.cardSelect[1] * 6) < len - 1) {
game.cardSelect[0] = 0;
game.cardSelect[1]++;
} else {
break;
};
} while (game.deck[game.cardSelect[0] + (game.cardSelect[1] * 6)].level > 0);
if (game.cardSelect[0] < 2 && (game.cardSelect[0] < (len - 1) % 3 || game.cardSelect[1] < Math.floor(len / 3))) {
game.cardSelect[0]++;
} else if (game.cardSelect[0] + (game.cardSelect[1] * 3) < len - 1) {
game.cardSelect[0] = 0;
game.cardSelect[1]++;
};
actionTimer = 1;
return;
} else if (action === DIR.UP) {
if (game.cardSelect[1] > 0) {
game.cardSelect[1]--;
};
while (game.deck[game.cardSelect[0] + (game.cardSelect[1] * 6)].level > 0) {
if (game.cardSelect[0] > 0) {
game.cardSelect[0]--;
} else if (game.cardSelect[1] > 0) {
game.cardSelect[0] = 5;
game.cardSelect[1]--;
} else {
break;
};
};
actionTimer = 1;
return;
} else if (action === DIR.DOWN) {
if (game.cardSelect[1] < Math.floor(len / 6)) {
if (game.cardSelect[1] < Math.floor(len / 3)) {
game.cardSelect[1]++;
};
while (game.deck[game.cardSelect[0] + (game.cardSelect[1] * 6)]?.level > 0) {
if (game.cardSelect[0] < 5 && (game.cardSelect[0] < (len - 1) % 6 || game.cardSelect[1] < Math.floor(len / 6))) {
game.cardSelect[0]++;
} else if (game.cardSelect[0] + (game.cardSelect[1] * 6) < len - 1) {
game.cardSelect[0] = 0;
game.cardSelect[1]++;
} else {
break;
};
};
actionTimer = 1;
return;
};
Expand Down Expand Up @@ -744,10 +716,11 @@ function performAction() {
if (game.select[1] == 1) {
game.select = [S.REFINER, 0];
} else {
if (game.select[1] == 0) game.deck[game.cardSelect[0] + game.cardSelect[1] * 6].level = 1;
refinableDeck[game.cardSelect[0] + game.cardSelect[1] * 3].level = 1;
refinableDeck = [];
for (let index = 0; index < game.rewards.length; index++) {
if (game.rewards[index] == "1 refiner") {
if (game.select[1] == 0) game.rewards[index] += " - claimed";
game.rewards[index] += " - claimed";
game.select = [S.REWARDS, index];
break;
};
Expand Down Expand Up @@ -903,12 +876,8 @@ function performAction() {
return;
};
// activate refiner
if (game.select[0] === S.REFINER) {
if (game.deck[game.cardSelect[0] + (game.cardSelect[1] * 6)].level == 0) {
game.select = [S.CONF_REFINE, 1];
} else {
game.select = [S.REWARDS, game.rewards.indexOf("1 refiner")];
};
if (game.select[0] === S.REFINER && refinableDeck[game.cardSelect[0] + game.cardSelect[1] * 3]) {
game.select = [S.CONF_REFINE, 1];
actionTimer = 2;
return;
};
Expand Down
14 changes: 8 additions & 6 deletions js/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ const cards = {
/**
* Returns a card's attribute.
* @param {string} attr - the attribute to return.
* @param {number} id - the card's id.
* @param {number} id - the card's id. Defaults to `0`.
* @param {number} level - the card's level. Defaults to `0`.
*/
function getCardAttr(attr, id, level = 0) {
function getCardAttr(attr, id = 0, level = 0) {
if (!cards[id] || cards[id][attr] === null) return;
if (attr == "name") return title(cards[id].name) + "+".repeat(level);
if (typeof cards[id][attr] == "object") {
Expand Down Expand Up @@ -308,14 +308,16 @@ for (const key in cards) {
};

class Card {
id = 0;
level = 0;

/**
* Returns a new card.
* @param {number} id - the card's id.
* @param {number} id - the card's id. Defaults to `0`.
* @param {number} level - the card's level. Defaults to `0`.
*/
constructor(id, level = 0) {
if (cards[id] === undefined) this.id = 0;
else this.id = id;
constructor(id = 0, level = 0) {
this.id = id;
this.level = level;
};
};
Expand Down
1 change: 1 addition & 0 deletions js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ gameplay = ""
+ "Then, you can use your new knowledge and cards to reach higher heights next time.",
changelog = ""
+ "<b>Version 2.1 - Revolution<s>"
+ " - finally reworked the refiner screen!\n"
+ " - added two new options, including auto end turn!\n"
+ " - there is one new artifact (shhhhh... it's a secret)\n"
+ " - some bugfixes and performance optimizations\n"
Expand Down
28 changes: 14 additions & 14 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let global = {
charStage: {
[CHARACTER.KNIGHT]: 0,
},
version: 2,
version: 2.1,
}, game = {
character: CHARACTER.KNIGHT,
difficulty: 0,
Expand Down Expand Up @@ -65,7 +65,7 @@ let global = {
map: [],
traveled: [],
seed: randomize((Math.round(Date.now() * (Math.random() + 0.01)) % (16 ** 6 - 1)).toString(16).toUpperCase()),
}, popups = [], notif = [-1, 0, "", 0], menuLocation = MENU.TITLE, menuSelect = 0, winAnim = 0;
}, popups = [], notif = [-1, 0, "", 0], menuLocation = MENU.TITLE, menuSelect = 0, refinableDeck = [], winAnim = 0;

/**
* Checks if there is any active popups.
Expand Down Expand Up @@ -335,7 +335,7 @@ function loadRoom() {
game.enemies.push(new Enemy(+enemy));
};
};
if (type === ROOM.BOSS || game.floor == 11) fadeMusic();
if (type === ROOM.BOSS || (game.floor > 10 && game.floor % 10 == 1)) fadeMusic();
enterBattle();
} else if (type === ROOM.TREASURE) {
game.traveled.push(+place[1]);
Expand All @@ -359,6 +359,7 @@ function loadRoom() {
game.traveled.push(+place[1]);
game.select = [S.CONF_EVENT, -1];
game.state = STATE.EVENT;
game.rewards = [];
game.turn = 10000;
};
};
Expand Down Expand Up @@ -434,10 +435,6 @@ function updateVisuals() {
if (game.select[0] === SS.SELECT_HAND) graphics.handSelect();
else graphics.hand();
};
if (game.select[0] === S.PURIFIER || game.select[0] === S.CONF_PURIFY || game.select[0] === S.REFINER || game.select[0] === S.CONF_REFINE) {
graphics.rewards(false);
graphics.deck(game.deck);
};
if (game.select[0] === S.MAP) {
graphics.map();
} else if (game.select[0] === S.CONF_EVENT) {
Expand All @@ -461,6 +458,12 @@ function updateVisuals() {
} else if (game.select[0] === S.DISCARD && game.select[1]) {
if (game.select[2] && game.select[2][0] === S.MAP) graphics.map();
graphics.deck(game.discard);
} else if (game.select[0] === S.PURIFIER || game.select[0] === S.CONF_PURIFY) {
graphics.rewards(false);
graphics.deck(game.deck);
} else if (game.select[0] === S.REFINER || game.select[0] === S.CONF_REFINE) {
graphics.rewards(false);
graphics.refiner();
};
if (game.select[0] === S.MAP && game.select[1]) {
graphics.deck(game.deck);
Expand Down Expand Up @@ -537,17 +540,14 @@ function updateVisuals() {
let x = 99, y = 20;
draw.rect("#0008");
draw.box(x + 1, y + 1, 200, 26);
let cardObj = game.deck[game.cardSelect[0] + game.cardSelect[1] * 6];
let cardObj = refinableDeck[game.cardSelect[0] + game.cardSelect[1] * 3];
draw.lore(x + 2, y + 2, "Are you sure you want to improve the card " + getCardAttr("name", cardObj.id, cardObj.level) + "?\nIf you have multiple, this will only improve one copy of the card.", {"text-small": true});
if (game.select[1] == 0) draw.rect("#fff", x + 1, y + 13, 23, 14);
else if (game.select[1] == 1) draw.rect("#fff", x + 23, y + 13, 53, 14);
else draw.rect("#fff", x + 75, y + 13, 29, 14);
else draw.rect("#fff", x + 23, y + 13, 29, 14);
draw.box(x + 3, y + 15, 19, 10);
draw.box(x + 25, y + 15, 49, 10);
draw.box(x + 77, y + 15, 25, 10);
draw.box(x + 25, y + 15, 25, 10);
draw.lore(x + 4, y + 16, "YES");
draw.lore(x + 26, y + 16, "RESELECT");
draw.lore(x + 78, y + 16, "BACK");
draw.lore(x + 26, y + 16, "BACK");
draw.card(cardObj, -1, 51, true, 100, true);
draw.card(new Card(cardObj.id, 1), -1, 51, true, 234, true);
draw.image(I.card.refine, (200 - I.card.refine.width / 2), 95);
Expand Down
98 changes: 76 additions & 22 deletions js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,23 @@ const info = {
if (EFF_DESC[type]) return draw.textBox(x + 71, y, 24, EFF_DESC[type], {"text-small": true});
return draw.textBox(x + 71, y, ("" + type).replace(/<.+?>/g, "").length, type, {"text-small": true});
},
/**
* Draws an infobox for a card in the refinable deck.
* @param {string | number} type - the infobox contains `EFF_DESC[type]`.
* @param {number} xPlus - adds to the x-coordinate of the infobox.
* @param {number} yPlus - adds to the y-coordinate of the infobox.
*/
refinableDeck(type, xPlus = 0, yPlus = 0) {
let x = 72 + (game.cardSelect[0] * 68) + xPlus, y = 15 + (game.cardSelect[1] * 100) - game.deckPos + yPlus;
if (game.cardSelect[0] >= 2) {
const ref = cards[refinableDeck[game.cardSelect[0] + (game.cardSelect[1] * 3)].id];
if (ref.keywords.includes(CARD_EFF.UNPLAYABLE) && ref.rarity <= 1) x -= 143;
else x -= 145;
if (!EFF_DESC[type]) x += (24 - ("" + type).replace(/<.+?>/g, "").length) * 3;
};
if (EFF_DESC[type]) return draw.textBox(x, y, 24, EFF_DESC[type], {"text-small": true});
return draw.textBox(x, y, ("" + type).replace(/<.+?>/g, "").length, type, {"text-small": true});
},
/**
* Draws an infobox for the player.
* @param {number} type - the infobox contains `EFF_DESC[type]`.
Expand Down Expand Up @@ -1412,10 +1429,6 @@ const graphics = {
for (let x = 0, y = 0; x + (y * 6) < len; x++) {
if (x === game.cardSelect[0] && y === game.cardSelect[1] && game.select[0] !== S.CONF_REFINE) {
selected = [x, y];
} else if ((game.select[0] === S.REFINER || game.select[0] === S.CONF_REFINE) && deck[x + (y * 6)].level > 0) {
ctx.globalAlpha = 0.75;
draw.card(deck[x + (y * 6)], -1, 14 + (y * 98) - game.deckPos, false, 2 + (x * 66), inOutsideDeck());
ctx.globalAlpha = 1;
} else {
draw.card(deck[x + (y * 6)], -1, 14 + (y * 98) - game.deckPos, false, 2 + (x * 66), inOutsideDeck());
};
Expand All @@ -1425,22 +1438,14 @@ const graphics = {
};
};
if (selected) {
if ((game.select[0] === S.REFINER || game.select[0] === S.CONF_REFINE) && deck[selected[0] + (selected[1] * 6)].level > 0) {
ctx.globalAlpha = 0.75;
draw.card(deck[selected[0] + (selected[1] * 6)], -1, 14 + (selected[1] * 98) - game.deckPos, true, 2 + (selected[0] * 66), inOutsideDeck());
ctx.globalAlpha = 1;
} else {
draw.card(deck[selected[0] + (selected[1] * 6)], -1, 14 + (selected[1] * 98) - game.deckPos, true, 2 + (selected[0] * 66), inOutsideDeck());
};
draw.card(deck[selected[0] + (selected[1] * 6)], -1, 14 + (selected[1] * 98) - game.deckPos, true, 2 + (selected[0] * 66), inOutsideDeck());
};
if (game.select[0] !== S.CONF_REFINE) {
graphics.target();
selected = game.cardSelect;
if (game.deckPos >= 98 * selected[1]) {
game.deckPos -= Math.min(10, Math.abs(game.deckPos - (98 * selected[1])));
} else if (game.deckPos <= (98 * (selected[1] - 1)) + 11) {
game.deckPos += Math.min(10, Math.abs(game.deckPos - ((98 * (selected[1] - 1)) + 11)));
};
graphics.target();
selected = game.cardSelect;
if (game.deckPos >= 98 * selected[1]) {
game.deckPos -= Math.min(10, Math.abs(game.deckPos - (98 * selected[1])));
} else if (game.deckPos <= (98 * (selected[1] - 1)) + 11) {
game.deckPos += Math.min(10, Math.abs(game.deckPos - ((98 * (selected[1] - 1)) + 11)));
};
};
draw.rect("#0004", 0, 0, 400, 13);
Expand All @@ -1449,9 +1454,54 @@ const graphics = {
else if (game.select[0] === S.VOID) draw.lore(200 - 2, 1, "Void", {"color": "#fff", "text-align": DIR.CENTER});
else if (game.select[0] === S.MAP) draw.lore(200 - 2, 1, "Cards", {"color": "#fff", "text-align": DIR.CENTER});
else if (game.select[0] === S.PURIFIER || game.select[0] === S.CONF_PURIFY) draw.lore(200 - 2, 1, "Purifier: Pick a Card to Destroy", {"color": "#fff", "text-align": DIR.CENTER});
else if (game.select[0] === S.REFINER || game.select[0] === S.CONF_REFINE) draw.lore(200 - 2, 1, "Refiner: Pick a Card to Improve", {"color": "#fff", "text-align": DIR.CENTER});
draw.rect("#fff", 1, 12, 398, 1);
},
/**
* Draws the refiner selection screen on the canvas.
*/
refiner() {
if (refinableDeck.length == 0) {
refinableDeck = game.deck.filter(card => card.level == 0);
if (refinableDeck.length == 0) refinableDeck = [new Card()];
};
draw.rect("#000c");
draw.rect("#fff", 207, 14, 1, 185);
const len = refinableDeck.length;
if (len > 0) {
if (game.cardSelect[0] + (game.cardSelect[1] * 3) >= len) game.cardSelect = [(len - 1) % 3, Math.floor((len - 1) / 3)];
if (game.deckPos > Math.max(100 * (Math.floor((len - 1) / 3) - 1) + 14, 0)) game.deckPos = Math.max(100 * (Math.floor((len - 1) / 3) - 1) + 14, 0);
let selected;
for (let x = 0, y = 0; x + (y * 3) < len; x++) {
if (x === game.cardSelect[0] && y === game.cardSelect[1] && game.select[0] !== S.CONF_REFINE) {
selected = [x, y];
} else if (refinableDeck[x + (y * 3)].level == 0) {
draw.card(refinableDeck[x + (y * 3)], -1, 15 + (y * 100) - game.deckPos, false, 3 + (x * 68), inOutsideDeck());
};
if (x >= 2) {
x = -1;
y++;
};
};
if (selected) {
draw.card(refinableDeck[selected[0] + (selected[1] * 3)], -1, 15 + (selected[1] * 100) - game.deckPos, true, 3 + (selected[0] * 68), true);
};
graphics.target();
selected = game.cardSelect;
if (game.deckPos >= 100 * selected[1]) {
game.deckPos -= Math.min(10, Math.abs(game.deckPos - (100 * selected[1])));
} else if (game.deckPos <= (100 * (selected[1] - 1)) + 14) {
game.deckPos += Math.min(10, Math.abs(game.deckPos - ((100 * (selected[1] - 1)) + 14)));
};
};
draw.rect("#0004", 0, 0, 400, 13);
draw.lore(200 - 2, 1, "Refiner: Pick a Card to Improve", {"color": "#fff", "text-align": DIR.CENTER});
draw.rect("#fff", 1, 12, 398, 1);
let cardObj = refinableDeck[game.cardSelect[0] + (game.cardSelect[1] * 3)];
draw.lore(213, 18, "Press B to go back to the reward selection screen.\n\nPress space or enter to refine the selected card.\n\nA preview of the refined card is shown below.", {"color": "#FFFFFF", "text-small": true});
draw.card(cardObj, -1, 51, true, 213, true);
draw.card(new Card(cardObj.id, 1), -1, 51, true, 329, true);
draw.image(I.card.refine, 305 - I.card.refine.width / 2, 95);
},
/**
* Draws the player's hand on the canvas.
*/
Expand Down Expand Up @@ -1619,10 +1669,14 @@ const graphics = {
info.artifact(game.room[6][game.select[1]], 179 + (game.select[1] * 32), 90);
} else if (game.select[0] === S.DECK && game.select[1] == 1 && game.deckLocal.length) {
graphics.cardInfo("deck", game.deckLocal.slice().cardSort()[game.cardSelect[0] + (game.cardSelect[1] * 6)]);
} else if ((game.select[0] === S.VOID || game.select[0] === S.DISCARD) && game.select[1] == 1 && game[game.select[0] === S.VOID ? "void" : "discard"].length) {
graphics.cardInfo("deck", game[game.select[0] === S.VOID ? "void" : "discard"][game.cardSelect[0] + (game.cardSelect[1] * 6)]);
} else if (game.select[0] === S.DISCARD && game.select[1] == 1 && game.discard.length) {
graphics.cardInfo("deck", game.discard[game.cardSelect[0] + (game.cardSelect[1] * 6)]);
} else if (game.select[0] === S.VOID && game.select[1] == 1 && game.void.length) {
graphics.cardInfo("deck", game.void[game.cardSelect[0] + (game.cardSelect[1] * 6)]);
} else if (game.select[0] === S.CARD_REWARD && game.select[1] > -1 && game.select[1] < get.cardRewardChoices()) {
graphics.cardInfo("reward", new Card(game.room[5][game.select[1]]));
} else if (game.select[0] === S.REFINER || game.select[0] === S.CONF_REFINE) {
graphics.cardInfo("refinableDeck", refinableDeck[game.cardSelect[0] + (game.cardSelect[1] * 3)]);
} else if (inOutsideDeck()) {
graphics.cardInfo("deck", game.deck[game.cardSelect[0] + (game.cardSelect[1] * 6)]);
};
Expand Down
Loading

0 comments on commit 8279909

Please sign in to comment.