Skip to content

Commit

Permalink
try use preset names when displaying trade request in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Jan 28, 2024
1 parent a295939 commit 0898a7e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
17 changes: 14 additions & 3 deletions src/sock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as store from './store.jsx';
import { arenaCost } from './userutil.js';
import { shuffle } from './util.js';
import OrigCards from './vanilla/Cards.js';
import { presets } from './ui.js';

const endpoint = `${location.protocol === 'http:' ? 'ws://' : 'wss://'}
${location.hostname}:${
Expand Down Expand Up @@ -186,6 +187,18 @@ const sockEvents = {
userEmit('challrecv', { f: data.f });
},
offertrade(data) {
let flagstr;
if (data.flags && data.flags.length) {
for (const p of presets) {
if (p[1].length === data.flags.length) {
if (data.flags.every(f => p[1].includes(f))) {
flagstr = p[0];
break;
}
}
}
flagstr ??= data.flag.sort().join(' ');
}
store.chat(() => (
<div
style="cursor:pointer;color:#69f"
Expand All @@ -204,9 +217,7 @@ const sockEvents = {
}
}}>
{`${data.f} offers to trade with you${
data.flags && data.flags.length ?
' using ' + data.flags.join(' ')
: ''
data.flags && data.flags.length ? ' using ' + flagstr : ''
}!`}
</div>
));
Expand Down
22 changes: 22 additions & 0 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,25 @@ export const strcols = [
export function maybeLightenStr(card) {
return strcols[card.element + card.upped * 13];
}
export const presets = [
[
'Spins-only',
['no-shop', 'no-up-pillar'],
'Spending money is not allowed other than battle entry fees. That means no buying packs, & no upgrading pillars! Trading is allowed, but only with other Spins-Only alts.',
],
[
'Spins-only Self-found',
['no-shop', 'no-up-pillar', 'no-trade'],
"Just like Spins-only, but trading is also disabled. You're truly limited to what you can win from the AI.",
],
[
'Spins-only Hard',
['no-shop', 'no-up-pillar', 'hardcore'],
'Just like Spins-only, but everytime you lose, you permanently lost a card form your deck. Trading is allowed, but only with other Spins-only Hardcore alts.',
],
[
'Spins-only Self-found Hard',
['no-shop', 'no-up-pillar', 'no-trade', 'hardcore'],
'Just like Spins-only Self-found, but everytime you lose, you permanently lose a card from your deck. Roguelike mode!',
],
];
25 changes: 1 addition & 24 deletions src/views/Alts.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSignal, createMemo } from 'solid-js';

import { eleNames } from '../ui.js';
import { eleNames, presets } from '../ui.js';
import { userEmit } from '../sock.jsx';
import ExitBtn from '../Components/ExitBtn.jsx';
import * as store from '../store.jsx';
Expand Down Expand Up @@ -38,29 +38,6 @@ function Preset(props) {
);
}

const presets = [
[
'Spins-only',
['no-shop', 'no-up-pillar'],
'Spending money is not allowed other than battle entry fees. That means no buying packs, & no upgrading pillars! Trading is allowed, but only with other Spins-Only alts.',
],
[
'Spins-only Self-found',
['no-shop', 'no-up-pillar', 'no-trade'],
"Just like Spins-only, but trading is also disabled. You're truly limited to what you can win from the AI.",
],
[
'Spins-only Hard',
['no-shop', 'no-up-pillar', 'hardcore'],
'Just like Spins-only, but everytime you lose, you permanently lost a card form your deck. Trading is allowed, but only with other Spins-only Hardcore alts.',
],
[
'Spins-only Self-found Hard',
['no-shop', 'no-up-pillar', 'no-trade', 'hardcore'],
'Just like Spins-only Self-found, but everytime you lose, you permanently lose a card from your deck. Roguelike mode!',
],
];

function Flags(props) {
for (const p of presets) {
if (p[1].length === props.flags.length) {
Expand Down

0 comments on commit 0898a7e

Please sign in to comment.