mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
no duplicate reward slots
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -11,8 +11,8 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||
<title>Multi Roomba Rover</title>
|
||||
<script type="module" crossorigin src="/assets/index-BaS9tmKz.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-DTYY_hd_.css">
|
||||
<script type="module" crossorigin src="/assets/index-C1njEZEY.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-7nrE9xLC.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -7,7 +7,7 @@ function randLetter() {
|
||||
module.exports = {
|
||||
id: 'chatSpam',
|
||||
name: 'Chat Spam',
|
||||
goal: 50,
|
||||
goal: 100,
|
||||
async run(ctx) {
|
||||
const nickname = randLetter();
|
||||
const messageCount = 100;
|
||||
|
||||
@@ -5,7 +5,7 @@ const { app } = require('../globals/http');
|
||||
const io = require('../globals/io');
|
||||
const logger = require('../globals/logger').child('buttonBoxService');
|
||||
const { publishEvent } = require('./eventBus');
|
||||
const { getRewardById, pickRandomReward } = require('../rewards');
|
||||
const { getRewardById, listRewards } = require('../rewards');
|
||||
const roverManager = require('./roverManager');
|
||||
const { issueCommand } = require('./commandService');
|
||||
const { sendAlert } = require('./alertService');
|
||||
@@ -108,9 +108,11 @@ function loadState() {
|
||||
|
||||
function ensureRewardAssignments() {
|
||||
if (!state) return;
|
||||
const seen = new Set();
|
||||
state.buttons.forEach((button) => {
|
||||
const reward = getRewardById(button.rewardId);
|
||||
if (reward) {
|
||||
if (reward && !seen.has(reward.id)) {
|
||||
seen.add(reward.id);
|
||||
button.rewardName = reward.name || null;
|
||||
button.rewardNumber = reward.number;
|
||||
button.goal = reward.goal;
|
||||
@@ -120,14 +122,27 @@ function ensureRewardAssignments() {
|
||||
return;
|
||||
}
|
||||
assignNewReward(button);
|
||||
if (button.rewardId) {
|
||||
seen.add(button.rewardId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function assignNewReward(button) {
|
||||
const reward = pickRandomReward(button?.rewardId || null) || pickRandomReward(null);
|
||||
if (!reward) {
|
||||
throw new Error('No rewards configured');
|
||||
}
|
||||
const allRewards = listRewards();
|
||||
if (!allRewards.length) throw new Error('No rewards configured');
|
||||
|
||||
const usedByOtherButtons = new Set(
|
||||
state.buttons
|
||||
.filter((entry) => entry.id !== button.id)
|
||||
.map((entry) => entry.rewardId)
|
||||
.filter((rewardId) => typeof rewardId === 'string' && rewardId.length > 0),
|
||||
);
|
||||
const uniqueCandidates = allRewards.filter((reward) => !usedByOtherButtons.has(reward.id));
|
||||
const pool = uniqueCandidates.length ? uniqueCandidates : allRewards;
|
||||
const reward = pool[Math.floor(Math.random() * pool.length)] || null;
|
||||
if (!reward) throw new Error('No rewards configured');
|
||||
|
||||
button.rewardId = reward.id;
|
||||
button.rewardName = reward.name || null;
|
||||
button.rewardNumber = reward.number;
|
||||
|
||||
@@ -89,14 +89,14 @@ export default function ButtonBoxPanel() {
|
||||
const gain = ctx.createGain();
|
||||
osc.type = 'square';
|
||||
osc.frequency.value = freq;
|
||||
const peakGain = 0.08 * effectiveAlertVolume;
|
||||
const peakGain = 0.14 * effectiveAlertVolume;
|
||||
gain.gain.setValueAtTime(0.0001, ctx.currentTime);
|
||||
gain.gain.exponentialRampToValueAtTime(Math.max(0.0001, peakGain), ctx.currentTime + 0.01);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, ctx.currentTime + 0.11);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, ctx.currentTime + 0.2);
|
||||
osc.connect(gain);
|
||||
gain.connect(ctx.destination);
|
||||
osc.start();
|
||||
osc.stop(ctx.currentTime + 0.12);
|
||||
osc.stop(ctx.currentTime + 0.21);
|
||||
}
|
||||
|
||||
function onIncrement(payload = {}) {
|
||||
@@ -142,9 +142,9 @@ export default function ButtonBoxPanel() {
|
||||
<article
|
||||
key={id}
|
||||
className={[
|
||||
'surface px-0.5 py-0.5 text-center transition-colors duration-200',
|
||||
incActive ? 'border border-cyan-400/70 bg-cyan-900/40' : '',
|
||||
rewardActive ? 'border border-fuchsia-400/80 bg-fuchsia-900/40' : '',
|
||||
'surface px-0.5 py-0.5 text-center',
|
||||
incActive ? 'bg-cyan-900/45' : '',
|
||||
rewardActive ? 'bg-fuchsia-900/45' : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')}
|
||||
|
||||
Reference in New Issue
Block a user