Skip to content

Commit

Permalink
work on parser
Browse files Browse the repository at this point in the history
  • Loading branch information
konekowo committed Jun 18, 2024
1 parent 5b7169a commit 3f775b5
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/Util/Beatmap/Data/BeatmapData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import {GeneralData} from "./Sections/General/GeneralData";
import {EditorData} from "./Sections/Editor/EditorData";
import {Metadata} from "./Sections/Metadata/Metadata";
import {DifficultyData} from "./Sections/Difficulty/DifficultyData";
import {EventsData} from "./Sections/Events/EventsData";

/**
* <a href="https://osu.ppy.sh/wiki/en/Client/File_formats/osu_%28file_format%29">.osu (file format)</a>
*/
export class BeatmapData {
/**
* General information about the beatmap
Expand All @@ -15,5 +20,12 @@ export class BeatmapData {
* <a href="https://osu.ppy.sh/wiki/en/Client/Beatmap_editor/Song_setup#general">Information</a> used to identify the beatmap
*/
public Metadata: Metadata = new Metadata();

/**
* <a href="https://osu.ppy.sh/wiki/en/Client/Beatmap_editor/Song_setup#difficulty">Difficulty settings</a>
*/
public Difficulty: DifficultyData = new DifficultyData();
/**
* Beatmap and storyboard graphic events
*/
public Events: EventsData = new EventsData();
}
29 changes: 29 additions & 0 deletions src/Util/Beatmap/Data/Sections/Difficulty/DifficultyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* <a href="https://osu.ppy.sh/wiki/en/Client/Beatmap_editor/Song_setup#difficulty">Difficulty settings</a>
*/
export class DifficultyData {
/**
* HP setting (0–10)
*/
public HPDrainRate!: number;
/**
* CS setting (0–10)
*/
public CircleSize!: number;
/**
* OD setting (0–10)
*/
public OverallDifficulty!: number;
/**
* AR setting (0–10)
*/
public ApproachRate!: number;
/**
* Base slider velocity in hundreds of <a href="https://osu.ppy.sh/wiki/en/Client/Beatmap_editor/osu%21_pixel">osu! pixels</a> per beat
*/
public SliderMultiplier!: number;
/**
* Amount of slider ticks per beat
*/
public SliderTickRate!: number;
}
2 changes: 1 addition & 1 deletion src/Util/Beatmap/Data/Sections/Editor/EditorData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class EditorData {
/**
* Time in milliseconds of <a href="https://osu.ppy.sh/wiki/en/Client/Beatmap_editor/Compose#song-timeline">bookmarks</a>
*/
public Bookmarks: number[] | undefined;
public Bookmarks: number[] = [];
/**
* <a href="https://osu.ppy.sh/wiki/en/Client/Beatmap_editor/Distance_snap">Distance snap</a> multiplier
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {EventTypes} from "./EventTypes";

export class Event {
/**
* Type of the event. Some events may be referred to by either a name or a number.
*/
public eventType!: EventTypes;
/**
* Start time of the event, in milliseconds from the beginning of the beatmap's audio. For events that do not use a start time, the default is 0.
*/
public startTime: number = 0;
/**
* Extra parameters specific to the event's type.
*/
public eventParams!: (string | number)[];
}
23 changes: 23 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/EventBackground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Event} from "./Event";
import {EventTypes} from "./EventTypes";
export class EventBackground extends Event {
public eventType = EventTypes.BACKGROUND;
public startTime = 0;
/**
* Location of the background image relative to the beatmap directory. Double quotes are
* usually included surrounding the filename, but they are not required.
*/
public filename!: string;
/**
* Offset in osu! pixels from the centre of the screen.
* For example, an offset of 50,100 would have the background shown 50 osu! pixels to the
* right and 100 osu! pixels down from the centre of the screen. If the offset is 0,0, writing it is optional.
*/
public xOffset!: number;
/**
* Offset in osu! pixels from the centre of the screen.
* For example, an offset of 50,100 would have the background shown 50 osu! pixels to the
* right and 100 osu! pixels down from the centre of the screen. If the offset is 0,0, writing it is optional.
*/
public yOffset!: number;
}
7 changes: 7 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/EventTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum EventTypes {
BACKGROUND = 0,
VIDEO = "Video",
// storyboard
SPRITE = "Sprite",
ANIMATION = "Animation"
}
8 changes: 8 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/EventVideo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Event} from "./Event";
import {EventTypes} from "./EventTypes";

