Skip to content

Commit aa87512

Browse files
committed
Merge branch 'development'
2 parents db8db37 + 3132072 commit aa87512

File tree

48 files changed

+1308
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1308
-250
lines changed

Diff for: README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ This webapp is still very new and there should be a lot of changes to come in th
3333
### Default overlay:
3434
<img src="./previews/Default.gif" width="480">
3535

36-
I'm always open to new ideas and sugguestions, so if you feel like something could be added or improved feel free to drop me a message on Github or Discord.
36+
I'm always open to new ideas and sugguestions, so if you feel like something could be added or improved feel free to drop me a message on Github or Discord.
37+
38+
### A note to developers:
39+
If you would like a web template for obtaining the data from DataPuller, feel free to use the files in [this](./src/assets/js/overlay/) folder.
40+
In my update for BSDP 2.1 I had patched a bit of the `client.ts` file to make it compatiable with the new `types/` folder, as a result you may want to clean up that file if you wish to use it.
41+
The `types/` folder contains a set of classes and interfaces that can convert any of the data from BSDP version 2.0 and above into a single format that can be used in your peoject, this will save you from having to bother about getting different bits of data for each specific version of BSDP as I have done that for you. All you need to do is pass the json data into the `Parser` class (found in `types/web`) and depending on the data method you passed to, you will recieve the formatted data for that endpoint.

Diff for: src/.todo

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Todo:
2626

2727
//The project is in a good enough state to be made public without these being done. I will work on these in the future but cant really be bothered for this release.
2828
Public release:
29+
☐ Rewrite the client helper to match nicer with the new version parser.
2930
☐ Add scores with modifiers.
3031
☐ Replace browser location when redirected to http (possibly fixed).
3132
☐ Tell the browser to cache the elements for faster loading.
@@ -53,7 +54,7 @@ Todo:
5354
☐ add some browser specific features (styles).
5455
☐ Fix 'history.replaceState' https to http.
5556
☐ Fix arg redirection from 'u-readie...' to 'readie...'.
56-
57+
5758
Optional:
5859
☐ Convert all colours to HSL.
5960
☐ add a rotation option.

Diff for: src/assets/js/overlay/client.ts

+26-168
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Dictionary, Main } from "../main.js";
22
import { EventDispatcher } from "../eventDispatcher.js";
3+
import { Parser, MapData, LiveData } from "./types/web.js";
34

45
export class Client
56
{
@@ -106,177 +107,34 @@ class CustomWebSocket
106107
//setTimeout(() => { this.Connect(); }, 5000); //This is causing the websocket to fill up memory.
107108
}
108109

