Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sejong25
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Tear of Sejong
sejong25
Commits
5020b7bf
Commit
5020b7bf
authored
Aug 04, 2019
by
18신대성
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web db에 유저정보 저장하게 구현
parent
7d3bafca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
5 deletions
+87
-5
FirebaseClient.js
js/FirebaseClient.js
+86
-5
main.js
js/main.js
+1
-0
No files found.
js/FirebaseClient.js
View file @
5020b7bf
...
...
@@ -50,10 +50,29 @@ FirebaseClient.prototype.onAuthChange = function(user)
FirebaseClient
.
prototype
.
setLogin
=
function
()
{
this
.
database
=
firebase
.
database
();
this
.
database
.
goOnline
();
document
.
getElementById
(
'
mainTitle
'
).
style
.
display
=
'
none
'
;
document
.
getElementById
(
'
titleImg
'
).
style
.
display
=
'
none
'
;
game
=
new
Phaser
.
Game
(
config
);
this
.
database
.
goOnline
();
var
userDataRef
=
this
.
database
.
ref
(
'
/user-data/
'
+
this
.
auth
.
currentUser
.
uid
);
userDataRef
.
once
(
'
value
'
).
then
(
function
(
snapshot
)
{
if
(
snapshot
.
exists
())
{
PlayerData
.
userData
=
snapshot
.
val
();
}
else
{
let
newUserData
=
new
UserData
();
PlayerData
.
userData
=
newUserData
;
userDataRef
.
set
(
newUserData
);
}
})
.
then
(
function
()
{
game
=
new
Phaser
.
Game
(
config
);
});
document
.
getElementById
(
'
mainTitle
'
).
style
.
display
=
'
none
'
;
document
.
getElementById
(
'
titleImg
'
).
style
.
display
=
'
none
'
;
}
FirebaseClient
.
prototype
.
setLogOut
=
function
()
...
...
@@ -177,8 +196,70 @@ FirebaseClient.prototype.signInWithPopup = function(provider)
});
}
FirebaseClient
.
prototype
.
updateUserData
=
function
(
key
,
valueChanged
,
replace
=
false
)
{
var
beforeData
=
PlayerData
.
userData
;
var
updates
=
{};
switch
(
key
)
{
case
'
exp
'
:
updates
.
exp
=
replace
?
(
valueChanged
)
:
(
beforeData
.
exp
+
valueChanged
);
beforeData
.
exp
=
updates
.
exp
;
break
;
case
'
money
'
:
updates
.
money
=
replace
?
(
valueChanged
)
:
(
beforeData
.
money
+
valueChanged
);
beforeData
.
money
=
updates
.
money
;
break
;
case
'
hopae
'
:
if
(
beforeData
.
hopae
!=
null
)
{
updates
.
hopae
.
push
(
valueChanged
);
beforeData
.
hopae
.
push
(
valueChanged
);
}
else
{
beforeData
.
hopae
=
[
valueChanged
];
updates
.
hopae
=
[
valueChanged
];
}
break
;
case
'
item
'
:
if
(
beforeData
.
item
!=
null
)
{
updates
.
item
.
push
(
valueChanged
);
beforeData
.
item
.
push
(
valueChanged
);
}
else
{
beforeData
.
item
=
[
valueChanged
];
updates
.
item
=
[
valueChanged
];
}
break
;
default
:
console
.
log
(
'
[ERROR] database has no key for
'
+
key
);
break
;
}
return
this
.
database
.
ref
(
'
/user-data/
'
+
this
.
auth
.
currentUser
.
uid
).
update
(
updates
);
}
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
window
.
fbClient
=
new
FirebaseClient
();
console
.
log
(
'
done load
'
);
});
\ No newline at end of file
});
class
UserData
{
constructor
()
{
this
.
userName
=
prompt
(
"
유저의 이름을 입력해주세요.
"
);
this
.
exp
=
0
;
this
.
rank
=
-
1
;
this
.
hopae
=
[
{
name
:
prompt
(
"
첫번째 호패의 닉네임을 입력해주세요.
"
),
type
:
'
wood
'
}
];
this
.
title
=
[];
this
.
money
=
0
;
this
.
item
=
[];
}
}
\ No newline at end of file
js/main.js
View file @
5020b7bf
...
...
@@ -25,6 +25,7 @@ var PlayerData = PlayerData || {};
PlayerData
.
id
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
PlayerData
.
userData
=
null
;
// 현재 들어가있는 Game Room의 정보
var
RoomData
=
RoomData
||
{};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment