Skip to content

Commit cdef150

Browse files
authored
Post event bug fixes (#18)
* First batch of post event fixes * Improve game info box * Better url parsing for tracker * Fix 1v1 bidwars not updating when pinned * Fix multi bidwars not updating when pinned * Cleanup * Apply mask to fade out war * Move over last el a bit * Add arrow mask * Development for dummies * Fix default theme * Store css vars in a prop
1 parent c6d210f commit cdef150

File tree

16 files changed

+382
-205
lines changed

16 files changed

+382
-205
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Alternatively, you can use [DeaDBeeF](https://deadbeef.sourceforge.io/) with the
7070
* https://calculateaspectratio.com/ for helping me (duncte) wiht some math
7171
7272
## Development
73+
***Install nodecg first before doing anything else***
74+
7375
To get this bundle set-up for development run the following commands.
7476
***Make sure to install speedcontrol!***
7577
> ```

configschema.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"properties": {
4848
"theme": {
4949
"$comment": "Theme to be used in the graphical overlays; will use default if none supplied.",
50-
"type": "string"
50+
"type": "string",
51+
"default": "bsg"
5152
},
5253
"shorts": {
5354
"$comment": "This/these must match the tracker, if that feature is enabled.",
@@ -99,7 +100,8 @@
99100
"required": [
100101
"shorts",
101102
"thisEvent",
102-
"online"
103+
"online",
104+
"theme"
103105
]
104106
},
105107
"omnibar": {

layout_assets/arrow mask.png

6.95 KB
Loading

src/extension/omnibar.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ function getPrize(): Prizes[0] | undefined {
5050

5151
// Gets a random (but weighted) active milestone.
5252
let lastBidId = -1;
53-
function getBid(): Bids[0] | undefined {
53+
54+
function getClonedBid(): Bids[0] | undefined {
5455
// Just return nothing if there are no bids to show.
5556
if (!bids.value.length) return undefined;
5657
let filtered = clone(bids.value).filter((b) => b.id !== lastBidId);
@@ -90,13 +91,16 @@ let loopsWithoutResult = 0;
9091
async function showNext(): Promise<void> {
9192
// If there is a pin to start showing.
9293
const { pin } = omnibar.value;
94+
9395
if (pin) {
9496
let item: DonationTotalMilestones[0] | Bids[0] | undefined;
97+
9598
if (pin.type === 'Milestone') {
9699
item = donationTotalMilestones.value.find((m) => m.id === pin.id);
97100
} else if (pin.type === 'Bid') {
98101
item = bids.value.find((b) => b.id === pin.id);
99102
}
103+
100104
if (item) {
101105
item = clone(item);
102106
nodecg().log.debug('[Omnibar] Pin available, will show:', pin.type);
@@ -115,6 +119,7 @@ async function showNext(): Promise<void> {
115119
id: uuid(),
116120
props: {
117121
seconds: -1,
122+
bidId: pin.type === 'Bid' ? item.id : undefined,
118123
bid: pin.type === 'Bid' ? item : undefined,
119124
milestone: pin.type === 'Milestone' ? item : undefined,
120125
dash: dashConfig,
@@ -201,12 +206,13 @@ async function showNext(): Promise<void> {
201206
},
202207
};
203208
} else if (next.type === 'Bid') {
204-
const bid = getBid();
209+
const bid = getClonedBid();
205210
if (!bid) { showNext(); return; }
206211
omnibar.value.current = { ...next,
207212
props: {
208213
...next.props,
209214
bid,
215+
bidId: bid.id,
210216
dash: {
211217
text: bid.war ? 'Upcoming Bid War' : 'Upcoming Goal',
212218
fontSize: 34,

src/extension/tracker/bids.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import needle from 'needle';
33
import { eventInfo, getCookies } from '.';
44
import { get as nodecg } from '../util/nodecg';
55
import { bids } from '../util/replicants';
6-
import utils from './utils';
7-
8-
const { trackerUrl } = utils;
6+
import { trackerUrl } from './utils';
97

108
const eventConfig = nodecg().bundleConfig.event;
119
const { useTestData } = nodecg().bundleConfig;
@@ -61,12 +59,23 @@ function processRawBids(rawBids: Tracker.Bid[]): Tracker.FormattedBid[] {
6159
// Sort bid war options from largest to smallest.
6260
if (bid.options && bid.options.length) {
6361
bid.options = bid.options.sort((a, b) => {
64-
if (a.total > b.total) {
65-
return -1;
66-
}
67-
if (a.total < b.total) {
62+
// TODO: revert if we want this
63+
// if (a.total > b.total) {
64+
// return -1;
65+
// }
66+
// if (a.total < b.total) {
67+
// return 1;
68+
// }
69+
// return 0;
70+
71+
if (a.id > b.id) {
6872
return 1;
6973
}
74+
75+
if (a.id < b.id) {
76+
return -1;
77+
}
78+
7079
return 0;
7180
});
7281
}
@@ -103,22 +112,29 @@ async function updateBids(): Promise<void> {
103112
cookies: getCookies(),
104113
},
105114
);
115+
106116
if (!resp.statusCode || resp.statusCode >= 300 || resp.statusCode < 200) {
107117
throw new Error(`status code ${resp.statusCode ?? 'unknown'}`);
108118
}
119+
109120
if (!Array.isArray(resp.body)) {
110121
throw new Error('received non-array type');
111122
}
123+
112124
const currentBids = processRawBids(resp.body);
125+
113126
if (!Array.isArray(currentBids)) {
114127
throw new Error('currentBids result was non-array type');
115128
}
129+
130+
nodecg().log.debug('[Tracker] Updated bids:', JSON.stringify(currentBids));
116131
bids.value = currentBids;
117132
} catch (err) {
118133
nodecg().log.warn('[Tracker] Error updating bids');
119134
nodecg().log.debug('[Tracker] Error updating bids:', err);
120135
bids.value.length = 0; // Clear the array so we do not display incorrect information.
121136
}
137+
122138
setTimeout(updateBids, refreshTime);
123139
}
124140

src/extension/tracker/donations.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import needle from 'needle';
33
import { get as nodecg } from '../util/nodecg';
44
import { donationsToRead } from '../util/replicants';
55
import { eventInfo, getCookies } from './index';
6-
import utils from './utils';
7-
8-
const { trackerUrl } = utils;
6+
import { trackerUrl } from './utils';
97

108
const eventConfig = nodecg().bundleConfig.event;
119
const { useTestData } = nodecg().bundleConfig;

src/extension/tracker/index.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import type { DeepWritable } from 'ts-essentials';
88
import { get as nodecg } from '../util/nodecg';
99
import { mq } from '../util/rabbitmq';
1010
import { donationTotal } from '../util/replicants';
11-
import utils from './utils';
12-
13-
const { trackerUrl } = utils;
11+
import { trackerUrl, trackerAdminUrl } from './utils';
1412

1513
export const eventInfo: Tracker.EventInfo[] = [];
1614
const eventConfig = nodecg().bundleConfig.event;
@@ -200,7 +198,7 @@ async function loginToTracker(): Promise<void> {
200198
if (isFirstLogin) nodecg().log.info('[Tracker] Logging in');
201199
else nodecg().log.info('[Tracker] Refreshing session');
202200

203-
const loginURL = `https://${config.address}/admin/login/`;
201+
const loginURL = trackerAdminUrl('/login/');
204202
try {
205203
// Access login page to get CSRF token.
206204
const resp1 = await needle('get', loginURL);
@@ -225,8 +223,15 @@ async function loginToTracker(): Promise<void> {
225223
},
226224
);
227225

226+
nodecg().log.debug('[Tracker] Login response:', {
227+
status: resp2.statusCode,
228+
body: resp2.body,
229+
headers: resp2.headers,
230+
cookies: resp2.cookies,
231+
});
232+
228233
// If we're not being redirected or there's no session token, the login failed.
229-
if (resp2.statusCode !== 302 || (resp2.cookies && !resp2.cookies.tracker_session)) {
234+
if (resp2.statusCode !== 302 || (resp2.cookies && !resp2.cookies.sessionid)) {
230235
throw new Error('Log in was unsuccessful, is your username/password correct?');
231236
}
232237

@@ -294,7 +299,13 @@ async function setup(): Promise<void> {
294299
// Update the donation total to a random number while testing
295300
if (useTestData) {
296301
setInterval(() => {
297-
donationTotal.value += Math.random() * 1000;
302+
let newDonoAmount = donationTotal.value + (Math.random() * 1000);
303+
304+
if (newDonoAmount > 70_000) {
305+
newDonoAmount = 0;
306+
}
307+
308+
donationTotal.value = newDonoAmount;
298309
nodecg().sendMessage('donationTotalUpdated', { total: donationTotal.value });
299310
}, 10 * 1000);
300311
}

src/extension/tracker/prizes.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import needle from 'needle';
33
import { eventInfo, getCookies } from '.';
44
import { get as nodecg } from '../util/nodecg';
55
import { prizes } from '../util/replicants';
6-
import utils from './utils';
7-
8-
const { trackerUrl } = utils;
6+
import { trackerUrl } from './utils';
97

108
const { useTestData } = nodecg().bundleConfig;
119
const refreshTime = 60 * 1000; // Get prizes every 60s.

src/extension/tracker/utils.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@ import { get as nodecg } from '@esa-layouts/util/nodecg';
22

33
const config = nodecg().bundleConfig.tracker;
44

5-
function trackerUrl(path: string): string {
6-
return `https://${config.address}/tracker${path}`;
5+
function getTrackerBaseUrl(): string {
6+
const addr = config.address;
7+
const proto = addr.startsWith('http') ? '' : 'https://';
8+
9+
return `${proto}${addr}`;
10+
}
11+
12+
export function trackerUrl(path: string): string {
13+
const addr = getTrackerBaseUrl();
14+
15+
return `${addr}/tracker${path}`;
716
}
817

9-
export default {
10-
trackerUrl,
11-
};
18+
export function trackerAdminUrl(path: string): string {
19+
const addr = getTrackerBaseUrl();
20+
21+
return `${addr}/admin${path}`;
22+
}

src/graphics/game-layout/16x9-1p-largecam.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
height: '176px',
3434
}"
3535
>
36-
<run-info text-align="left" line-right/>
36+
<run-info text-align="left" line-right info-is-row/>
3737
</div>
3838

3939
<!-- Timer -->

src/graphics/game-layout/16x9-1p.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
height: '176px',
6464
}"
6565
>
66-
<run-info text-align="left" />
66+
<run-info text-align="left" info-is-row />
6767
</div>
6868

6969
<!-- Media Box / Reader / Comms -->

src/graphics/game-layout/components/GameCapture.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default class extends Vue {
9191
9292
@Watch('x32GameAudio')
9393
onX32GameAudioChange(newVal: ChanData[]): void {
94-
if (this.gameLayouts?.selected?.endsWith('1p')) {
94+
if (this.gameLayouts?.selected?.includes('-1p')) {
9595
this.showSpeakerIcon = false;
9696
return;
9797
}

0 commit comments

Comments
 (0)