Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
abstrakt8 committed Sep 16, 2021
2 parents 23a30a6 + 9cfadb1 commit 4c348f9
Show file tree
Hide file tree
Showing 52 changed files with 563 additions and 271 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 abstrakt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This file was deleted.

3 changes: 0 additions & 3 deletions apps/desktop-frontend/src/app/electron/electron-api.ts

This file was deleted.

15 changes: 12 additions & 3 deletions apps/desktop/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
"extends": "../../.eslintrc.json",
"ignorePatterns": ["!**/*"],
"overrides": [
{ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], "rules": {} },
{ "files": ["*.ts", "*.tsx"], "rules": {} },
{ "files": ["*.js", "*.jsx"], "rules": {} }
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
5 changes: 4 additions & 1 deletion libs/api/common/src/blueprints/LocalBlueprintController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class LocalBlueprintController {
async redirectToFolder(@Res() res: Response, @Param("md5hash") md5hash: string, @Param("file") file: string) {
const blueprintMetaData = await this.blueprint(md5hash);
const { folderName } = blueprintMetaData;
const url = `/static/songs/${folderName}/${file}`;
// We need to encode the URI components for cases such as:
// "E:\osu!\Songs\1192060 Camellia - #1f1e33\Camellia - #1f1e33 (Realazy) [Amethyst Storm].osu"
// The two `#` characters need to be encoded to `%23` in both cases.
const url = `/static/songs/${encodeURIComponent(folderName)}/${encodeURIComponent(file)}`;
res.redirect(url);
}
}
2 changes: 1 addition & 1 deletion libs/api/common/src/replays/LocalReplayController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LocalReplayService } from "./LocalReplayService";
*/
@Controller("replays")
export class LocalReplayController {
private logger = new Logger("LocalReplayController");
private logger = new Logger(LocalReplayController.name);

constructor(private localReplayService: LocalReplayService) {}

Expand Down
5 changes: 3 additions & 2 deletions libs/api/common/src/skins/SkinController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export class SkinController {
const { hd, animated, name } = query;
const hdIfExists = hd === 1;
const animatedIfExists = animated === 1;
this.logger.log(`Skin requested ${name} with hd=${hdIfExists} animated=${animatedIfExists}`);
const decodedName = decodeURIComponent(name);
this.logger.log(`Skin requested ${decodedName} with hd=${hdIfExists} animated=${animatedIfExists}`);
// TODO: Inject these parameters ...
const info = await this.skinService.getSkinInfo(name);
const info = await this.skinService.getSkinInfo(decodedName);
res.json(info);
}
}
8 changes: 4 additions & 4 deletions libs/api/common/src/skins/SkinNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const SKIN_NAME_RESOLVER_CONFIG = "SkinsFolderConfig";
export class SkinNameResolver {
constructor(@Inject(SKIN_NAME_RESOLVER_CONFIG) private readonly skinNameResolverConfig: SkinNameResolverConfig) {}

resolveNameToPath(name: string): string | null {
const [prefix, ...path] = name.split("/");
const folderPath = this.skinNameResolverConfig.find((c) => c.prefix === prefix);
resolveNameToPath(name: string) {
const [source, folder] = name.split("/");
const folderPath = this.skinNameResolverConfig.find((c) => c.prefix === source);
if (folderPath === undefined) {
return null;
}
return join(folderPath.path, ...path);
return { source, name: folder, path: join(folderPath.path, folder) };
}
}
70 changes: 62 additions & 8 deletions libs/api/common/src/skins/SkinService.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,83 @@
import { Injectable, Logger } from "@nestjs/common";
import { SkinFolderReader } from "@rewind/osu-local/skin-reader";
import { GetTextureFileOption, OsuSkinTextureResolver, SkinFolderReader } from "@rewind/osu-local/skin-reader";
import { SkinNameResolver } from "./SkinNameResolver";
import { DEFAULT_SKIN_TEXTURE_CONFIG, OsuSkinTextures } from "@rewind/osu/skin";

const OSU_DEFAULT_SKIN_ID = "rewind/OsuDefaultSkin";

@Injectable()
export class SkinService {
private logger = new Logger(SkinService.name);

constructor(private readonly skinNameResolver: SkinNameResolver) {}

/**
* In the future we also want to get the skin info with the beatmap as the parameters in order to retrieve
* beatmap related skin files as well.
*/

async resolve(
osuSkinTexture: OsuSkinTextures,
options: GetTextureFileOption,
list: { prefix: string; resolver: OsuSkinTextureResolver }[],
) {
for (const { prefix, resolver } of list) {
const filePaths = await resolver.resolve(osuSkinTexture, options);
if (filePaths.length === 0) {
continue;
}
return filePaths.map((path) => `${prefix}/${path}`);
}
this.logger.warn(`No skin has the skin texture ${osuSkinTexture}`);
return [];
}

/**
* @param skinName will be resolved through the given skin name resolver.
*/
async getSkinInfo(skinName: string) {
const path = this.skinNameResolver.resolveNameToPath(skinName);
if (path === null) {
this.logger.error(`Skin ${skinName} could not be resolved to a path.`);
throw new Error("Skin not found");
this.logger.log(`Getting skin info for name=${skinName}`);

const resolved = this.skinNameResolver.resolveNameToPath(skinName);
if (resolved === null) {
// Maybe error will be logged through middleware?
throw new Error(`Skin ${skinName} could not be found in the folders`);
}
const { name, path, source } = resolved;

const osuDefaultSkinResolver = await SkinFolderReader.getSkinResolver(
this.skinNameResolver.resolveNameToPath(OSU_DEFAULT_SKIN_ID)?.path,
);
const skinResolver = await SkinFolderReader.getSkinResolver(path);
// TODO: Include default osu! skin
// const defaultSkinResolver = await SkinFolderReader.getSkinResolver("");
const { config } = skinResolver;

// Load from local config ?
const { hdIfExists, animatedIfExists } = { hdIfExists: true, animatedIfExists: true };
// TODO: Give through params
const option = { hdIfExists: true, animatedIfExists: true };

const files = await skinResolver.resolveAllTextureFiles({ hdIfExists, animatedIfExists });
// const files = await skinResolver.resolveAllTextureFiles({ hdIfExists, animatedIfExists });
const skinTextureKeys = Object.keys(DEFAULT_SKIN_TEXTURE_CONFIG);
const files = await Promise.all(
skinTextureKeys.map(async (key) => ({
key,
paths: await this.resolve(key as OsuSkinTextures, option, [
// In the future beatmap stuff can be listed here as well
{
prefix: ["static", "skins", source, name].map(encodeURIComponent).join("/"),
resolver: skinResolver,
},
{
prefix: ["static", "skins", "rewind", "OsuDefaultSkin"].map(encodeURIComponent).join("/"),
resolver: osuDefaultSkinResolver,
},
// {
// prefix: `/static/skins/${encodeURIComponent(skinName)}`,
// resolver: defaultSkinResolver,
// },
]),
})),
);

return { config, files };
}
Expand Down
3 changes: 1 addition & 2 deletions libs/api/desktop/test/setup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as request from "supertest";
import { setupBootstrap } from "@rewind/api/desktop";
import { INestApplication } from "@nestjs/common";
import { DesktopConfigService } from "../src/config/DesktopConfigService";
import { join } from "path";
Expand All @@ -17,7 +16,7 @@ describe("Setup E2E", () => {
let app: INestApplication;

beforeAll(async () => {
app = await setupBootstrap({ userDataPath: applicationDataPath });
// app = await setupBootstrap({ userDataPath: applicationDataPath });
});

it("/GET desktop", () => {
Expand Down
18 changes: 0 additions & 18 deletions libs/electron/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
export interface ElectronAPI {
getAppVersion: () => Promise<string>;
platform: string;
}

export const validSendChannels = ["openDirectorySelect", "reboot"] as const;
export type ValidSendChannel = typeof validSendChannels[number];

export const validReceiveChannels = ["directorySelected"] as const;
export type ValidReceiveChannel = typeof validReceiveChannels[number];

type Destroyer = () => void;

export interface SecureElectronAPI {
send: (channel: ValidSendChannel, ...args: string[]) => void;
receive: (channel: ValidReceiveChannel, func: (...args: any[]) => void) => Destroyer;
}

export interface FrontendPreloadAPI {
getAppVersion: () => Promise<string>;
getPlatform: () => Promise<string>; // actually NodeJS.Platform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sprite, Texture } from "pixi.js";
import { inject, injectable } from "inversify";
import { StageViewService } from "../../StageViewService";
import { STAGE_HEIGHT, STAGE_WIDTH } from "../stage/GameStagePreparer";
import { STAGE_WIDTH } from "../stage/GameStagePreparer";
import type { RewindTextureMap } from "../../../STAGE_TYPES";
import { STAGE_TYPES } from "../../../STAGE_TYPES";

Expand All @@ -22,9 +22,8 @@ export class BackgroundPreparer {
}

prepare() {
// this.background.texture = this.textureManager.getTexture("BACKGROUND");
this.background.width = STAGE_WIDTH;
this.background.height = STAGE_HEIGHT;
const scaling = STAGE_WIDTH / this.background.texture.width;
this.background.scale.set(scaling, scaling);

this.background.alpha = this.theaterViewService.getView().backgroundDim;
return this.background;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject, injectable } from "inversify";
import { GameSimulator } from "../../GameSimulator";
import { Container, Text } from "pixi.js";
import { AnalysisHitErrorBar } from "../../../../pixi/components/HitErrorBar";
import { OsuClassicHitErrorBar } from "@rewind/osu-pixi/classic-components";
import { calculateDigits, OsuClassicAccuracy, OsuClassicNumber } from "@rewind/osu-pixi/classic-components";
import { hitWindowsForOD } from "@rewind/osu/math";
import { STAGE_HEIGHT, STAGE_WIDTH } from "../stage/GameStagePreparer";
Expand All @@ -13,7 +13,7 @@ import { STAGE_TYPES } from "../../../STAGE_TYPES";
export class ForegroundHUDPreparer {
container: Container;
stats: Text;
hitErrorBar: AnalysisHitErrorBar;
hitErrorBar: OsuClassicHitErrorBar;

constructor(
@inject(STAGE_TYPES.BEATMAP) private readonly beatmap: Beatmap,
Expand All @@ -22,7 +22,7 @@ export class ForegroundHUDPreparer {
) {
this.container = new Container();
this.stats = new Text("", { fontSize: 16, fill: 0xeeeeee, fontFamily: "Arial", align: "left" });
this.hitErrorBar = new AnalysisHitErrorBar();
this.hitErrorBar = new OsuClassicHitErrorBar();
}

prepare() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Container } from "pixi.js";
import { OsuClassicCursor } from "@rewind/osu-pixi/classic-components";
import { findIndexInReplayAtTime, interpolateReplayPosition } from "../../../../../utils/Replay";
import { AnalysisCursor } from "../../../../pixi/components/AnalysisCursor";
import { AnalysisCursor } from "@rewind/osu-pixi/rewind";
import { OsuAction } from "@rewind/osu/core";
import { inject, injectable } from "inversify";
import { STAGE_TYPES } from "../../../STAGE_TYPES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
OsuClassicSliderTick,
SliderBodySettings,
} from "@rewind/osu-pixi/classic-components";
import { RGB, Vec2 } from "@rewind/osu/math";
import { sliderRepeatAngle } from "../../../../../utils/Sliders";
import { RGB, sliderRepeatAngle, Vec2 } from "@rewind/osu/math";
import { GameplayClock } from "../../../core/GameplayClock";
import { StageViewService } from "../../StageViewService";
import { StageSkinService } from "../../../StageSkinService";
import { injectable } from "inversify";
import { TemporaryObjectPool } from "../../../../pixi/pooling/TemporaryObjectPool";
import { TemporaryObjectPool } from "../../../pooling/TemporaryObjectPool";
import { SliderTextureService } from "../../SliderTextureService";

const DEBUG_FOLLOW_CIRCLE_COLOR = 0xff0000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class BlueprintService {
constructor(@inject(TYPES.API_URL) private apiUrl: string, private readonly textureManager: TextureManager) {}

async retrieveBlueprint(blueprintId: string) {
const url = `${this.apiUrl}/api/blueprints/${blueprintId}/osu`;
const url = `${this.apiUrl}/api/blueprints/${encodeURIComponent(blueprintId)}/osu`;
const res = await fetch(url);
const data = await res.text();
// TODO: Emit
Expand All @@ -29,7 +29,7 @@ export class BlueprintService {
// - (?) Storyboard

async retrieveBlueprintResources(blueprintId: string) {
const url = `${this.apiUrl}/api/blueprints/${blueprintId}/bg`;
const url = `${this.apiUrl}/api/blueprints/${encodeURIComponent(blueprintId)}/bg`;
return this.textureManager.loadTexture("BACKGROUND", url);
}
}
3 changes: 2 additions & 1 deletion libs/feature-replay-viewer/src/app/theater/ReplayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class ReplayService {
constructor(@inject(TYPES.API_URL) private apiUrl: string) {}

async retrieveReplay(replayId: string): Promise<OsuReplay> {
const url = [this.apiUrl, "api", "replays", "exported", replayId].join("/");
const url = [this.apiUrl, "api", "replays", "exported", encodeURIComponent(replayId)].join("/");
console.log(url);
// const url = "";
const res = (await axios
.get(url)
Expand Down
13 changes: 8 additions & 5 deletions libs/feature-replay-viewer/src/app/theater/RewindStageCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { injectable } from "inversify";
import { BlueprintService } from "./BlueprintService";
import { ReplayService } from "./ReplayService";
import { createRewindStage } from "../stage/createRewindStage";
import { buildBeatmap } from "@rewind/osu/core";
import { buildBeatmap, determineDefaultPlaybackSpeed } from "@rewind/osu/core";
import { SkinService } from "./SkinService";
import { AudioService } from "./AudioService";
import { TextureManager } from "./TextureManager";
import { defaultViewSettings } from "../stage/rewind/ViewSettings";
import { determineDefaultPlaybackSpeed } from "../../utils";
import { defaultSkinId } from "./SkinId";

const defaultSkinName = "rewind/RewindDefaultSkin";
// There will also be a default osu! std skin

@injectable()
export class RewindStageCreator {
Expand All @@ -25,10 +25,13 @@ export class RewindStageCreator {
const [blueprint, replay, skin] = await Promise.all([
this.blueprintService.retrieveBlueprint(blueprintId),
this.replayService.retrieveReplay(replayId),
this.skinService.loadSkin(defaultSkinName),
this.blueprintService.retrieveBlueprintResources(blueprintId),

// TODO: Loading the beatmap specific skin
this.skinService.loadSkin(defaultSkinId),
]);

await this.blueprintService.retrieveBlueprintResources(blueprintId);

// If the building is too slow or unbearable, we should push the building to a WebWorker
const beatmap = buildBeatmap(blueprint, { addStacking: true, mods: replay.mods });

Expand Down
13 changes: 13 additions & 0 deletions libs/feature-replay-viewer/src/app/theater/SkinId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type SkinSource = "rewind" | "osu";

export interface SkinId {
source: SkinSource;
name: string;
}

export const defaultSkinId: SkinId = { source: "rewind", name: "RewindDefaultSkin" };
// export const defaultSkinId: SkinId = { source: "osu", name: "- 《CK》 WhiteCat 2.1 _ old -lite" };
// export const defaultSkinId: SkinId = { source: "osu", name: "idke+1.2" };
// export const defaultSkinId: SkinId = { source: "osu", name: "Millhiore Lite" };
// export const defaultSkinId: SkinId = { source: "osu", name: "Toy 2018-09-07" };
// export const defaultSkinId: SkinId = { source: "osu", name: "- # BTMC ⌞Freedom Dive ↓⌝" };
Loading

0 comments on commit 4c348f9

Please sign in to comment.