Skip to content

Commit

Permalink
Change default screen resolution based on device type
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Schürz committed Jan 17, 2025
1 parent c1883c9 commit 585cfdd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
17 changes: 12 additions & 5 deletions packages/core/src/OsucadGameBase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Container, Drawable, PIXIRenderer, ReadonlyDependencyContainer } from '@osucad/framework';
import { AudioManager, Axes, Box, DependencyContainer, Game, IRenderer, provide, resolved } from '@osucad/framework';
import { AudioManager, Axes, Box, DependencyContainer, Game, IRenderer, isMobile, provide, resolved, Vec2 } from '@osucad/framework';
import { OsucadIcons } from '@osucad/resources';
import { RenderTarget } from 'pixi.js';
import { AudioMixer } from './audio/AudioMixer';
Expand Down Expand Up @@ -38,6 +38,16 @@ export abstract class OsucadGameBase extends Game implements IResourcesProvider
@provide(ColorProvider)
colors = new ColorProvider();

protected getTargetDrawSize() {
if (isMobile.phone)
return new Vec2(540, 400);

if (isMobile.any)
return new Vec2(640, 640);

return new Vec2(960, 768);
}

protected override load(dependencies: ReadonlyDependencyContainer) {
super.load(dependencies);

Expand All @@ -58,10 +68,7 @@ export abstract class OsucadGameBase extends Game implements IResourcesProvider
}),
new SafeAreaContainer({
child: new ScalingContainer({
desiredSize: {
x: 960,
y: 768,
},
desiredSize: this.getTargetDrawSize(),
fit: Fit.Fill,
child: new PerformanceOverlay({
child: new EditorActionContainer({
Expand Down
30 changes: 17 additions & 13 deletions packages/core/src/editor/multiplayer/MultiplayerCursorOverlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { InputManager, ReadonlyDependencyContainer } from '@osucad/framewor
import type { CursorPosition } from '@osucad/multiplayer';
import type { ConnectedUser } from './ConnectedUsers';
import type { MultiplayerCursorArea } from './MultiplayerCursorArea';
import { Anchor, Axes, CompositeDrawable, Container, DrawableSprite, MouseButton, ProxyDrawable, resolved, Vec2 } from '@osucad/framework';
import { getIcon } from '@osucad/resources';
import { Axes, BindableBoolean, CompositeDrawable, Container, MouseButton, ProxyDrawable, resolved, Vec2 } from '@osucad/framework';
import { DefaultCursor } from '../../graphics/cursor/DefaultCursorContainer';
import { MultiplayerClient } from './MultiplayerClient';

export class MultiplayerCursorOverlay extends CompositeDrawable {
Expand Down Expand Up @@ -120,20 +120,15 @@ class MultiplayerCursor extends CompositeDrawable {
) {
super();

this.addInternal(new Container({
scale: 0.5,
children: [
new DrawableSprite({
texture: getIcon('select'),
anchor: Anchor.TopLeft,
x: -5,
y: -4,
color: this.user.clientInfo.color,
}),
],
this.addInternal(this.#cursor = new DefaultCursor().with({
color: user.clientInfo.color,
}));
}

readonly #cursor: DefaultCursor;

buttonPressed = new BindableBoolean();

protected override loadComplete() {
super.loadComplete();

Expand All @@ -143,13 +138,22 @@ class MultiplayerCursor extends CompositeDrawable {
if (key === 'cursor')
this.updatePosition();
});

this.buttonPressed.bindValueChanged((e) => {
if (e.value)
this.#cursor.animateMouseDown();
else
this.#cursor.animateMouseUp();
}, true);
}

#targetPosition = new Vec2();

updatePosition() {
const { cursor } = this.user.presence;

this.buttonPressed.value = cursor?.pressed ?? false;

if (!cursor) {
this.fadeOut();
this.setActiveArea(null);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/graphics/cursor/DefaultCursorContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export class DefaultCursor extends CompositeDrawable {
this.animateMouseUp();
}

protected animateMouseDown() {
animateMouseDown() {
this.#sprite.scaleTo(0.8, 1000, EasingFunction.OutQuart);
this.#sprite.moveTo(new Vec2(-5, -4), 1000, EasingFunction.OutQuart);

this.#shadow.scaleTo(0.8, 1000, EasingFunction.OutQuart);
this.#shadow.moveTo(new Vec2(-5, -2), 1000, EasingFunction.OutQuart);
}

protected animateMouseUp() {
animateMouseUp() {
this.#sprite.scaleTo(1, 200, EasingFunction.OutBack);
this.#sprite.moveTo(new Vec2(-4, -3), 200, EasingFunction.OutBack);

Expand Down

0 comments on commit 585cfdd

Please sign in to comment.