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

player waiting scene 레이아웃/스타일링 #137

Merged
merged 6 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/frontend/engine/GameObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,60 @@ const GameObject = class {
this.animationFrame = requestAnimationFrame(animateFunction);
}

roll(
Copy link
Collaborator

Choose a reason for hiding this comment

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

아예 roll 메소드를 구현하셨군요! move와는 다르게 중간에 끊길 일이 없어서 CSS로도 충분하지 않았나 생각해봅니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그렇네요 생각해보니...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Front-line-dev 시도해봤는데 transform rotateZ를 적용하는 과정에서 이유를 알 수 없게 의도치않은 동작이 나왔습니다. 예를들어 keyframe에 rotateZ(360deg)를 주면 카드가 1바퀴를 돌아야되는데 가만히 있는 동작을 보여주네요. transition을 이용하면 잘 되는데 animate()를 이용하면 안 되는게 저도 황당하네요. 일단은 보류하게 해주세요.

x = 0,
y = 0,
duration = TIME.ONE_SECOND / 2,
rollCount = 1,
rollClockwise = Math.random() < 0.5,
) {
// TODO: move()와 겹치는 부분들 refactor...
this.position = [x, y];
const xString = makeUnitString(x, '%');
const yString = makeUnitString(y, '%');

if (this.animationFrame) cancelAnimationFrame(this.animationFrame);
if (!xString && !yString) {
this.instance.style.removeProperty('top');
this.instance.style.removeProperty('left');
}
if (duration === 0) {
this.instance.style.top = yString;
this.instance.style.left = xString;
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

오 이런 코드라면 위에서 하나씩 떨어지는거 말고 실제 게임처럼 각자 플레이어의 방향에서 카드가 날아오게 할 수도 있겠네요! 예를 들어 플레이어가 4명 있으면 상하좌우에서 하나씩 날아오는...? 갑자기 생각나서 이야기 해봤습니다! ㅋㅋ

const initialY = makeFloat(this.instance.style.top) || 0;
const initialX = makeFloat(this.instance.style.left) || 0;
const targetY = y;
const targetX = x;

let start = null;
const animateFunction = (timestamp) => {
if (!start) start = timestamp;
const elapsed = timestamp - start;
if (elapsed > duration) {
this.instance.style.top = yString;
this.instance.style.left = xString;
this.animationFrame = null;
return;
}
const newY = initialY + (targetY - initialY) * (elapsed / duration);
const newX = initialX + (targetX - initialX) * (elapsed / duration);
Copy link
Collaborator

Choose a reason for hiding this comment

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

newY newX 로직이 같아서 이것도 별도 함수로 빼면 좋겠군용

this.angle = rollClockwise
? this.angle + rollCount * 4 * (elapsed / duration)
: this.angle - rollCount * 4 * (elapsed / duration);
ramram1048 marked this conversation as resolved.
Show resolved Hide resolved
this.rotateStyle = makeUnitString(this.angle, 'deg');

this.instance.style.left = makeUnitString(newX, '%');
this.instance.style.top = makeUnitString(newY, '%');
this.instance.style.transform = `rotateZ(${this.rotateStyle}) ${this.originStyle}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

y -> top / x -> left 이 관계가 있어서 이것도 뭔가 객체같은 걸로 빼면 편할 것 같아요!~


requestAnimationFrame(animateFunction);
};

this.animationFrame = requestAnimationFrame(animateFunction);
}

rotate(angle = 0, duration = TIME.ONE_SECOND / 5) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIME.TWO_HUNDREDS_MILI_SEC 는 넘 길까요 ㅋ.ㅋ 흠

Copy link
Collaborator

Choose a reason for hiding this comment

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

애매하긴 하다..

Copy link
Member

Choose a reason for hiding this comment

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

음 개인적으로는 1초를 가장 작은 단위로 두고 이걸 사용하는게 오히려 util로써 의미를 가지지 않을까 싶기도 하네요! 위의 코드에도 argument 기본값이 TIME.ONE_SECOND / 2 로 설정되어 있는데 TIME.FIVE_HUNDREDS_MILI_SEC 이렇게 하나하나 다 나누면 오히려 이상할 것 같기도 합니다!

this.angle = angle;
const angleString = makeUnitString(angle, 'deg');
Expand Down
52 changes: 50 additions & 2 deletions src/frontend/scenes/playerWaiting/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
import rendePlayerWaiting from './render';
import './style.scss';
import CardObject from '@engine/CardObject';
import DuckObject from '@engine/DuckObject';
import { DUCK_TYPE } from '@utils/type';
import PlayerManager from '@utils/PlayerManager';
import { $id } from '@utils/dom';
import renderPlayerWaiting from './render';
import { moveMyDuck } from '../waitingRoom/events';

const createDuck = ({
color = '',
x = 25 + Math.random() * 50,
y = 25 + Math.random() * 50,
} = {}) => {
const duck = new DuckObject({ type: DUCK_TYPE.CURSOR });
duck.setColor(color);
duck.createElement();
duck.setOriginCenter();
duck.move(x, y, 0);
duck.setDepth(2);
duck.attachToRoot();
return duck;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

오늘 말씀해주신것처럼 오리는 waitingRoom에서 한번 만든 뒤, 안 사용하는 화면에서는 숨기는 식으로 하면 될거같아요


const PlayerWaiting = class {
constructor() {
this.cards = [];
this.ducks = new Map();

PlayerManager.forEach(({ socketID, ...duckData }) => {
const duck = createDuck(duckData);
this.ducks.set(socketID, duck);
});
const myDuck = this.ducks.get(PlayerManager.currentPlayerID);
myDuck.setDepth(3);
this.duckMoveEvent = (e) => moveMyDuck(e, myDuck);
$id('root').addEventListener('click', this.duckMoveEvent);
this.dropNewCard();
}

dropNewCard() {
const newCard = new CardObject();
newCard.move(50, -50, 0);
newCard.setWidth(150);
newCard.angle = Math.random() * 360 - 180;
newCard.roll(40 + Math.random() * 20, 65 + Math.random() * 20, 3000);
newCard.attachToRoot();

this.cards = [...this.cards, newCard];
}

render() {
const { arrayToBeRemoved = [] } = rendePlayerWaiting();
const { arrayToBeRemoved } = renderPlayerWaiting();
this.arrayToBeRemoved = arrayToBeRemoved;
}

Expand Down
Empty file.
8 changes: 7 additions & 1 deletion src/frontend/scenes/playerWaiting/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './playerWaiting.scss';
import ProgressBarObject from '@engine/ProgressBarObject';
import TextObject from '@engine/TextObject';
import TIME from '@utils/time';
import TEXT from '@utils/text';

const renderPlayerWaiting = () => {
const ProgressBar = new ProgressBarObject();
Expand All @@ -9,6 +10,11 @@ const renderPlayerWaiting = () => {
ProgressBar.setTime(TIME.SELECT_CARD);
ProgressBar.start();

const HelpText = new TextObject();
HelpText.addClass('player-waiting-helper-text');
HelpText.setContent(TEXT.WAIT_PLAYER_SELECT);
HelpText.attachToRoot();

const arrayToBeRemoved = [ProgressBar];

return {
Expand Down
12 changes: 12 additions & 0 deletions src/frontend/scenes/playerWaiting/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import '@utils/common';

.player-waiting-helper-text {
position: absolute;
z-index: $z-index-layouts;
top: 30%;
left: 50%;
font-size: x-large;
text-align: center;
transform: translateX(-50%);
white-space: nowrap;
}
ramram1048 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/frontend/utils/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const TEXT = {
TELLER_SELECT: '당신은 이야기꾼입니다.\n어떤 카드로 이야기를 해볼까요?',
WAIT_TELLER_SELECT:
'이야기꾼이 카드를 고르고 있습니다.\n잠시만 기다려주세요.',
WAIT_PLAYER_SELECT:
'다른 플레이어들이 카드를 고르고 있습니다.\n잠시만 기다려주세요.',
TELLER: {
true: '당신은 이야기꾼입니다.\n어떤 카드로 이야기를 해볼까요?',
false: '이야기꾼이 카드를 고르고 있습니다.\n잠시만 기다려주세요.',
Expand Down