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