Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

버그 수정 및 좋아요 토글 #170

Merged
merged 9 commits into from
Dec 8, 2022
4 changes: 2 additions & 2 deletions backend/src/socket/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class SocketGateway implements OnGatewayConnection, OnGatewayDisconnect {

client['userData'] = {
...userData,
x: -25,
y: 400,
x: 800,
y: 800,
direction: 'right',
state: 'wait',
userState: 'on',
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/component/Game/Phaser/Player/myPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
changePosition,
changeState,
calcMoveToPos,
changeDirection,
} from '../../util';
import { Player } from './player';

Expand Down Expand Up @@ -71,6 +72,9 @@ export class MyPlayer extends Player {
const move: any = calcMoveToPos(this, this.heldDirection);
this.getBody().setVelocity(move.x * this.speed, move.y * this.speed);

const direction = move.x > 0 ? 'right' : 'left';
changeDirection(this, direction);

changePosition(this, move.x * this.speed, move.y * this.speed);
} else {
this.checkAndSetState('wait');
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/component/Game/Phaser/Player/otherPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { changePosition, changeState } from '../../util';
import { changeDirection, changePosition, changeState } from '../../util';
import { Player } from './player';

export class OtherPlayer extends Player {
constructor(scene: Phaser.Scene, data: any) {
super(scene, data.x, data.y, data.id, data.characterName, data.nickname);
}
update(state: string, x: number, y: number) {
update(state: string, x: number, y: number, direction: string) {
const prevState = this.state;
this.state = state;

changeDirection(this, direction);

if (this.x !== x || this.y !== y)
changePosition(this, x - this.x, y - this.y);
if (prevState !== this.state) changeState(this);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/component/Game/Phaser/Player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Player extends Phaser.Physics.Arcade.Sprite {
);

scene.physics.add.existing(this);
this.getBody().setCollideWorldBounds(true).setSize(64, 64);
this.getBody().setCollideWorldBounds(true).setSize(30, 50);

changeState(this);
}
Expand Down
24 changes: 16 additions & 8 deletions frontend/src/component/Game/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ export default class Game extends Phaser.Scene {

this.myPlayer = new MyPlayer(
this,
400,
400,
800,
800,
data.id,
data.hair,
data.nickname,
data.socket
);

const debugGraphics = this.add.graphics().setAlpha(0.7);
this.townLayer.renderDebug(debugGraphics, {
tileColor: null,
collidingTileColor: new Phaser.Display.Color(243, 234, 48, 255),
});
// const debugGraphics = this.add.graphics().setAlpha(0.7);
// this.townLayer.renderDebug(debugGraphics, {
// tileColor: null,
// collidingTileColor: new Phaser.Display.Color(243, 234, 48, 255),
// });

this.physics.add.collider(this.myPlayer, this.townLayer);

Expand All @@ -74,6 +74,13 @@ export default class Game extends Phaser.Scene {
emitter.on('updateHair', (hair: string) => {
this.myPlayer?.updateHair(hair);
});

window.onclick = (e: MouseEvent) => {
const elem = e.target as HTMLElement;
const checkInput = elem.tagName === 'INPUT';

this.input.keyboard.manager.enabled = !checkInput;
};
}

preload() {
Expand Down Expand Up @@ -203,7 +210,8 @@ export default class Game extends Phaser.Scene {
const id = data.id.toString().trim();

if (!this.otherPlayer[id]) return;
this.otherPlayer[id].update(data.state, data.x, data.y);
const { state, x, y, direction } = data;
this.otherPlayer[id].update(state, x, y, direction);
});

this.socket.on('userLeaved', (data: any) => {
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/component/Game/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ export const changeState = (player: any) => {
}
};

export const changeDirection = (player: any, moveX: number) => {
export const changeDirection = (player: any, direction: string) => {
if (!player.character || !player.hair) return;
if (player.direction === 'left' && moveX <= 0) return;
if (player.direction === 'right' && moveX >= 0) return;
if (player.direction === direction) return;

player.character.toggleFlipX();
player.hair.toggleFlipX();
player.dust.toggleFlipX();

player.direction = player.direction === 'left' ? 'right' : 'left';
player.direction = direction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빠른 수정 👍

};

export const calcMoveToPos = (player: any, dir: string[]) => {
Expand Down Expand Up @@ -57,8 +56,6 @@ export const changePosition = (player: any, x: number, y: number) => {
player.x += x;
player.y += y;

changeDirection(player, x);

player.character.setPosition(player.x, player.y);
player.hair.setPosition(player.x, player.y);

Expand Down
28 changes: 22 additions & 6 deletions frontend/src/component/SleepyBoard/content.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import axios from 'axios';
import { useEffect, useState } from 'react';
import * as style from './sleepyboard.styled';
import { calcTime } from './util';

Expand All @@ -8,13 +9,27 @@ const Content = ({ data }: { data: any }) => {
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAgVBMVEVVYIDn7O3///9KVnlTXn/q7+9NWXva4ONRXH7t8vJMWHvp7u9FUna+xM1JVXlibIng4udZZIP09feTmazc3uRrdJBeaIa2usbGydNye5SAh57t7vH4+frV2N+6vsqnrryJkaWhprZ8hJunrLuQlqrEytKZoLHL0dZueJKEjaHT2d6zE6BNAAAMeElEQVR4nO2de5eCOA+HK5RargJeUMdRRx1v3/8DLqCOKNcmQdg9+zvv2T3v/qE+0zRJ2zRlWttahf7JjX4Oy8V0NAsYY8FsNF0sDz+Re/LDVevfz1r87NCf/2zPzHF0yxKSc844SxT/k3MpLEt3nOC83c/9sMVf0Rah744XgafHYKxaMaruBYux67f0S9og9KMls3RRx/bCKXQrWEZtUFIThvMxcyypAPeUtBw2nlNbLCnh13rJdQGie0jocrn+ovxRhITzHddhg/c2lDrfuXQ+lopwcvBI8B6Q+uGb6JeREIbR1Kl1mmri0plGJFOSgNA/Mp0W7w6psyOBc0UTTpYC51uqJMRy0jHh94LaPF8VG+sC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3kBKziN4+M7INs9F85LOiUF9PqPmVOTgXwZ7QgZaoSezg0q+gqCKs3CKW3nHY6gD+MdbZKi/KtxsSlj/vLPXLZ/hSRns9K7dV7swrGaoJS6pQuGjLgZYxmqWxg+vraoQawsKwqJ8pMlBFxrLYkdt5UiXUondDtVjUXoCoZiyYj05ppG9MqL1WJgu274RvUJjLca8WsAFhtkpDSOIMVFFx7DhnGHmtiTYj1ObOY1Jvr13ypYzJfHwAOjVOpjFhHDSSv5sYnbrmuzFGt8v6dWFChVCbMMnE0ehoAr7JNgfb2FS5rAz0ioTa10hSd75AyDbXgTWrStXUCbWwpa7kQJnXZUWyDSLUtP4MYSKz8e9uTqiFXVNl1HQA1Qi1Vddcf1op/GoVQk3rx1y0lX6zGmEvLFXBQgGE2qrrmG+rWCiEsGuf2tyHwgk7dTiqAwgj7G4Y1QcQStjNbFSegRjCLpyqogtFE36aEWSgSMJPTkcTZqBoQm31GUYDwYckjBnbz+OADoaKsPVxxNgnEaHW5nzE89EQxn61jfhoQ+PDq2gIWzBWiuFLRUWokULivOerCAk1Ikiy0buJllDDQtrEeFoLhImAlGZIjqe1RBhrtTIVqsDseOzaoEvUFmGq1Sqs44zZwtbgUrVKeNcqJg1N07DtFDf5l2GaCVmraHf9A3HEDN2tpOABAAAAAElFTkSuQmCC';
const image =
'http://image.dongascience.com/Photo/2020/03/5bddba7b6574b95d37b6079c199d7101.jpg';
const { nickname, created_at, category, content } = data;
const { id, nickname, created_at, category, content } = data;
const createdDate = calcTime(created_at);

const [isLike, setIsLike] = useState(false);
const [isLike, setIsLike] = useState('');

const handleLike = () => {
setIsLike(!isLike);
const handleLike = async (e: React.MouseEvent) => {
const elem = e.target as HTMLButtonElement;
if (!elem.dataset.articleid) return;

const articleId = elem.dataset.articleid;
const value = isLike ? '' : articleId;

try {
let res;
if (value) res = await axios.put(`/api/board/like/${articleId}`);
else res = await axios.delete(`/api/board/like/${articleId}`);

if (res.status === 200) setIsLike(value);
} catch (e) {
console.log(e);
}
};

return (
Expand All @@ -29,9 +44,10 @@ const Content = ({ data }: { data: any }) => {
<div css={style.description}>{content}</div>
</div>
<button
data-articleid={id}
type="button"
onClick={handleLike}
css={style.likeBtn(isLike)}></button>
css={style.likeBtn(!!isLike)}></button>
</div>
);
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/store/atom/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { getCookieValue } from '../../page/Main';
import { v1 } from 'uuid';

const path =
location.origin === 'sleepywoods.kr' ? 'sleepywoods.kr' : 'localhost:3333';
location.origin === 'sleepywoods.kr'
? 'https//sleepywoods.kr'
: 'http//localhost:3333';

export const socketState = atom<Socket>({
key: `socketState/${v1()}`,
Expand Down