109-
private OnMessage(ev: MessageEvent<any>): void
110+
private async OnMessage(ev: MessageEvent<any>): Promise<void>
110111
{
111-
var jsonData: MapData | LiveData = JSON.parse(ev.data);
112-
this.eventDispatcher.DispatchEvent("message", jsonData);
113-
if (Main.urlParams.has("debug")) { console.log(jsonData); }
114-
}
115-
}
116-
117-
//Get new data types for these (null)
118-
export type MapData =
119-
{
120-
//Level
121-
InLevel: boolean,
122-
LevelPaused: boolean,
123-
LevelFinished: boolean,
124-
LevelFailed: boolean,
125-
LevelQuit: boolean,
126-
127-
//Map
128-
Hash: string | null,
129-
SongName: string | null,
130-
SongSubName: string | null,
131-
SongAuthor: string,
132-
Mapper: string | null,
133-
BSRKey: string | null,
134-
coverImage: string | null,
135-
Length: number,
136-
TimeScale: number,
137-
138-
//Difficulty
139-
MapType: string | null,
140-
Difficulty: string | null,
141-
CustomDifficultyLabel: string | null,
142-
BPM: number,
143-
NJS: number,
144-
Modifiers:
145-
{
146-
noFailOn0Energy: boolean,
147-
oneLife: boolean,
148-
fourLives: boolean,
149-
noBombs: boolean,
150-
noWalls: boolean,
151-
noArrows: boolean,
152-
ghostNotes: boolean,
153-
disappearingArrows: boolean,
154-
smallNotes: boolean,
155-
proMode: boolean,
156-
strictAngles: boolean,
157-
zenMode: boolean,
158-
slowerSong: boolean,
159-
fasterSong: boolean,
160-
superFastSong: boolean
161-
},
162-
ModifiersMultiplier: number,
163-
PracticeMode: boolean,
164-
PracticeModeModifiers:
165-
{
166-
songSpeedMul: number,
167-
startInAdvanceAndClearNotes: number,
168-
startSongTime: number
169-
},
170-
PP: number,
171-
Star: number,
172-
173-
//Misc
174-
GameVersion: string,
175-
PluginVersion: string,
176-
IsMultiplayer: boolean,
177-
PreviousRecord: number,
178-
PreviousBSR: string | null,
179-
unixTimestamp: number
180-
}
181-
182-
export type LiveData =
183-
{
184-
//Score
185-
Score: number,
186-
ScoreWithMultipliers: number,
187-
MaxScore: number,
188-
MaxScoreWithMultipliers: number,
189-
Rank: string | null,
190-
FullCombo: boolean,
191-
Combo: number,
192-
Misses: number,
193-
Accuracy: number,
194-
BlockHitScore: number[] | null,
195-
PlayerHealth: number,
112+
const deserializedData: object = JSON.parse(ev.data);
196113

197-
//Misc
198-
TimeElapsed: number,
199-
unixTimestamp: number
200-
}
201-
202-
export class SampleData
203-
{
204-
public static readonly mapData: MapData =
205-
{
206-
GameVersion: "1.13.2",
207-
PluginVersion: "2.0.2.0",
208-
InLevel: true,
209-
LevelPaused: false,
210-
LevelFinished: false,
211-
LevelFailed: false,
212-
LevelQuit: false,
213-
Hash: "648B6FE961C398DE638FA1E614878F1194ADF92E",
214-
SongName: "Tera I/O",
215-
SongSubName: "[200 Step]",
216-
SongAuthor: "Camellia",
217-
Mapper: "cerret",
218-
BSRKey: "11a27",
219-
coverImage: `https://readiefur.com/bsdp-overlay/assets/images/TeraIO.jpg`,
220-
Length: 336,
221-
TimeScale: 0,
222-
MapType: "Standard",
223-
Difficulty: "ExpertPlus",
224-
CustomDifficultyLabel: "Normal",
225-
BPM: 200,
226-
NJS: 23,
227-
Modifiers:
114+
//This has been put together in a somewhat sort of hacky way to be compatible with the old (existing) website.
115+
//I would rewrite parts of the site but I can't be bothered to do that right now.
116+
let parsedData: MapData | LiveData | null = null;
117+
try
228118
{
229-
noFailOn0Energy: false,
230-
oneLife: false,
231-
fourLives: false,
232-
noBombs: false,
233-
noWalls: false,
234-
noArrows: false,
235-
ghostNotes: false,
236-
disappearingArrows: true,
237-
smallNotes: false,
238-
proMode: false,
239-
strictAngles: true,
240-
zenMode: false,
241-
slowerSong: false,
242-
fasterSong: false,
243-
superFastSong: false
244-
},
245-
ModifiersMultiplier: 1,
246-
PracticeMode: false,
247-
PracticeModeModifiers:
119+
//This will fail if the data does not contain a "PluginVersion" property/
120+
parsedData = await Parser.ParseMapDataObj(deserializedData);
121+
}
122+
catch
248123
{
249-
songSpeedMul: 1,
250-
startInAdvanceAndClearNotes: 0,
251-
startSongTime: 0
252-
},
253-
PP: 0,
254-
Star: 0,
255-
IsMultiplayer: false,
256-
PreviousRecord: 2714014,
257-
PreviousBSR: "123ba",
258-
unixTimestamp: 1631935482036
259-
}
124+
//If it fails, we can assume the data is a type of LiveData.
125+
//However we still want to try/catch this becuase it could fail if a converter hasn't been loaded yet.
126+
try { parsedData = await Parser.ParseLiveDataObj(deserializedData); }
127+
catch {}
128+
}
260129

261-
public static readonly liveData: LiveData =
262-
{
263-
Score: 574728,
264-
ScoreWithMultipliers: 574728,
265-
MaxScore: 612835,
266-
MaxScoreWithMultipliers: 612835,
267-
Rank: "SS",
268-
FullCombo: false,
269-
Combo: 352,
270-
Misses: 2,
271-
Accuracy: 94.20143961906433,
272-
BlockHitScore:
273-
[
274-
70,
275-
30,
276-
14
277-
],
278-
PlayerHealth: 87,
279-
TimeElapsed: 77,
280-
unixTimestamp: 1631935485375
130+
if (parsedData == null)
131+
{
132+
//If we failed to parse the data, log an error to the console with the input data and return early (drop the message).
133+
console.error("Failed to parse data from websocket.", deserializedData);
134+
return;
135+
}
136+
137+
this.eventDispatcher.DispatchEvent("message", parsedData);
138+
if (Main.urlParams.has("debug")) { console.log(parsedData); }
281139
}
282-
}
140+
}

Diff for: src/assets/js/overlay/overlayHelper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DragElement } from "../dragElement.js";
22
import { Dictionary, Main, ReturnData } from "../main.js";
3-
import { LiveData, MapData } from "./client.js";
3+
import { MapData, LiveData } from "./types/web.js";
44

55
export class OverlayHelper
66
{
@@ -187,4 +187,4 @@ export interface ElementScript
187187
ResetData(): void;
188188
UpdateMapData(data: MapData): void;
189189
UpdateLiveData(data: LiveData): void;
190-
}
190+
}

0 commit comments

Comments
 (0)