export class EventVideo extends Event {
public eventType = EventTypes.VIDEO;
public startTime = 0;

}
8 changes: 8 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/EventsData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Event} from "./Event";

/**
* Beatmap and storyboard graphic events
*/
export class EventsData {
public Events: Event[] = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {EventStoryboard} from "./EventStoryboard";
import {EventTypes} from "../EventTypes";

export class EventSprite extends EventStoryboard {
public eventType = EventTypes.SPRITE;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {StoryboardCommand} from "./StoryboardCommand";
import {Event} from "../Event";
import {Layer} from "./Layer";
import {Origin} from "./Origin";

export class EventStoryboard extends Event {
public startTime = -1;
/**
* Each <a href="https://osu.ppy.sh/wiki/en/Storyboard/Scripting/Objects">object declaration</a>
* is followed by one or more commands. These tell the object to do something, called an event,
* such as move or change colour. You can think of each command as affecting a variable
* (or set of variables) for that object; once a command is finished, the object keeps those values until
* another command changes it. Objects who don't have a particular type of
* command used will use the default value for that variable.
*/
public Commands: StoryboardCommand[] = [];
/**
* (layer) is the <a href="https://osu.ppy.sh/wiki/en/Storyboard/Scripting/General_Rules">layer</a>
* the object appears on.
*/
public layer!: Layer;
/**
* (origin) is where on the image should osu! consider that image's origin (coordinate)
* to be. This affects the (x) and (y) values, as well as several other command-specific
* behaviours. For example, choosing (origin) = TopLeft will let the (x),(y) values determine,
* where the top left corner of the image itself should be on the screen. The valid values are listed below.
*/
public origin!: Origin;
/**
* (filepath) is, in laymans terms, the filename of the image you want. But it's not always quite that simple:
* - If you have a subfolder inside your Song Folder, you need to include that, as well.
* - Example: "backgrounds/sky.jpg" if you have a subfolder called "backgrounds" with an image called "sky.jpg" in it.
* Start listing directories only from the Song Folder, where the .osu or .osb file is (i.e., a relative filepath).
* It should not have something like "C:" anywhere in it.
* - Animations are referred to without their number. So if you have "sample0.png" and "sample1.png" as two frames
* to make a single animation, you want to refer to it as "sample.png".
* - The ""s are technically optional, but they're required if your filename or subfolder name has spaces.
* - Example: "SB/J_K.jpg" rather than SB/J_K.jpg. The prior will find in SB folder for J_K.jpg while the later will
* null the instance (it finds SB/J, an invalid variable).
*/
public filepath!: string;

}
6 changes: 6 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/Storyboard/Layer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum Layer {
Background = 0,
Fail = 1,
Pass = 2,
Foreground = 3
}
15 changes: 15 additions & 0 deletions src/Util/Beatmap/Data/Sections/Events/Storyboard/Origin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum Origin {
TopLeft = 0,
Centre = 1,
CentreLeft = 2,
TopRight = 3,
BottomCentre = 4,
TopCentre = 5,
/**
* (same effect as TopLeft, but should not be used)
*/
Custom = 6,
CentreRight = 7,
BottomLeft = 8,
BottomRight = 9
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {StoryboardCompoundCommand} from "./StoryboardCompoundCommand";

export class StoryboardCommand {
public CompoundCommands: StoryboardCompoundCommand[] = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class StoryboardCompoundCommand {

}
2 changes: 1 addition & 1 deletion src/Util/Beatmap/Parser/BeatmapParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {BeatmapData} from "../Data/BeatmapData";

export class BeatmapParser {
public static parse(osuFileContent: string): BeatmapData {
public static parse(osuFileContent: string, storyBoardFileContent?: string): BeatmapData {
// TODO: parse .osu! file
return new BeatmapData();
}
Expand Down

0 comments on commit 3f775b5

Please sign in to comment.