Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
113bdbf4
Commit
113bdbf4
authored
10 years ago
by
echicken
Browse files
Options
Downloads
Patches
Plain Diff
ScoreBoard has now become the more general-purpose DBHelper.
parent
9144827a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xtrn/lemons/dbhelper.js
+68
-30
68 additions, 30 deletions
xtrn/lemons/dbhelper.js
with
68 additions
and
30 deletions
xtrn/lemons/
scoreboard
.js
→
xtrn/lemons/
dbhelper
.js
+
68
−
30
View file @
113bdbf4
// An interface to the Lemons JSON DB.
Slightly more than a scoreboard.
var
ScoreBoard
=
function
(
host
,
port
)
{
// An interface to the Lemons JSON DB.
var
DBHelper
=
function
(
host
,
port
)
{
var
frames
=
{};
var
jsonClient
=
new
JSONClient
(
host
,
port
);
...
...
@@ -8,30 +8,38 @@ var ScoreBoard = function(host, port) {
score in Lemons! */
this
.
addScore
=
function
(
score
,
level
)
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
try
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
var
entry
=
{
'
player
'
:
user
.
alias
,
'
system
'
:
system
.
name
,
'
level
'
:
level
,
'
score
'
:
score
};
var
entry
=
{
'
player
'
:
user
.
alias
,
'
system
'
:
system
.
name
,
'
level
'
:
level
,
'
score
'
:
score
};
jsonClient
.
write
(
DBNAME
,
"
SCORES.LATEST
"
,
entry
,
2
);
jsonClient
.
write
(
DBNAME
,
"
SCORES.LATEST
"
,
entry
,
2
);
}
catch
(
err
)
{
log
(
LOG_DEBUG
,
err
);
}
}
// Returns the high scores array (20 most recent scores.)
this
.
getScores
=
function
()
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
try
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
var
scores
=
jsonClient
.
read
(
DBNAME
,
"
SCORES.HIGH
"
,
1
);
var
scores
=
jsonClient
.
read
(
DBNAME
,
"
SCORES.HIGH
"
,
1
);
}
catch
(
err
)
{
log
(
LOG_DEBUG
,
err
);
}
if
(
!
scores
)
scores
=
[];
if
(
typeof
scores
==
"
undefined
"
||
!
scores
)
var
scores
=
[];
return
scores
;
...
...
@@ -42,27 +50,29 @@ var ScoreBoard = function(host, port) {
an empty database.) */
this
.
getHighestLevel
=
function
()
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
try
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
var
player
=
jsonClient
.
read
(
DBNAME
,
"
PLAYERS.
"
+
base64_encode
(
user
.
alias
+
"
@
"
+
system
.
name
),
1
);
var
player
=
jsonClient
.
read
(
DBNAME
,
"
PLAYERS.
"
+
base64_encode
(
user
.
alias
+
"
@
"
+
system
.
name
),
1
);
if
(
!
player
)
return
0
;
if
(
!
player
)
return
0
;
return
player
.
LEVEL
;
return
player
.
LEVEL
;
}
catch
(
err
)
{
log
(
LOG_DEBUG
,
err
);
return
0
;
}
}
// Display the scoreboard.
this
.
open
=
function
()
{
if
(
!
jsonClient
.
connected
)
jsonClient
.
connect
(
host
,
port
);
this
.
showScores
=
function
()
{
frames
.
scoreFrame
=
new
Frame
(
frame
.
x
,
...
...
@@ -117,6 +127,26 @@ var ScoreBoard = function(host, port) {
}
/* Fetch levels from the DB if possible, fall back to local file if not.
Update local file if level data read from DB. */
this
.
getLevels
=
function
()
{
var
f
=
new
File
(
js
.
exec_dir
+
"
levels.json
"
);
try
{
var
levels
=
jsonClient
.
read
(
DBNAME
,
"
LEVELS
"
,
1
);
f
.
open
(
"
w
"
);
f
.
write
(
JSON
.
stringify
(
levels
));
}
catch
(
err
)
{
f
.
open
(
"
r
"
);
var
levels
=
JSON
.
parse
(
f
.
read
());
}
f
.
close
();
return
levels
;
}
// Close the scoreboard if it's open, disconnect the JSON-DB client.
this
.
close
=
function
()
{
if
(
typeof
frames
.
scoreFrame
!=
"
undefined
"
)
...
...
@@ -124,4 +154,12 @@ var ScoreBoard = function(host, port) {
jsonClient
.
disconnect
();
}
this
.
cycle
=
function
()
{
try
{
jsonClient
.
cycle
();
}
catch
(
err
)
{
log
(
LOG_DEBUG
,
err
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment