fork from scoresaber-reloaded
This commit is contained in:
commit
cc884eec07
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
node_modules
|
||||||
|
public/build
|
||||||
|
build-info.js
|
||||||
|
# Local Netlify folder
|
||||||
|
.netlify
|
674
LICENSE.md
Normal file
674
LICENSE.md
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
49
README.md
Normal file
49
README.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# ScoreSaber Reloaded
|
||||||
|
|
||||||
|
[![Netlify Status](https://api.netlify.com/api/v1/badges/38bf7c3a-dbfb-428b-9ff7-3fc86ef68f23/deploy-status)](https://app.netlify.com/sites/modest-morse-77235d/deploys)
|
||||||
|
|
||||||
|
## Users
|
||||||
|
|
||||||
|
Just go to [ssr.motzel.dev](https://ssr.motzel.dev)
|
||||||
|
|
||||||
|
|
||||||
|
## Devs
|
||||||
|
|
||||||
|
### Install the dependencies
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configure Netlify account
|
||||||
|
|
||||||
|
Create a new Netlify project and link it to the forked repo.
|
||||||
|
|
||||||
|
#### Install netlify dev CLI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install netlify-cli -g
|
||||||
|
```
|
||||||
|
|
||||||
|
Then start Netlify dev environment
|
||||||
|
|
||||||
|
```bash
|
||||||
|
netlify dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Navigate to [localhost:8888](http://localhost:8888). You should see app running.
|
||||||
|
|
||||||
|
### Building and running in production mode
|
||||||
|
|
||||||
|
By default, Netlify builds the app after every change to the master branch in the repository, so all you need is
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git push
|
||||||
|
```
|
||||||
|
### ... but I don't use Netlify
|
||||||
|
|
||||||
|
Check your hosting provider's documentation.
|
||||||
|
|
||||||
|
Note that the project uses Netlify redirects to bypass CORS issues in the Beat Savior API and to fetch some of the ScoreSaber subpages (not all data is available in the SS API yet).
|
||||||
|
|
||||||
|
Check the contents of [netlify.toml](https://github.com/motzel/scoresaber-reloaded/blob/master/netlify.toml) and see how you can resolve this with your provider.
|
35
netlify.toml
Normal file
35
netlify.toml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
[build]
|
||||||
|
publish = "public/"
|
||||||
|
|
||||||
|
[functions]
|
||||||
|
directory = "functions"
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/cors/beat-savior/*"
|
||||||
|
to = "https://www.beatsavior.io/api/livescores/player/:splat"
|
||||||
|
status = 200
|
||||||
|
force = true
|
||||||
|
headers = {X-From = "Netlify"}
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/cors/score-saber/*"
|
||||||
|
to = "https://www.scoresaber.com/:splat"
|
||||||
|
status = 200
|
||||||
|
force = true
|
||||||
|
headers = {X-From = "Netlify"}
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = '/build/*'
|
||||||
|
to = '/build/:splat'
|
||||||
|
status = 200
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = '/assets/*'
|
||||||
|
to = '/assets/:splat'
|
||||||
|
status = 200
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/*"
|
||||||
|
to = "/index.html"
|
||||||
|
status = 200
|
||||||
|
force = true
|
43
package.json
Normal file
43
package.json
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"name": "svelte-app",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup -c",
|
||||||
|
"dev": "rollup -c -w",
|
||||||
|
"start": "sirv public --no-clear --single",
|
||||||
|
"validate": "svelte-check"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@rollup/plugin-commonjs": "^17.0.0",
|
||||||
|
"@rollup/plugin-node-resolve": "^11.0.0",
|
||||||
|
"@rollup/plugin-typescript": "^8.0.0",
|
||||||
|
"@tsconfig/svelte": "^1.0.0",
|
||||||
|
"broadcast-channel": "^3.6.0",
|
||||||
|
"chart.js": "^3.5.0",
|
||||||
|
"chartjs-adapter-luxon": "^1.1.0",
|
||||||
|
"chartjs-plugin-zoom": "^1.1.1",
|
||||||
|
"comlink": "^4.3.1",
|
||||||
|
"eventemitter3": "^4.0.7",
|
||||||
|
"idb": "^6.1.2",
|
||||||
|
"immer": "^9.0.5",
|
||||||
|
"json-stable-stringify": "^1.0.1",
|
||||||
|
"luxon": "^2.0.2",
|
||||||
|
"p-queue": "^7.1.0",
|
||||||
|
"rollup": "^2.3.4",
|
||||||
|
"rollup-plugin-css-only": "^3.1.0",
|
||||||
|
"rollup-plugin-livereload": "^2.0.0",
|
||||||
|
"rollup-plugin-svelte": "^7.0.0",
|
||||||
|
"rollup-plugin-svg": "^2.0.0",
|
||||||
|
"rollup-plugin-terser": "^7.0.0",
|
||||||
|
"svelte": "^3.0.0",
|
||||||
|
"svelte-check": "^1.0.0",
|
||||||
|
"svelte-preprocess": "^4.0.0",
|
||||||
|
"svelte-routing": "^1.6.0",
|
||||||
|
"tslib": "^2.0.0",
|
||||||
|
"typescript": "^4.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"sirv-cli": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
BIN
public/assets/accsaber-logo.png
Normal file
BIN
public/assets/accsaber-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
public/assets/favicon.png
Normal file
BIN
public/assets/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
public/assets/miss.gif
Normal file
BIN
public/assets/miss.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 425 KiB |
1
public/assets/scoresaber-logo.svg
Normal file
1
public/assets/scoresaber-logo.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 208.62 205.19"><defs><style>.cls-1{fill:#191919;}.cls-2{fill:#eabc00;}.cls-3{fill:#ffed3b;}.cls-4{fill:#ffde1a;}.cls-5{fill:#f2f2f2;}</style></defs><title>ScoreSaberLogo</title><g id="Logo"><g id="Border"><rect class="cls-1" x="35.64" width="137.77" height="20.97"/><rect class="cls-1" x="173.08" y="16.27" width="19.14" height="20.76"/><rect class="cls-1" x="187.38" y="34.99" width="21.24" height="138.97"/><rect class="cls-1" x="172.38" y="172.54" width="19.86" height="17.76"/><rect class="cls-1" x="35.41" y="189.19" width="137.95" height="16"/><rect class="cls-1" x="17.03" y="172.78" width="18.89" height="17.68"/><rect class="cls-1" y="35.11" width="24.16" height="138.73"/><rect class="cls-1" x="16.95" y="16.42" width="18.77" height="18.73"/></g><g id="Base"><g id="Bottom"><rect class="cls-2" x="35.51" y="172.32" width="138.16" height="17.95"/></g><g id="Right"><rect class="cls-3" x="171.95" y="35.03" width="20.32" height="138.81"/></g><g id="Top"><rect class="cls-3" x="35.62" y="16.54" width="137.84" height="33.51"/></g><g id="Left"><rect class="cls-2" x="16.92" y="35.03" width="29.84" height="138.59"/></g><rect class="cls-4" x="35.52" y="35.03" width="137.69" height="138.81"/></g><g id="Arrow"><rect class="cls-5" x="75.3" y="53.51" width="61.89" height="12.32"/><rect class="cls-5" x="120" y="78.32" width="17.68" height="14.59"/><rect class="cls-5" x="75.19" y="78.27" width="17.41" height="15.03"/><rect class="cls-5" x="92.38" y="93.24" width="28.11" height="12.32"/><rect class="cls-5" x="136.86" y="65.84" width="17.35" height="13.14"/><rect class="cls-5" x="58.73" y="65.62" width="17.22" height="13.14"/></g></g></svg>
|
After Width: | Height: | Size: 1.7 KiB |
BIN
public/assets/song-default.png
Normal file
BIN
public/assets/song-default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.1 KiB |
9177
public/assets/ss-bulma.css
Normal file
9177
public/assets/ss-bulma.css
Normal file
File diff suppressed because it is too large
Load Diff
206
public/assets/ssr.css
Normal file
206
public/assets/ssr.css
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
:root {
|
||||||
|
--background: #222;
|
||||||
|
--foreground: #252525;
|
||||||
|
--textColor: #eee;
|
||||||
|
--ppColour: #8992e8;
|
||||||
|
--alternate: #72a8ff;
|
||||||
|
--selected: #3273dc;
|
||||||
|
--hover: #333;
|
||||||
|
--highlight: #484848;
|
||||||
|
--decrease: #f94022;
|
||||||
|
--increase: #42b129;
|
||||||
|
--dimmed: #3e3e3e;
|
||||||
|
--faded: #666;
|
||||||
|
--color-ahead: rgb(0, 128, 0);
|
||||||
|
--color-behind: rgb(128, 0, 0);
|
||||||
|
--color-highlight: darkgreen;
|
||||||
|
--error: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
height: --webkit-fill-available;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--background)!important;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 1rem;
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: -webkit-fill-available;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--foreground);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ssr-page-container {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inc {
|
||||||
|
color: var(--increase);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dec {
|
||||||
|
color: var(--decrease);
|
||||||
|
}
|
||||||
|
|
||||||
|
*[title]:not([title=""]):not(.clickable) {cursor: help;}
|
||||||
|
|
||||||
|
.scoresaber-icon {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-size: cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-image: url("./scoresaber-logo.svg");
|
||||||
|
}
|
||||||
|
|
||||||
|
.beatsavior-icon {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-size: cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:cc='http://creativecommons.org/ns%23' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape' width='72.723976mm' height='63.291668mm' viewBox='0 0 72.723976 63.291668' version='1.1' id='svg3827' sodipodi:docname='bsicon_ter.svg' inkscape:version='0.92.4 (5da689c313, 2019-01-14)'%3E%3Cdefs id='defs3821' /%3E%3Csodipodi:namedview id='base' pagecolor='%23ffffff' bordercolor='%23666666' borderopacity='1.0' inkscape:pageopacity='0.0' inkscape:pageshadow='2' inkscape:zoom='1.4' inkscape:cx='40.905424' inkscape:cy='61.353566' inkscape:document-units='mm' inkscape:current-layer='layer1' showgrid='false' inkscape:window-width='1920' inkscape:window-height='1017' inkscape:window-x='-8' inkscape:window-y='-8' inkscape:window-maximized='1' /%3E%3Cmetadata id='metadata3824'%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=''%3E%3Cdc:format%3Eimage/svg+xml%3C/dc:format%3E%3Cdc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage' /%3E%3Cdc:title%3E%3C/dc:title%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cg inkscape:label='Calque 1' inkscape:groupmode='layer' id='layer1' style='opacity:1' transform='translate(-0.72553574,-0.71711111)'%3E%3Crect style='fill:%23000200;fill-opacity:1;stroke:%23000000;stroke-width:1.98928511;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal' id='rect4531' width='63.5' height='10.583332' x='5.4550524' y='10.242103' inkscape:export-xdpi='81.844757' inkscape:export-ydpi='81.844757' /%3E%3Crect style='fill:%23ffffff;fill-opacity:1;stroke:none;stroke-width:3.35483217;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal' id='rect4533' width='6.6145835' height='6.6145835' x='25.298788' y='11.565023' inkscape:export-xdpi='81.844757' inkscape:export-ydpi='81.844757' /%3E%3Crect style='fill:%23ffffff;fill-opacity:1;stroke:none;stroke-width:3.92078424;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal' id='rect4533-5' width='6.6145835' height='6.6145835' x='42.496708' y='11.565023' inkscape:export-xdpi='81.844757' inkscape:export-ydpi='81.844757' /%3E%3Cg id='g4614' transform='rotate(-23.417079,-23.695385,307.31208)' inkscape:export-xdpi='81.844757' inkscape:export-ydpi='81.844757'%3E%3Crect y='86.127083' x='125.67709' height='1.3229166' width='50.270832' id='rect4610' style='fill:%230000ff;fill-opacity:1;stroke:%230000ff;stroke-width:2.64583325;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' /%3E%3Crect y='85.333328' x='109.80208' height='2.6458333' width='15.875' id='rect4605' style='fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:2.64583325;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' /%3E%3C/g%3E%3Cg transform='rotate(-156.98422,82.908484,73.919009)' id='g4614-3' inkscape:export-xdpi='81.844757' inkscape:export-ydpi='81.844757'%3E%3Crect y='86.127083' x='125.67709' height='1.3229166' width='50.270832' id='rect4610-6' style='fill:%23ff0000;fill-opacity:1;stroke:%23ff0000;stroke-width:2.64583325;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' /%3E%3Crect y='85.333328' x='109.80208' height='2.6458333' width='15.875' id='rect4605-7' style='fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:2.64583325;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1' /%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.accsaber-icon {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-size: cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-image: url("./accsaber-logo.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > * {
|
||||||
|
grid-column: 1/1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-0 {
|
||||||
|
grid-row: 1/1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-1 {
|
||||||
|
grid-row: 2/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-2 {
|
||||||
|
grid-row: 3/3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-3 {
|
||||||
|
grid-row: 4/4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-4 {
|
||||||
|
grid-row: 5/5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-5 {
|
||||||
|
grid-row: 6/6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-6 {
|
||||||
|
grid-row: 7/7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-7 {
|
||||||
|
grid-row: 8/8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-8 {
|
||||||
|
grid-row: 9/9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-9 {
|
||||||
|
grid-row: 10/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-10 {
|
||||||
|
grid-row: 11/11;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-transition-helper > .row-11 {
|
||||||
|
grid-row: 12/12;
|
||||||
|
}
|
||||||
|
|
||||||
|
.has-pointer-events {
|
||||||
|
pointer-events: fill;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-only {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet-only {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.up-to-tablet {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767px) {
|
||||||
|
.mobile-only {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet-and-up {
|
||||||
|
display: none!important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.above-tablet {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width:768px) and (max-width: 1023px) {
|
||||||
|
.tablet-only {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 1023px) {
|
||||||
|
.up-to-tablet {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-and-up {
|
||||||
|
display: none!important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 1750px) {
|
||||||
|
body:not(.slim) .ssr-page-container {
|
||||||
|
max-width: 1750px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 360px) {
|
||||||
|
body {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 320px) {
|
||||||
|
html {
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
}
|
9
public/assets/swiped-events.min.js
vendored
Normal file
9
public/assets/swiped-events.min.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/*!
|
||||||
|
* swiped-events.js - v1.1.4
|
||||||
|
* Pure JavaScript swipe events
|
||||||
|
* https://github.com/john-doherty/swiped-events
|
||||||
|
* @inspiration https://stackoverflow.com/questions/16348031/disable-scrolling-when-touch-moving-certain-element
|
||||||
|
* @author John Doherty <www.johndoherty.info>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
!function(t,e){"use strict";"function"!=typeof t.CustomEvent&&(t.CustomEvent=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:void 0};var a=e.createEvent("CustomEvent");return a.initCustomEvent(t,n.bubbles,n.cancelable,n.detail),a},t.CustomEvent.prototype=t.Event.prototype),e.addEventListener("touchstart",function(t){if("true"===t.target.getAttribute("data-swipe-ignore"))return;s=t.target,r=Date.now(),n=t.touches[0].clientX,a=t.touches[0].clientY,u=0,i=0},!1),e.addEventListener("touchmove",function(t){if(!n||!a)return;var e=t.touches[0].clientX,r=t.touches[0].clientY;u=n-e,i=a-r},!1),e.addEventListener("touchend",function(t){if(s!==t.target)return;var e=parseInt(l(s,"data-swipe-threshold","20"),10),o=parseInt(l(s,"data-swipe-timeout","500"),10),c=Date.now()-r,d="",p=t.changedTouches||t.touches||[];Math.abs(u)>Math.abs(i)?Math.abs(u)>e&&c<o&&(d=u>0?"swiped-left":"swiped-right"):Math.abs(i)>e&&c<o&&(d=i>0?"swiped-up":"swiped-down");if(""!==d){var b={dir:d.replace(/swiped-/,""),xStart:parseInt(n,10),xEnd:parseInt((p[0]||{}).clientX||-1,10),yStart:parseInt(a,10),yEnd:parseInt((p[0]||{}).clientY||-1,10)};s.dispatchEvent(new CustomEvent("swiped",{bubbles:!0,cancelable:!0,detail:b})),s.dispatchEvent(new CustomEvent(d,{bubbles:!0,cancelable:!0,detail:b}))}n=null,a=null,r=null},!1);var n=null,a=null,u=null,i=null,r=null,s=null;function l(t,n,a){for(;t&&t!==e.documentElement;){var u=t.getAttribute(n);if(u)return u;t=t.parentNode}return a}}(window,document);
|
21
public/index.html
Normal file
21
public/index.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||||
|
|
||||||
|
<title>ScoreSaber Reloaded</title>
|
||||||
|
|
||||||
|
<link rel='icon' type='image/png' href='/assets/favicon.png' />
|
||||||
|
<link rel='stylesheet' href='/assets/ss-bulma.css' />
|
||||||
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" />
|
||||||
|
<link rel="stylesheet" href="/assets/ssr.css?20210925" />
|
||||||
|
<link rel='stylesheet' href='/build/bundle.css' />
|
||||||
|
|
||||||
|
<script src="/assets/swiped-events.min.js"></script>
|
||||||
|
<script defer src='/build/bundle.js'></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
150
rollup.config.js
Normal file
150
rollup.config.js
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
import svelte from 'rollup-plugin-svelte';
|
||||||
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
|
import livereload from 'rollup-plugin-livereload';
|
||||||
|
import { terser } from 'rollup-plugin-terser';
|
||||||
|
import sveltePreprocess from 'svelte-preprocess';
|
||||||
|
import css from 'rollup-plugin-css-only';
|
||||||
|
import svg from 'rollup-plugin-svg';
|
||||||
|
|
||||||
|
const production = !process.env.ROLLUP_WATCH;
|
||||||
|
|
||||||
|
const buildVersion = execSync("git rev-parse --short HEAD").toString();
|
||||||
|
fs.writeFileSync('build-info.js', 'export default ' + JSON.stringify({
|
||||||
|
buildDate: (new Date()).toISOString().substr(0, 19).replace('T', ' ') + ' UTC',
|
||||||
|
buildVersion
|
||||||
|
}))
|
||||||
|
|
||||||
|
function serve() {
|
||||||
|
let server;
|
||||||
|
|
||||||
|
function toExit() {
|
||||||
|
if (server) server.kill(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
writeBundle() {
|
||||||
|
if (server) return;
|
||||||
|
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
|
||||||
|
stdio: ['ignore', 'inherit', 'inherit'],
|
||||||
|
shell: true
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGTERM', toExit);
|
||||||
|
process.on('exit', toExit);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
input: 'src/main.js',
|
||||||
|
output: {
|
||||||
|
sourcemap: true,
|
||||||
|
format: 'iife',
|
||||||
|
name: 'app',
|
||||||
|
file: 'public/build/bundle.js',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
svelte({
|
||||||
|
preprocess: sveltePreprocess({sourceMap: !production}),
|
||||||
|
compilerOptions: {
|
||||||
|
// enable run-time checks when not in production
|
||||||
|
dev: !production,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
// we'll extract any component CSS out into
|
||||||
|
// a separate file - better for performance
|
||||||
|
css({output: 'bundle.css'}),
|
||||||
|
|
||||||
|
svg(),
|
||||||
|
|
||||||
|
// If you have external dependencies installed from
|
||||||
|
// npm, you'll most likely need these plugins. In
|
||||||
|
// some cases you'll need additional configuration -
|
||||||
|
// consult the documentation for details:
|
||||||
|
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
||||||
|
resolve({
|
||||||
|
browser: true,
|
||||||
|
dedupe: ['svelte'],
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
|
||||||
|
// In dev mode, call `npm run start` once
|
||||||
|
// the bundle has been generated
|
||||||
|
!production && serve(),
|
||||||
|
|
||||||
|
// Watch the `public` directory and refresh the
|
||||||
|
// browser on changes when not in production
|
||||||
|
!production && livereload('public'),
|
||||||
|
|
||||||
|
// If we're building for production (npm run build
|
||||||
|
// instead of npm run dev), minify
|
||||||
|
production && terser(),
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'copy-comlink',
|
||||||
|
generateBundle() {
|
||||||
|
const buildDir = './public/build'
|
||||||
|
if (!fs.existsSync(buildDir)){
|
||||||
|
fs.mkdirSync(buildDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.resolve('./node_modules/comlink/dist/umd/comlink.min.js'),
|
||||||
|
path.resolve('./public/build/comlink.min.js'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
watch: {
|
||||||
|
clearScreen: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
input: 'src/workers/stats-worker.js',
|
||||||
|
output: {
|
||||||
|
sourcemap: true,
|
||||||
|
format: 'iife',
|
||||||
|
name: 'app',
|
||||||
|
file: 'public/build/stats-worker.js',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// If you have external dependencies installed from
|
||||||
|
// npm, you'll most likely need these plugins. In
|
||||||
|
// some cases you'll need additional configuration -
|
||||||
|
// consult the documentation for details:
|
||||||
|
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
||||||
|
resolve({
|
||||||
|
browser: true,
|
||||||
|
dedupe: ['svelte'],
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
|
||||||
|
// If we're building for production (npm run build
|
||||||
|
// instead of npm run dev), minify
|
||||||
|
production && terser(),
|
||||||
|
{
|
||||||
|
name: 'copy-test-worker',
|
||||||
|
load() {
|
||||||
|
this.addWatchFile(path.resolve('./src/workers/stats-worker.js'));
|
||||||
|
},
|
||||||
|
generateBundle() {
|
||||||
|
const buildDir = './public/build'
|
||||||
|
if (!fs.existsSync(buildDir)){
|
||||||
|
fs.mkdirSync(buildDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.resolve('./src/workers/stats-worker.js'),
|
||||||
|
path.resolve('./public/build/stats-worker.js'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
90
src/App.svelte
Normal file
90
src/App.svelte
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<script>
|
||||||
|
import {setContext} from 'svelte'
|
||||||
|
import {Router, Route, navigate} from "svelte-routing";
|
||||||
|
import buildInfo from '../build-info';
|
||||||
|
import createContainerStore from './stores/container';
|
||||||
|
import HomePage from './pages/Home.svelte';
|
||||||
|
import SearchPage from './pages/Search.svelte';
|
||||||
|
import RankingPage from './pages/Ranking.svelte';
|
||||||
|
import LeaderboardPage from './pages/Leaderboard.svelte';
|
||||||
|
import FriendsPage from './pages/Friends.svelte';
|
||||||
|
import PlayerPage from './pages/Player.svelte';
|
||||||
|
import TwitchPage from './pages/Twitch.svelte';
|
||||||
|
import NotFoundPage from './pages/NotFound.svelte';
|
||||||
|
import PrivacyPage from './pages/Privacy.svelte';
|
||||||
|
import CreditsPage from './pages/Credits.svelte';
|
||||||
|
import Nav from './components/Nav.svelte';
|
||||||
|
|
||||||
|
export let url = "";
|
||||||
|
|
||||||
|
let mainEl = null;
|
||||||
|
|
||||||
|
const containerStore = createContainerStore();
|
||||||
|
|
||||||
|
setContext('pageContainer', containerStore);
|
||||||
|
|
||||||
|
$: if (mainEl) containerStore.observe(mainEl)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Router {url}>
|
||||||
|
<Nav />
|
||||||
|
|
||||||
|
<main bind:this={mainEl}>
|
||||||
|
<div class="ssr-page-container">
|
||||||
|
<Route path="/u/:initialPlayerId/*initialParams" let:params>
|
||||||
|
<PlayerPage initialPlayerId={params.initialPlayerId} initialParams={params.initialParams}/>
|
||||||
|
</Route>
|
||||||
|
<Route path="/privacy" component="{PrivacyPage}" />
|
||||||
|
<Route path="/credits" component="{CreditsPage}" />
|
||||||
|
<Route path="/friends" component="{FriendsPage}" />
|
||||||
|
<Route path="/ranking/:type/*page" let:params>
|
||||||
|
<RankingPage type={params.type} page={params.page} />
|
||||||
|
</Route>
|
||||||
|
<Route path="/leaderboard/:type/:leaderboardId/*page" let:params>
|
||||||
|
<LeaderboardPage leaderboardId={params.leaderboardId} type={params.type} page={params.page} />
|
||||||
|
</Route>
|
||||||
|
<Route path="/search" component="{SearchPage}" />
|
||||||
|
<Route path="/twitch" component="{TwitchPage}" />
|
||||||
|
<Route path="/" component="{HomePage}" />
|
||||||
|
<Route path="/*" component="{NotFoundPage}" />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</Router>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>ScoreSaber Reloaded by <a href="https://github.com/motzel">motzel</a></p>
|
||||||
|
<p class="build">Build: {buildInfo.buildVersion} ({buildInfo.buildDate})</p>
|
||||||
|
<p>
|
||||||
|
<a href="/privacy" on:click|preventDefault={() => navigate('/privacy')}>Privacy policy</a> |
|
||||||
|
<a href="/credits" on:click|preventDefault={() => navigate('/credits')}>Credits</a>
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
main {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ssr-page-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: 1fr;
|
||||||
|
overflow: hidden;
|
||||||
|
min-height: calc(100vh - 9rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ssr-page-container :global(> *) {
|
||||||
|
grid-area: 1 / 1 / 1 / 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.build {
|
||||||
|
font-size: .875em;
|
||||||
|
color: var(--faded);
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
margin: 1rem 0;
|
||||||
|
font-size: .75em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
227
src/components/BeatSavior/Details.svelte
Normal file
227
src/components/BeatSavior/Details.svelte
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
<script>
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
import {convertArrayToObjectByKey, opt} from '../../utils/js'
|
||||||
|
import createPlayerService from '../../services/scoresaber/player'
|
||||||
|
import beatSaviorRepository from '../../db/repository/beat-savior'
|
||||||
|
import Hands from './Stats/Hands.svelte'
|
||||||
|
import OtherStats from './Stats/OtherStats.svelte'
|
||||||
|
import Grid from './Stats/Grid.svelte'
|
||||||
|
import Chart from './Stats/Chart.svelte'
|
||||||
|
import History from './History.svelte'
|
||||||
|
import Switcher from '../Common/Switcher.svelte'
|
||||||
|
import {formatNumber} from '../../utils/format'
|
||||||
|
import Button from '../Common/Button.svelte'
|
||||||
|
|
||||||
|
export let beatSavior;
|
||||||
|
export let leaderboard;
|
||||||
|
export let playerId;
|
||||||
|
export let noHistory = false;
|
||||||
|
|
||||||
|
const playerService = createPlayerService();
|
||||||
|
|
||||||
|
let allSongRunsWithOtherPlayers = [];
|
||||||
|
let allSongRuns = [];
|
||||||
|
let selectedRun = beatSavior;
|
||||||
|
let previouslySelected = null;
|
||||||
|
let compareTo = null;
|
||||||
|
|
||||||
|
let withOtherPlayers = false;
|
||||||
|
|
||||||
|
const switcherOptions = [
|
||||||
|
{id: 'none', title: 'No comparision', iconFa: 'fas fa-times'},
|
||||||
|
{id: 'best', title: 'Compare to the best', iconFa: 'fas fa-cubes'},
|
||||||
|
{id: 'last-clicked', title: 'Compare to previously selected', iconFa: 'fas fa-mouse'},
|
||||||
|
];
|
||||||
|
|
||||||
|
let selectedSwitcherOption = switcherOptions[1];
|
||||||
|
|
||||||
|
function extractGridAcc(beatSavior) {
|
||||||
|
const gridAcc = opt(beatSavior, 'trackers.accuracyTracker.gridAcc');
|
||||||
|
if (!gridAcc) return null;
|
||||||
|
|
||||||
|
return gridAcc && Array.isArray(gridAcc) && gridAcc.length === 12
|
||||||
|
? gridAcc.slice(-4).concat(gridAcc.slice(4, 8)).concat(gridAcc.slice(0, 4))
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAllLeaderboardPlays(playerId, leaderboard) {
|
||||||
|
if (!playerId || !leaderboard) return;
|
||||||
|
|
||||||
|
let hash = opt(leaderboard, 'song.hash');
|
||||||
|
const diff = opt(leaderboard, 'diffInfo.diff')
|
||||||
|
|
||||||
|
if (!hash || !diff) return;
|
||||||
|
|
||||||
|
const allCachedPlayers = convertArrayToObjectByKey(await playerService.getAll(), 'playerId');
|
||||||
|
|
||||||
|
hash = hash.toLowerCase();
|
||||||
|
|
||||||
|
allSongRunsWithOtherPlayers = Object.entries(
|
||||||
|
(await beatSaviorRepository().getAllFromIndex('beat-savior-hash',
|
||||||
|
hash))
|
||||||
|
.filter(bs => bs && bs.diff === diff && ((allCachedPlayers && allCachedPlayers[bs.playerId]) || bs.playerId === playerId))
|
||||||
|
.map(bs => ({...bs, playerName: opt(allCachedPlayers, `${bs.playerId}.name`, null)}))
|
||||||
|
.reduce((cum, bs) => {
|
||||||
|
if (!cum[bs.playerId]) cum[bs.playerId] = [];
|
||||||
|
|
||||||
|
cum[bs.playerId].push(bs);
|
||||||
|
cum[bs.playerId].sort((a, b) => b?.trackers?.scoreTracker?.rawRatio - a?.trackers?.scoreTracker?.rawRatio);
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, {}),
|
||||||
|
)
|
||||||
|
.reduce((cum, [currentPlayerId, bsArr]) => cum.concat(currentPlayerId === playerId ? bsArr : bsArr[0]), [])
|
||||||
|
.sort((a, b) => b.timeSet && a.timeSet ? b.timeSet - a.timeSet : 0);
|
||||||
|
|
||||||
|
allSongRuns = withOtherPlayers
|
||||||
|
? allSongRunsWithOtherPlayers
|
||||||
|
: allSongRunsWithOtherPlayers.filter(bs => bs.playerId === playerId)
|
||||||
|
|
||||||
|
if (!selectedRun || !allSongRuns.find(r => r.beatSaviorId === selectedRun.beatSaviorId)) {
|
||||||
|
selectedRun = best ? allSongRuns.find(r => r.beatSaviorId === best.beatSaviorId) : allSongRuns[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previouslySelected && allSongRuns.find(r => r.beatSaviorId === previouslySelected.beatSaviorId))
|
||||||
|
previouslySelected = selectedRun;
|
||||||
|
|
||||||
|
if (compareTo && allSongRuns.find(r => r.beatSaviorId === compareTo.beatSaviorId))
|
||||||
|
compareTo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRunSelected(event) {
|
||||||
|
if (!event || !event.detail || (selectedRun && event.detail.beatSaviorId === selectedRun.beatSaviorId)) return;
|
||||||
|
|
||||||
|
previouslySelected = selectedRun ? {...selectedRun} : null;
|
||||||
|
selectedRun = event.detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSwitcherChanged(e) {
|
||||||
|
selectedSwitcherOption = e.detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCompareTo(type, selected, best, previous) {
|
||||||
|
switch (type) {
|
||||||
|
case 'none':
|
||||||
|
compareTo = null;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'best':
|
||||||
|
compareTo = opt(best, 'beatSaviorId') !== opt(selected, 'beatSaviorId') ? best : null;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'last-clicked':
|
||||||
|
compareTo = opt(previous, 'beatSaviorId') !== opt(selected, 'beatSaviorId') ? previous : null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRunName(run) {
|
||||||
|
if (!run) return null;
|
||||||
|
|
||||||
|
const updatedRun = allSongRuns.find(r => r.beatSaviorId === run.beatSaviorId);
|
||||||
|
if (updatedRun) run = updatedRun;
|
||||||
|
|
||||||
|
const acc = opt(run, 'trackers.scoreTracker.rawRatio')
|
||||||
|
|
||||||
|
return `${withOtherPlayers && run.playerName ? run.playerName + ' / ' : ''}${formatNumber(acc * 100)}%${run.beatSaviorId === best.beatSaviorId ? ' (BEST)' : ''} run`
|
||||||
|
}
|
||||||
|
|
||||||
|
$: best = beatSavior;
|
||||||
|
$: if (beatSavior && !selectedRun) selectedRun = beatSavior;
|
||||||
|
$: accGrid = extractGridAcc(selectedRun)
|
||||||
|
$: getAllLeaderboardPlays(playerId, leaderboard, withOtherPlayers)
|
||||||
|
$: updateCompareTo(opt(selectedSwitcherOption, 'id', 'none'), selectedRun, best, previouslySelected)
|
||||||
|
$: accCompareGrid = extractGridAcc(compareTo)
|
||||||
|
$: name = getRunName(selectedRun)
|
||||||
|
$: compareToName = getRunName(compareTo)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if selectedRun}
|
||||||
|
<section class="beat-savior" class:with-history={!noHistory && allSongRunsWithOtherPlayers && allSongRunsWithOtherPlayers.length > 1} transition:fade>
|
||||||
|
{#if !noHistory && allSongRunsWithOtherPlayers && allSongRunsWithOtherPlayers.length > 1}
|
||||||
|
<nav>
|
||||||
|
<header>
|
||||||
|
<Switcher values={switcherOptions} value={selectedSwitcherOption} on:change={onSwitcherChanged}/>
|
||||||
|
|
||||||
|
{#if withOtherPlayers || (allSongRunsWithOtherPlayers && allSongRunsWithOtherPlayers.length > allSongRuns.length)}
|
||||||
|
<Button iconFa="fas fa-users" type={withOtherPlayers ? 'primary' : 'default'}
|
||||||
|
title="Show/hide scores of other players" noMargin={true}
|
||||||
|
on:click={() => withOtherPlayers = !withOtherPlayers}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<History withPlayerName={withOtherPlayers} runs={allSongRuns} selectedId={selectedRun.beatSaviorId}
|
||||||
|
compareToId={opt(compareTo, 'beatSaviorId')} bestId={opt(beatSavior, 'beatSaviorId')}
|
||||||
|
on:selected={onRunSelected}
|
||||||
|
/>
|
||||||
|
</nav>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Hands stats={selectedRun.stats} compareTo={compareTo ? compareTo.stats : null} {name} {compareToName}/>
|
||||||
|
<OtherStats beatSavior={selectedRun} compareTo={compareTo} {name} {compareToName}/>
|
||||||
|
<Grid {accGrid} compareTo={accCompareGrid} {name} {compareToName} />
|
||||||
|
<Chart beatSavior={selectedRun} compareTo={compareTo} {name} {compareToName} />
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.beat-savior {
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
grid-gap: 1.5em;
|
||||||
|
align-items: center;
|
||||||
|
justify-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior.with-history {
|
||||||
|
grid-template-columns: auto 1fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior.with-history nav {
|
||||||
|
grid-column: 1 / 1;
|
||||||
|
grid-row: 1 / span 2;
|
||||||
|
align-self: start;
|
||||||
|
max-width: 10.5em;
|
||||||
|
max-height: 17em;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: .75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767px) {
|
||||||
|
.beat-savior {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-gap: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior.with-history {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior.with-history nav {
|
||||||
|
grid-row: 1/2;
|
||||||
|
max-width: 100%;
|
||||||
|
flex-direction: row;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior.with-history > :global(.stats) {
|
||||||
|
grid-row: 2/3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior > :global(.stats) {
|
||||||
|
grid-row: 1/2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
93
src/components/BeatSavior/HandAcc.svelte
Normal file
93
src/components/BeatSavior/HandAcc.svelte
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<script>
|
||||||
|
import ssrConfig from '../../ssr-config'
|
||||||
|
import {formatNumber} from '../../utils/format'
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import Donut from '../Common/Donut.svelte'
|
||||||
|
|
||||||
|
const MAX_BLOCK_VALUE = 115;
|
||||||
|
|
||||||
|
export let value;
|
||||||
|
export let cut;
|
||||||
|
export let color;
|
||||||
|
export let hand = "left";
|
||||||
|
export let name = null
|
||||||
|
export let compareToValue = null;
|
||||||
|
export let compareToCut = null;
|
||||||
|
export let compareToName = null;
|
||||||
|
|
||||||
|
function getRgba(color) {
|
||||||
|
const keys = ['r', 'g', 'b', 'a']
|
||||||
|
|
||||||
|
const isOk = color && keys.reduce((ok, key) => ok && Number.isFinite(color[key]) && color[key] >= 0 && color[key] <= 1, true);
|
||||||
|
if (!isOk) return hand === 'left' ? ssrConfig.leftSaberColor : ssrConfig.rightSaberColor;
|
||||||
|
|
||||||
|
return 'rgba(' + keys.reduce((prev, key) => prev.concat(key !== 'a' ? Math.round(color[key] * 255) : color[key]), []) + ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
$: accValue = Number.isFinite(value) && value >= 0 && value <= 115 ? value : 0;
|
||||||
|
$: percentage = accValue / MAX_BLOCK_VALUE;
|
||||||
|
$: cutsRounded = (configStore, $configStore, cut && Array.isArray(cut) ? cut.map(c => Number.isFinite(c) ? formatNumber(c) : 0) : null);
|
||||||
|
$: rgba = getRgba(color);
|
||||||
|
|
||||||
|
$: compareToAccValue = Number.isFinite(compareToValue) && compareToValue >= 0 && compareToValue <= 115 ? compareToValue : 0;
|
||||||
|
$: compareToPercentage = compareToAccValue / MAX_BLOCK_VALUE;
|
||||||
|
$: compareToCutsRounded = (configStore, $configStore, compareToCut && Array.isArray(compareToCut) ? compareToCut.map(c => Number.isFinite(c) ? formatNumber(c) : 0) : null);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if cutsRounded}
|
||||||
|
<section class={hand}>
|
||||||
|
{#if cutsRounded && hand === 'left'}
|
||||||
|
<div class="cuts">
|
||||||
|
{#each cutsRounded as c, idx}
|
||||||
|
<span title={idx === 0 ? 'Preswing' : (idx === 1 ? 'Accuracy' : 'Postswing')}>
|
||||||
|
{#if compareToCutsRounded && compareToCutsRounded[idx]}
|
||||||
|
<small>{compareToCutsRounded[idx]}</small>
|
||||||
|
{/if}
|
||||||
|
{c}
|
||||||
|
</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="donut">
|
||||||
|
<Donut value={value} {percentage} color={rgba} {compareToValue} {compareToPercentage} {name} {compareToName} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if cutsRounded && hand === 'right'}
|
||||||
|
<div class="cuts">
|
||||||
|
{#each cutsRounded as c, idx}
|
||||||
|
<span title={idx === 0 ? 'Preswing' : (idx === 1 ? 'Accuracy' : 'Postswing')}>
|
||||||
|
{c}
|
||||||
|
{#if compareToCutsRounded && compareToCutsRounded[idx]}
|
||||||
|
<small>{compareToCutsRounded[idx]}</small>
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cuts {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: .875em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.donut {
|
||||||
|
width: 4em;
|
||||||
|
margin: 0 .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
color: var(--faded)
|
||||||
|
}
|
||||||
|
</style>
|
229
src/components/BeatSavior/History.svelte
Normal file
229
src/components/BeatSavior/History.svelte
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import {formatDate} from '../../utils/date'
|
||||||
|
import {formatNumber, padNumber} from '../../utils/format'
|
||||||
|
import FormattedDate from '../Common/FormattedDate.svelte'
|
||||||
|
import Accuracy from '../Common/Accuracy.svelte'
|
||||||
|
|
||||||
|
export let playerId;
|
||||||
|
export let runs;
|
||||||
|
export let selectedId;
|
||||||
|
export let bestId;
|
||||||
|
export let compareToId;
|
||||||
|
export let withPlayerName = false;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let itemsEl = null;
|
||||||
|
|
||||||
|
function processRuns(runs, withPlayerName = false) {
|
||||||
|
if (!runs || !runs.length) return null;
|
||||||
|
|
||||||
|
return runs.map(run => {
|
||||||
|
const acc = opt(run, 'trackers.scoreTracker.rawRatio')
|
||||||
|
const percentage = opt(run, 'trackers.scoreTracker.modifiedRatio')
|
||||||
|
const mods = opt(run, 'trackers.scoreTracker.modifiers', [])
|
||||||
|
const won = opt(run, 'trackers.winTracker.won', false)
|
||||||
|
const endTime = opt(run, 'trackers.winTracker.endTime', null);
|
||||||
|
const timeSet = run.timeSet
|
||||||
|
|
||||||
|
let failedAt = null;
|
||||||
|
if (endTime && !won) {
|
||||||
|
let minutes = padNumber(Math.floor(endTime / 60));
|
||||||
|
let seconds = padNumber(Math.round(endTime - minutes * 60));
|
||||||
|
if (seconds >= 60) {
|
||||||
|
minutes = padNumber(minutes + 1)
|
||||||
|
seconds = padNumber(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
failedAt = `${minutes}:${seconds}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!acc || !percentage || !timeSet) return null;
|
||||||
|
|
||||||
|
const name = `${withPlayerName && run.playerName ? run.playerName + ' / ' : ''}${formatDate(timeSet)} / ${formatNumber(acc*100)}%${!won ? ` / FAILED AT ${failedAt}` : `${run.beatSaviorId === bestId ? ' / BEST' : ''}`}`
|
||||||
|
|
||||||
|
return {...run, name, acc: acc * 100, percentage: percentage * 100, won, mods, failedAt}
|
||||||
|
})
|
||||||
|
.filter(run => run)
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToBestId(selectedId) {
|
||||||
|
if (!selectedId || !itemsEl) return;
|
||||||
|
|
||||||
|
const selectedEl = itemsEl.querySelector(`[data-id="${selectedId}"]`);
|
||||||
|
if (!selectedEl) return;
|
||||||
|
|
||||||
|
const {top: itemsElRectTop} = itemsEl.getBoundingClientRect();
|
||||||
|
const {top: selectedElTop} = selectedEl.getBoundingClientRect();
|
||||||
|
|
||||||
|
itemsEl.parentNode.scrollTo({
|
||||||
|
top: selectedElTop - itemsElRectTop,
|
||||||
|
left: 0,
|
||||||
|
behavior: 'smooth'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onSelectChange(e) {
|
||||||
|
const selectedItem = processedRuns ? processedRuns.find(r => r.beatSaviorId === selectedId) : null;
|
||||||
|
if (!selectedItem) return;
|
||||||
|
|
||||||
|
dispatch('selected', selectedItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
$: processedRuns = processRuns(runs, withPlayerName)
|
||||||
|
$: if(itemsEl && selectedId && bestId === selectedId) scrollToBestId(bestId)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if processedRuns && processedRuns.length}
|
||||||
|
<div class="scroll-wrapper">
|
||||||
|
<section bind:this={itemsEl}>
|
||||||
|
{#each processedRuns as run (run.beatSaviorId)}
|
||||||
|
<div data-id={run.beatSaviorId} class="item"
|
||||||
|
class:selected={run.beatSaviorId === selectedId} class:compare={run.beatSaviorId === compareToId}
|
||||||
|
on:click={() => dispatch('selected', run)}
|
||||||
|
>
|
||||||
|
<Accuracy score={run} noSecondMetric={true}>
|
||||||
|
<small slot="label-before">
|
||||||
|
{#if withPlayerName && run.playerName}
|
||||||
|
<div class="player-name">{run.playerName}</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<FormattedDate date={run.timeSet} absolute={true}/>
|
||||||
|
</small>
|
||||||
|
<small class:fail={!run.won} class:best={run.beatSaviorId === bestId} slot="label-after">
|
||||||
|
{#if !run.won}
|
||||||
|
{#if run.failedAt}
|
||||||
|
FAILED AT {run.failedAt}
|
||||||
|
{:else}
|
||||||
|
FAIL
|
||||||
|
{/if}
|
||||||
|
{:else if run.beatSaviorId === bestId}
|
||||||
|
BEST
|
||||||
|
{/if}
|
||||||
|
</small>
|
||||||
|
</Accuracy>
|
||||||
|
<i class="fas fa-balance-scale-left"></i>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="select-wrapper">
|
||||||
|
<select bind:value={selectedId} on:change={onSelectChange}>
|
||||||
|
{#each processedRuns as run (run.beatSaviorId)}
|
||||||
|
<option value={run.beatSaviorId}>{run.name}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.scroll-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
margin-top: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-wrapper {
|
||||||
|
display: none;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
section :global(.badge) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scroll-wrapper::-webkit-scrollbar {
|
||||||
|
width: .25rem;
|
||||||
|
}
|
||||||
|
body::-webkit-scrollbar-track {
|
||||||
|
background: var(--foreground, #fff);
|
||||||
|
}
|
||||||
|
.scroll-wrapper::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--selected, #3273dc) ;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 3px solid var(--selected, #3273dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
display: block;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
position: relative;
|
||||||
|
opacity: .25;
|
||||||
|
transition: opacity 200ms;
|
||||||
|
cursor: pointer !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item.selected {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item > i.fas {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
right: .25em;
|
||||||
|
bottom: 1em;
|
||||||
|
font-size: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item:hover:not(.selected) {
|
||||||
|
opacity: .6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item.compare > i.fas {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item :global(*) {
|
||||||
|
cursor: pointer!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fail, .best {
|
||||||
|
font-size: .75em;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--decrease);
|
||||||
|
}
|
||||||
|
|
||||||
|
.best {
|
||||||
|
color: var(--increase);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.switch-types .button) {
|
||||||
|
margin-bottom: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.switch-types .button i) {
|
||||||
|
align-items: flex-end!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-name {
|
||||||
|
font-size: .8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767px) {
|
||||||
|
.scroll-wrapper {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-wrapper {
|
||||||
|
display: inline-block;
|
||||||
|
flex: 1;
|
||||||
|
margin-left: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
142
src/components/BeatSavior/Stats/Chart.svelte
Normal file
142
src/components/BeatSavior/Stats/Chart.svelte
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
import {opt} from '../../../utils/js'
|
||||||
|
|
||||||
|
export let beatSavior = null;
|
||||||
|
export let name = null;
|
||||||
|
export let compareTo = null;
|
||||||
|
export let compareToName = null;
|
||||||
|
export let height = "250px";
|
||||||
|
|
||||||
|
let canvas = null;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let themeName = 'darkss';
|
||||||
|
let theme = null;
|
||||||
|
|
||||||
|
async function setupChart(canvas, chartData, compareChartData, name, compareToName) {
|
||||||
|
if (!canvas || !chartData || !Object.keys(chartData).length) return;
|
||||||
|
|
||||||
|
const accColor = theme && theme.alternate ? theme.alternate : "#72a8ff";
|
||||||
|
const compareColor = theme && theme.dimmed ? theme.alternate : "#3e3e3e";
|
||||||
|
|
||||||
|
const data = Object.values(chartData).map(v => v * 100);
|
||||||
|
const mainMinValue = Math.floor(Math.max(Math.floor(data.reduce((min, cur) => cur < min ? cur : min, 100)), 0) * 0.99);
|
||||||
|
const mainMaxValue = Math.ceil(Math.min(Math.ceil(data.reduce((max, cur) => cur > max ? cur : max, 0)), 100));
|
||||||
|
|
||||||
|
const compareData = compareChartData ? Object.values(compareChartData).map(v => v * 100) : null;
|
||||||
|
const compareMinValue = compareChartData ? Math.floor(Math.max(Math.floor(compareData.reduce((min, cur) => cur < min ? cur : min, 100)), 0) * 0.99) : 100;
|
||||||
|
const compareMaxValue = compareChartData ? Math.ceil(Math.min(Math.ceil(compareData.reduce((max, cur) => cur > max ? cur : max, 0)), 100)) : 0;
|
||||||
|
|
||||||
|
const minValue = Math.min(mainMinValue, compareMinValue)
|
||||||
|
const maxValue = Math.max(mainMaxValue, compareMaxValue)
|
||||||
|
|
||||||
|
const datasets = [
|
||||||
|
{
|
||||||
|
label: name ? name : 'Selected',
|
||||||
|
data,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
borderColor: accColor,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 0,
|
||||||
|
type: 'line',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (compareData) datasets.push({
|
||||||
|
label: compareToName ? compareToName : 'Compared',
|
||||||
|
data: compareData,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
borderColor: compareColor,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 0,
|
||||||
|
type: 'line',
|
||||||
|
})
|
||||||
|
|
||||||
|
const labels = Object.keys(compareData && compareData.length > data.length ? compareChartData : chartData)
|
||||||
|
.map(v => Math.floor(v / 60) + ':' + (v % 60).toString().padStart(2, '0'))
|
||||||
|
|
||||||
|
if (!chart)
|
||||||
|
{
|
||||||
|
chart = new Chart(
|
||||||
|
canvas,
|
||||||
|
{
|
||||||
|
data: {labels, datasets},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
interaction: {
|
||||||
|
mode: 'index',
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
callbacks: {
|
||||||
|
label(ctx) {
|
||||||
|
return formatNumber(ctx.parsed.y) + '%'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
scaleLabel: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
autoSkip: true,
|
||||||
|
autoSkipPadding: 4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
min: minValue,
|
||||||
|
max: maxValue,
|
||||||
|
ticks: {
|
||||||
|
callback: function(val) {
|
||||||
|
return val+'%'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chart.data = {labels, datasets}
|
||||||
|
chart.options.plugins.legend.display = !!compareData;
|
||||||
|
chart.options.scales.y.min = minValue;
|
||||||
|
chart.options.scales.y.max = maxValue;
|
||||||
|
chart.update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: data = opt(beatSavior, 'trackers.scoreGraphTracker.graph', null)
|
||||||
|
$: compareData = opt(beatSavior, 'beatSaviorId') !== opt(compareTo, 'beatSaviorId') ? opt(compareTo, 'trackers.scoreGraphTracker.graph', null) : null
|
||||||
|
$: setupChart(canvas, data, compareData, name, compareToName)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if data}
|
||||||
|
<section class="chart" style="--height: {height}">
|
||||||
|
<canvas class="chartjs" bind:this={canvas}></canvas>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
position: relative;
|
||||||
|
margin: 0 auto !important;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 100% !important;
|
||||||
|
height: var(--height);
|
||||||
|
}
|
||||||
|
</style>
|
57
src/components/BeatSavior/Stats/Grid.svelte
Normal file
57
src/components/BeatSavior/Stats/Grid.svelte
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<script>
|
||||||
|
import {configStore} from '../../../stores/config'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
import Value from '../../Common/Value.svelte'
|
||||||
|
|
||||||
|
const MAX_BLOCK_VALUE = 115;
|
||||||
|
|
||||||
|
export let accGrid = null;
|
||||||
|
export let name = null;
|
||||||
|
export let compareTo = null;
|
||||||
|
export let compareToName = null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if accGrid && Array.isArray(accGrid) && accGrid.length === 12}
|
||||||
|
<div class="grid">
|
||||||
|
{#each accGrid as gridVal, idx}
|
||||||
|
<span>
|
||||||
|
{#if Number.isFinite(gridVal)}
|
||||||
|
<div>
|
||||||
|
<Value value={gridVal} digits={2} title={(configStore, $configStore, `${compareTo && compareToName && name ? `[${name}]: ` : ''}${formatNumber(gridVal/MAX_BLOCK_VALUE*100)}%`)}/>
|
||||||
|
|
||||||
|
{#if compareTo && compareTo[idx] && Number.isFinite(compareTo[idx])}
|
||||||
|
<small>
|
||||||
|
<Value value={compareTo[idx]} digits={2} title={(configStore, $configStore, `${compareTo && compareToName ? `[${compareToName}]: ` : ''}${formatNumber(compareTo[idx]/MAX_BLOCK_VALUE*100)}%`)}/>
|
||||||
|
</small>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.grid {
|
||||||
|
display: inline-grid;
|
||||||
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
|
grid-gap: .5em;
|
||||||
|
font-size: .75em;
|
||||||
|
min-height: 12em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid > span {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: var(--dimmed);
|
||||||
|
width: 3.5em;
|
||||||
|
height: 3.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div > small {
|
||||||
|
display: block;
|
||||||
|
color: var(--faded);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
142
src/components/BeatSavior/Stats/Hands.svelte
Normal file
142
src/components/BeatSavior/Stats/Hands.svelte
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<script>
|
||||||
|
import ssrConfig from '../../../ssr-config'
|
||||||
|
import HandAcc from '../HandAcc.svelte'
|
||||||
|
import Badge from '../../Common/Badge.svelte'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
|
||||||
|
export let stats = null;
|
||||||
|
export let name = null;
|
||||||
|
export let compareTo = null;
|
||||||
|
export let compareToName = null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if stats}
|
||||||
|
<div class="acc">
|
||||||
|
<div class="left">
|
||||||
|
<HandAcc value={stats.accLeft} cut={stats.leftAverageCut} color={stats.saberAColor} hand="left" {name}
|
||||||
|
compareToValue={compareTo ? compareTo.accLeft : null} compareToCut={compareTo ? compareTo.leftAverageCut : null} {compareToName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if stats.leftTimeDependence}
|
||||||
|
<div class="td badge-stat">
|
||||||
|
<Badge label="TD" title="Left hand time dependence" value={stats.leftTimeDependence}
|
||||||
|
color="white" bgColor={ssrConfig.leftSaberColor}
|
||||||
|
digits={3} fluid={true}>
|
||||||
|
<small slot="additional">
|
||||||
|
{#if compareTo}{formatNumber(compareTo.leftTimeDependence, 3)}{/if}
|
||||||
|
</small>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if stats.leftPreswing}
|
||||||
|
<div class="preswing badge-stat">
|
||||||
|
<Badge label="PRE" title="Left hand preswing" value={stats.leftPreswing * 100}
|
||||||
|
color="white" bgColor={ssrConfig.leftSaberColor}
|
||||||
|
digits={2} suffix="%" fluid={true}>
|
||||||
|
<small slot="additional">
|
||||||
|
{#if compareTo}{formatNumber(compareTo.leftPreswing * 100, 2)}%{/if}
|
||||||
|
</small>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if stats.leftPostswing}
|
||||||
|
<div class="postswing badge-stat">
|
||||||
|
<Badge label="POST" title="Left hand postswing" value={stats.leftPostswing * 100}
|
||||||
|
color="white" bgColor={ssrConfig.leftSaberColor}
|
||||||
|
digits={2} suffix="%" fluid={true}>
|
||||||
|
<small slot="additional">
|
||||||
|
{#if compareTo}{formatNumber(compareTo.leftPostswing * 100, 2)}%{/if}
|
||||||
|
</small>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="right">
|
||||||
|
<HandAcc value={stats.accRight} cut={stats.rightAverageCut} color={stats.saberBColor} hand="right" {name}
|
||||||
|
compareToValue={compareTo ? compareTo.accRight : null} compareToCut={compareTo ? compareTo.rightAverageCut : null} {compareToName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if stats.rightTimeDependence}
|
||||||
|
<div class="td badge-stat">
|
||||||
|
<Badge label="TD" title="Right hand time dependence" value={stats.rightTimeDependence}
|
||||||
|
color="white" bgColor={ssrConfig.rightSaberColor}
|
||||||
|
digits={3} fluid={true}>
|
||||||
|
<small slot="additional">
|
||||||
|
{#if compareTo}{formatNumber(compareTo.rightTimeDependence, 3)}{/if}
|
||||||
|
</small>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if stats.rightPreswing}
|
||||||
|
<div class="preswing badge-stat">
|
||||||
|
<Badge label="PRE" title="Right hand preswing" value={stats.rightPreswing * 100}
|
||||||
|
color="white" bgColor={ssrConfig.rightSaberColor}
|
||||||
|
digits={2} suffix="%" fluid={true}>
|
||||||
|
<small slot="additional">
|
||||||
|
{#if compareTo}{formatNumber(compareTo.rightPreswing * 100, 2)}%{/if}
|
||||||
|
</small>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if stats.rightPostswing}
|
||||||
|
<div class="postswing badge-stat">
|
||||||
|
<Badge label="POST" title="Right hand postswing" value={stats.rightPostswing * 100}
|
||||||
|
color="white" bgColor={ssrConfig.rightSaberColor}
|
||||||
|
digits={2} suffix="%" fluid={true}>
|
||||||
|
<small slot="additional">
|
||||||
|
{#if compareTo}{formatNumber(compareTo.rightPostswing * 100, 2)}%{/if}
|
||||||
|
</small>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.acc {
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-stat {
|
||||||
|
font-size: .8em;
|
||||||
|
margin-top: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right .badge-stat {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-stat :global(.badge) {
|
||||||
|
margin: 0;
|
||||||
|
padding-bottom: .25em;
|
||||||
|
width: 95%;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right .badge-stat :global(.badge) {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-stat :global(.badge .value) {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-stat :global(.badge .label) {
|
||||||
|
min-width: 3.5em!important;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right .badge-stat :global(.badge .label) {
|
||||||
|
min-width: 3.5em!important;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
opacity: .5;
|
||||||
|
padding: 3px .25em 0 0;
|
||||||
|
}
|
||||||
|
</style>
|
188
src/components/BeatSavior/Stats/OtherStats.svelte
Normal file
188
src/components/BeatSavior/Stats/OtherStats.svelte
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
<script>
|
||||||
|
import ssrConfig from '../../../ssr-config'
|
||||||
|
import {opt} from '../../../utils/js'
|
||||||
|
import {formatNumber, padNumber} from '../../../utils/format'
|
||||||
|
import {configStore} from '../../../stores/config'
|
||||||
|
import Value from '../../Common/Value.svelte'
|
||||||
|
import Badge from '../../Common/Badge.svelte'
|
||||||
|
|
||||||
|
export let beatSavior = null;
|
||||||
|
export let name = null;
|
||||||
|
export let compareTo = null;
|
||||||
|
export let compareToName = null;
|
||||||
|
export let isAverage = false;
|
||||||
|
|
||||||
|
function formatFailedAt(beatSavior) {
|
||||||
|
const endTime = opt(beatSavior, 'trackers.winTracker.endTime');
|
||||||
|
const won = opt(beatSavior, 'trackers.winTracker.won', false);
|
||||||
|
if (!endTime || won) return null;
|
||||||
|
|
||||||
|
let failedAt = null;
|
||||||
|
if (endTime) {
|
||||||
|
let minutes = padNumber(Math.floor(endTime / 60));
|
||||||
|
let seconds = padNumber(Math.round(endTime - minutes * 60));
|
||||||
|
if (seconds >= 60) {
|
||||||
|
minutes = padNumber(minutes + 1)
|
||||||
|
seconds = padNumber(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
failedAt = `${minutes}:${seconds}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return failedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
$: stats = beatSavior ? beatSavior.stats : null;
|
||||||
|
$: fc = stats && !stats.miss && !stats.wallHit && !stats.bombHit;
|
||||||
|
|
||||||
|
$: totalMistakes = stats ? stats.miss + stats.wallHit + stats.bombHit : null;
|
||||||
|
$: leftBadCuts = isAverage ? (stats?.leftBadCuts ?? null) : opt(beatSavior, 'trackers.hitTracker.leftBadCuts', null)
|
||||||
|
$: leftMissedNotes = isAverage ? (stats?.leftMiss ?? null) : opt(beatSavior, 'trackers.hitTracker.leftMiss', null)
|
||||||
|
$: leftMiss = (leftBadCuts || 0) + (leftMissedNotes || 0)
|
||||||
|
$: rightBadCuts = isAverage ? (stats?.rightBadCuts ?? null) : opt(beatSavior, 'trackers.hitTracker.rightBadCuts', null)
|
||||||
|
$: rightMissedNotes = isAverage ? (stats?.rightMiss ?? null) : opt(beatSavior, 'trackers.hitTracker.rightMiss', null)
|
||||||
|
$: rightMiss = (rightBadCuts || 0) + (rightMissedNotes || 0)
|
||||||
|
|
||||||
|
$: compareToStats = compareTo ? compareTo.stats : null;
|
||||||
|
$: compareToFc = compareToStats && !compareToStats.miss && !compareToStats.wallHit && !compareToStats.bombHit;
|
||||||
|
$: compareToTotalMistakes = compareToStats ? compareToStats.miss + compareToStats.wallHit + compareToStats.bombHit : null;
|
||||||
|
$: compareToLeftBadCuts = opt(compareTo, 'trackers.hitTracker.leftBadCuts', null)
|
||||||
|
$: compareToLeftMissedNotes = opt(compareTo, 'trackers.hitTracker.leftMiss', null)
|
||||||
|
$: compareToLeftMiss = compareTo ? (compareToLeftBadCuts || 0) + (compareToLeftMissedNotes || 0) : null
|
||||||
|
$: compareToRightBadCuts = opt(compareTo, 'trackers.hitTracker.rightBadCuts', null)
|
||||||
|
$: compareToRightMissedNotes = opt(compareTo, 'trackers.hitTracker.rightMiss', null)
|
||||||
|
$: compareToRightMiss = compareTo ? (compareToRightBadCuts || 0) + (compareToRightMissedNotes || 0) : null
|
||||||
|
$: failedAt = formatFailedAt(beatSavior)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if stats}
|
||||||
|
<div class="stats" style="--left-saber-color: {ssrConfig.leftSaberColor}; --right-saber-color: {ssrConfig.rightSaberColor}">
|
||||||
|
{#if isAverage && stats.acc}
|
||||||
|
<Badge label="Acc" color="white" bgColor="var(--dimmed)" fluid={true} value={stats?.acc ?? 0} suffix="%" />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if !stats.won}
|
||||||
|
<Badge color="red" bgColor="var(--dimmed)" fluid={true} onlyLabel={true}>
|
||||||
|
<svelte:fragment slot="label">
|
||||||
|
FAIL {#if failedAt} AT {failedAt}{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if !isAverage}
|
||||||
|
{#if fc && (!compareToStats || compareToFc)}
|
||||||
|
<Badge color="darkorange" bgColor="var(--dimmed)" fluid={true} onlyLabel={true}>
|
||||||
|
<svelte:fragment slot="label">
|
||||||
|
FC
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<Badge label="FC" color="white" bgColor="var(--dimmed)" fluid={true} value={stats?.fc ? stats?.fc * 100 : 0} suffix="%" />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if !fc || isAverage || (compareToStats && !compareToFc)}
|
||||||
|
<Badge label="Total mistakes" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={totalMistakes} digits={isAverage ? 2 : 0} prevValue={compareToTotalMistakes} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
{#if stats.miss || (compareToStats && compareToStats.miss)}
|
||||||
|
<span class="left addon"><Value value={leftMiss} digits={isAverage ? 2 : 0} title="Left hand total mistakes" prevValue={compareToLeftMiss} prevAbsolute={true} prevWithSign={false}/></span>
|
||||||
|
<span class="right addon"><Value value={rightMiss} digits={isAverage ? 2 : 0} title="Right hand total mistakes" prevValue={compareToRightMiss} prevAbsolute={true} prevWithSign={false}/></span>
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
<Badge label="Missed notes" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={stats.missedNotes} digits={isAverage ? 2 : 0} prevValue={compareToStats ? compareToStats.missedNotes : null} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
{#if stats.missedNotes || (compareToStats && compareToStats.missedNotes)}
|
||||||
|
<span class="left addon"><Value value={leftMissedNotes} digits={isAverage ? 2 : 0} title="Left hand missed notes" prevValue={compareToLeftMissedNotes} prevAbsolute={true} prevWithSign={false}/></span>
|
||||||
|
<span class="right addon"><Value value={rightMissedNotes} digits={isAverage ? 2 : 0} title="Right hand missed notes" prevValue={compareToRightMissedNotes} prevAbsolute={true} prevWithSign={false}/></span>
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
<Badge label="Bad cuts" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={stats.badCuts} digits={isAverage ? 2 : 0} prevValue={compareToStats ? compareToStats.badCuts : null} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
{#if stats.badCuts || (compareToStats && compareToStats.badCuts)}
|
||||||
|
<span class="left addon"><Value value={leftBadCuts} digits={isAverage ? 2 : 0} title="Left hand bad cuts" prevValue={compareToLeftBadCuts} prevAbsolute={true} prevWithSign={false}/></span>
|
||||||
|
<span class="right addon"><Value value={rightBadCuts} digits={isAverage ? 2 : 0} title="Right hand bad cuts" prevValue={compareToRightBadCuts} prevAbsolute={true} prevWithSign={false}/></span>
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
|
||||||
|
<Badge label="Bomb hit" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={stats.bombHit} digits={isAverage ? 3 : 0} prevValue={compareToStats ? compareToStats.bombHit : null} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
|
||||||
|
<Badge label="Wall hit" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={stats.wallHit} digits={isAverage ? 3 : 0} prevValue={compareToStats ? compareToStats.wallHit : null} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Badge label="Max combo" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={stats.maxCombo} digits={isAverage ? 2 : 0} prevValue={compareToStats ? compareToStats.maxCombo : null} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
|
||||||
|
<Badge label="Pauses" color="white" bgColor="var(--dimmed)" fluid={true}>
|
||||||
|
<svelte:fragment slot="value">
|
||||||
|
<Value value={stats.pauses} digits={isAverage ? 3 : 0} prevValue={compareToStats ? compareToStats.pauses : null} prevAbsolute={true} prevWithSign={false} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.stats {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
align-self: flex-start;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
font-size: .9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats > * {
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 5.25em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats :global(.badge .value) {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats .block {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats .addon {
|
||||||
|
padding: 0 .25em;
|
||||||
|
margin-left: .5em;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: var(--foreground);
|
||||||
|
font-size: .75em;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
.stats .addon + .addon {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
.stats .addon.left {
|
||||||
|
background-color: var(--left-saber-color);
|
||||||
|
}
|
||||||
|
.stats .addon.right {
|
||||||
|
background-color: var(--right-saber-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats :global(.value small.prev) {
|
||||||
|
display: inline;
|
||||||
|
opacity: .5;
|
||||||
|
margin-left: .5em;
|
||||||
|
color: var(--textColor)
|
||||||
|
}
|
||||||
|
</style>
|
85
src/components/Common/Accuracy.svelte
Normal file
85
src/components/Common/Accuracy.svelte
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<script>
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import {diffColors} from '../../utils/scoresaber/format'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import {formatDate} from '../../utils/date'
|
||||||
|
import Badge from './Badge.svelte'
|
||||||
|
import Value from './Value.svelte'
|
||||||
|
|
||||||
|
export let score;
|
||||||
|
export let prevScore = null;
|
||||||
|
export let showPercentageInstead = false;
|
||||||
|
export let noSecondMetric = false;
|
||||||
|
export let secondMetricInsteadOfDiff = false;
|
||||||
|
|
||||||
|
const badgesDef = [
|
||||||
|
{name: 'SS+', min: 95, max: null, color: diffColors.expertPlus},
|
||||||
|
{name: 'SS', min: 90, max: 95, color: diffColors.expert},
|
||||||
|
{name: 'S+', min: 85, max: 90, color: diffColors.hard},
|
||||||
|
{name: 'S', min: 80, max: 85, color: diffColors.normal},
|
||||||
|
{name: 'A', min: 70, max: 80, color: diffColors.easy},
|
||||||
|
{name: '-', min: null, max: 70, color: 'var(--dimmed)'},
|
||||||
|
];
|
||||||
|
|
||||||
|
badgesDef.forEach(badge => {
|
||||||
|
badge.desc = `${showPercentageInstead ? 'Percentage' : 'Accuracy'} ${badge.name} (${!badge.min ? `< ${badge.max}%` : (!badge.max ? `> ${badge.min}%` : `${badge.min}% - ${badge.max}%`)})`;
|
||||||
|
});
|
||||||
|
|
||||||
|
function getBadge(acc) {
|
||||||
|
if (!acc) return null;
|
||||||
|
|
||||||
|
return badgesDef.reduce((cum, badge) => ((!badge.min || badge.min <= acc) && (!badge.max || badge.max > acc)) ? badge : cum, badgesDef[badgesDef.length - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$: badge = getBadge(showPercentageInstead ? opt(score, 'percentage') : opt(score, 'acc'));
|
||||||
|
$: mods = opt(score, 'mods')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor={badge ? badge.color : 'var(--dimmed)'} title={badge ? badge.desc : badge} label="">
|
||||||
|
<span slot="label">
|
||||||
|
<slot name="label-before"></slot>
|
||||||
|
<Value value={showPercentageInstead ? score.percentage : score.acc}
|
||||||
|
prevValue={showPercentageInstead ? opt(prevScore, 'percentage') : opt(prevScore, 'acc')}
|
||||||
|
title={badge ? badge.desc : null} inline={false} suffix="%" suffixPrev="%" zero="-" withZeroSuffix={false}
|
||||||
|
prevTitle={"${value} on " + (configStore, $configStore, formatDate(opt(prevScore, 'timeSet'), 'short', 'short'))}
|
||||||
|
/>
|
||||||
|
<slot name="label-after"></slot>
|
||||||
|
{#if !noSecondMetric && secondMetricInsteadOfDiff && ((showPercentageInstead && score.acc) || (!showPercentageInstead && score.percentage)) && score.acc !== score.percentage}
|
||||||
|
<small>
|
||||||
|
<Value value={showPercentageInstead ? score.acc : score.percentage}
|
||||||
|
withZeroSuffix={true} inline={false} suffix="%" suffixPrev="%"
|
||||||
|
title={showPercentageInstead ? 'Accuracy' : 'Percentage'}
|
||||||
|
/>
|
||||||
|
</small>
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<small class="mods" slot="additional" title={mods ? 'Mods: ' + mods.join(', ') : null}>{#if mods && mods.length}{`${mods.join(' ')}`}{/if}</small>
|
||||||
|
</Badge>
|
||||||
|
|
||||||
|
{#if !noSecondMetric && !secondMetricInsteadOfDiff && score.mods && score.mods.length && score.acc !== score.percentage}
|
||||||
|
<small>
|
||||||
|
<Value value={!showPercentageInstead ? score.percentage : score.acc}
|
||||||
|
withZeroSuffix={true} inline={false} suffix="%" suffixPrev="%"
|
||||||
|
title={showPercentageInstead ? 'Accuracy' : 'Percentage'}
|
||||||
|
/>
|
||||||
|
</small>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
small {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mods {
|
||||||
|
max-width: 1.5em;
|
||||||
|
max-height: 2em;
|
||||||
|
line-height: 1;
|
||||||
|
white-space: normal!important;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mods:empty {display: none!important;}
|
||||||
|
</style>
|
108
src/components/Common/Autocomplete.svelte
Normal file
108
src/components/Common/Autocomplete.svelte
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher, onMount} from 'svelte';
|
||||||
|
import Button from './Button.svelte'
|
||||||
|
import Error from './Error.svelte'
|
||||||
|
import Dropdown from './Dropdown.svelte'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let value = "";
|
||||||
|
export let error = null;
|
||||||
|
export let searchFunc = null;
|
||||||
|
export let searchOnInput = false;
|
||||||
|
export let placeholder = "";
|
||||||
|
export let noItemsFound = "No items found";
|
||||||
|
export let withButton = true;
|
||||||
|
|
||||||
|
let items = [];
|
||||||
|
let isLoading = false;
|
||||||
|
let shown = false;
|
||||||
|
let inputEl = null;
|
||||||
|
|
||||||
|
async function search(value) {
|
||||||
|
if (!searchFunc) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
error = null;
|
||||||
|
isLoading = true;
|
||||||
|
shown = false;
|
||||||
|
|
||||||
|
items = await searchFunc(value);
|
||||||
|
|
||||||
|
shown = true;
|
||||||
|
} catch (err) {
|
||||||
|
error = err;
|
||||||
|
shown = false;
|
||||||
|
} finally {
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectItem(item) {
|
||||||
|
shown = false;
|
||||||
|
|
||||||
|
value = item;
|
||||||
|
|
||||||
|
dispatch('selected', item)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onKeyDown(e) {
|
||||||
|
if (e.key === 'Enter') search(e.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value && searchOnInput && searchFunc) search(value);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (inputEl) inputEl.focus();
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="autocomplete">
|
||||||
|
<input bind:this={inputEl} bind:value {placeholder}
|
||||||
|
on:input={e => searchOnInput ? search(e.target.value) : null}
|
||||||
|
on:keydown={onKeyDown}
|
||||||
|
disabled={isLoading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if withButton}
|
||||||
|
<span class="button-cont">
|
||||||
|
<Button iconFa="fas fa-search" type="primary" loading={isLoading} disabled={isLoading}
|
||||||
|
on:click={() => search(value)}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<div><Error {error}/></div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Dropdown {items} {shown} noItems={noItemsFound} on:select={event => selectItem(event.detail)}>
|
||||||
|
<svelte:fragment slot="row" let:item>
|
||||||
|
<slot name="row" {item}></slot>
|
||||||
|
</svelte:fragment>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div.autocomplete {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
min-width: 16rem;
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--foreground);
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid var(--faded);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
input::placeholder {
|
||||||
|
color: var(--faded) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.button-cont {
|
||||||
|
font-size: .75em;
|
||||||
|
}
|
||||||
|
</style>
|
19
src/components/Common/Avatar.svelte
Normal file
19
src/components/Common/Avatar.svelte
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
|
||||||
|
export let player;
|
||||||
|
|
||||||
|
$: avatar = opt(player, 'playerInfo.avatar')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if avatar}
|
||||||
|
<figure class="image is-24x24" on:click>
|
||||||
|
<img src={avatar} alt=""/>
|
||||||
|
</figure>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
img {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
</style>
|
137
src/components/Common/Badge.svelte
Normal file
137
src/components/Common/Badge.svelte
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<script>
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
|
import Value from "./Value.svelte";
|
||||||
|
|
||||||
|
export let label = null;
|
||||||
|
export let fluid = false;
|
||||||
|
export let value = 0;
|
||||||
|
export let color = "var(--textColor)";
|
||||||
|
export let bgColor = "var(--background)"
|
||||||
|
export let title = "";
|
||||||
|
export let zero = "0";
|
||||||
|
export let digits = 2;
|
||||||
|
export let type = "number";
|
||||||
|
export let prefix = "";
|
||||||
|
export let suffix = "";
|
||||||
|
export let onlyLabel = false;
|
||||||
|
export let clickable = false;
|
||||||
|
export let notSelected = false;
|
||||||
|
export let styling = "";
|
||||||
|
export let prevValue = null;
|
||||||
|
export let prevLabel = null;
|
||||||
|
export let prevSuffix = null;
|
||||||
|
export let reversePrevSign = false;
|
||||||
|
export let inline = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class={"badge " + styling} class:clickable class:not-selected={notSelected} class:fluid={fluid} style="--color:{color}; --background-color:{bgColor}" title={title} transition:fade={{ duration: 500 }} on:click>
|
||||||
|
<span class="label"><slot name="label">{label}</slot></span>
|
||||||
|
{#if !onlyLabel}
|
||||||
|
<span class="spacer"></span>
|
||||||
|
<span class="value">
|
||||||
|
<slot name="value">
|
||||||
|
{#if type === 'number'}<Value value={value} {zero} {digits} {prefix} {suffix} {prevValue} {prevLabel} suffixPrev={prevSuffix} {reversePrevSign} {inline}/>{:else}{value}{/if}
|
||||||
|
</slot>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
{#if $$slots.additional}<slot name="additional"></slot>{/if}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.badge {
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
align-items: center;
|
||||||
|
color: var(--color, #eee);
|
||||||
|
background-color: var(--background-color, #222);
|
||||||
|
margin: 0 .5em .5em 0;
|
||||||
|
padding: .125em;
|
||||||
|
border-radius: .25em;
|
||||||
|
transition: opacity .25s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge.not-selected {
|
||||||
|
opacity: .35;
|
||||||
|
}
|
||||||
|
.badge.not-selected:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.badge.clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge span {
|
||||||
|
display: inline-block;
|
||||||
|
width: 50%;
|
||||||
|
text-align: center;
|
||||||
|
min-width: min-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge .spacer {
|
||||||
|
width: 1px;
|
||||||
|
min-width: auto;
|
||||||
|
height: .875em;
|
||||||
|
margin-top: .075em;
|
||||||
|
border-left: 1px solid var(--color, #eee);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge span.label {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 1em;
|
||||||
|
color: inherit;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge span.value {
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge.fluid span {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
.badge.fluid span.label {
|
||||||
|
padding: 0 .5em;
|
||||||
|
}
|
||||||
|
.badge.fluid span.value {
|
||||||
|
padding: 0 .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge.text:before {
|
||||||
|
content: "\A";
|
||||||
|
width: 5px;
|
||||||
|
height: 5px;
|
||||||
|
display: inline-block;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--textColor);
|
||||||
|
margin-right: .5rem;
|
||||||
|
top: -3px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.badge.text {
|
||||||
|
background: transparent!important;
|
||||||
|
display: block !important;
|
||||||
|
padding: 0!important;
|
||||||
|
margin: 0 0 0.05em 0!important;
|
||||||
|
}
|
||||||
|
.badge.text span.label {
|
||||||
|
display: inline;
|
||||||
|
padding: 0!important;
|
||||||
|
}
|
||||||
|
.badge.text span.label:after {
|
||||||
|
content: ":";
|
||||||
|
margin-left: .125em;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.badge.text span.spacer {
|
||||||
|
border-left-width: 0px;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
.badge.text span.value {
|
||||||
|
padding: 0!important;
|
||||||
|
min-width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge[title]:not([title=""]) {
|
||||||
|
pointer-events: fill;
|
||||||
|
}
|
||||||
|
</style>
|
182
src/components/Common/Button.svelte
Normal file
182
src/components/Common/Button.svelte
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte';
|
||||||
|
import Spinner from './Spinner.svelte'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let label = "";
|
||||||
|
export let icon = null;
|
||||||
|
export let iconFa = null;
|
||||||
|
export let disabled = false;
|
||||||
|
export let type = 'default';
|
||||||
|
export let cls = "";
|
||||||
|
export let title = null;
|
||||||
|
export let noMargin = false;
|
||||||
|
export let color = null;
|
||||||
|
export let bgColor = null;
|
||||||
|
export let notSelected = false;
|
||||||
|
export let options = null;
|
||||||
|
export let selectedOption = null;
|
||||||
|
export let loading = false;
|
||||||
|
export let url = null;
|
||||||
|
|
||||||
|
if (!selectedOption && options && Array.isArray(options) && options.length) selectedOption = options[0];
|
||||||
|
|
||||||
|
const types = {
|
||||||
|
default: {
|
||||||
|
color: "#444",
|
||||||
|
activeColor: "#222",
|
||||||
|
bgColor: "#dbdbdb",
|
||||||
|
activeBgColor: "#aaa",
|
||||||
|
border: "transparent",
|
||||||
|
activeBorder: "transparent",
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
color: "#dbdbdb",
|
||||||
|
activeColor: "#fff",
|
||||||
|
bgColor: "#3273db",
|
||||||
|
activeBgColor: "#2366d1",
|
||||||
|
border: "transparent",
|
||||||
|
activeBorder: "transparent",
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
color: "var(--textColor)",
|
||||||
|
activeColor: "var(--textColor)",
|
||||||
|
bgColor: "transparent",
|
||||||
|
activeBgColor: "transparent",
|
||||||
|
border: "transparent",
|
||||||
|
activeBorder: "transparent",
|
||||||
|
},
|
||||||
|
twitch: {
|
||||||
|
color: "#dbdbdb",
|
||||||
|
activeColor: "#fff",
|
||||||
|
bgColor: "#9146ff",
|
||||||
|
activeBgColor: "#8333ff",
|
||||||
|
border: "transparent",
|
||||||
|
activeBorder: "transparent",
|
||||||
|
},
|
||||||
|
danger: {
|
||||||
|
color: "#dbdbdb",
|
||||||
|
activeColor: "#fff",
|
||||||
|
bgColor: "red",
|
||||||
|
activeBgColor: "#bf0000",
|
||||||
|
border: "transparent",
|
||||||
|
activeBorder: "transparent",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
$: selectedType = types[type] ? types[type] : types.default;
|
||||||
|
$: margin = label && label.length ? ".45em" : "1px"
|
||||||
|
$: btnPadding = label && label.length ? "calc(.45em - 1px) 1em" : "calc(.45em - 1px) .25em";
|
||||||
|
$: btnMargin = noMargin ? 0 : "0 0 .45em 0";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if url && url.length}
|
||||||
|
<a href={url}
|
||||||
|
style="--color:{color ? color : selectedType.color}; --bg-color: {bgColor ? bgColor : selectedType.bgColor}; --border:{selectedType.border};--active-color: {selectedType.activeColor}; --active-bg-color: {selectedType .activeBgColor}; --active-border: {selectedType.activeBorder}; --margin: {margin}; --btn-padding: {btnPadding}; --btn-margin: {btnMargin}" on:click|preventDefault={() => dispatch('click', selectedOption)} {disabled} {title} class={'button clickable ' + (type?type:'default') + ' ' + cls}
|
||||||
|
class:not-selected={notSelected} class:disabled={disabled}>
|
||||||
|
{#if icon && !loading}<span class="icon">{@html icon}</span>{/if}
|
||||||
|
{#if iconFa && !loading}<i class={iconFa}></i>{/if}
|
||||||
|
{#if loading}<i><Spinner /></i>{/if}
|
||||||
|
<span>{label}</span>
|
||||||
|
<slot></slot>
|
||||||
|
</a>
|
||||||
|
{:else}
|
||||||
|
<button style="--color:{color ? color : selectedType.color}; --bg-color: {bgColor ? bgColor : selectedType.bgColor}; --border:{selectedType.border};--active-color: {selectedType.activeColor}; --active-bg-color: {selectedType .activeBgColor}; --active-border: {selectedType.activeBorder}; --margin: {margin}; --btn-padding: {btnPadding}; --btn-margin: {btnMargin}" on:click={() => dispatch('click', selectedOption)} {disabled} {title} class={'button clickable ' + (type?type:'default') + ' ' + cls}
|
||||||
|
class:not-selected={notSelected}>
|
||||||
|
{#if icon}<span class="icon">{@html icon}</span>{/if}
|
||||||
|
{#if iconFa && !loading}<i class={iconFa}></i>{/if}
|
||||||
|
{#if loading}<i><Spinner /></i>{/if}
|
||||||
|
<span>{label}</span>
|
||||||
|
<slot></slot>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
a.button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
vertical-align: top;
|
||||||
|
padding: var(--btn-padding, calc(.45em - 1px) 1em);
|
||||||
|
margin: var(--btn-margin, 0 0 .45em 0);
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 1px solid var(--border, #dbdbdb);
|
||||||
|
border-radius: .2em;
|
||||||
|
font-size: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--color, #363636)!important;
|
||||||
|
background-color: var(--bg-color, #3273dc)!important;
|
||||||
|
outline: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
color: var(--active-color, #fff);
|
||||||
|
border-color: var(--active-border, #b5b5b5)
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:active {
|
||||||
|
background-color: var(--active-bg-color, #fff);
|
||||||
|
}
|
||||||
|
|
||||||
|
a.button[disabled] {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
button[disabled], a.button.disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: .35;
|
||||||
|
color: var(--active-color, white);
|
||||||
|
background-color: var(--bg-color, #3273dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button .icon:first-child:not(:last-child), .button i:first-child:not(:last-child) {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 1.3em;
|
||||||
|
height: 1.3em;
|
||||||
|
margin-left: calc(- var(--margin, .45em) - 1px);
|
||||||
|
margin-right: var(--margin, .45em);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button :global(.dropdown-trigger button) {
|
||||||
|
color: inherit!important;
|
||||||
|
background-color: inherit!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.not-selected {
|
||||||
|
opacity: .35!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.not-selected:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.button.is-loading::after) {
|
||||||
|
border-color: transparent transparent rgba(0,0,0,.7) rgba(0,0,0,.7)!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.button.twitch.is-loading::after) {
|
||||||
|
border-color: transparent transparent rgba(219,219,219,1) rgba(219,219,219,1)!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(button .icon svg), :global(button i) {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1.3em;
|
||||||
|
height: 1.3em;
|
||||||
|
vertical-align: -.125em;
|
||||||
|
overflow: visible;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
fill: currentColor;
|
||||||
|
}
|
||||||
|
</style>
|
137
src/components/Common/Carousel.svelte
Normal file
137
src/components/Common/Carousel.svelte
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<script>
|
||||||
|
import createContainerStore from '../../stores/container'
|
||||||
|
import {onMount} from 'svelte'
|
||||||
|
|
||||||
|
export let cards = null;
|
||||||
|
|
||||||
|
let mainEl = null;
|
||||||
|
let swipeHandlersBinded = false;
|
||||||
|
let currentItem = 0;
|
||||||
|
let carouselHeight = 0;
|
||||||
|
|
||||||
|
const containerStore = createContainerStore();
|
||||||
|
|
||||||
|
async function updateHeight(carousel, item, delay = 0) {
|
||||||
|
if (!carousel) return;
|
||||||
|
|
||||||
|
const setHeight = () => {
|
||||||
|
const itemNode = carousel.querySelector(`.cards-wrapper > div:nth-child(${item + 1})`);
|
||||||
|
if (!itemNode) return;
|
||||||
|
|
||||||
|
const rect = itemNode.getBoundingClientRect();
|
||||||
|
if (rect.height) carouselHeight = rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delay) setHeight();
|
||||||
|
|
||||||
|
setTimeout(setHeight, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
function swipeLeft() {
|
||||||
|
if (cards && currentItem < cards.length - 1) currentItem++;
|
||||||
|
}
|
||||||
|
|
||||||
|
function swipeRight() {
|
||||||
|
if (currentItem > 0) currentItem--;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCardHeightChanged() {
|
||||||
|
if (mainEl) updateHeight(mainEl, currentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
if (mainEl) {
|
||||||
|
mainEl.removeEventListener('swiped-left', swipeLeft);
|
||||||
|
mainEl.removeEventListener('swiped-right', swipeRight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$: if (mainEl) {
|
||||||
|
containerStore.observe(mainEl)
|
||||||
|
if (!swipeHandlersBinded) {
|
||||||
|
mainEl.addEventListener('swiped-left', swipeLeft);
|
||||||
|
mainEl.addEventListener('swiped-right', swipeRight);
|
||||||
|
|
||||||
|
swipeHandlersBinded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$: cards, currentItem = 0;
|
||||||
|
$: cardsHash = cards ? cards.map(c => c.name).join(':') : null;
|
||||||
|
$: updateHeight(mainEl, currentItem, cards && cards[currentItem] && cardsHash ? cards[currentItem].delay || 0 : 0)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if cards && cards.length}
|
||||||
|
<section bind:this={mainEl} class="carousel"
|
||||||
|
style="--cards-cnt: {cards.length}; --width: {$containerStore.nodeWidth}px; --height: {carouselHeight}px; --item:{currentItem}"
|
||||||
|
data-swipe-threshold="50"
|
||||||
|
>
|
||||||
|
<div class="cards-wrapper">
|
||||||
|
{#each cards as card, cardIdx (card.name)}
|
||||||
|
{#key card.name}
|
||||||
|
<div>
|
||||||
|
<svelte:component this={card.component} {...card.props}
|
||||||
|
on:height-changed={onCardHeightChanged}
|
||||||
|
on:player-gain-changed
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/key}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if cards.length > 1}
|
||||||
|
<div class="bullets">
|
||||||
|
{#each cards as card, cardIdx}
|
||||||
|
<span class:active={cardIdx === currentItem} on:click={() => currentItem = cardIdx}></span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.carousel {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 120px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cards-wrapper {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(var(--cards-cnt), 100%);
|
||||||
|
grid-template-rows: 1fr;
|
||||||
|
height: var(--height);
|
||||||
|
min-height: inherit;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cards-wrapper > div {
|
||||||
|
width: 100%;
|
||||||
|
height: max-content;
|
||||||
|
transition: transform 300ms;
|
||||||
|
transition-timing-function: ease-out;
|
||||||
|
transform: translate3d(calc(var(--width, 0) * var(--item, 0) * -1), 0, 0);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bullets {
|
||||||
|
margin-top: 1em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bullets > span {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
background-color: var(--dimmed);
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 0 .25em;
|
||||||
|
transition: background-color 300ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bullets > span.active {
|
||||||
|
background-color: var(--textColor);
|
||||||
|
}
|
||||||
|
</style>
|
52
src/components/Common/Change.svelte
Normal file
52
src/components/Common/Change.svelte
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<script>
|
||||||
|
import Value from './Value.svelte'
|
||||||
|
import {onMount} from 'svelte'
|
||||||
|
|
||||||
|
export let value = 0;
|
||||||
|
export let digits = 2;
|
||||||
|
|
||||||
|
let resolvedValue = value;
|
||||||
|
let unsubscribe = null;
|
||||||
|
function resolveValue(value) {
|
||||||
|
if (value && value.subscribe) {
|
||||||
|
unsubscribe = value.subscribe(value => resolvedValue = value);
|
||||||
|
} else {
|
||||||
|
resolvedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
if (unsubscribe) unsubscribe();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$: resolveValue(value);
|
||||||
|
$: minValue = Math.pow(10, -digits-1)
|
||||||
|
$: absoluteValue = Math.abs(value);
|
||||||
|
|
||||||
|
$: mainClass = (resolvedValue ? (resolvedValue > minValue ? "inc" : (resolvedValue < -minValue ? "dec" : "zero")): "");
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class={mainClass}>
|
||||||
|
{#if value > 0}
|
||||||
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7l4-4m0 0l4 4m-4-4v18"></path></svg>
|
||||||
|
{:else if value < 0}
|
||||||
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 17l-4 4m0 0l-4-4m4 4V3"></path></svg>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Value value={absoluteValue} zero="" {digits} />
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
span {
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
}
|
||||||
|
</style>
|
176
src/components/Common/ChartBrowser.svelte
Normal file
176
src/components/Common/ChartBrowser.svelte
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
import 'chartjs-adapter-luxon';
|
||||||
|
import {DAY, formatDate, formatDateWithOptions} from '../../utils/date'
|
||||||
|
import {formatNumber} from '../../utils/format'
|
||||||
|
|
||||||
|
export let data = null;
|
||||||
|
export let color = "#2366d1";
|
||||||
|
export let tooltipTitleFunc = null;
|
||||||
|
export let tooltipLabelFunc = null;
|
||||||
|
export let tickFormatFunc = null;
|
||||||
|
export let type = 'time';
|
||||||
|
export let order = 'desc';
|
||||||
|
export let displayType = 'bar';
|
||||||
|
export let linearRoundPrecision = 2;
|
||||||
|
export let height = "80px";
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let canvas = null;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
async function setupChart(canvas, data, tooltipTitleFunc, tooltipLabelFunc) {
|
||||||
|
if (!canvas || !data?.length) return;
|
||||||
|
|
||||||
|
const skipped = (ctx, value) => ctx.p0.skip || ctx.p1.skip ? value : undefined;
|
||||||
|
|
||||||
|
const yAxes = {
|
||||||
|
y: {
|
||||||
|
display: false,
|
||||||
|
grid: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const xAxis = {
|
||||||
|
type,
|
||||||
|
display: true,
|
||||||
|
offset: true,
|
||||||
|
time: {
|
||||||
|
unit: 'month',
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
reverse: order !== 'asc',
|
||||||
|
ticks: {
|
||||||
|
major: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
backdropPadding: 0,
|
||||||
|
padding: 0,
|
||||||
|
font: function (context) {
|
||||||
|
const font = {size: 11};
|
||||||
|
|
||||||
|
if (context?.tick?.major) font.weight = 'bold';
|
||||||
|
|
||||||
|
return font;
|
||||||
|
},
|
||||||
|
callback: (val, idx, ticks) => {
|
||||||
|
if (!ticks?.[idx]) return '';
|
||||||
|
|
||||||
|
if (tickFormatFunc) return tickFormatFunc(val, idx, ticks);
|
||||||
|
|
||||||
|
return type === 'time'
|
||||||
|
? formatDateWithOptions(new Date(ticks[idx]?.value), {
|
||||||
|
localeMatcher: 'best fit',
|
||||||
|
year: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
})
|
||||||
|
: formatNumber(ticks[idx]?.value, linearRoundPrecision);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const datasets = [{
|
||||||
|
label: 'Date',
|
||||||
|
data,
|
||||||
|
fill: false,
|
||||||
|
backgroundColor: color,
|
||||||
|
borderColor: color,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 1,
|
||||||
|
maxBarThickness: 3,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: displayType ?? 'bar',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
|
||||||
|
if (!chart) {
|
||||||
|
chart = new Chart(
|
||||||
|
canvas,
|
||||||
|
{
|
||||||
|
type: 'line',
|
||||||
|
data: {datasets},
|
||||||
|
options: {
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
spanGaps: DAY,
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
interaction: {
|
||||||
|
mode: 'index',
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
onClick(e, item) {
|
||||||
|
if ((item?.[0]?.element?.$context?.raw?.page ?? null) === null) return;
|
||||||
|
|
||||||
|
dispatch('page-changed', {page: item[0].element.$context.raw.page, raw: item[0].element.$context.raw});
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
position: 'nearest',
|
||||||
|
displayColors: false,
|
||||||
|
callbacks: {
|
||||||
|
title(ctx) {
|
||||||
|
if (!ctx?.[0]?.raw) return '';
|
||||||
|
|
||||||
|
return tooltipTitleFunc ? tooltipTitleFunc(ctx[0]) : formatDate(new Date(ctx[0].raw?.x), 'long', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
label(ctx) {
|
||||||
|
return tooltipLabelFunc
|
||||||
|
? tooltipLabelFunc(ctx)
|
||||||
|
: (ctx?.raw?.page ?? null) !== null ? `Click to go to page ${ctx.raw.page + 1}` : null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: xAxis,
|
||||||
|
...yAxes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
chart.data = {datasets}
|
||||||
|
chart.options.scales = {x: xAxis, ...yAxes}
|
||||||
|
chart.update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: setupChart(canvas, data, tooltipTitleFunc, tooltipLabelFunc)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if data?.length}
|
||||||
|
<section class="chart" style="--height: {height}">
|
||||||
|
<canvas class="chartjs" bind:this={canvas}></canvas>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
position: relative;
|
||||||
|
margin: 1rem auto 0 auto;
|
||||||
|
height: var(--height, 32px);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
</style>
|
94
src/components/Common/Dialog.svelte
Normal file
94
src/components/Common/Dialog.svelte
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import Button from '../Common/Button.svelte';
|
||||||
|
import Modal from "../Common/Modal.svelte";
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let title;
|
||||||
|
export let message
|
||||||
|
export let closeable = true;
|
||||||
|
export let type = 'alert';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal showCloseButton={false} {closeable} on:close={() => dispatch(type === 'alert' ? 'confirm' : 'cancel')}
|
||||||
|
width="auto" height="auto">
|
||||||
|
<header>
|
||||||
|
<slot name="header">
|
||||||
|
{title}
|
||||||
|
</slot>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<slot name="content">
|
||||||
|
{#if message && message.length}<p>{message}</p>{/if}
|
||||||
|
</slot>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<slot name="footer">
|
||||||
|
<span class="left"><slot name="footer-left"></slot></span>
|
||||||
|
|
||||||
|
<span class="right"><slot name="footer-right">
|
||||||
|
{#if type === 'alert'}
|
||||||
|
<Button label="Ok" type="primary" on:click={() => dispatch('confirm')}/>
|
||||||
|
{:else if type === 'confirm'}
|
||||||
|
<Button label="Ok" type="primary" on:click={() => dispatch('confirm')}/>
|
||||||
|
<Button label="Ok" type="primary" on:click={() => dispatch('cancel')}/>
|
||||||
|
{/if}
|
||||||
|
</slot></span>
|
||||||
|
</slot>
|
||||||
|
</footer>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:global('.ss-modal') {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
font-size: 1.25em;
|
||||||
|
margin-top: .4em;
|
||||||
|
margin-bottom: .8em;
|
||||||
|
color: var(--alternate);
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
color: var(--textColor);
|
||||||
|
overflow-y: auto;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
main::-webkit-scrollbar {
|
||||||
|
width: .25rem;
|
||||||
|
}
|
||||||
|
body::-webkit-scrollbar-track {
|
||||||
|
background: var(--foreground, #fff);
|
||||||
|
}
|
||||||
|
main::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--selected, #3273dc) ;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 3px solid var(--selected, #3273dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
margin-top: 2em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer .left, footer .right {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer .right {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer :global(.button) {
|
||||||
|
margin-right: .25em !important;
|
||||||
|
}
|
||||||
|
</style>
|
79
src/components/Common/Donut.svelte
Normal file
79
src/components/Common/Donut.svelte
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<script>
|
||||||
|
import {formatNumber} from '../../utils/format'
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
|
||||||
|
export let name = null;
|
||||||
|
export let value = 0;
|
||||||
|
export let percentage = 0;
|
||||||
|
export let color = '#6fdb6f';
|
||||||
|
export let background = 'transparent';
|
||||||
|
export let digits = 2;
|
||||||
|
export let valueProps = {};
|
||||||
|
export let animDuration = 1000;
|
||||||
|
|
||||||
|
export let compareToValue = null;
|
||||||
|
export let compareToPercentage = null;
|
||||||
|
export let compareToName = null;
|
||||||
|
|
||||||
|
$: percentageValue = (1 - percentage) * 440;
|
||||||
|
$: percentageValueFormatted = (configStore, $configStore, formatNumber(percentage * 100, digits));
|
||||||
|
|
||||||
|
$: compareToPercentageValueFormatted = (configStore, $configStore, compareToPercentage ? formatNumber(compareToPercentage * 100, digits) : null);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="donut" style="--percentage:{percentageValue ? percentageValue : 0};--duration: {animDuration}; --backgroundColor: {background}">
|
||||||
|
<span>
|
||||||
|
<Value {value} {...valueProps} title={percentageValueFormatted + '%'} prevTitle={compareToPercentageValueFormatted + '%'} prevValue={compareToValue} prevAbsolute={true} prevWithSign={false}>
|
||||||
|
<svelte:fragment slot="prev" let:formatted let:value>
|
||||||
|
{#if value}<small>{formatted}</small>{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Value>
|
||||||
|
</span>
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 160 160" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g>
|
||||||
|
<circle id="circle" class="circle_animation" r="69.85699" cy="81" cx="81" stroke-width="12" stroke="{color}" fill="none"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.donut {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 4.5em;
|
||||||
|
height: 4.5em;
|
||||||
|
font-size: .875em;
|
||||||
|
background-color: var(--backgroundColor);
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.donut > span {
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.circle_animation {
|
||||||
|
stroke-dasharray: 440;
|
||||||
|
stroke-dashoffset: var(--percentage, 0)!important;
|
||||||
|
|
||||||
|
-webkit-animation: donut var(--duration)ms ease-out forwards;
|
||||||
|
animation: donut var(--duration)ms ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.donut > span :global(small) {
|
||||||
|
line-height: 1;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--faded);
|
||||||
|
}
|
||||||
|
</style>
|
76
src/components/Common/Dropdown.svelte
Normal file
76
src/components/Common/Dropdown.svelte
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let items = [];
|
||||||
|
export let shown = false;
|
||||||
|
export let noItems = null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="dropdown-menu" role="menu" class:shown>
|
||||||
|
<div class="dropdown-content">
|
||||||
|
{#if items && items.length}
|
||||||
|
{#each items as item}
|
||||||
|
<div class="dropdown-item" on:click={() => dispatch('select', item)}>
|
||||||
|
<slot name="row" {item}>
|
||||||
|
{item}
|
||||||
|
</slot>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
{:else if noItems}
|
||||||
|
<div class="menu-label">{noItems}</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.dropdown-menu {
|
||||||
|
display: none;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
width: 100%;
|
||||||
|
max-height: 15rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
border: 1px solid var(--dimmed);
|
||||||
|
border-radius: .25rem;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu.shown {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu::-webkit-scrollbar {
|
||||||
|
width: .25rem;
|
||||||
|
}
|
||||||
|
body::-webkit-scrollbar-track {
|
||||||
|
background: var(--foreground, #fff);
|
||||||
|
}
|
||||||
|
.dropdown-menu::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--selected, #3273dc) ;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 3px solid var(--selected, #3273dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu .dropdown-content {
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--background);
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu .dropdown-item {
|
||||||
|
color: inherit;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu .dropdown-item:hover {
|
||||||
|
background-color: var(--selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content .menu-label {
|
||||||
|
padding: .5em;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
</style>
|
31
src/components/Common/Error.svelte
Normal file
31
src/components/Common/Error.svelte
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<script>
|
||||||
|
export let error;
|
||||||
|
export let withTrace = false;
|
||||||
|
|
||||||
|
function getMessage(error) {
|
||||||
|
return error && error.toString ? error.toString() : 'Unknown error';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStack(error) {
|
||||||
|
return error.stack
|
||||||
|
}
|
||||||
|
|
||||||
|
$: message = getMessage(error)
|
||||||
|
$: stack = withTrace ? getStack(error) : null
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if message}
|
||||||
|
<span>{message}</span>
|
||||||
|
{/if}
|
||||||
|
{#if stack}
|
||||||
|
{#each stack.split('\n') as line}
|
||||||
|
<div>{line}</div>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
span {
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--decrease, 'red');
|
||||||
|
}
|
||||||
|
</style>
|
25
src/components/Common/File.svelte
Normal file
25
src/components/Common/File.svelte
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte';
|
||||||
|
import Button from './Button.svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let accept;
|
||||||
|
export let disabled = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Button {...$$props}>
|
||||||
|
<input type="file" {accept} {disabled} on:change />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
input[type=file] {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
outline: none;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
</style>
|
17
src/components/Common/Flag.svelte
Normal file
17
src/components/Common/Flag.svelte
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let country;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if country && country.length}
|
||||||
|
<img src={`https://scoresaber.com/imports/images/flags/${country ? country.toLowerCase() : '' }.png`} loading="lazy"
|
||||||
|
class="country"
|
||||||
|
on:click|preventDefault={() => dispatch('flag-click', {country: country.toLowerCase()})}>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
27
src/components/Common/FormattedDate.svelte
Normal file
27
src/components/Common/FormattedDate.svelte
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<script>
|
||||||
|
import {dateFromString, formatDate, formatDateRelative, isValidDate} from '../../utils/date'
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
|
||||||
|
export let date = new Date();
|
||||||
|
export let prevDate = null;
|
||||||
|
export let noDate = "";
|
||||||
|
export let prevPrefix = "";
|
||||||
|
export let absolute = false;
|
||||||
|
|
||||||
|
$: dateObj = isValidDate(date) ? date : dateFromString(date)
|
||||||
|
$: dateTitle = (configStore, $configStore, dateObj && !absolute ? formatDate(dateObj) : null)
|
||||||
|
$: formatted = dateObj ? (absolute ? formatDate(dateObj) : formatDateRelative(dateObj)) : noDate
|
||||||
|
$: prevDateObj = prevDate ? (isValidDate(prevDate) ? prevDate : dateFromString(date)) : null
|
||||||
|
$: prevDateTitle = (configStore, $configStore, prevDateObj && !absolute ? formatDate(prevDateObj) : null)
|
||||||
|
$: prevFormatted = prevDateObj ? (absolute ? formatDate(prevDateObj) : formatDateRelative(prevDateObj)) : "";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span
|
||||||
|
title={dateTitle}>{formatted}</span>{#if prevDateObj }<small title={prevDateTitle}>{prevPrefix}{prevFormatted}</small>{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
small {
|
||||||
|
display: block;
|
||||||
|
color: var(--faded);
|
||||||
|
}
|
||||||
|
</style>
|
139
src/components/Common/Modal.svelte
Normal file
139
src/components/Common/Modal.svelte
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher, onDestroy} from 'svelte';
|
||||||
|
import Button from '../Common/Button.svelte';
|
||||||
|
import {fade, fly} from 'svelte/transition'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
const close = () => dispatch('close');
|
||||||
|
|
||||||
|
export let showCloseButton = true;
|
||||||
|
export let closeable = true;
|
||||||
|
export let width = "calc(100vw - 4em)";
|
||||||
|
export let height = "auto";
|
||||||
|
|
||||||
|
let modal;
|
||||||
|
|
||||||
|
const handle_keydown = e => {
|
||||||
|
if (closeable && e.key === 'Escape') {
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.key === 'Tab') {
|
||||||
|
// trap focus
|
||||||
|
const nodes = modal.querySelectorAll('*');
|
||||||
|
const tabbable = Array.from(nodes).filter(n => n.tabIndex >= 0);
|
||||||
|
|
||||||
|
let index = tabbable.indexOf(document.activeElement);
|
||||||
|
if (index === -1 && e.shiftKey) index = 0;
|
||||||
|
|
||||||
|
index += tabbable.length + (e.shiftKey ? -1 : 1);
|
||||||
|
index %= tabbable.length;
|
||||||
|
|
||||||
|
tabbable[index].focus();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const previously_focused = typeof document !== 'undefined' && document.activeElement;
|
||||||
|
|
||||||
|
if (previously_focused) {
|
||||||
|
onDestroy(() => {
|
||||||
|
previously_focused.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$: heightInPx = !isNaN(parseInt(height, 10)) ? parseInt(height, 10) : null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={handle_keydown}/>
|
||||||
|
|
||||||
|
<div class="ss-modal-background" on:click={() => {closeable ? close() : null}} transition:fade></div>
|
||||||
|
|
||||||
|
<div class="ss-modal" role="dialog" aria-modal="true" bind:this={modal} style="--width: {width}; --height: {height};"
|
||||||
|
transition:fly={{y: heightInPx ? heightInPx : 300}}>
|
||||||
|
<div class="inner">
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if closeable && showCloseButton}
|
||||||
|
<Button iconFa="fas fa-times" on:click={close} cls="close"/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.ss-modal-background {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: rgba(0, 0, 0, 0.75);
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ss-modal {
|
||||||
|
position: fixed;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
width: var(--width);
|
||||||
|
height: var(--height);
|
||||||
|
min-width: 25em;
|
||||||
|
max-width: 60em;
|
||||||
|
max-height: 80vh;
|
||||||
|
overflow: auto;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
padding: 1em;
|
||||||
|
color: var(--textColor);
|
||||||
|
background: var(--background);
|
||||||
|
z-index: 2000;
|
||||||
|
border-radius: .5em;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ss-modal .inner {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ss-modal::-webkit-scrollbar {
|
||||||
|
width: .25rem;
|
||||||
|
}
|
||||||
|
body::-webkit-scrollbar-track {
|
||||||
|
background: var(--foreground, #fff);
|
||||||
|
}
|
||||||
|
.ss-modal::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--selected, #3273dc) ;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 3px solid var(--selected, #3273dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.ss-modal button.close) {
|
||||||
|
position: absolute !important;
|
||||||
|
top: .5em;
|
||||||
|
right: .5em;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.ss-modal {
|
||||||
|
top: auto;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
transform: none;
|
||||||
|
width: 100%;
|
||||||
|
min-width: min(20em, 100vw);
|
||||||
|
max-width: none;
|
||||||
|
min-height: 12em;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
309
src/components/Common/Pager.svelte
Normal file
309
src/components/Common/Pager.svelte
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher, onMount} from 'svelte';
|
||||||
|
import Spinner from './Spinner.svelte'
|
||||||
|
import {debounce} from '../../utils/debounce'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
const WINDOW_RESIZE_DEBOUNCE_TIME = 500;
|
||||||
|
const MINIMUM_PAGES = 5;
|
||||||
|
|
||||||
|
export let totalItems = null;
|
||||||
|
export let currentPage = 0;
|
||||||
|
export let itemsPerPage = 10;
|
||||||
|
export let itemsPerPageValues = [5, 10, 15, 20, 25];
|
||||||
|
export let displayMax = 11;
|
||||||
|
export let hide = false;
|
||||||
|
export let mode = 'pages';
|
||||||
|
export let loadingPage = null;
|
||||||
|
|
||||||
|
let displayStart = false;
|
||||||
|
let displayEnd = false;
|
||||||
|
let prevItemsPerPage = itemsPerPage;
|
||||||
|
|
||||||
|
let navEl = null;
|
||||||
|
let currentDisplayMax = displayMax;
|
||||||
|
|
||||||
|
function dispatchEvent(page = 0, initial = false) {
|
||||||
|
let to = (page + 1) * itemsPerPage - 1;
|
||||||
|
if (isTotalItemsAvailable && to > totalItems - 1) to = totalItems - 1;
|
||||||
|
|
||||||
|
dispatch('page-changed', {page, itemsPerPage, from: page * itemsPerPage, to, total: totalItems, initial});
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
dispatchEvent(currentPage, true);
|
||||||
|
})
|
||||||
|
|
||||||
|
async function onPageChanged(page) {
|
||||||
|
if (loadingPage) return;
|
||||||
|
|
||||||
|
dispatchEvent(page, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcPages(total, current, max) {
|
||||||
|
const needToDisplayFacetedPages = total > max;
|
||||||
|
|
||||||
|
const middle = Math.floor(max / 2);
|
||||||
|
const startPage = current > middle && needToDisplayFacetedPages ? current - middle + 1 : 0;
|
||||||
|
|
||||||
|
displayStart = current > middle && needToDisplayFacetedPages;
|
||||||
|
displayEnd = current + middle + 1 < total && needToDisplayFacetedPages;
|
||||||
|
|
||||||
|
if (currentPage > pagesTotal - 1) currentPage = pagesTotal - 1;
|
||||||
|
if (currentPage < 0) currentPage = 0;
|
||||||
|
|
||||||
|
return allPages.slice(startPage - (needToDisplayFacetedPages && !displayEnd ? middle - total + current + 1 : 0), startPage + max - (displayStart ? 1 : 0) - (displayEnd ? 1 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEnd(currentPage, itemsPerPage, totalItems) {
|
||||||
|
const end = (currentPage + 1) * itemsPerPage;
|
||||||
|
|
||||||
|
return isTotalItemsAvailable && end > totalItems ? totalItems : end;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onItemsPerPageChanged() {
|
||||||
|
const firstItem = prevItemsPerPage * currentPage
|
||||||
|
|
||||||
|
prevItemsPerPage = itemsPerPage;
|
||||||
|
currentPage = Math.floor(firstItem / itemsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onWindowResize() {
|
||||||
|
if (!navEl) return;
|
||||||
|
|
||||||
|
const minPositionWidth = 8.5 * 16;
|
||||||
|
const itemWidth = 51.85;
|
||||||
|
|
||||||
|
const pagerWidth = opt(navEl.getBoundingClientRect(), 'width', null);
|
||||||
|
if (!pagerWidth) return;
|
||||||
|
|
||||||
|
const numOfPagesThatWillFit = Math.floor((pagerWidth - minPositionWidth) / itemWidth) - 4;
|
||||||
|
currentDisplayMax = numOfPagesThatWillFit <= displayMax ? numOfPagesThatWillFit : displayMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedOnWindowResize = debounce(() => onWindowResize(), WINDOW_RESIZE_DEBOUNCE_TIME);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
window.addEventListener('resize', debouncedOnWindowResize);
|
||||||
|
|
||||||
|
onWindowResize();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('resize', debouncedOnWindowResize)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$: isTotalItemsAvailable = Number.isFinite(totalItems);
|
||||||
|
$: pagesTotal = isTotalItemsAvailable ? Math.ceil(totalItems / itemsPerPage) : null;
|
||||||
|
$: allPages = isTotalItemsAvailable ? Array(pagesTotal).fill(null).map((val, idx) => idx + 1) : []
|
||||||
|
$: displayedPages = isTotalItemsAvailable ? calcPages(pagesTotal, currentPage, currentDisplayMax) : [];
|
||||||
|
$: startItem = currentPage * itemsPerPage + 1;
|
||||||
|
$: endItem = getEnd(currentPage, itemsPerPage, totalItems);
|
||||||
|
$: currentMode = !isTotalItemsAvailable || currentDisplayMax < MINIMUM_PAGES ? 'simple' : mode;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if (pagesTotal > 1 || currentMode === 'simple') && !hide}
|
||||||
|
<nav class="pagination" class:simple={currentMode === 'simple'} bind:this={navEl}
|
||||||
|
class:no-items-per-page={!itemsPerPageValues}>
|
||||||
|
<div class="position">{startItem} - {endItem}
|
||||||
|
{#if totalItems} / {totalItems}{/if}
|
||||||
|
</div>
|
||||||
|
<ul class="pagination-list">
|
||||||
|
{#if currentMode === 'simple'}
|
||||||
|
{#if currentPage !== 0}
|
||||||
|
<li>
|
||||||
|
<button on:click={() => onPageChanged(0)} class="pagination-link">
|
||||||
|
{#if loadingPage === 0}
|
||||||
|
<Spinner/>
|
||||||
|
{:else}
|
||||||
|
<i class="fas fa-step-backward"></i>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<button on:click={() => onPageChanged(currentPage - 1)} class="pagination-link">
|
||||||
|
{#if loadingPage === currentPage - 1}
|
||||||
|
<Spinner/>
|
||||||
|
{:else}
|
||||||
|
<i class="fas fa-chevron-left"></i>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{:else}
|
||||||
|
<li><span class="pagination-link disabled"><i class="fas fa-step-backward"></i></span></li>
|
||||||
|
<li><span class="pagination-link disabled"><i class="fas fa-chevron-left"></i></span></li>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if !isTotalItemsAvailable || currentPage !== pagesTotal - 1}
|
||||||
|
<li>
|
||||||
|
<button on:click={() => onPageChanged(currentPage + 1)} class="pagination-link">
|
||||||
|
{#if loadingPage === currentPage + 1}
|
||||||
|
<Spinner/>
|
||||||
|
{:else}
|
||||||
|
<i class="fas fa-chevron-right"></i>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{#if isTotalItemsAvailable}
|
||||||
|
<li>
|
||||||
|
<button on:click={() => onPageChanged(pagesTotal - 1)} class="pagination-link">
|
||||||
|
{#if loadingPage === pagesTotal - 1}
|
||||||
|
<Spinner/>
|
||||||
|
{:else}
|
||||||
|
<i class="fas fa-step-forward"></i>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{:else}
|
||||||
|
<li><span class="pagination-link disabled"><i class="fas fa-step-forward"></i></span></li>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<li><span class="pagination-link disabled"><i class="fas fa-chevron-right"></i></span></li>
|
||||||
|
<li><span class="pagination-link disabled"><i class="fas fa-step-forward"></i></span></li>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
{#if displayStart}
|
||||||
|
<li class:is-loading={loadingPage === 0}>
|
||||||
|
<button on:click={() => onPageChanged(0)}
|
||||||
|
class={'pagination-link' + (currentPage === 0 ? ' is-current' : '')}>
|
||||||
|
<span class="spinner"><Spinner/></span>
|
||||||
|
<span class="page">1</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li><span class="pagination-ellipsis">…</span></li>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#each displayedPages as page}
|
||||||
|
<li class:is-loading={loadingPage === page - 1}>
|
||||||
|
<button on:click={() => onPageChanged(page-1)}
|
||||||
|
class={'pagination-link' + (currentPage === page - 1 ? ' is-current' : '')}>
|
||||||
|
<span class="spinner"><Spinner/></span>
|
||||||
|
<span class="page">{page}</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
{#if displayEnd}
|
||||||
|
<li><span class="pagination-ellipsis">…</span></li>
|
||||||
|
<li class:is-loading={loadingPage === pagesTotal - 1}>
|
||||||
|
<button on:click={() => onPageChanged(pagesTotal - 1)}
|
||||||
|
class={'pagination-link' + (currentPage === pagesTotal - 1 ? ' is-current' : '')}>
|
||||||
|
<span class="spinner"><Spinner/></span>
|
||||||
|
<span class="page">{pagesTotal}</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</ul>
|
||||||
|
{#if itemsPerPageValues && itemsPerPageValues.length}
|
||||||
|
<div class="items-per-page"><select bind:value={itemsPerPage} on:change={onItemsPerPageChanged}>
|
||||||
|
{#each itemsPerPageValues as ipp}
|
||||||
|
<option value={ipp}>{ipp}</option>
|
||||||
|
{/each}
|
||||||
|
</select></div>
|
||||||
|
{/if}
|
||||||
|
</nav>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
button {
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
font-size: 1em;
|
||||||
|
border: none;
|
||||||
|
color: var(--textColor, #000);
|
||||||
|
background-color: var(--foreground, #fff);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination.no-items-per-page {
|
||||||
|
justify-content: space-between !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-list {
|
||||||
|
max-width: none !important;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination.simple .pagination-list {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination.simple .pagination-list button i {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.pagination-link {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-link {
|
||||||
|
border-color: var(--alternate);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-link.is-current, .pagination:not(.simple) button:hover {
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--selected);
|
||||||
|
border-color: var(--selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-link.is-current {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-link:focus {
|
||||||
|
border-color: #dbdbdb !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-link .spinner {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-loading .pagination-link .spinner {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-loading .pagination-link .page {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.position {
|
||||||
|
min-width: 8.5em;
|
||||||
|
order: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-list {
|
||||||
|
order: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-per-page {
|
||||||
|
order: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767px) {
|
||||||
|
.pagination {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination.no-items-per-page .pagination-list {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
34
src/components/Common/PlayerNameWithFlag.svelte
Normal file
34
src/components/Common/PlayerNameWithFlag.svelte
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte';
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import Flag from './Flag.svelte'
|
||||||
|
|
||||||
|
export let player;
|
||||||
|
export let type = 'scoresaber/recent'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
$: country = opt(player, 'playerInfo.countries.0.country')
|
||||||
|
$: name = opt(player, 'name')
|
||||||
|
$: playerId = opt(player, 'playerId')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a href={`/u/${playerId}/${type}/1`} class="player-name clickable has-pointer-events" title={name} on:click|preventDefault>
|
||||||
|
<Flag {country} on:flag-click />
|
||||||
|
<span>{name}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
a {
|
||||||
|
color: inherit!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-name {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-name :global(> img) {
|
||||||
|
margin-right: .125rem;
|
||||||
|
}
|
||||||
|
</style>
|
51
src/components/Common/QueueStats.svelte
Normal file
51
src/components/Common/QueueStats.svelte
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<script>
|
||||||
|
import queue from '../../network/queues/queues'
|
||||||
|
import {tweened} from 'svelte/motion'
|
||||||
|
import {cubicOut} from 'svelte/easing';
|
||||||
|
import Donut from './Donut.svelte'
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
|
||||||
|
const TWEEN_DEFAULT_OPTIONS = {duration: 200, easing: cubicOut};
|
||||||
|
|
||||||
|
const ssApiQueueStats = queue.SCORESABER_API;
|
||||||
|
|
||||||
|
let progressTween = tweened(0, TWEEN_DEFAULT_OPTIONS);
|
||||||
|
|
||||||
|
$: progressTween.set(
|
||||||
|
Math.round($ssApiQueueStats.progress.progress * 100),
|
||||||
|
{...TWEEN_DEFAULT_OPTIONS, duration: $ssApiQueueStats.progress.progress === 0 ? 0 : TWEEN_DEFAULT_OPTIONS.duration},
|
||||||
|
);
|
||||||
|
|
||||||
|
$: waiting = opt($ssApiQueueStats, 'rateLimit.waiting')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if ($ssApiQueueStats.progress.count > 2 && $progressTween < 100) || waiting }
|
||||||
|
<aside transition:fade={{duration: TWEEN_DEFAULT_OPTIONS.duration * 2}} class:waiting={waiting}>
|
||||||
|
<Donut color={waiting > 0 ? "#bf2a42" : "#8f48db"}
|
||||||
|
background="var(--background)"
|
||||||
|
value={waiting > 0 ? waiting/1000 : $progressTween}
|
||||||
|
valueProps={{digits:0, suffix: waiting > 0 ? '' : '%'}}
|
||||||
|
percentage={waiting && $ssApiQueueStats.progress.count <= 2 ? 1 : $progressTween/100}
|
||||||
|
digits={0}
|
||||||
|
animDuration={0}
|
||||||
|
/>
|
||||||
|
</aside>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
aside {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: .25rem;
|
||||||
|
font-size: .65em;
|
||||||
|
}
|
||||||
|
|
||||||
|
aside :global(.donut > span) {
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
aside.waiting :global(.donut > span) {
|
||||||
|
font-size: 1.4em;
|
||||||
|
}
|
||||||
|
</style>
|
34
src/components/Common/Skeleton.svelte
Normal file
34
src/components/Common/Skeleton.svelte
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<script>
|
||||||
|
export let width = "100%";
|
||||||
|
export let height = "1em";
|
||||||
|
export let inline = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style="--width: {width}; --height: {height}; --inline: {inline}" class="skeleton-fade" class:inline> </div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div {
|
||||||
|
width: var(--width, "100%");
|
||||||
|
height: var(--height, "1em");
|
||||||
|
max-height: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
background-color: var(--dimmed);
|
||||||
|
animation: skeleton-fade 1.5s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.inline {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes skeleton-fade {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
34
src/components/Common/Spinner.svelte
Normal file
34
src/components/Common/Spinner.svelte
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<script>
|
||||||
|
export let width = "1em";
|
||||||
|
export let height = "1em";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
style="--width: {width}; --height: {height}"
|
||||||
|
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||||
|
<path fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
svg {
|
||||||
|
width: var(--width);
|
||||||
|
height: var(--height);
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
svg circle {
|
||||||
|
opacity: .25;
|
||||||
|
}
|
||||||
|
svg path {
|
||||||
|
opacity: .75;
|
||||||
|
}
|
||||||
|
@keyframes spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
54
src/components/Common/Switcher.svelte
Normal file
54
src/components/Common/Switcher.svelte
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte';
|
||||||
|
|
||||||
|
import Button from '../Common/Button.svelte'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let values;
|
||||||
|
export let value = values && values.length ? values[0] : null;
|
||||||
|
export let loadingValue = null;
|
||||||
|
|
||||||
|
async function onChange(newValue) {
|
||||||
|
dispatch('change', newValue)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if values && (values.length > 1 || (values.length === 1 && values[0] !== value)) }
|
||||||
|
<div class="switch-types">
|
||||||
|
{#if values && values.length}
|
||||||
|
{#each values as currentValue }
|
||||||
|
<Button
|
||||||
|
icon={currentValue.icon}
|
||||||
|
iconFa={currentValue.iconFa}
|
||||||
|
loading={loadingValue === currentValue}
|
||||||
|
label={currentValue.label}
|
||||||
|
title={currentValue.title}
|
||||||
|
type={currentValue === value ? 'primary' : 'default'}
|
||||||
|
color={currentValue.color ? 'white' : null}
|
||||||
|
bgColor={currentValue.color ? currentValue.color : null}
|
||||||
|
notSelected={currentValue !== value}
|
||||||
|
url={currentValue.url}
|
||||||
|
on:click={() => onChange(currentValue)}
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.switch-types {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-size: .75rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-types :global(.button) {
|
||||||
|
font-weight: 500;
|
||||||
|
margin-right: .125rem !important;
|
||||||
|
margin-bottom: .125rem !important;
|
||||||
|
}
|
||||||
|
</style>
|
67
src/components/Common/Value.svelte
Normal file
67
src/components/Common/Value.svelte
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<script>
|
||||||
|
import {onMount} from 'svelte'
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import {round, formatNumber, substituteVars} from '../../utils/format'
|
||||||
|
|
||||||
|
export let value = 0;
|
||||||
|
export let prevValue = null;
|
||||||
|
export let reversePrevSign = false;
|
||||||
|
export let digits = 2;
|
||||||
|
export let zero = formatNumber(0, Number.isInteger(digits) ? digits : 2);
|
||||||
|
export let withSign = false;
|
||||||
|
export let prefix = "";
|
||||||
|
export let withZeroPrefix = false;
|
||||||
|
export let suffix = "";
|
||||||
|
export let suffixPrev = null;
|
||||||
|
export let withZeroSuffix = false;
|
||||||
|
export let inline = false;
|
||||||
|
export let useColorsForValue = false;
|
||||||
|
export let prevLabel = "";
|
||||||
|
export let title = null;
|
||||||
|
export let prevTitle = null;
|
||||||
|
export let prevAbsolute = false;
|
||||||
|
export let forcePrev = false;
|
||||||
|
export let prevWithSign = true;
|
||||||
|
|
||||||
|
let resolvedValue = value;
|
||||||
|
let unsubscribe = null;
|
||||||
|
function resolveValue(value) {
|
||||||
|
if (value && value.subscribe) {
|
||||||
|
unsubscribe = value.subscribe(value => resolvedValue = value);
|
||||||
|
} else {
|
||||||
|
resolvedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFormattedValue(value, digits, withSign, minValue, prefix, suffix, withZeroPrefix, withZeroSuffix) {
|
||||||
|
return Number.isFinite(value) && Math.abs(value) > minValue
|
||||||
|
? prefix + formatNumber(value, digits, withSign) + suffix
|
||||||
|
: (withZeroPrefix ? prefix : "") + zero + (withZeroSuffix ? suffix : "")
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
if (unsubscribe) unsubscribe();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$: resolveValue(value);
|
||||||
|
$: minValue = Math.pow(10, -digits-1)
|
||||||
|
$: minDiff = Math.pow(10, -digits)
|
||||||
|
$: formatted = getFormattedValue(resolvedValue, digits, withSign, minValue, prefix, suffix, withZeroPrefix, withZeroSuffix, configStore && $configStore);
|
||||||
|
$: showPrevValue = Number.isFinite(prevValue)&& resolvedValue !== null && Math.abs(round(prevValue-resolvedValue, digits)) >= minDiff || forcePrev;
|
||||||
|
$: prevFormatted = (configStore, $configStore, prevValue && Number.isFinite(prevValue) ? (prevLabel ? prevLabel + ': ' : '') + formatNumber(prevValue, digits, prevWithSign) + suffix : "")
|
||||||
|
$: prevLabelFormatted = (configStore, $configStore, prevValue && Number.isFinite(prevValue) ? (prevLabel ? prevLabel + ': ' : '') + formatNumber(prevValue, digits) + suffix : "")
|
||||||
|
$: prevDiff = Number.isFinite(prevValue) ? (prevAbsolute ? prevValue : resolvedValue - prevValue) * (reversePrevSign ? -1 : 1) : null;
|
||||||
|
$: prevDiffFormatted = Number.isFinite(prevDiff) ? (configStore, $configStore, resolvedValue, Number.isFinite(prevDiff) ? formatNumber(prevDiff, digits, !prevAbsolute) + (suffixPrev ? suffixPrev : suffix) : "") : null
|
||||||
|
$: prevClass = (prevDiff !== null ? (prevDiff > minValue ? "inc" : (prevDiff < -minValue ? "dec" : "zero")): "") + (!inline ? " block" : " inline") + ' prev';
|
||||||
|
$: mainClass = (useColorsForValue && resolvedValue ? (resolvedValue > minValue ? "inc" : (resolvedValue < -minValue ? "dec" : "zero")): "");
|
||||||
|
$: prevTitleFormatted = substituteVars(prevTitle ? prevTitle : "${value}", {value: prevLabelFormatted})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class={mainClass} {title}><slot name="value" value={resolvedValue} {formatted}>{formatted}</slot></span>{#if showPrevValue} <small class={`has-pointer-events ${prevClass}`} title={prevTitleFormatted}><slot name="prev" value={prevValue} formatted={prevFormatted} diff={prevDiff} diffFormatted={prevDiffFormatted}>{prevDiffFormatted}</slot></small>{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
small.block {display: block;}
|
||||||
|
small.inline {margin-left: .5em;}
|
||||||
|
</style>
|
239
src/components/Nav.svelte
Normal file
239
src/components/Nav.svelte
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
<script>
|
||||||
|
import eventBus from '../utils/broadcast-channel-pubsub'
|
||||||
|
import {onMount} from 'svelte'
|
||||||
|
import {navigate} from 'svelte-routing'
|
||||||
|
import createFriendsStore from '../stores/scoresaber/friends'
|
||||||
|
import {configStore} from '../stores/config'
|
||||||
|
import createPlayerService from '../services/scoresaber/player'
|
||||||
|
import Dropdown from './Common/Dropdown.svelte'
|
||||||
|
import MenuLine from './Player/MenuLine.svelte'
|
||||||
|
import QueueStats from './Common/QueueStats.svelte'
|
||||||
|
import {opt} from '../utils/js'
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
import Settings from './Others/Settings.svelte'
|
||||||
|
|
||||||
|
const playerService = createPlayerService();
|
||||||
|
|
||||||
|
let player = null;
|
||||||
|
let settingsNotificationBadge = null;
|
||||||
|
|
||||||
|
function navigateToPlayer(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
navigate(`/u/${playerId}/scoresaber/recent/1`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFriendClick(event) {
|
||||||
|
if (!event.detail) return;
|
||||||
|
|
||||||
|
friendsMenuShown = false;
|
||||||
|
|
||||||
|
navigateToPlayer(event.detail.playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateMainPlayer(playerId) {
|
||||||
|
if (!playerId) {
|
||||||
|
player = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player = await playerService.get(playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const playerChangedUnsubscribe = eventBus.on('player-profile-changed', player => {
|
||||||
|
if (mainPlayerId && player && player.playerId === mainPlayerId) updateMainPlayer(mainPlayerId)
|
||||||
|
})
|
||||||
|
|
||||||
|
const settingsBadgeUnsubscribe = eventBus.on('settings-notification-badge', message => settingsNotificationBadge = message);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
playerChangedUnsubscribe();
|
||||||
|
settingsBadgeUnsubscribe();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const friends = createFriendsStore();
|
||||||
|
|
||||||
|
let friendsMenuShown = false;
|
||||||
|
|
||||||
|
let showSettings = false;
|
||||||
|
|
||||||
|
$: mainPlayerId = opt($configStore, 'users.main');
|
||||||
|
$: updateMainPlayer(mainPlayerId)
|
||||||
|
$: newSettingsAvailable = $configStore ? configStore.getNewSettingsAvailable() : undefined;
|
||||||
|
$: notificationBadgeTitle = (settingsNotificationBadge ? [settingsNotificationBadge + '\n'] : []).concat(newSettingsAvailable ? ['New settings are available:'].concat(newSettingsAvailable) : []).join('\n');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<nav class="ssr-page-container">
|
||||||
|
{#if player}
|
||||||
|
<a href={`/u/${player.playerId}/scoresaber/recent/1`} on:click|preventDefault={() =>
|
||||||
|
navigateToPlayer(player.playerId)} transition:fade>
|
||||||
|
{#if opt(player, 'playerInfo.avatar')}
|
||||||
|
<img src={player.playerInfo.avatar} class="avatar" alt="" />
|
||||||
|
{:else}
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
Me
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="friends" on:mouseover={() => friendsMenuShown = true} on:mouseleave={() => friendsMenuShown = false}>
|
||||||
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path></svg>
|
||||||
|
|
||||||
|
Friends
|
||||||
|
|
||||||
|
<Dropdown items={$friends} shown={friendsMenuShown} on:select={onFriendClick} noItems="No friends, add someone">
|
||||||
|
<svelte:fragment slot="row" let:item>
|
||||||
|
<MenuLine player={item} withRank={false} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="/ranking/global" on:click|preventDefault={() => navigate('/ranking/global')}>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM4.332 8.027a6.012 6.012 0 011.912-2.706C6.512 5.73 6.974 6 7.5 6A1.5 1.5 0 019 7.5V8a2 2 0 004 0 2 2 0 011.523-1.943A5.977 5.977 0 0116 10c0 .34-.028.675-.083 1H15a2 2 0 00-2 2v2.197A5.973 5.973 0 0110 16v-2a2 2 0 00-2-2 2 2 0 01-2-2 2 2 0 00-1.668-1.973z" clip-rule="evenodd" />
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
Ranking
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="right">
|
||||||
|
<a href="/search" on:click|preventDefault={() => navigate('/search')}>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
Search
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="settings" title={notificationBadgeTitle} on:click={() => showSettings = true}>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
Settings
|
||||||
|
|
||||||
|
{#if settingsNotificationBadge || newSettingsAvailable}<div class="notification-badge"></div>{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<QueueStats />
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<Settings bind:show={showSettings} />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
nav {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
height: 2.75rem;
|
||||||
|
background-color: var(--foreground);
|
||||||
|
border-bottom: 1px solid var(--dimmed);
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav > *:not(.right), nav > .right > * {
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
font-size: 1rem;
|
||||||
|
padding: .5rem 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav > *:not(.right):hover, nav > .right > *:hover {
|
||||||
|
background-color: var(--selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav a {
|
||||||
|
color: inherit!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.friends {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.friends :global(.dropdown-menu) {
|
||||||
|
width: 15rem !important;
|
||||||
|
max-width: 60vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav svg, nav .avatar {
|
||||||
|
width: 1.25rem;
|
||||||
|
height: 1.25rem;
|
||||||
|
margin-right: .5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav .avatar {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav .right {
|
||||||
|
flex: 1;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-badge {
|
||||||
|
position: absolute;
|
||||||
|
top: .65rem;
|
||||||
|
left: 1.75rem;
|
||||||
|
width: .5em;
|
||||||
|
height: .5em;
|
||||||
|
background-color: red;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: pulse 1.5s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 450px) {
|
||||||
|
nav {
|
||||||
|
height: 3.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav > *:not(.right), nav > .right > * {
|
||||||
|
flex: 1;
|
||||||
|
border-right: 1px solid var(--dimmed);
|
||||||
|
flex-direction: column;
|
||||||
|
font-size: .75rem;
|
||||||
|
}
|
||||||
|
nav > *:last-child, nav > .right > *:last-child {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav svg, nav .avatar {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0% {
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
70% {
|
||||||
|
transform: scale(1);
|
||||||
|
box-shadow: 0 0 0 10px rgba(255, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 0 0 0 rgba(255, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
37
src/components/Others/Select.svelte
Normal file
37
src/components/Others/Select.svelte
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<script>
|
||||||
|
export let value = null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="select-wrapper">
|
||||||
|
<select bind:value class="select-element">
|
||||||
|
<slot />
|
||||||
|
</select>
|
||||||
|
<i class="fa fa-chevron-down select-arrow" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.select-wrapper {
|
||||||
|
position: relative;
|
||||||
|
display: block;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.select-element {
|
||||||
|
width: 100%;
|
||||||
|
font-size: 1em;
|
||||||
|
padding: 0.5em 2em 0.5em 1em;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-moz-appearance: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
}
|
||||||
|
.select-element::-ms-expand {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.select-arrow {
|
||||||
|
position: absolute;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
top: 50%;
|
||||||
|
right: 0;
|
||||||
|
transform: translate(-0.75em, -50%);
|
||||||
|
}
|
||||||
|
</style>
|
254
src/components/Others/Settings.svelte
Normal file
254
src/components/Others/Settings.svelte
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
<script>
|
||||||
|
import produce from 'immer'
|
||||||
|
import {configStore, DEFAULT_LOCALE, getSupportedLocales} from '../../stores/config'
|
||||||
|
import createTwitchService from '../../services/twitch'
|
||||||
|
import {ROUTER} from 'svelte-routing/src/contexts'
|
||||||
|
import {getContext, onMount} from 'svelte'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import eventBus from '../../utils/broadcast-channel-pubsub'
|
||||||
|
import {DAY} from '../../utils/date'
|
||||||
|
import {exportJsonData, importDataHandler} from '../../utils/export-import'
|
||||||
|
import Dialog from '../Common/Dialog.svelte'
|
||||||
|
import Button from '../Common/Button.svelte'
|
||||||
|
import File from '../Common/File.svelte'
|
||||||
|
import Select from "./Select.svelte"
|
||||||
|
|
||||||
|
export let show = false;
|
||||||
|
|
||||||
|
const DEFAULT_SCORE_COMPARISON_METHOD = 'in-place';
|
||||||
|
const DEFAULT_SECONDARY_PP_METRICS = 'attribution';
|
||||||
|
const DEFAULT_AVATAR_ICONS = 'only-if-needed';
|
||||||
|
|
||||||
|
let twitchToken = null;
|
||||||
|
|
||||||
|
let twitchService = createTwitchService();
|
||||||
|
|
||||||
|
const {activeRoute} = getContext(ROUTER);
|
||||||
|
|
||||||
|
const scoreComparisonMethods = [
|
||||||
|
{name: 'In place', value: DEFAULT_SCORE_COMPARISON_METHOD},
|
||||||
|
{name: 'In details', value: 'in-details'},
|
||||||
|
];
|
||||||
|
|
||||||
|
const secondaryPpMetrics = [
|
||||||
|
{name: 'Weighted PP', value: 'weighted'},
|
||||||
|
{name: 'Actual contribution to the total PP', value: DEFAULT_SECONDARY_PP_METRICS},
|
||||||
|
];
|
||||||
|
|
||||||
|
const avatarIcons = [
|
||||||
|
{name: 'Always show', value: 'show'},
|
||||||
|
{name: 'Show when needed', value: DEFAULT_AVATAR_ICONS},
|
||||||
|
{name: 'Always hide', value: 'hide'},
|
||||||
|
];
|
||||||
|
|
||||||
|
let currentLocale = DEFAULT_LOCALE;
|
||||||
|
let currentScoreComparisonMethod = DEFAULT_SCORE_COMPARISON_METHOD;
|
||||||
|
let currentSecondaryPpMetrics = DEFAULT_SECONDARY_PP_METRICS;
|
||||||
|
let currentAvatarIcons = DEFAULT_AVATAR_ICONS;
|
||||||
|
|
||||||
|
function onConfigUpdated(config) {
|
||||||
|
if (config?.locale) currentLocale = config.locale;
|
||||||
|
if (config?.scoreComparison) currentScoreComparisonMethod = config?.scoreComparison?.method ?? DEFAULT_SCORE_COMPARISON_METHOD;
|
||||||
|
if (config?.preferences?.secondaryPp) currentSecondaryPpMetrics = config?.preferences?.secondaryPp ?? DEFAULT_SECONDARY_PP_METRICS;
|
||||||
|
if (config?.preferences?.avatarIcons) currentAvatarIcons = config?.preferences?.avatarIcons ?? DEFAULT_AVATAR_ICONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSave() {
|
||||||
|
if (!configStore || !$configStore) return;
|
||||||
|
|
||||||
|
$configStore = produce($configStore, draft => {
|
||||||
|
draft.locale = currentLocale;
|
||||||
|
draft.scoreComparison.method = currentScoreComparisonMethod;
|
||||||
|
draft.preferences.secondaryPp = currentSecondaryPpMetrics;
|
||||||
|
draft.preferences.avatarIcons = currentAvatarIcons;
|
||||||
|
})
|
||||||
|
|
||||||
|
show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCancel() {
|
||||||
|
if (configStore && $configStore) {
|
||||||
|
currentLocale = $configStore.locale;
|
||||||
|
currentScoreComparisonMethod = $configStore.scoreComparison.method;
|
||||||
|
currentSecondaryPpMetrics = $configStore.preferences.secondaryPp;
|
||||||
|
currentAvatarIcons = $configStore.preferences.avatarIcons;
|
||||||
|
}
|
||||||
|
|
||||||
|
show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let showTwitchLinkBtn = true;
|
||||||
|
let twitchBtnLabel = 'Link to Twitch'
|
||||||
|
let twitchBtnTitle = null;
|
||||||
|
let twitchBtnDisabled = true;
|
||||||
|
|
||||||
|
function refreshTwitchButton(twitchToken) {
|
||||||
|
const tokenExpireInDays = twitchToken ? Math.floor(twitchToken.expires_in / DAY) : null;
|
||||||
|
const tokenExpireSoon = tokenExpireInDays <= 7;
|
||||||
|
|
||||||
|
eventBus.publish('settings-notification-badge', twitchToken && tokenExpireSoon ? 'Twitch token is required for renewal' : null);
|
||||||
|
|
||||||
|
showTwitchLinkBtn = !twitchToken || tokenExpireSoon;
|
||||||
|
|
||||||
|
twitchBtnLabel = !twitchToken || !tokenExpireSoon ? 'Link to Twitch' : 'Renew Twitch token'
|
||||||
|
twitchBtnTitle = twitchToken && tokenExpireInDays > 0 ? `Days left: ${tokenExpireInDays}` : null;
|
||||||
|
twitchBtnDisabled = !tokenExpireSoon;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let isExporting = false;
|
||||||
|
let isImporting = false;
|
||||||
|
let importBtn = null;
|
||||||
|
|
||||||
|
async function onExport() {
|
||||||
|
try {
|
||||||
|
isExporting = true;
|
||||||
|
|
||||||
|
await exportJsonData();
|
||||||
|
} finally {
|
||||||
|
isExporting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onImport(e) {
|
||||||
|
try {
|
||||||
|
isImporting = true;
|
||||||
|
if (importBtn) importBtn.$set({disabled: true});
|
||||||
|
|
||||||
|
importDataHandler(
|
||||||
|
e,
|
||||||
|
msg => {
|
||||||
|
isImporting = false;
|
||||||
|
|
||||||
|
alert(msg)
|
||||||
|
|
||||||
|
importBtn.$set({disabled: false});
|
||||||
|
},
|
||||||
|
async json => {
|
||||||
|
isImporting = false;
|
||||||
|
if (importBtn) importBtn.$set({disabled: false});
|
||||||
|
|
||||||
|
eventBus.publish('data-imported', {});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
isImporting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const twitchTokenRefreshedUnsubscriber = eventBus.on('twitch-token-refreshed', newTwitchToken => twitchToken = newTwitchToken)
|
||||||
|
|
||||||
|
twitchToken = await twitchService.getCurrentToken();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
twitchTokenRefreshedUnsubscriber();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$: onConfigUpdated(configStore && $configStore ? $configStore : null);
|
||||||
|
$: refreshTwitchButton(twitchToken)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if show}
|
||||||
|
<Dialog title="Settings" closeable={true} on:confirm={onCancel}>
|
||||||
|
<svelte:fragment slot="content">
|
||||||
|
{#if configStore && $configStore}
|
||||||
|
<section class="options">
|
||||||
|
<section class="option">
|
||||||
|
<label title="All numbers and dates will be formatted according to the rules of the selected country">Localization</label>
|
||||||
|
<Select bind:value={currentLocale}>
|
||||||
|
{#each getSupportedLocales() as locale (locale.id)}
|
||||||
|
<option value={locale.id}>{locale.name}</option>
|
||||||
|
{/each}
|
||||||
|
</Select>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="option">
|
||||||
|
<label title="Comparison of a current player's score against the main player will be displayed either immediately or after expanding the details">Score comparison</label>
|
||||||
|
<Select bind:value={currentScoreComparisonMethod}>
|
||||||
|
{#each scoreComparisonMethods as option (option.value)}
|
||||||
|
<option value={option.value}>{option.name}</option>
|
||||||
|
{/each}
|
||||||
|
</Select>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="option">
|
||||||
|
<label title="Second PP metric displayed next to the score, either weighted PP or actual contribution of the score to the total PP (cached players only)">Secondary PP metrics</label>
|
||||||
|
<Select bind:value={currentSecondaryPpMetrics}>
|
||||||
|
{#each secondaryPpMetrics as option (option.value)}
|
||||||
|
<option value={option.value}>{option.name}</option>
|
||||||
|
{/each}
|
||||||
|
</Select>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="option">
|
||||||
|
<label
|
||||||
|
title="Determines when to show icons on player avatars">Icons on avatars</label>
|
||||||
|
<Select bind:value={currentAvatarIcons}>
|
||||||
|
{#each avatarIcons as option (option.value)}
|
||||||
|
<option value={option.value}>{option.name}</option>
|
||||||
|
{/each}
|
||||||
|
</Select>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="option twitch">
|
||||||
|
<label title="If there is a Twitch VOD available then an icon will appear next to the score which will take you directly to the appropriate VOD location.">Twitch</label>
|
||||||
|
<Button type="twitch" iconFa="fab fa-twitch"
|
||||||
|
label={twitchBtnLabel} title={twitchBtnTitle}
|
||||||
|
on:click={() => window.location.href = twitchService.getAuthUrl(opt($activeRoute, 'uri', ''))}/>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
{:else}
|
||||||
|
Loading...
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
|
||||||
|
<svelte:fragment slot="footer-left">
|
||||||
|
<File iconFa="fas fa-file-export" title="Import SSR data from file" loading={isImporting} disabled={isImporting}
|
||||||
|
accept="application/json" bind:this={importBtn} on:change={onImport}/>
|
||||||
|
<Button iconFa="fas fa-file-import" title="Export SSR data to file" on:click={onExport} loading={isExporting} disabled={isExporting}/>
|
||||||
|
</svelte:fragment>
|
||||||
|
|
||||||
|
<svelte:fragment slot="footer-right">
|
||||||
|
<Button iconFa="fas fa-save" label="Save" type="primary" on:click={onSave} disabled={!configStore}/>
|
||||||
|
<Button label="Cancel" on:click={onCancel}/>
|
||||||
|
</svelte:fragment>
|
||||||
|
</Dialog>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.options {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
grid-gap: 1em;
|
||||||
|
align-items: start;
|
||||||
|
justify-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.75em;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--faded) !important;
|
||||||
|
margin-bottom: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.twitch :global(.button) {
|
||||||
|
font-size: .875em;
|
||||||
|
width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.options {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
92
src/components/Player/Avatar.svelte
Normal file
92
src/components/Player/Avatar.svelte
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<script>
|
||||||
|
import Spinner from '../Common/Spinner.svelte'
|
||||||
|
|
||||||
|
export let playerInfo;
|
||||||
|
export let isLoading = false;
|
||||||
|
export let centered = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class="avatar-container" class:loading={isLoading} class:centered>
|
||||||
|
<span class="no-image">?</span>
|
||||||
|
|
||||||
|
{#if playerInfo && playerInfo.avatar}
|
||||||
|
<img src={playerInfo.avatar} class="avatar" alt="" />
|
||||||
|
{/if}
|
||||||
|
<span class="spinner">
|
||||||
|
<Spinner width="100%" height="100%"/>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.avatar-container {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
transition: transform 300ms;
|
||||||
|
z-index: 2;
|
||||||
|
position: absolute;
|
||||||
|
top: .75rem;
|
||||||
|
left: .75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading img, .loading .no-image {
|
||||||
|
transform: scale(.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
top: .75rem;
|
||||||
|
left: .75rem;
|
||||||
|
color: var(--faded);
|
||||||
|
z-index: 10
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading .spinner {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-image {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
border-radius: 50%;
|
||||||
|
color: var(--foreground);
|
||||||
|
background-color: var(--dimmed);
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 75px;
|
||||||
|
line-height: 1;
|
||||||
|
z-index: 0;
|
||||||
|
transition: transform 300ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-container.centered {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.avatar-container.centered img {
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
.avatar-container.centered .spinner {
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media(max-width: 768px) {
|
||||||
|
.avatar-container {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
.spinner {
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
342
src/components/Player/Charts/AccHistoryChart.svelte
Normal file
342
src/components/Player/Charts/AccHistoryChart.svelte
Normal file
@ -0,0 +1,342 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
import {
|
||||||
|
formatDate,
|
||||||
|
formatDateWithOptions,
|
||||||
|
toSsMidnight,
|
||||||
|
} from '../../../utils/date'
|
||||||
|
import createPlayerService from '../../../services/scoresaber/player'
|
||||||
|
import {debounce} from '../../../utils/debounce'
|
||||||
|
import {onLegendClick} from './utils/legend-click-handler'
|
||||||
|
import {getContext} from 'svelte'
|
||||||
|
import {DateTime} from 'luxon'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let rankHistory = null;
|
||||||
|
export let height = "350px";
|
||||||
|
|
||||||
|
const CHART_DAYS = 50;
|
||||||
|
const CHART_DEBOUNCE = 300;
|
||||||
|
|
||||||
|
const pageContainer = getContext('pageContainer');
|
||||||
|
|
||||||
|
const playerService = createPlayerService();
|
||||||
|
|
||||||
|
let canvas = null;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let lastHistoryHash = null;
|
||||||
|
let playerHistory = null;
|
||||||
|
|
||||||
|
const calcHistoryHash = (accHistory) =>
|
||||||
|
(accHistory ? Object.values(accHistory).map(h => Object.values(h).join(',')).join(':') : '')
|
||||||
|
;
|
||||||
|
|
||||||
|
async function refreshPlayerHistory(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
playerHistory = await playerService.getPlayerHistory(playerId) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupChart(hash, canvas) {
|
||||||
|
if (!hash || !canvas || chartHash === lastHistoryHash) return;
|
||||||
|
|
||||||
|
lastHistoryHash = chartHash;
|
||||||
|
|
||||||
|
if (rankHistory.length < CHART_DAYS) rankHistory = Array(CHART_DAYS - rankHistory.length).fill(null).concat(rankHistory);
|
||||||
|
|
||||||
|
const gridColor = '#2a2a2a'
|
||||||
|
const averageColor = '#3273dc';
|
||||||
|
const medianColor = '#8992e8';
|
||||||
|
const stdDevColor = '#f94022';
|
||||||
|
const ssPlusColor = 'rgba(143,72,219, .4)';
|
||||||
|
const ssColor = 'rgba(190,42,66, .4)';
|
||||||
|
const sPlusColor = 'rgba(255,99,71, .4)';
|
||||||
|
const sColor = 'rgba(89,176,244, .4)';
|
||||||
|
const aColor = 'rgba(60,179,113, .4)';
|
||||||
|
|
||||||
|
const datasets = [];
|
||||||
|
|
||||||
|
const dtAccSaberToday = DateTime.fromJSDate(toSsMidnight(new Date()));
|
||||||
|
const dayTimestamps = Array(CHART_DAYS).fill(0).map((_, idx) => toSsMidnight(dtAccSaberToday.minus({days: CHART_DAYS - 1 - idx}).toJSDate()).getTime());
|
||||||
|
|
||||||
|
const xAxis = {
|
||||||
|
type: 'time',
|
||||||
|
display: true,
|
||||||
|
offset: true,
|
||||||
|
time: {
|
||||||
|
unit: 'day',
|
||||||
|
},
|
||||||
|
scaleLabel: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
autoSkip: false,
|
||||||
|
major: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
font: function (context) {
|
||||||
|
if (context.tick && context.tick.major) {
|
||||||
|
return {
|
||||||
|
weight: 'bold',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: (val, idx, ticks) => {
|
||||||
|
if (!ticks?.[idx]) return '';
|
||||||
|
|
||||||
|
return formatDateWithOptions(new Date(ticks[idx]?.value), {
|
||||||
|
localeMatcher: 'best fit',
|
||||||
|
day: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const isScoreDataAvailable = playerHistory && playerHistory.find(h => !!h.avgAcc);
|
||||||
|
|
||||||
|
let yAxes = {
|
||||||
|
y: {
|
||||||
|
display: true,
|
||||||
|
position: 'left',
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: 'Acc',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => formatNumber(val, 2) + '%',
|
||||||
|
precision: 2
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (additionalHistory && Object.keys(additionalHistory).length) {
|
||||||
|
if (isScoreDataAvailable)
|
||||||
|
yAxes = {
|
||||||
|
...yAxes,
|
||||||
|
y1: {
|
||||||
|
display: true,
|
||||||
|
position: 'right',
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: 'Maps count',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => val === Math.floor(val) ? val : null,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
drawOnChartArea: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
y2: {
|
||||||
|
display: false,
|
||||||
|
position: 'right',
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: 'Std dev',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => val,
|
||||||
|
precision: 3,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const skipped = (ctx, value) => ctx.p0.skip || ctx.p1.skip ? value : undefined;
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: 'avgAcc',
|
||||||
|
secKey: 'averageRankedAccuracy',
|
||||||
|
name: 'Average',
|
||||||
|
borderColor: averageColor,
|
||||||
|
round: 2,
|
||||||
|
axis: 'y',
|
||||||
|
axisOrder: 0,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
.concat(
|
||||||
|
isScoreDataAvailable
|
||||||
|
? [
|
||||||
|
{key: 'medianAcc', name: 'Median', borderColor: medianColor, round: 2, axis: 'y', axisOrder: 1},
|
||||||
|
{key: 'stdDeviation', name: 'Std dev', borderColor: stdDevColor, round: 4, axis: 'y2', axisOrder: 10},
|
||||||
|
{
|
||||||
|
key: 'accBadges', keys: [
|
||||||
|
{key: 'SS+', name: 'SS+', backgroundColor: ssPlusColor, axisOrder: 2},
|
||||||
|
{key: 'SS', name: 'SS', backgroundColor: ssColor, axisOrder: 3},
|
||||||
|
{key: 'S+', name: 'S+', backgroundColor: sPlusColor, axisOrder: 4},
|
||||||
|
{key: 'S', name: 'S', backgroundColor: sColor, axisOrder: 5},
|
||||||
|
{key: 'A', name: 'A', backgroundColor: aColor, axisOrder: 5},
|
||||||
|
], round: 0, axis: 'y1',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
.forEach(obj => {
|
||||||
|
const {key, secKey, keys, name, axis, ...options} = obj;
|
||||||
|
if (keys && Array.isArray(keys)) {
|
||||||
|
keys.forEach(obj => {
|
||||||
|
const {key: innerKey, name, ...innerOptions} = obj;
|
||||||
|
const fieldData = dayTimestamps.map(x => ({x, y: additionalHistory?.[x]?.[key]?.[innerKey] ?? 0}));
|
||||||
|
|
||||||
|
datasets.push({
|
||||||
|
...options,
|
||||||
|
...innerOptions,
|
||||||
|
yAxisID: axis,
|
||||||
|
label: name,
|
||||||
|
data: fieldData,
|
||||||
|
fill: true,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 1,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: 'bar',
|
||||||
|
stack: key,
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const fieldData = dayTimestamps.map(x => ({x, y: additionalHistory?.[x]?.[key] ?? null}));
|
||||||
|
|
||||||
|
datasets.push({
|
||||||
|
...options,
|
||||||
|
yAxisID: axis,
|
||||||
|
label: name,
|
||||||
|
data: fieldData,
|
||||||
|
fill: false,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 1,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chart)
|
||||||
|
{
|
||||||
|
chart = new Chart(
|
||||||
|
canvas,
|
||||||
|
{
|
||||||
|
type: 'line',
|
||||||
|
data: {datasets},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
mode: 'index',
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
onClick: onLegendClick,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
position: 'nearest',
|
||||||
|
callbacks: {
|
||||||
|
title(ctx) {
|
||||||
|
if (!ctx?.[0]?.raw) return '';
|
||||||
|
|
||||||
|
const nextDayDate = DateTime.fromMillis(ctx[0].raw?.x).plus({days: 1}).toJSDate();
|
||||||
|
const nextDayDateFormatted = nextDayDate > new Date() ? 'now' : formatDate(nextDayDate, 'short', 'short');
|
||||||
|
|
||||||
|
return `${formatDate(new Date(ctx[0].raw?.x), 'short', 'short')} - ${nextDayDateFormatted}`;
|
||||||
|
},
|
||||||
|
label(ctx) {
|
||||||
|
switch (ctx.dataset.label) {
|
||||||
|
case 'SS+':
|
||||||
|
case 'SS':
|
||||||
|
case 'S+':
|
||||||
|
case 'S':
|
||||||
|
case 'A':
|
||||||
|
return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}`
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}%`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: xAxis,
|
||||||
|
...yAxes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chart.data = {datasets};
|
||||||
|
chart.options.scales = {x: xAxis, ...yAxes};
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let debouncedChartHash = null;
|
||||||
|
const debounceChartHash = debounce(chartHash => debouncedChartHash = chartHash, CHART_DEBOUNCE);
|
||||||
|
|
||||||
|
$: refreshPlayerHistory(playerId);
|
||||||
|
|
||||||
|
$: additionalHistory = playerHistory && playerHistory.length
|
||||||
|
? playerHistory.reduce((cum, h) => {
|
||||||
|
const time = toSsMidnight(h.ssDate)?.getTime()
|
||||||
|
if (!time) return cum;
|
||||||
|
|
||||||
|
const history = {[time]: {averageRankedAccuracy: h. averageRankedAccuracy, avgAcc: h.avgAcc, medianAcc: h.medianAcc, stdDeviation:h.stdDeviation, accBadges: h.accBadges}};
|
||||||
|
|
||||||
|
return {...cum, ...history};
|
||||||
|
}, {})
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$: chartHash = calcHistoryHash(rankHistory, additionalHistory);
|
||||||
|
$: debounceChartHash(chartHash)
|
||||||
|
$: if (debouncedChartHash) setupChart(debouncedChartHash, canvas)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if rankHistory && rankHistory.length}
|
||||||
|
<section class="chart" style="--height: {height}">
|
||||||
|
<canvas class="chartjs" bind:this={canvas} height={parseInt(height,10)}></canvas>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
position: relative;
|
||||||
|
margin: 1rem auto 0 auto;
|
||||||
|
height: var(--height, 300px);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
</style>
|
388
src/components/Player/Charts/AccMapsChart.svelte
Normal file
388
src/components/Player/Charts/AccMapsChart.svelte
Normal file
@ -0,0 +1,388 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
import zoomPlugin from 'chartjs-plugin-zoom';
|
||||||
|
import {formatNumber, roundToPrecision} from '../../../utils/format'
|
||||||
|
import {formatDateRelative} from '../../../utils/date'
|
||||||
|
import {debounce} from '../../../utils/debounce'
|
||||||
|
import {worker} from '../../../utils/worker-wrappers'
|
||||||
|
import regionsPlugin from './utils/regions-plugin'
|
||||||
|
import {capitalize} from '../../../utils/js'
|
||||||
|
import Spinner from '../../Common/Spinner.svelte'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let averageAcc = null;
|
||||||
|
export let medianAcc = null;
|
||||||
|
export let type = 'accuracy'; // or percentage
|
||||||
|
export let height = "350px";
|
||||||
|
|
||||||
|
Chart.register(zoomPlugin);
|
||||||
|
|
||||||
|
const CHART_DEBOUNCE = 300;
|
||||||
|
|
||||||
|
let canvas = null;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let lastHistoryHash = null;
|
||||||
|
let playerScores = null;
|
||||||
|
|
||||||
|
let isLoading = false;
|
||||||
|
|
||||||
|
const calcPlayerScoresHash = playerScores => (playerScores?.length ?? 0) + averageAcc + medianAcc;
|
||||||
|
|
||||||
|
const getPlayerRankedScores = async playerId => {
|
||||||
|
if (!playerId) return null;
|
||||||
|
|
||||||
|
isLoading = true;
|
||||||
|
|
||||||
|
const rankedScores = await worker.getPlayerRankedScoresWithStars(playerId);
|
||||||
|
|
||||||
|
isLoading = false;
|
||||||
|
|
||||||
|
return rankedScores;
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshPlayerRankedScores = async playerId => playerScores = await getPlayerRankedScores(playerId)
|
||||||
|
|
||||||
|
async function setupChart(hash, canvas) {
|
||||||
|
if (!hash || !canvas || !playerScores?.length || chartHash === lastHistoryHash) return;
|
||||||
|
|
||||||
|
const mapColor = '#ffffff';
|
||||||
|
const mapBorderColor = '#003e54';
|
||||||
|
const ssPlusColor = 'rgba(143,72,219, .4)';
|
||||||
|
const ssColor = 'rgba(190,42,66, .4)';
|
||||||
|
const sPlusColor = 'rgba(255,99,71, .4)';
|
||||||
|
const sColor = 'rgba(89,176,244, .4)';
|
||||||
|
const aColor = 'rgba(60,179,113, .4)';
|
||||||
|
const averageLinesColor = 'rgba(255,255,255,.35)'
|
||||||
|
|
||||||
|
lastHistoryHash = chartHash;
|
||||||
|
|
||||||
|
const skipped = (ctx, value) => ctx.p0.skip || ctx.p1.skip ? value : undefined;
|
||||||
|
|
||||||
|
let maxStars = 0;
|
||||||
|
let minAcc = 100;
|
||||||
|
const chartData = await Promise.all(playerScores
|
||||||
|
.filter(s => !!s?.score?.pp || !!s?.stars)
|
||||||
|
.map(async s => {
|
||||||
|
const acc = type === 'percentage' ? (s?.score?.percentage ? s?.score?.percentage : s?.score?.acc) : s?.score?.acc ?? 0;
|
||||||
|
|
||||||
|
if (s.stars > maxStars) maxStars = s.stars;
|
||||||
|
if (acc < minAcc) minAcc = acc;
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: s.stars,
|
||||||
|
y: acc,
|
||||||
|
leaderboardId: s.leaderboardId,
|
||||||
|
name: s?.leaderboard?.song?.name,
|
||||||
|
songAuthor: s?.leaderboard?.song?.authorName,
|
||||||
|
levelAuthor: s?.leaderboard?.song?.levelAuthorName,
|
||||||
|
diff: s?.leaderboard?.diffInfo?.diff,
|
||||||
|
timeSet: s.timeSet,
|
||||||
|
mods: s?.score?.mods,
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
const avgData = Object.entries(
|
||||||
|
chartData.reduce((cum, point) => {
|
||||||
|
const roundedStars = roundToPrecision(point.x, 0.5);
|
||||||
|
if (!cum[roundedStars]) cum[roundedStars] = [];
|
||||||
|
|
||||||
|
cum[roundedStars].push(point.y);
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, {}),
|
||||||
|
)
|
||||||
|
.reduce((cum, [stars, points]) => {
|
||||||
|
const sum = points.reduce((sum, point) => sum + point, 0);
|
||||||
|
const best = points.reduce((max, point) => point > max ? point : max, 0);
|
||||||
|
|
||||||
|
const x = parseFloat(stars);
|
||||||
|
|
||||||
|
const median = points.length > 1
|
||||||
|
? (points.sort((a, b) => a - b))[Math.ceil(points.length / 2)]
|
||||||
|
: sum
|
||||||
|
|
||||||
|
cum.best.push({x, y: best});
|
||||||
|
cum.avg.push({x, y: sum / points.length});
|
||||||
|
cum.median.push({x, y: median});
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, {avg: [], best: [], median: []})
|
||||||
|
|
||||||
|
Object.keys(avgData).forEach(key => avgData[key] = avgData[key].sort((a, b) => a.x - b.x))
|
||||||
|
|
||||||
|
maxStars = roundToPrecision(maxStars, .5) + .5;
|
||||||
|
minAcc = Math.floor(minAcc - 1);
|
||||||
|
if (minAcc < 0) minAcc = 0;
|
||||||
|
|
||||||
|
let averageLines = [];
|
||||||
|
if (averageAcc) averageLines.push({
|
||||||
|
min: averageAcc,
|
||||||
|
max: averageAcc,
|
||||||
|
color: averageLinesColor,
|
||||||
|
label: 'Average',
|
||||||
|
position: {vertical: 'bottom'},
|
||||||
|
});
|
||||||
|
if (medianAcc) averageLines.push({
|
||||||
|
min: medianAcc,
|
||||||
|
max: medianAcc,
|
||||||
|
color: averageLinesColor,
|
||||||
|
label: 'Median',
|
||||||
|
position: {horizontal: 'right'},
|
||||||
|
});
|
||||||
|
|
||||||
|
const datasets = [
|
||||||
|
{
|
||||||
|
label: 'Maps',
|
||||||
|
borderColor: mapBorderColor,
|
||||||
|
backgroundColor: mapColor,
|
||||||
|
fill: false,
|
||||||
|
pointRadius: 3,
|
||||||
|
pointHoverRadius: 4,
|
||||||
|
data: chartData,
|
||||||
|
order: 4,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
yAxisID: 'y',
|
||||||
|
label: 'Best',
|
||||||
|
borderColor: 'rgba(60,179,113, .75)',
|
||||||
|
data: avgData.best,
|
||||||
|
fill: false,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 2,
|
||||||
|
pointHoverRadius: 4,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
yAxisID: 'y',
|
||||||
|
label: 'Average',
|
||||||
|
borderColor: '#3273dc',
|
||||||
|
data: avgData.avg,
|
||||||
|
fill: false,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 2,
|
||||||
|
pointHoverRadius: 4,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
yAxisID: 'y',
|
||||||
|
label: 'Median',
|
||||||
|
borderColor: '#8992e8',
|
||||||
|
data: avgData.median,
|
||||||
|
fill: false,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 2,
|
||||||
|
pointHoverRadius: 4,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!chart) {
|
||||||
|
chart = new Chart(
|
||||||
|
canvas,
|
||||||
|
{
|
||||||
|
type: 'scatter',
|
||||||
|
data: {
|
||||||
|
datasets,
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
mode: 'nearest',
|
||||||
|
intersect: true,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
displayColors: false,
|
||||||
|
position: 'nearest',
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
},
|
||||||
|
callbacks: {
|
||||||
|
label: function (ctx) {
|
||||||
|
if (!ctx || !ctx?.dataset?.data[ctx?.dataIndex]) return '';
|
||||||
|
|
||||||
|
const ret = [];
|
||||||
|
|
||||||
|
switch (ctx?.dataset?.label) {
|
||||||
|
case 'Maps':
|
||||||
|
const song = ctx.dataset.data[ctx.dataIndex];
|
||||||
|
if (song) {
|
||||||
|
ret.push(formatDateRelative(song.timeSet));
|
||||||
|
ret.push(`${song.name} (${capitalize(song?.diff?.replace('Plus', '+' ?? ''))})`);
|
||||||
|
ret.push(`${song.songAuthor} / ${song.levelAuthor}`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
title: function (ctx) {
|
||||||
|
if (!ctx?.[0]?.raw) return '';
|
||||||
|
|
||||||
|
switch (ctx?.[0].dataset?.label) {
|
||||||
|
case 'Maps':
|
||||||
|
const mods = ctx[0].raw?.mods ?? null;
|
||||||
|
const stars = formatNumber(ctx[0].raw?.x ?? 0, 2);
|
||||||
|
const acc = formatNumber(ctx[0].raw?.y ?? 0, 2);
|
||||||
|
|
||||||
|
return type === 'percentage'
|
||||||
|
? `Percentage: ${acc}%${mods?.length ? ' (' + mods.join(', ') + ')' : ''} | Stars: ${stars}★`
|
||||||
|
: `Accuracy: ${acc}%${mods?.length ? ' (' + mods.join(', ') + ')' : ''} | Stars: ${stars}★`
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (ctx && Array.isArray(ctx))
|
||||||
|
return [`Stars: ${ctx?.[0]?.raw?.x}★`]
|
||||||
|
.concat(
|
||||||
|
ctx.map(d => `${d?.dataset?.label ?? ''}: ${formatNumber(d?.raw?.y ?? 0)}%`),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
zoom: {
|
||||||
|
pan: {
|
||||||
|
enabled: true,
|
||||||
|
mode: 'xy',
|
||||||
|
},
|
||||||
|
zoom: {
|
||||||
|
wheel: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
pinch: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
mode: 'xy',
|
||||||
|
},
|
||||||
|
limits: {
|
||||||
|
x: {min: 0, max: maxStars},
|
||||||
|
y: {min: minAcc, max: 100},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
regions: {
|
||||||
|
regions: [
|
||||||
|
{min: 95, max: 100, color: ssPlusColor},
|
||||||
|
{min: 90, max: 95, color: ssColor},
|
||||||
|
{min: 85, max: 90, color: sPlusColor},
|
||||||
|
{min: 80, max: 85, color: sColor},
|
||||||
|
{min: 0, max: 80, color: aColor},
|
||||||
|
].concat(averageLines),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
type: 'linear',
|
||||||
|
scaleLabel: {
|
||||||
|
display: false,
|
||||||
|
labelString: 'Stars',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
min: 0,
|
||||||
|
stepSize: 0.5,
|
||||||
|
callback: val => formatNumber(val, 1) + '★',
|
||||||
|
},
|
||||||
|
max: maxStars,
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
type: 'linear',
|
||||||
|
scaleLabel: {
|
||||||
|
display: true,
|
||||||
|
labelString: 'Acc',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
max: 100,
|
||||||
|
callback: val => formatNumber(val, 2) + '%',
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: "rgba(0,0,0,0.1)",
|
||||||
|
display: true,
|
||||||
|
drawBorder: true,
|
||||||
|
drawOnChartArea: true,
|
||||||
|
},
|
||||||
|
min: minAcc,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onClick(e, item, chart) {
|
||||||
|
if (!item?.[0]?.element?.$context?.raw?.leaderboardId) return;
|
||||||
|
|
||||||
|
window.open(`/leaderboard/global/${item[0].element.$context.raw.leaderboardId}`, '_blank');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [regionsPlugin],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
chart.data = {datasets}
|
||||||
|
chart.update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let debouncedChartHash = null;
|
||||||
|
const debounceChartHash = debounce(chartHash => debouncedChartHash = chartHash, CHART_DEBOUNCE);
|
||||||
|
|
||||||
|
$: refreshPlayerRankedScores(playerId);
|
||||||
|
|
||||||
|
$: chartHash = calcPlayerScoresHash(playerScores);
|
||||||
|
$: debounceChartHash(chartHash)
|
||||||
|
$: if (debouncedChartHash) setupChart(debouncedChartHash, canvas)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<section class="chart" style="--height: {height}">
|
||||||
|
<canvas class="chartjs" bind:this={canvas} height={parseInt(height,10)}></canvas>
|
||||||
|
{#if isLoading}
|
||||||
|
<Spinner width="10em" height="10em" />
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
position: relative;
|
||||||
|
margin: 1rem auto 0 auto;
|
||||||
|
height: var(--height, 300px);
|
||||||
|
}
|
||||||
|
|
||||||
|
section :global(svg) {
|
||||||
|
position: absolute;
|
||||||
|
top: calc((100% - 10em) / 2);
|
||||||
|
left: calc((100% - 10em) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
</style>
|
335
src/components/Player/Charts/AccSaberChart.svelte
Normal file
335
src/components/Player/Charts/AccSaberChart.svelte
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher, getContext} from 'svelte'
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
import 'chartjs-adapter-luxon';
|
||||||
|
import {DateTime} from 'luxon';
|
||||||
|
import createAccSaberService from '../../../services/accsaber'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
import {
|
||||||
|
addToDate,
|
||||||
|
DAY,
|
||||||
|
formatDate,
|
||||||
|
formatDateWithOptions,
|
||||||
|
toAccSaberMidnight,
|
||||||
|
} from '../../../utils/date'
|
||||||
|
import {debounce} from '../../../utils/debounce'
|
||||||
|
import {convertArrayToObjectByKey} from '../../../utils/js'
|
||||||
|
import {capitalize} from '../../../utils/js'
|
||||||
|
import Switcher from '../../Common/Switcher.svelte'
|
||||||
|
import {onLegendClick} from './utils/legend-click-handler'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let playerHistory = null;
|
||||||
|
export let height = "350px";
|
||||||
|
|
||||||
|
const CHART_DEBOUNCE = 300;
|
||||||
|
const CHART_DAYS = 30;
|
||||||
|
|
||||||
|
const pageContainer = getContext('pageContainer');
|
||||||
|
|
||||||
|
const accSaberService = createAccSaberService();
|
||||||
|
|
||||||
|
let canvas = null;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let isLoading = false;
|
||||||
|
let lastHistoryHash = null;
|
||||||
|
let playerRankHistory = null;
|
||||||
|
let availableCategories = null;
|
||||||
|
let category = 'overall';
|
||||||
|
|
||||||
|
const calcHistoryHash = (playerId, playerRankHistory, category) =>
|
||||||
|
(playerId ?? '') +
|
||||||
|
(playerRankHistory?.map(h => h?.accSaberDate?.getTime())?.join(':') ?? '') +
|
||||||
|
(playerRankHistory?.map(h => Object.keys(h?.categories ?? {})?.length ?? 0)?.join(':') ?? '') +
|
||||||
|
category
|
||||||
|
;
|
||||||
|
|
||||||
|
async function refreshPlayerRankHistory(playerId, playerHistory) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
isLoading = true;
|
||||||
|
|
||||||
|
const playerHistoryPromises = await Promise.all([
|
||||||
|
accSaberService.fetchPlayerRankHistory(playerId).catch(e => null),
|
||||||
|
playerHistory,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const theOldestChartHistory = addToDate(-49 * DAY, toAccSaberMidnight(new Date()))
|
||||||
|
const dbHistory = (playerHistoryPromises?.[1] ?? []).filter(h => h.accSaberDate >= theOldestChartHistory)
|
||||||
|
|
||||||
|
const enhancedFetchedHistory = (playerHistoryPromises?.[0]?.history ?? [])
|
||||||
|
.map(h => {
|
||||||
|
const dbItem = dbHistory.find(dbH => dbH?.accSaberDate?.getTime() === h?.date?.getTime());
|
||||||
|
if (dbItem?.categories?.overall) dbItem.categories.overall.rank = h.rank;
|
||||||
|
|
||||||
|
return dbItem ?? {
|
||||||
|
playerId: playerHistoryPromises?.[0]?.playerId ?? null,
|
||||||
|
accSaberDate: h.date,
|
||||||
|
categories: {overall: {rank: h.rank}},
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
const timestampsInEnhancedFetchedHistory = enhancedFetchedHistory.map(h => h?.accSaberDate?.getTime())
|
||||||
|
|
||||||
|
playerRankHistory = enhancedFetchedHistory.concat(
|
||||||
|
dbHistory.filter(dbH => !timestampsInEnhancedFetchedHistory.includes(dbH?.accSaberDate?.getTime())),
|
||||||
|
)
|
||||||
|
|
||||||
|
availableCategories = [...new Set(playerRankHistory.reduce((categories, h) => {
|
||||||
|
if (h.accSaberDate && h.categories) categories = categories.concat(Object.keys(h.categories));
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}, []))].map(c => ({label: capitalize(c)}))
|
||||||
|
|
||||||
|
isLoading = false;
|
||||||
|
|
||||||
|
dispatch('height-changed');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupChart(hash, canvas) {
|
||||||
|
if (!hash || !canvas || !playerRankHistory?.length || !selectedCategory?.label || chartHash === lastHistoryHash)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastHistoryHash = chartHash;
|
||||||
|
|
||||||
|
const category = selectedCategory?.label?.toLowerCase();
|
||||||
|
|
||||||
|
const gridColor = "#2a2a2a"
|
||||||
|
const rankColor = "#3e95cd";
|
||||||
|
const ppColor = "#007100";
|
||||||
|
const accColor = "#3273dc";
|
||||||
|
const rankedPlayCountColor = "#3e3e3e";
|
||||||
|
|
||||||
|
const dtAccSaberToday = DateTime.fromJSDate(toAccSaberMidnight(new Date()));
|
||||||
|
const dayTimestamps = Array(CHART_DAYS).fill(0).map((_, idx) => toAccSaberMidnight(dtAccSaberToday.minus({days: CHART_DAYS - 1 - idx}).toJSDate()).getTime());
|
||||||
|
|
||||||
|
const playerRankHistoryByTimestamp = convertArrayToObjectByKey(playerRankHistory.filter(h => h.accSaberDate).map(h => ({
|
||||||
|
...h,
|
||||||
|
timestamp: h.accSaberDate.getTime(),
|
||||||
|
})), 'timestamp');
|
||||||
|
|
||||||
|
const yAxes = {
|
||||||
|
y: {
|
||||||
|
display: true,
|
||||||
|
position: 'left',
|
||||||
|
reverse: true,
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: 'Rank',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => val === Math.floor(val) ? val : null,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const skipped = (ctx, value) => ctx.p0.skip || ctx.p1.skip ? value : undefined;
|
||||||
|
|
||||||
|
const datasets = [];
|
||||||
|
|
||||||
|
[
|
||||||
|
{key: 'rank', label: 'Rank', borderColor: rankColor, axis: 'y', round: 0, gridColor, precision: 0},
|
||||||
|
{key: 'averageAcc', label: 'Acc', borderColor: accColor, axis: 'y2', round: 0, axisDisplay: true, valueMult: 100, tickSuffix: '%', precision: 2},
|
||||||
|
{key: 'ap', label: 'AP', borderColor: ppColor, axis: 'y3', round: 2, axisDisplay: false, precision: 0},
|
||||||
|
{key: 'rankedPlays', label: 'Plays', backgroundColor: rankedPlayCountColor, borderColor: rankedPlayCountColor, axis: 'y4', round: 0, axisDisplay: false, type: 'bar', barThickness: 3, maxMult: 1.5, precision: 0}].forEach(obj => {
|
||||||
|
const {key, axis, axisDisplay, label, valueMult, tickSuffix, precision, type, max, maxMult, gridColor, ...options} = obj;
|
||||||
|
|
||||||
|
const data = dayTimestamps.map(t => {
|
||||||
|
const val = playerRankHistoryByTimestamp?.[t]?.categories?.[category]?.[key] ?? null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: t,
|
||||||
|
y: val ? val * (valueMult ?? 1) : (type === 'bar' ? 0 : val),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataExists = data.some(v => (type !== 'bar' && v.y !== null) || (type === 'bar' && v.y !== 0));
|
||||||
|
if (!dataExists) return;
|
||||||
|
|
||||||
|
const maxVal = data.reduce((max, v) => v.y > max ? v.y : max, 0);
|
||||||
|
|
||||||
|
if (!yAxes[axis]) yAxes[axis] = {
|
||||||
|
display: axisDisplay ?? false,
|
||||||
|
position: 'right',
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: label,
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => formatNumber(val, obj.precision ?? obj.round ?? 2) + (tickSuffix ?? ''),
|
||||||
|
precision: precision ?? 2
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
drawOnChartArea: gridColor ? true : false,
|
||||||
|
},
|
||||||
|
max: max ? max : (maxMult ? maxVal * maxMult : null),
|
||||||
|
}
|
||||||
|
|
||||||
|
datasets.push(
|
||||||
|
{
|
||||||
|
yAxisID: axis,
|
||||||
|
label,
|
||||||
|
data,
|
||||||
|
fill: false,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 1,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: type ?? 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
...options,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
const xAxis = {
|
||||||
|
type: 'time',
|
||||||
|
display: true,
|
||||||
|
offset: true,
|
||||||
|
time: {
|
||||||
|
unit: 'day',
|
||||||
|
},
|
||||||
|
scaleLabel: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
autoSkip: false,
|
||||||
|
major: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
font: function (context) {
|
||||||
|
if (context.tick && context.tick.major) {
|
||||||
|
return {
|
||||||
|
weight: 'bold',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: (val, idx, ticks) => {
|
||||||
|
if (!ticks?.[idx]) return '';
|
||||||
|
|
||||||
|
return formatDateWithOptions(new Date(ticks[idx]?.value), {
|
||||||
|
localeMatcher: 'best fit',
|
||||||
|
day: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!chart) {
|
||||||
|
chart = new Chart(
|
||||||
|
canvas,
|
||||||
|
{
|
||||||
|
type: 'line',
|
||||||
|
data: {datasets},
|
||||||
|
options: {
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
spanGaps: DAY,
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
interaction: {
|
||||||
|
mode: 'index',
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
onClick: onLegendClick,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
position: 'nearest',
|
||||||
|
callbacks: {
|
||||||
|
title(ctx) {
|
||||||
|
if (!ctx?.[0]?.raw) return '';
|
||||||
|
|
||||||
|
const nextDayDate = DateTime.fromMillis(ctx[0].raw?.x).plus({days: 1}).toJSDate();
|
||||||
|
const nextDayDateFormatted = nextDayDate > new Date() ? 'now' : formatDate(nextDayDate, 'short', 'short');
|
||||||
|
|
||||||
|
return `${formatDate(new Date(ctx[0].raw?.x), 'short', 'short')} - ${nextDayDateFormatted}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
label(ctx) {
|
||||||
|
switch (ctx.dataset.label) {
|
||||||
|
case 'Rank':
|
||||||
|
return ` ${ctx.dataset.label}: #${formatNumber(ctx.parsed.y, ctx.dataset.round)}`;
|
||||||
|
case 'AP':
|
||||||
|
return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}AP`;
|
||||||
|
case 'Acc':
|
||||||
|
return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}%`;
|
||||||
|
default:
|
||||||
|
return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: xAxis,
|
||||||
|
...yAxes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
chart.data = {datasets}
|
||||||
|
chart.options.scales = {x: xAxis, ...yAxes}
|
||||||
|
chart.update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let debouncedChartHash = null;
|
||||||
|
const debounceChartHash = debounce(chartHash => debouncedChartHash = chartHash, CHART_DEBOUNCE);
|
||||||
|
|
||||||
|
$: refreshPlayerRankHistory(playerId, playerHistory);
|
||||||
|
|
||||||
|
$: selectedCategory = availableCategories?.find(c => c.label === capitalize(category)) ?? null;
|
||||||
|
|
||||||
|
$: chartHash = calcHistoryHash(playerId, playerRankHistory, category);
|
||||||
|
$: debounceChartHash(chartHash)
|
||||||
|
$: if (debouncedChartHash) setupChart(debouncedChartHash, canvas)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if playerRankHistory?.length}
|
||||||
|
<section class="chart" style="--height: {height}">
|
||||||
|
<canvas class="chartjs" bind:this={canvas} height={parseInt(height,10)}></canvas>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="chart-switcher">
|
||||||
|
<Switcher values={availableCategories} value={selectedCategory} on:change={e => category = e?.detail?.label ?? 'overall'} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
position: relative;
|
||||||
|
margin: 1rem auto 0 auto;
|
||||||
|
height: var(--height, 300px);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-switcher {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
</style>
|
454
src/components/Player/Charts/SsChart.svelte
Normal file
454
src/components/Player/Charts/SsChart.svelte
Normal file
@ -0,0 +1,454 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
import 'chartjs-adapter-luxon';
|
||||||
|
import {DateTime} from 'luxon';
|
||||||
|
import {getContext, onMount} from 'svelte'
|
||||||
|
import createPlayerService from '../../../services/scoresaber/player'
|
||||||
|
import createScoresService from '../../../services/scoresaber/scores'
|
||||||
|
import createBeatSaviorService from '../../../services/beatsavior'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
import {
|
||||||
|
dateFromString,
|
||||||
|
formatDate,
|
||||||
|
formatDateWithOptions,
|
||||||
|
toSsMidnight,
|
||||||
|
} from '../../../utils/date'
|
||||||
|
import eventBus from '../../../utils/broadcast-channel-pubsub'
|
||||||
|
import {debounce} from '../../../utils/debounce'
|
||||||
|
import {onLegendClick} from './utils/legend-click-handler'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let rankHistory = null;
|
||||||
|
export let playerHistory = null;
|
||||||
|
export let height = "350px";
|
||||||
|
|
||||||
|
const CHART_DAYS = 50;
|
||||||
|
const CHART_DEBOUNCE = 300;
|
||||||
|
const MAGIC_INACTIVITY_RANK = 999999;
|
||||||
|
|
||||||
|
const pageContainer = getContext('pageContainer');
|
||||||
|
|
||||||
|
const playerService = createPlayerService();
|
||||||
|
const scoresService = createScoresService();
|
||||||
|
const beatSaviorService = createBeatSaviorService();
|
||||||
|
|
||||||
|
let canvas = null;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let lastHistoryHash = null;
|
||||||
|
let playerScores = null;
|
||||||
|
let activityHistory = null;
|
||||||
|
let beatSaviorWonHistory = null;
|
||||||
|
let beatSaviorFailedHistory = null;
|
||||||
|
|
||||||
|
const calcHistoryHash = (rankHistory, additionalHistory, activityHistory, beatSaviorHistory) =>
|
||||||
|
(rankHistory && rankHistory.length ? rankHistory.join(':') : '') +
|
||||||
|
(additionalHistory ? Object.values(additionalHistory).map(h => Object.values(h).join(',')).join(':') : '') +
|
||||||
|
(activityHistory && activityHistory.length ? activityHistory.join(':') : '') +
|
||||||
|
(beatSaviorHistory && beatSaviorHistory.length ? beatSaviorHistory.join(':') : '')
|
||||||
|
;
|
||||||
|
|
||||||
|
const mapScoresToHistory = scores => {
|
||||||
|
if (!Object.keys(scores)?.length) return null;
|
||||||
|
|
||||||
|
const dtSsToday = DateTime.fromJSDate(toSsMidnight(new Date()));
|
||||||
|
|
||||||
|
return Array(CHART_DAYS).fill(0)
|
||||||
|
.map((_, idx) => {
|
||||||
|
const agoTimeset = dtSsToday.minus({days: CHART_DAYS - 1 - idx}).toMillis();
|
||||||
|
|
||||||
|
return {x: agoTimeset, y: scores[agoTimeset] ? scores[agoTimeset] : 0};
|
||||||
|
})
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshPlayerScores(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
playerScores = await scoresService.getPlayerScores(playerId)
|
||||||
|
|
||||||
|
const dtSsToday = DateTime.fromJSDate(toSsMidnight(new Date()));
|
||||||
|
const oldestDate = dtSsToday.minus({days: CHART_DAYS - 1}).toJSDate();
|
||||||
|
|
||||||
|
const lastScores = playerScores
|
||||||
|
.filter(score => score.timeSet && score.timeSet > oldestDate)
|
||||||
|
.reduce((cum, score) => {
|
||||||
|
const allSongScores = [score.timeSet.getTime()]
|
||||||
|
.concat(
|
||||||
|
score.history && score.history.length
|
||||||
|
? score.history.filter(h => h.timeSet && h.timeSet > oldestDate).map(h => h.timeSet.getTime())
|
||||||
|
: []
|
||||||
|
);
|
||||||
|
|
||||||
|
allSongScores.forEach(t => {
|
||||||
|
const ssDate = toSsMidnight(new Date(t));
|
||||||
|
const ssTimestamp = ssDate.getTime();
|
||||||
|
|
||||||
|
if (!cum.hasOwnProperty(ssTimestamp)) cum[ssTimestamp] = 0;
|
||||||
|
|
||||||
|
cum[ssTimestamp]++;
|
||||||
|
});
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, {})
|
||||||
|
;
|
||||||
|
|
||||||
|
activityHistory = mapScoresToHistory(lastScores);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshPlayerBeatSaviorScores(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
const scores = await beatSaviorService.getPlayerScores(playerId);
|
||||||
|
|
||||||
|
const dtSsToday = DateTime.fromJSDate(toSsMidnight(new Date()));
|
||||||
|
const oldestDate = dtSsToday.minus({days: CHART_DAYS - 1}).toJSDate();
|
||||||
|
|
||||||
|
const lastScores = scores.filter(score => score.timeSet && score.timeSet > oldestDate)
|
||||||
|
|
||||||
|
const countScores = (scores, incFunc) => scores
|
||||||
|
.reduce((cum, score) => {
|
||||||
|
const ssDate = toSsMidnight(score.timeSet);
|
||||||
|
const ssTimestamp = ssDate.getTime();
|
||||||
|
|
||||||
|
if (!cum.hasOwnProperty(ssTimestamp)) cum[ssTimestamp] = 0;
|
||||||
|
|
||||||
|
if (incFunc(score)) cum[ssTimestamp]++;
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
beatSaviorWonHistory = mapScoresToHistory(countScores(lastScores, score => !!(score.trackers.winTracker.won ?? false)));
|
||||||
|
beatSaviorFailedHistory = mapScoresToHistory(countScores(lastScores, score => !(score.trackers.winTracker.won ?? false)));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupChart(hash, canvas) {
|
||||||
|
if (!hash || !canvas || !rankHistory || !Object.keys(rankHistory).length || chartHash === lastHistoryHash) return;
|
||||||
|
|
||||||
|
lastHistoryHash = chartHash;
|
||||||
|
|
||||||
|
if (rankHistory.length < CHART_DAYS) rankHistory = Array(CHART_DAYS - rankHistory.length).fill(null).concat(rankHistory);
|
||||||
|
|
||||||
|
const gridColor = '#2a2a2a'
|
||||||
|
const rankColor = "#3e95cd";
|
||||||
|
const ppColor = "#007100";
|
||||||
|
const rankedPlayCountColor = "#3e3e3e";
|
||||||
|
const totalPlayCountColor = "#666";
|
||||||
|
const activityColor = "#333"
|
||||||
|
|
||||||
|
const dtAccSaberToday = DateTime.fromJSDate(toSsMidnight(new Date()));
|
||||||
|
const dayTimestamps = Array(CHART_DAYS).fill(0).map((_, idx) => toSsMidnight(dtAccSaberToday.minus({days: CHART_DAYS - 1 - idx}).toJSDate()).getTime());
|
||||||
|
|
||||||
|
const data = rankHistory
|
||||||
|
.map((h, idx) => ({x: dayTimestamps[idx], y :h === MAGIC_INACTIVITY_RANK ? null : h}));
|
||||||
|
|
||||||
|
const datasets = [
|
||||||
|
{
|
||||||
|
yAxisID: 'y',
|
||||||
|
label: 'Rank',
|
||||||
|
data,
|
||||||
|
fill: false,
|
||||||
|
borderColor: rankColor,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 0,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
round: 0,
|
||||||
|
type: 'line',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const xAxis = {
|
||||||
|
type: 'time',
|
||||||
|
display: true,
|
||||||
|
offset: true,
|
||||||
|
time: {
|
||||||
|
unit: 'day',
|
||||||
|
},
|
||||||
|
scaleLabel: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
autoSkip: false,
|
||||||
|
major: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
font: function (context) {
|
||||||
|
if (context.tick && context.tick.major) {
|
||||||
|
return {
|
||||||
|
weight: 'bold',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: (val, idx, ticks) => {
|
||||||
|
if (!ticks?.[idx]) return '';
|
||||||
|
|
||||||
|
return formatDateWithOptions(new Date(ticks[idx]?.value), {
|
||||||
|
localeMatcher: 'best fit',
|
||||||
|
day: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const yAxes = {
|
||||||
|
y: {
|
||||||
|
display: true,
|
||||||
|
position: 'left',
|
||||||
|
reverse: true,
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: 'Rank',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => val === Math.floor(val) ? val : null,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: gridColor,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let lastYIdx = 0;
|
||||||
|
|
||||||
|
if (additionalHistory && Object.keys(additionalHistory).length) {
|
||||||
|
const skipped = (ctx, value) => ctx.p0.skip || ctx.p1.skip ? value : undefined;
|
||||||
|
|
||||||
|
[
|
||||||
|
{key: 'pp', name: 'PP', borderColor: ppColor, round: 2, axisDisplay: true, precision: 0},
|
||||||
|
{
|
||||||
|
key: 'rankedPlayCount',
|
||||||
|
name: 'Ranked play count',
|
||||||
|
borderColor: rankedPlayCountColor,
|
||||||
|
round: 0,
|
||||||
|
axisDisplay: false,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'totalPlayCount',
|
||||||
|
name: 'Total play count',
|
||||||
|
borderColor: totalPlayCountColor,
|
||||||
|
round: 0,
|
||||||
|
axisDisplay: false,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
.forEach(obj => {
|
||||||
|
const {key, name, axisDisplay, usePrevAxis, precision, ...options} = obj;
|
||||||
|
const fieldData = dayTimestamps.map(x => ({x, y: additionalHistory?.[x]?.[key] ?? null}));
|
||||||
|
|
||||||
|
if (!usePrevAxis) lastYIdx++;
|
||||||
|
const axisKey = `y${lastYIdx}`
|
||||||
|
yAxes[axisKey] = {
|
||||||
|
display: axisDisplay,
|
||||||
|
position: 'right',
|
||||||
|
title: {
|
||||||
|
display: $pageContainer.name !== 'phone',
|
||||||
|
text: name,
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => val === Math.floor(val) ? val : null,
|
||||||
|
precision
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
drawOnChartArea: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
datasets.push({
|
||||||
|
...options,
|
||||||
|
yAxisID: axisKey,
|
||||||
|
label: name,
|
||||||
|
data: fieldData,
|
||||||
|
fill: false,
|
||||||
|
borderWidth: 2,
|
||||||
|
pointRadius: 1,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
tension: 0.4,
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
borderWidth: ctx => skipped(ctx, 1),
|
||||||
|
borderDash: ctx => skipped(ctx, [6, 6]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare common axis for activity & beat savior histories
|
||||||
|
let scoresAxisKey = null;
|
||||||
|
if (activityHistory?.length || (beatSaviorWonHistory?.length && beatSaviorFailedHistory?.length)) {
|
||||||
|
lastYIdx++;
|
||||||
|
|
||||||
|
scoresAxisKey = `y${lastYIdx}`
|
||||||
|
|
||||||
|
yAxes[scoresAxisKey] = {
|
||||||
|
display: false,
|
||||||
|
position: 'right',
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Scores count',
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: val => val,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
drawOnChartArea: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activityHistory?.length) {
|
||||||
|
datasets.push({
|
||||||
|
yAxisID: scoresAxisKey,
|
||||||
|
label: 'SS scores',
|
||||||
|
data: activityHistory,
|
||||||
|
fill: false,
|
||||||
|
backgroundColor: activityColor,
|
||||||
|
round: 0,
|
||||||
|
type: 'bar',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (beatSaviorWonHistory?.length && beatSaviorFailedHistory?.length) {
|
||||||
|
datasets.push({
|
||||||
|
yAxisID: scoresAxisKey,
|
||||||
|
label: 'Beat Savior pass',
|
||||||
|
data: beatSaviorWonHistory,
|
||||||
|
fill: false,
|
||||||
|
backgroundColor: '#9c27b0',
|
||||||
|
round: 0,
|
||||||
|
type: 'bar',
|
||||||
|
stack: 'beatsavior',
|
||||||
|
order: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
datasets.push({
|
||||||
|
yAxisID: scoresAxisKey,
|
||||||
|
label: 'Beat Savior fail',
|
||||||
|
data: beatSaviorFailedHistory,
|
||||||
|
fill: false,
|
||||||
|
backgroundColor: '#7f4e88',
|
||||||
|
round: 0,
|
||||||
|
type: 'bar',
|
||||||
|
stack: 'beatsavior',
|
||||||
|
order: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chart)
|
||||||
|
{
|
||||||
|
chart = new Chart(
|
||||||
|
canvas,
|
||||||
|
{
|
||||||
|
type: 'line',
|
||||||
|
data: {datasets},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
mode: 'index',
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
onClick: onLegendClick,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
position: 'nearest',
|
||||||
|
callbacks: {
|
||||||
|
title(ctx) {
|
||||||
|
if (!ctx?.[0]?.raw) return '';
|
||||||
|
|
||||||
|
const nextDayDate = DateTime.fromMillis(ctx[0].raw?.x).plus({days: 1}).toJSDate();
|
||||||
|
const nextDayDateFormatted = nextDayDate > new Date() ? 'now' : formatDate(nextDayDate, 'short', 'short');
|
||||||
|
|
||||||
|
return `${formatDate(new Date(ctx[0].raw?.x), 'short', 'short')} - ${nextDayDateFormatted}`;
|
||||||
|
},
|
||||||
|
label(ctx) {
|
||||||
|
switch(ctx.dataset.label) {
|
||||||
|
case 'Rank': return ` ${ctx.dataset.label}: #${formatNumber(ctx.parsed.y, ctx.dataset.round)}`;
|
||||||
|
case 'PP': return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}pp`;
|
||||||
|
default: return ` ${ctx.dataset.label}: ${formatNumber(ctx.parsed.y, ctx.dataset.round)}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: xAxis,
|
||||||
|
...yAxes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chart.data = {datasets};
|
||||||
|
chart.options.scales = {x: xAxis, ...yAxes};
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const playerScoresUpdatedUnsubscriber = eventBus.on('player-scores-updated', async({playerId: updatedPlayerId}) => {
|
||||||
|
if (updatedPlayerId !== playerId) return;
|
||||||
|
|
||||||
|
await refreshPlayerScores(updatedPlayerId)
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
playerScoresUpdatedUnsubscriber();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let debouncedChartHash = null;
|
||||||
|
const debounceChartHash = debounce(chartHash => debouncedChartHash = chartHash, CHART_DEBOUNCE);
|
||||||
|
|
||||||
|
$: refreshPlayerScores(playerId);
|
||||||
|
$: refreshPlayerBeatSaviorScores(playerId);
|
||||||
|
|
||||||
|
$: additionalHistory = playerHistory?.length
|
||||||
|
? playerHistory.reduce((cum, h) => {
|
||||||
|
const time = dateFromString(h.ssDate)?.getTime()
|
||||||
|
if (!time) return cum;
|
||||||
|
|
||||||
|
const history = {[time]: {pp: h.pp, rankedPlayCount: h.rankedPlayCount, totalPlayCount: h.totalPlayCount}};
|
||||||
|
return {...cum, ...history};
|
||||||
|
}, {})
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$: chartHash = calcHistoryHash(rankHistory, additionalHistory, activityHistory, (beatSaviorWonHistory ?? []).concat(beatSaviorFailedHistory ?? []));
|
||||||
|
$: debounceChartHash(chartHash)
|
||||||
|
$: if (debouncedChartHash) setupChart(debouncedChartHash, canvas)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if rankHistory && rankHistory.length}
|
||||||
|
<section class="chart" style="--height: {height}">
|
||||||
|
<canvas class="chartjs" bind:this={canvas} height={parseInt(height,10)}></canvas>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
position: relative;
|
||||||
|
margin: 1rem auto 0 auto;
|
||||||
|
height: var(--height, 300px);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
</style>
|
54
src/components/Player/Charts/utils/legend-click-handler.js
Normal file
54
src/components/Player/Charts/utils/legend-click-handler.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
export const onLegendClick = (event, legendItem, legend) => {
|
||||||
|
const idx = legendItem.datasetIndex;
|
||||||
|
const ci = legend.chart;
|
||||||
|
|
||||||
|
const scales = legend?.chart?.config?.options?.scales;
|
||||||
|
if (!scales) return;
|
||||||
|
|
||||||
|
const {x: xAxis, ...yAxes} = scales;
|
||||||
|
|
||||||
|
if (ci.isDatasetVisible(idx)) {
|
||||||
|
ci.hide(idx);
|
||||||
|
legendItem.hidden = true;
|
||||||
|
} else {
|
||||||
|
ci.show(idx);
|
||||||
|
legendItem.hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (legend?.chart) {
|
||||||
|
const yAxisIdsToShow = (legend?.legendItems ?? [])
|
||||||
|
.sort((a,b) => (ci?.config?.data?.datasets?.[a?.datasetIndex]?.axisOrder ?? a?.datasetIndex) - (ci?.config?.data?.datasets?.[b?.datasetIndex]?.axisOrder ?? b?.datasetIndex))
|
||||||
|
.reduce((cum, legendItem) => {
|
||||||
|
// done
|
||||||
|
if (cum.second) return cum;
|
||||||
|
|
||||||
|
// skip hidden legend items
|
||||||
|
if (legendItem?.hidden) return cum;
|
||||||
|
|
||||||
|
const yAxisId = ci?.getDatasetMeta(legendItem?.datasetIndex)?.yAxisID ?? null;
|
||||||
|
if (!yAxisId) return cum;
|
||||||
|
|
||||||
|
if (!cum.first) {
|
||||||
|
cum.first = yAxisId;
|
||||||
|
} else if (yAxisId !== cum.first) {
|
||||||
|
cum.second = yAxisId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, {first: null, second: null});
|
||||||
|
|
||||||
|
Object.keys(yAxes).forEach(currentAxisKey => {
|
||||||
|
if (![yAxisIdsToShow.first, yAxisIdsToShow.second].includes(currentAxisKey)) {
|
||||||
|
yAxes[currentAxisKey].display = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
yAxes[currentAxisKey].display = true;
|
||||||
|
if (yAxisIdsToShow.first === currentAxisKey) yAxes[currentAxisKey].position = 'left';
|
||||||
|
if (yAxisIdsToShow.second === currentAxisKey) yAxes[currentAxisKey].position = 'right';
|
||||||
|
});
|
||||||
|
|
||||||
|
legend.chart.options.scales = {x: xAxis, ...yAxes}
|
||||||
|
legend.chart.update();
|
||||||
|
}
|
||||||
|
}
|
39
src/components/Player/Charts/utils/regions-plugin.js
Normal file
39
src/components/Player/Charts/utils/regions-plugin.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
export default {
|
||||||
|
id: 'regions',
|
||||||
|
beforeDraw(chart, args, options) {
|
||||||
|
if (!options?.regions || !Array.isArray(options.regions)) return;
|
||||||
|
|
||||||
|
const {ctx, chartArea: {left, top, right, bottom}, scales: {y}} = chart;
|
||||||
|
const width = right - left;
|
||||||
|
|
||||||
|
let fontSize = parseInt(ctx.font,10);
|
||||||
|
if (isNaN(fontSize)) fontSize = 12;
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
|
||||||
|
options.regions.forEach(region => {
|
||||||
|
if (y.min <= region.max && y.max >= region.min) {
|
||||||
|
const minY = Math.max(region.min, y.min);
|
||||||
|
const maxY = Math.min(region.max, y.max);
|
||||||
|
const top = y.getPixelForValue(maxY);
|
||||||
|
const height = region.min === region.max ? 1 : y.getPixelForValue(minY) - y.getPixelForValue(maxY);
|
||||||
|
|
||||||
|
ctx.fillStyle = region.color;
|
||||||
|
ctx.fillRect(left, top, width, height);
|
||||||
|
|
||||||
|
if (region.label) {
|
||||||
|
const labelWidth = ctx.measureText(region.label)?.width ?? 0;
|
||||||
|
|
||||||
|
ctx.textBaseline = 'top';
|
||||||
|
ctx.fillText(
|
||||||
|
region.label,
|
||||||
|
region?.position?.horizontal === 'right' ? right - labelWidth - 3 : left + 3,
|
||||||
|
region?.position?.vertical === 'bottom' ? top + 2 : top - fontSize - 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
}
|
144
src/components/Player/Icons.svelte
Normal file
144
src/components/Player/Icons.svelte
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<script>
|
||||||
|
import createPlayersStore from '../../stores/scoresaber/players'
|
||||||
|
import createTwitchService from '../../services/twitch'
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import eventBus from '../../utils/broadcast-channel-pubsub'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import Button from '../Common/Button.svelte'
|
||||||
|
import {onMount} from 'svelte'
|
||||||
|
import TwitchLinkModal from './TwitchLinkModal.svelte'
|
||||||
|
|
||||||
|
export let playerId;
|
||||||
|
|
||||||
|
let playersStore = createPlayersStore();
|
||||||
|
const twitchService = createTwitchService();
|
||||||
|
|
||||||
|
let twitchToken = null;
|
||||||
|
let playerTwitchProfile = null;
|
||||||
|
|
||||||
|
let showLinkingModal = false;
|
||||||
|
|
||||||
|
function onSetAsMain() {
|
||||||
|
if (!configStore || !playerId) return;
|
||||||
|
|
||||||
|
const newConfig = {...$configStore}
|
||||||
|
if (!newConfig.users) newConfig.users = {};
|
||||||
|
newConfig.users.main = playerId;
|
||||||
|
|
||||||
|
$configStore = newConfig;
|
||||||
|
|
||||||
|
eventBus.publish('player-add-cmd', {playerId});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFriendsChange(op) {
|
||||||
|
if (!playerId || !op) return;
|
||||||
|
|
||||||
|
switch (op) {
|
||||||
|
case 'add':
|
||||||
|
eventBus.publish('player-add-cmd', {playerId});
|
||||||
|
break;
|
||||||
|
case 'remove':
|
||||||
|
eventBus.publish('player-remove-cmd', {playerId});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onTwitchLink(event) {
|
||||||
|
if (!opt(event, 'detail.id')) return;
|
||||||
|
|
||||||
|
playerTwitchProfile = event.detail;
|
||||||
|
|
||||||
|
await twitchService.updatePlayerProfile({...event.detail, playerId, profileLastUpdated: new Date()})
|
||||||
|
|
||||||
|
showLinkingModal = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onPlayerChanged(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
playerTwitchProfile = await twitchService.getPlayerProfile(playerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
twitchToken = await twitchService.getCurrentToken();
|
||||||
|
})
|
||||||
|
|
||||||
|
$: onPlayerChanged(playerId);
|
||||||
|
$: isProfileLinkedToTwitch = !!playerTwitchProfile?.login ?? false;
|
||||||
|
$: mainIsSet = !!$configStore?.users?.main ?? false;
|
||||||
|
$: isMain = configStore && playerId && opt($configStore, 'users.main') === playerId;
|
||||||
|
$: isFriend = playerId && !!$playersStore.find(p => p.playerId === playerId);
|
||||||
|
$: showAvatarIcons = $configStore?.preferences?.avatarIcons ?? 'only-if-needed';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if playerId}
|
||||||
|
<nav class:main={isMain}>
|
||||||
|
{#if !isMain}
|
||||||
|
{#if showAvatarIcons === 'show' || (showAvatarIcons === 'only-if-needed' && !mainIsSet)}
|
||||||
|
<Button title="Set as your profile" iconFa="fas fa-home" type="primary"
|
||||||
|
on:click={onSetAsMain}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if showAvatarIcons === 'show' || (showAvatarIcons === 'only-if-needed' && !isFriend)}
|
||||||
|
<Button title={isFriend ? "Remove from Friends" : "Add to Friends"}
|
||||||
|
iconFa={isFriend ? "fas fa-user-minus" : "fas fa-user-plus"} type={isFriend ? "danger" : "primary"}
|
||||||
|
on:click={() => onFriendsChange(isFriend ? 'remove' : 'add')}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if twitchToken && (showAvatarIcons === 'show' || (showAvatarIcons === 'only-if-needed' && !isProfileLinkedToTwitch))}
|
||||||
|
<Button type="twitch" iconFa="fab fa-twitch" title={`${isProfileLinkedToTwitch ? 'Re-link' : 'Link'} Twitch profile`}
|
||||||
|
on:click={() => showLinkingModal = true}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</nav>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if twitchToken}
|
||||||
|
<TwitchLinkModal {playerId} show={showLinkingModal}
|
||||||
|
on:link={onTwitchLink} on:cancel={() => showLinkingModal = false}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
nav {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: calc(50% - 50px);
|
||||||
|
text-align: left;
|
||||||
|
font-size: .75rem;
|
||||||
|
z-index: 15;
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button) {
|
||||||
|
border-radius: 50% !important;
|
||||||
|
transition: all 200ms !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button):nth-child(1) {
|
||||||
|
transform: translate3d(-40px, 60px, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button):nth-child(1):hover {
|
||||||
|
transform: translate3d(-40px, 60px, 0) scale(1.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button):nth-child(2) {
|
||||||
|
transform: translate3d(-50px, 24px, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button):nth-child(2):hover {
|
||||||
|
transform: translate3d(-50px, 24px, 0) scale(1.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button):nth-child(3) {
|
||||||
|
transform: translate3d(-47px, 0px, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(button):nth-child(3):hover {
|
||||||
|
transform: translate3d(-47px, 0px, 0) scale(1.2);
|
||||||
|
}
|
||||||
|
</style>
|
37
src/components/Player/MenuLine.svelte
Normal file
37
src/components/Player/MenuLine.svelte
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<script>
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import PlayerNameWithFlag from '../Common/PlayerNameWithFlag.svelte'
|
||||||
|
|
||||||
|
export let player = null;
|
||||||
|
export let withRank = true;
|
||||||
|
|
||||||
|
$: rank = opt(player, 'playerInfo.rank')
|
||||||
|
$: country = opt(player, 'playerInfo.countries.0.country')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if player}
|
||||||
|
<div class="player">
|
||||||
|
{#if withRank}
|
||||||
|
<span class="rank">#{rank}</span>
|
||||||
|
{/if}
|
||||||
|
<PlayerNameWithFlag {player} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div.player {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.player span.rank {
|
||||||
|
width: 4rem;
|
||||||
|
min-width: max-content;
|
||||||
|
text-align: right;
|
||||||
|
padding-right: .5rem;
|
||||||
|
flex-basis: 4rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
flex-grow: 0;
|
||||||
|
}
|
||||||
|
</style>
|
194
src/components/Player/PlayerStats.svelte
Normal file
194
src/components/Player/PlayerStats.svelte
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
<script>
|
||||||
|
import {navigate} from 'svelte-routing'
|
||||||
|
import {SS_HOST} from '../../network/queues/scoresaber/page-queue'
|
||||||
|
import {PLAYERS_PER_PAGE} from '../../utils/scoresaber/consts'
|
||||||
|
import {convertArrayToObjectByKey, opt} from '../../utils/js'
|
||||||
|
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
import Status from './Status.svelte'
|
||||||
|
import Skeleton from '../Common/Skeleton.svelte'
|
||||||
|
import Error from '../Common/Error.svelte'
|
||||||
|
import Badge from '../Common/Badge.svelte'
|
||||||
|
import {addToDate, DAY, formatDateRelative} from '../../utils/date'
|
||||||
|
|
||||||
|
export let name;
|
||||||
|
export let playerInfo;
|
||||||
|
export let prevInfo;
|
||||||
|
export let skeleton = false;
|
||||||
|
export let centered = false;
|
||||||
|
export let error = null;
|
||||||
|
|
||||||
|
function getCountryRankingUrl(countryObj) {
|
||||||
|
const rank = opt(countryObj, 'rankValue', opt(countryObj, 'rank', null));
|
||||||
|
if (!rank) return null;
|
||||||
|
|
||||||
|
const country = opt(countryObj, 'country', null);
|
||||||
|
if (!country) return null;
|
||||||
|
|
||||||
|
return `/ranking/${country.toLowerCase()}/${Math.floor((rank - 1) / PLAYERS_PER_PAGE) + 1}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigateToCountryRanking(countryObj) {
|
||||||
|
const url = getCountryRankingUrl(countryObj);
|
||||||
|
|
||||||
|
if (url && url.length) navigate(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigateToGlobalRanking(rank) {
|
||||||
|
if (!rank) return;
|
||||||
|
|
||||||
|
navigate(`/ranking/global/${Math.floor((rank - 1) / PLAYERS_PER_PAGE) + 1}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlayerCountries(playerInfo, prevInfo) {
|
||||||
|
if (!playerInfo?.countries) return [];
|
||||||
|
|
||||||
|
const prevCountries = convertArrayToObjectByKey(prevInfo?.countries ?? [], 'country');
|
||||||
|
return playerInfo.countries
|
||||||
|
.map(c => ({...c, prevRank: prevCountries?.[c.country]?.rank ?? null}));
|
||||||
|
}
|
||||||
|
|
||||||
|
$: rank = playerInfo ? (playerInfo.rankValue ? playerInfo.rankValue : playerInfo.rank) : null;
|
||||||
|
$: playerRole = playerInfo?.role ?? null;
|
||||||
|
$: countries = getPlayerCountries(playerInfo, prevInfo)
|
||||||
|
$: gainDate = Number.isFinite(prevInfo?.gainDaysAgo) ? formatDateRelative(addToDate(-prevInfo.gainDaysAgo * DAY)) : null
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if skeleton}
|
||||||
|
<h1 class="title is=4 has-text-centered-mobile" class:centered>
|
||||||
|
<Skeleton width="50%"/>
|
||||||
|
</h1>
|
||||||
|
<h2 class="title is-5" class:centered>
|
||||||
|
<Skeleton width="50%"/>
|
||||||
|
</h2>
|
||||||
|
{:else if playerInfo}
|
||||||
|
<h1 class="title is-4 has-text-centered-mobile" class:centered>
|
||||||
|
{#if name}
|
||||||
|
{#if playerInfo.externalProfileUrl}
|
||||||
|
<a href={playerInfo.externalProfileUrl} target="_blank" rel="noreferrer">{name}</a>
|
||||||
|
{:else}
|
||||||
|
{name}
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<span class="pp">
|
||||||
|
<Value value={opt(playerInfo, 'pp')} suffix="pp"
|
||||||
|
prevValue={opt(prevInfo, 'pp')} prevLabel={prevInfo?.pp && gainDate ? gainDate : null}
|
||||||
|
inline={true} zero="0pp"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span class="status"><Status {playerInfo}/></span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<h2 class="title is-5" class:centered>
|
||||||
|
<a href={`/ranking/global/${Math.floor((rank-1) / PLAYERS_PER_PAGE) + 1}`}
|
||||||
|
on:click|preventDefault={() => navigateToGlobalRanking(rank)} title="Go to global ranking"
|
||||||
|
class="clickable">
|
||||||
|
<i class="fas fa-globe-americas"></i>
|
||||||
|
|
||||||
|
<Value value={opt(playerInfo, 'rank')}
|
||||||
|
prevValue={opt(prevInfo, 'rank')} prevLabel={prevInfo?.rank && gainDate ? gainDate : null}
|
||||||
|
prefix="#" digits={0} zero="#0" inline={true} reversePrevSign={true}
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{#each countries as country}
|
||||||
|
<a href={getCountryRankingUrl(country)} on:click|preventDefault={() => navigateToCountryRanking(country)}
|
||||||
|
title="Go to country ranking" class="clickable">
|
||||||
|
<img
|
||||||
|
src={`${SS_HOST}/imports/images/flags/${country && country.country && country.country.toLowerCase ? country.country.toLowerCase() : ''}.png`}
|
||||||
|
alt={opt(country, 'country')}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Value value={country.rank}
|
||||||
|
prevValue={country.prevRank} prevLabel={country?.prevRank && gainDate ? gainDate : null}
|
||||||
|
prefix="#" digits={0} zero="#0" inline={true}
|
||||||
|
reversePrevSign={true}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if country.subRank && country.subRank !== country.rankValue}
|
||||||
|
<small>(#{ country.subRank })</small>
|
||||||
|
{/if}
|
||||||
|
</a>
|
||||||
|
{/each}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
{#if playerRole}
|
||||||
|
<div class="player-role up-to-tablet">
|
||||||
|
<Badge label={playerRole} onlyLabel={true} fluid={true} bgColor="var(--dimmed)" />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<div>
|
||||||
|
<Error {error}/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{:else if error}
|
||||||
|
<div>
|
||||||
|
<Error {error}/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
h1.centered, h2.centered {
|
||||||
|
text-align: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1.title {
|
||||||
|
margin-bottom: .25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 .pp {
|
||||||
|
color: var(--ppColour) !important;
|
||||||
|
font-size: smaller;
|
||||||
|
border-left: 1px solid var(--dimmed);
|
||||||
|
padding-left: .75rem;
|
||||||
|
margin-left: .5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 .status {
|
||||||
|
font-size: smaller;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2.title {
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 a {
|
||||||
|
border-right: 1px solid var(--dimmed);
|
||||||
|
padding: 0 .5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 a:first-of-type {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 a:last-of-type {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 a i {
|
||||||
|
color: var(--textColor);
|
||||||
|
font-size: smaller;
|
||||||
|
position: relative;
|
||||||
|
top: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 a img {
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-role {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
h2 {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
243
src/components/Player/Profile.svelte
Normal file
243
src/components/Player/Profile.svelte
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
<script>
|
||||||
|
import {getContext} from 'svelte'
|
||||||
|
import processPlayerData from './utils/profile';
|
||||||
|
import eventBus from '../../utils/broadcast-channel-pubsub'
|
||||||
|
import {worker} from '../../utils/worker-wrappers'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import createBeatSaviorService from '../../services/beatsavior'
|
||||||
|
import createAccSaberService from '../../services/accsaber'
|
||||||
|
import Avatar from './Avatar.svelte'
|
||||||
|
import PlayerStats from './PlayerStats.svelte'
|
||||||
|
import Icons from './Icons.svelte'
|
||||||
|
import ScoreSaberStats from './ProfileCards/ScoreSaberStats.svelte'
|
||||||
|
import MiniRanking from './ProfileCards/MiniRanking.svelte'
|
||||||
|
import TwitchVideos from './ProfileCards/TwitchVideos.svelte'
|
||||||
|
import PpCalc from './ProfileCards/PpCalc.svelte'
|
||||||
|
import AccSaber from './ProfileCards/AccSaber.svelte'
|
||||||
|
import BeatSavior from './ProfileCards/BeatSavior.svelte'
|
||||||
|
import Carousel from '../Common/Carousel.svelte'
|
||||||
|
import SsBadges from './SsBadges.svelte'
|
||||||
|
import Badge from '../Common/Badge.svelte'
|
||||||
|
|
||||||
|
export let playerData;
|
||||||
|
export let isLoading = false;
|
||||||
|
export let error = null;
|
||||||
|
export let skeleton = false;
|
||||||
|
export let twitchVideos = null;
|
||||||
|
|
||||||
|
const pageContainer = getContext('pageContainer');
|
||||||
|
|
||||||
|
const beatSaviorService = createBeatSaviorService();
|
||||||
|
const accSaberService = createAccSaberService();
|
||||||
|
|
||||||
|
let accSaberPlayerInfo = null;
|
||||||
|
let accSaberCategories = null;
|
||||||
|
let playerGain = null;
|
||||||
|
|
||||||
|
let playerStats = null;
|
||||||
|
eventBus.on('player-stats-calculated', stats => {
|
||||||
|
if (stats?.playerId && stats?.playerId === playerData?.playerId) playerStats = stats
|
||||||
|
})
|
||||||
|
|
||||||
|
let onePpBoundery = null;
|
||||||
|
|
||||||
|
let isBeatSaviorAvailable = false;
|
||||||
|
|
||||||
|
async function refreshBeatSaviorState(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
isBeatSaviorAvailable = await beatSaviorService.isDataForPlayerAvailable(playerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearPlayerStatsOnChange() {
|
||||||
|
playerStats = null;
|
||||||
|
playerGain = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function calcOnePpBoundary(playerId, isCached) {
|
||||||
|
if (!playerId || !isCached) {
|
||||||
|
onePpBoundery = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onePpBoundery = await worker.calcPpBoundary(playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateScoresStats(stats, onePp) {
|
||||||
|
return (stats && stats.length ? stats : [])
|
||||||
|
.concat(
|
||||||
|
onePp
|
||||||
|
? [{
|
||||||
|
label: '+ 1pp',
|
||||||
|
title: 'Determines how many raw PPs in the new play you need to achieve to increase your total PP by 1pp',
|
||||||
|
value: onePpBoundery,
|
||||||
|
digits: 2,
|
||||||
|
suffix: ' raw pp new play',
|
||||||
|
fluid: true,
|
||||||
|
bgColor: 'var(--dimmed)',
|
||||||
|
}]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPlayerGainChanged(e) {
|
||||||
|
if (e?.detail?.gainType !== 'scoresaber') return;
|
||||||
|
|
||||||
|
playerGain = e.detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateAccSaberPlayerInfo(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
accSaberPlayerInfo = await accSaberService.getPlayer(playerId);
|
||||||
|
accSaberCategories = await accSaberService.getCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
$: isCached = !!(playerData && playerData.scoresLastUpdated)
|
||||||
|
$: clearPlayerStatsOnChange(playerId)
|
||||||
|
$: playerId = playerData && playerData.playerId ? playerData.playerId : null;
|
||||||
|
$: name = playerData && playerData.name ? playerData.name : null;
|
||||||
|
$: ({playerInfo, scoresStats, accStats, accBadges, ssBadges} = processPlayerData(playerData, playerStats))
|
||||||
|
$: playerRole = playerInfo?.role ?? null;
|
||||||
|
$: calcOnePpBoundary(playerId, isCached);
|
||||||
|
$: refreshBeatSaviorState(playerId)
|
||||||
|
$: scoresStatsFinal = generateScoresStats(scoresStats, onePpBoundery)
|
||||||
|
$: rankChartData = (playerData?.playerInfo.rankHistory ?? []).concat(playerData?.playerInfo.rank)
|
||||||
|
$: updateAccSaberPlayerInfo(playerId);
|
||||||
|
|
||||||
|
$: swipeCards = []
|
||||||
|
.concat(
|
||||||
|
playerId
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
name: `stats-${playerId}`,
|
||||||
|
component: ScoreSaberStats,
|
||||||
|
props: {
|
||||||
|
playerId,
|
||||||
|
scoresStats: scoresStatsFinal,
|
||||||
|
accStats,
|
||||||
|
accBadges,
|
||||||
|
ssBadges,
|
||||||
|
isCached,
|
||||||
|
skeleton,
|
||||||
|
rankHistory: rankChartData,
|
||||||
|
},
|
||||||
|
delay: 500,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
.concat(
|
||||||
|
$pageContainer.name !== 'xxl'
|
||||||
|
? [{
|
||||||
|
name: `ranking-${playerId}`,
|
||||||
|
component: MiniRanking,
|
||||||
|
props: {playerInfo: opt(playerData, 'playerInfo')},
|
||||||
|
}]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
.concat(
|
||||||
|
onePpBoundery
|
||||||
|
?
|
||||||
|
[{
|
||||||
|
name: `ppcalc-${playerId}`,
|
||||||
|
component: PpCalc,
|
||||||
|
props: {playerId, worker},
|
||||||
|
}]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
.concat(
|
||||||
|
accSaberCategories && accSaberPlayerInfo && accSaberCategories.length && accSaberPlayerInfo.length
|
||||||
|
?
|
||||||
|
[{
|
||||||
|
name: `accsaber-${playerId}`,
|
||||||
|
component: AccSaber,
|
||||||
|
props: {categories: accSaberCategories, playerInfo: accSaberPlayerInfo},
|
||||||
|
}]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
.concat(
|
||||||
|
isBeatSaviorAvailable
|
||||||
|
?
|
||||||
|
[{
|
||||||
|
name: `beat-savior-${playerId}`,
|
||||||
|
component: BeatSavior,
|
||||||
|
props: {playerId},
|
||||||
|
}]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
.concat(
|
||||||
|
$pageContainer.name !== 'xxl' && twitchVideos && twitchVideos.length
|
||||||
|
? [{
|
||||||
|
name: `twitch-${playerId}`,
|
||||||
|
component: TwitchVideos,
|
||||||
|
props: {videos: twitchVideos},
|
||||||
|
}]
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
: [],
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="box has-shadow" class:loading={isLoading}>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column is-narrow avatar">
|
||||||
|
<Avatar {playerInfo} {isLoading}/>
|
||||||
|
|
||||||
|
{#if playerId && !isLoading}
|
||||||
|
<Icons {playerId} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if playerRole}
|
||||||
|
<div class="player-role above-tablet">
|
||||||
|
<Badge label={playerRole} onlyLabel={true} fluid={true} bgColor="var(--dimmed)" />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if ssBadges}
|
||||||
|
<div class="ss-badges">
|
||||||
|
<SsBadges badges={ssBadges}/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<PlayerStats {name} {playerInfo} prevInfo={playerGain} {skeleton} {error}/>
|
||||||
|
|
||||||
|
<Carousel cards={swipeCards} on:player-gain-changed={e => onPlayerGainChanged(e)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.column.avatar {
|
||||||
|
position: relative;
|
||||||
|
text-align: center;
|
||||||
|
margin-right: 1rem;
|
||||||
|
min-width: 188px;
|
||||||
|
width: 188px;
|
||||||
|
min-height: 190px;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-role {
|
||||||
|
width: 150px;
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ss-badges {
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.column.avatar {
|
||||||
|
margin-right: 0;
|
||||||
|
min-width: calc(188px + 1.5rem);
|
||||||
|
padding-bottom: 0;
|
||||||
|
min-height: 150px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ss-badges {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
185
src/components/Player/ProfileCards/AccSaber.svelte
Normal file
185
src/components/Player/ProfileCards/AccSaber.svelte
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
import {addToDate, DAY, formatDateRelative, toAccSaberMidnight} from '../../../utils/date'
|
||||||
|
import createAccSaberService from '../../../services/accsaber'
|
||||||
|
import Badge from '../../Common/Badge.svelte'
|
||||||
|
import AccSaberChart from '../Charts/AccSaberChart.svelte'
|
||||||
|
|
||||||
|
export let categories = null;
|
||||||
|
export let playerInfo = null;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let gainDaysAgo = 1;
|
||||||
|
|
||||||
|
const accSaberService = createAccSaberService();
|
||||||
|
|
||||||
|
let playerHistory = null;
|
||||||
|
let playerHistoryGain = null;
|
||||||
|
|
||||||
|
function refreshHistoryGain(playerId, playerHistory, daysAgo = 1) {
|
||||||
|
playerHistoryGain = null;
|
||||||
|
|
||||||
|
if (!playerId || (!playerHistory?.length)) return;
|
||||||
|
|
||||||
|
const todayAccSaberDate = toAccSaberMidnight(new Date());
|
||||||
|
|
||||||
|
let playerHistoryItem = accSaberService.getPlayerGain(playerHistory, daysAgo, daysAgo + 7 - 1);
|
||||||
|
if (!playerHistoryItem) return;
|
||||||
|
|
||||||
|
const gainDaysAgo = Math.floor((todayAccSaberDate - playerHistoryItem.accSaberDate) / DAY);
|
||||||
|
|
||||||
|
playerHistoryGain = {...playerHistoryItem, gainDaysAgo, gainType: 'accsaber'};
|
||||||
|
|
||||||
|
dispatch('player-gain-changed', playerHistoryGain);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshPlayerHistory(playerId) {
|
||||||
|
playerHistory = null;
|
||||||
|
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
playerHistory = await accSaberService.getPlayerHistory(playerId) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlayerInfoByCategory(categories, playerInfo, playerHistoryGain) {
|
||||||
|
return categories && playerInfo && categories.length && playerInfo.length
|
||||||
|
? categories
|
||||||
|
.map(c => ({
|
||||||
|
...c,
|
||||||
|
playerInfo: playerInfo.find(p => p.category === c.name),
|
||||||
|
}))
|
||||||
|
.map(c => ({
|
||||||
|
...c,
|
||||||
|
prevPlayerInfo: c.playerInfo && playerHistoryGain?.categories?.[c.name]
|
||||||
|
? {
|
||||||
|
...c.playerInfo,
|
||||||
|
...playerHistoryGain?.categories?.[c.name],
|
||||||
|
gainDaysAgo: c.playerInfo && playerHistoryGain ? playerHistoryGain.gainDaysAgo : null,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
}))
|
||||||
|
.filter(c => c.playerInfo)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
|
$: playerInfoByCategory = getPlayerInfoByCategory(categories, playerInfo, playerHistoryGain);
|
||||||
|
$: playerId = playerInfo?.[0]?.playerId ?? null;
|
||||||
|
$: refreshPlayerHistory(playerId)
|
||||||
|
$: refreshHistoryGain(playerId, playerHistory, gainDaysAgo)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if playerInfoByCategory}
|
||||||
|
<section class="accsaber" transition:fade>
|
||||||
|
<h3 class="title is-6">
|
||||||
|
<a href={`https://accsaber.com/player-profile/${playerInfoByCategory?.[0]?.playerInfo?.playerId}`}
|
||||||
|
target="_blank" rel="noreferrer">
|
||||||
|
<img src="/assets/accsaber-logo.png" alt="AccSaberLogo"/> <span>AccSaber</span>
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div class="stats">
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
{#if playerInfoByCategory?.[0]?.playerInfo?.hmd}
|
||||||
|
<Badge label="HMD" value={playerInfoByCategory[0].playerInfo.hmd} fluid={true} bgColor="var(--alternate)"
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#each playerInfoByCategory as category (category.name)}
|
||||||
|
<Badge label={category.displayName ?? category.name} value={category.playerInfo.rank} prefix="#"
|
||||||
|
prevValue={category?.prevPlayerInfo?.rank}
|
||||||
|
prevLabel={category?.prevPlayerInfo?.rank && Number.isFinite(category?.prevPlayerInfo?.gainDaysAgo) ? formatDateRelative(addToDate(-category?.prevPlayerInfo?.gainDaysAgo * DAY)) : null}
|
||||||
|
reversePrevSign={true}
|
||||||
|
digits={0} fluid={true} inline={true} bgColor="var(--dimmed)"
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#each playerInfoByCategory as category (category.name)}
|
||||||
|
<Badge label={category.displayName ?? category.name} value={category.playerInfo.ap}
|
||||||
|
prevValue={category?.prevPlayerInfo?.ap}
|
||||||
|
prevLabel={category?.prevPlayerInfo?.ap && Number.isFinite(category?.prevPlayerInfo?.gainDaysAgo) ? formatDateRelative(addToDate(-category?.prevPlayerInfo?.gainDaysAgo * DAY)) : null}
|
||||||
|
suffix=" AP" fluid={true} inline={true} bgColor="var(--ppColour)"
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
{#each playerInfoByCategory as category (category.name)}
|
||||||
|
<Badge label={category.displayName ?? category.name} value={category.playerInfo.averageAcc * 100} suffix="%"
|
||||||
|
prevValue={category?.prevPlayerInfo?.averageAcc ? category?.prevPlayerInfo?.averageAcc * 100 : null}
|
||||||
|
prevLabel={category?.prevPlayerInfo?.averageAcc && Number.isFinite(category?.prevPlayerInfo?.gainDaysAgo) ? formatDateRelative(addToDate(-category?.prevPlayerInfo?.gainDaysAgo * DAY)) : null}
|
||||||
|
fluid={true} inline={true} bgColor="var(--selected)"
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#each playerInfoByCategory as category (category.name)}
|
||||||
|
<Badge label={category.displayName ?? category.name} value={category.playerInfo.rankedPlays}
|
||||||
|
suffix=" play(s)"
|
||||||
|
prevValue={category?.prevPlayerInfo?.rankedPlays}
|
||||||
|
prevLabel={category?.prevPlayerInfo?.rankedPlays && Number.isFinite(category?.prevPlayerInfo?.gainDaysAgo) ? formatDateRelative(addToDate(-category?.prevPlayerInfo?.gainDaysAgo * DAY)) : null}
|
||||||
|
prevSuffix=" "
|
||||||
|
digits={0} fluid={true} inline={true} bgColor="var(--faded)"
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AccSaberChart {playerId} {playerHistory} on:height-changed/>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
width: 100%;
|
||||||
|
padding: .5em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
padding: .25em 0;
|
||||||
|
margin-bottom: .75em !important;
|
||||||
|
font-size: 1.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 a {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 a img {
|
||||||
|
margin-right: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 2em;
|
||||||
|
height: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats :global(.badge .value .prev.inc),
|
||||||
|
.stats :global(.badge .value .prev.dec) {
|
||||||
|
color: inherit!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 1200px) {
|
||||||
|
.stats {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto auto;
|
||||||
|
grid-column-gap: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
h3 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
275
src/components/Player/ProfileCards/BeatSavior.svelte
Normal file
275
src/components/Player/ProfileCards/BeatSavior.svelte
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
<script>
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
import createBeatSaviorService from '../../../services/beatsavior'
|
||||||
|
import Switcher from '../../Common/Switcher.svelte'
|
||||||
|
import Hands from '../../BeatSavior/Stats/Hands.svelte'
|
||||||
|
import OtherStats from '../../BeatSavior/Stats/OtherStats.svelte'
|
||||||
|
import Grid from '../../BeatSavior/Stats/Grid.svelte'
|
||||||
|
import {capitalize} from '../../../utils/js'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
|
||||||
|
const allFilters = [
|
||||||
|
{key: 'passed', label: 'All passed'},
|
||||||
|
{key: 'best', label: 'Only the best'},
|
||||||
|
];
|
||||||
|
|
||||||
|
let filters = allFilters;
|
||||||
|
let selectedType = filters[0];
|
||||||
|
|
||||||
|
const beatSaviorService = createBeatSaviorService();
|
||||||
|
|
||||||
|
let beatSaviorData = null;
|
||||||
|
let playerScoresAreAvailable = false;
|
||||||
|
|
||||||
|
function refreshAvailableFilters() {
|
||||||
|
const currentType = selectedType?.key ?? 'passed';
|
||||||
|
|
||||||
|
filters = allFilters.filter(f => playerScoresAreAvailable || f.key === 'passed')
|
||||||
|
selectedType = filters.find(f => f.key === currentType) ?? filters?.[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshBeatSaviorScores(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
beatSaviorData = (await beatSaviorService.getPlayerScoresWithScoreSaber(playerId))
|
||||||
|
?.filter(bsData => bsData?.trackers?.winTracker?.won ?? false);
|
||||||
|
|
||||||
|
playerScoresAreAvailable = beatSaviorData?.some(s => !!s.ssScore)
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateStats(scores) {
|
||||||
|
if (!scores?.length) return null;
|
||||||
|
|
||||||
|
const stats = scores
|
||||||
|
.reduce((stats, s) => {
|
||||||
|
stats.total++;
|
||||||
|
|
||||||
|
['left', 'right'].forEach(key => {
|
||||||
|
const keyCapitalized = capitalize(key);
|
||||||
|
|
||||||
|
const totalVar = `total${keyCapitalized}`;
|
||||||
|
const accVar = `acc${keyCapitalized}`;
|
||||||
|
const cutVar = `${key}AverageCut`;
|
||||||
|
const missVar = `${key}Miss`;
|
||||||
|
const badCutsVar = `${key}BadCuts`;
|
||||||
|
const timeDependenceVar = `${key}TimeDependence`;
|
||||||
|
const preSwing = `${key}Preswing`;
|
||||||
|
const postSwing = `${key}Postswing`;
|
||||||
|
|
||||||
|
if (Number.isFinite(s?.trackers?.accuracyTracker?.[accVar])) {
|
||||||
|
stats[totalVar]++;
|
||||||
|
|
||||||
|
stats[accVar] += s?.trackers?.accuracyTracker?.[accVar];
|
||||||
|
stats[timeDependenceVar] += Number.isFinite(s?.trackers?.accuracyTracker?.[timeDependenceVar]) ? s?.trackers?.accuracyTracker?.[timeDependenceVar] : 0;
|
||||||
|
stats[preSwing] += Number.isFinite(s?.trackers?.accuracyTracker?.[preSwing]) ? s?.trackers?.accuracyTracker?.[preSwing] : 0;
|
||||||
|
stats[postSwing] += Number.isFinite(s?.trackers?.accuracyTracker?.[postSwing]) ? s?.trackers?.accuracyTracker?.[postSwing] : 0;
|
||||||
|
|
||||||
|
stats[missVar] += Number.isFinite(s?.trackers?.hitTracker?.[missVar]) ? s?.trackers?.hitTracker?.[missVar] : 0;
|
||||||
|
stats[badCutsVar] += Number.isFinite(s?.trackers?.hitTracker?.[badCutsVar]) ? s?.trackers?.hitTracker?.[badCutsVar] : 0;
|
||||||
|
|
||||||
|
const cutData = s?.trackers?.accuracyTracker?.[cutVar];
|
||||||
|
if (cutData && Array.isArray(cutData) && cutData?.length === 3)
|
||||||
|
cutData.forEach((v, idx) => stats[cutVar][idx] += Number.isFinite(v) ? v : 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let gridAcc = s?.trackers?.accuracyTracker?.gridAcc;
|
||||||
|
if (Array.isArray(gridAcc) && gridAcc.length === 12) {
|
||||||
|
gridAcc = gridAcc.slice(-4).concat(gridAcc.slice(4, 8)).concat(gridAcc.slice(0, 4))
|
||||||
|
|
||||||
|
gridAcc.forEach((v, idx) => {
|
||||||
|
if (Number.isFinite(v)) {
|
||||||
|
stats.gridAcc[idx] += v;
|
||||||
|
stats.totalGridAcc[idx]++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const miss = Number.isFinite(s?.trackers?.hitTracker?.miss) ? s?.trackers?.hitTracker?.miss : 0;
|
||||||
|
const wallHit = Number.isFinite(s?.trackers?.hitTracker?.nbOfWallHit) ? s?.trackers?.hitTracker?.nbOfWallHit : 0;
|
||||||
|
const bombHit = Number.isFinite(s?.trackers?.hitTracker?.bombHit) ? s?.trackers?.hitTracker?.bombHit : 0;
|
||||||
|
|
||||||
|
stats.fc += !miss && !wallHit && !bombHit ? 1 : 0;
|
||||||
|
stats.miss += miss;
|
||||||
|
stats.bombHit += bombHit;
|
||||||
|
stats.wallHit += wallHit;
|
||||||
|
|
||||||
|
stats.acc += Number.isFinite(s?.trackers?.scoreTracker?.rawRatio) ? s?.trackers?.scoreTracker?.rawRatio * 100 : 0;
|
||||||
|
|
||||||
|
stats.pauses += Number.isFinite(s?.trackers?.winTracker?.nbOfPause) ? s?.trackers?.winTracker?.nbOfPause : 0;
|
||||||
|
|
||||||
|
stats.badCuts += Number.isFinite(s?.trackers?.hitTracker?.badCuts) ? s?.trackers?.hitTracker?.badCuts : 0;
|
||||||
|
stats.missedNotes += Number.isFinite(s?.trackers?.hitTracker?.missedNotes) ? s?.trackers?.hitTracker?.missedNotes : 0;
|
||||||
|
|
||||||
|
stats.maxCombo += Number.isFinite(s?.trackers?.hitTracker?.maxCombo) ? s?.trackers?.hitTracker?.maxCombo : 0;
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
total: 0,
|
||||||
|
totalLeft: 0,
|
||||||
|
totalRight: 0,
|
||||||
|
totalGridAcc: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
acc: 0,
|
||||||
|
fc: 0,
|
||||||
|
miss: 0,
|
||||||
|
badCuts: 0,
|
||||||
|
missedNotes: 0,
|
||||||
|
leftMiss: 0,
|
||||||
|
leftBadCuts: 0,
|
||||||
|
rightMiss: 0,
|
||||||
|
rightBadCuts: 0,
|
||||||
|
maxCombo: 0,
|
||||||
|
pauses: 0,
|
||||||
|
bombHit: 0,
|
||||||
|
wallHit: 0,
|
||||||
|
accLeft: 0,
|
||||||
|
accRight: 0,
|
||||||
|
leftTimeDependence: 0,
|
||||||
|
rightTimeDependence: 0,
|
||||||
|
leftPreswing: 0,
|
||||||
|
leftPostswing: 0,
|
||||||
|
rightPreswing: 0,
|
||||||
|
rightPostswing: 0,
|
||||||
|
leftAverageCut: [0, 0, 0],
|
||||||
|
rightAverageCut: [0, 0, 0],
|
||||||
|
gridAcc: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
won: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (!stats.total) return null;
|
||||||
|
|
||||||
|
if (stats.total) {
|
||||||
|
['acc', 'fc', 'miss', 'pauses', 'bombHit', 'wallHit', 'badCuts', 'missedNotes', 'maxCombo'].forEach(key => {
|
||||||
|
stats[key] = stats[key] / stats.total;
|
||||||
|
});
|
||||||
|
|
||||||
|
stats.gridAcc.forEach((v, idx) => stats.gridAcc[idx] = stats.totalGridAcc[idx] ? v / stats.totalGridAcc[idx] : 0);
|
||||||
|
|
||||||
|
['left', 'right'].forEach(key => {
|
||||||
|
const keyCapitalized = capitalize(key);
|
||||||
|
|
||||||
|
const totalVar = `total${keyCapitalized}`;
|
||||||
|
const cutVar = `${key}AverageCut`;
|
||||||
|
|
||||||
|
if (!stats[totalVar]) return;
|
||||||
|
|
||||||
|
[`acc${keyCapitalized}`, `${key}Miss`, `${key}BadCuts`, `${key}TimeDependence`, `${key}Preswing`, `${key}Postswing`].forEach(keyVar => {
|
||||||
|
if (Number.isFinite(stats[keyVar])) {
|
||||||
|
stats[keyVar] = stats[keyVar] / stats[totalVar];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (stats[cutVar] && Array.isArray(stats[cutVar]))
|
||||||
|
stats[cutVar].forEach((v, idx) => stats[cutVar][idx] = v / stats[totalVar]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: refreshBeatSaviorScores(playerId)
|
||||||
|
$: refreshAvailableFilters(playerScoresAreAvailable)
|
||||||
|
$: filteredScores = beatSaviorData?.filter(bsData => selectedType?.key !== 'best' || !!bsData?.ssScore) ?? null
|
||||||
|
$: stats = calculateStats(filteredScores);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="beat-savior" transition:fade>
|
||||||
|
<h3 class="title is-6">
|
||||||
|
<a href={`https://www.beatsavior.io/#/profile/${playerId}`} target="_blank" rel="noreferrer">
|
||||||
|
<span class="beatsavior-icon"></span>
|
||||||
|
<span>Beat Savior average</span>
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
{#if beatSaviorData?.length}
|
||||||
|
{#if filteredScores?.length}
|
||||||
|
{#if stats}
|
||||||
|
<div class="stats">
|
||||||
|
<OtherStats beatSavior={{stats}} isAverage={true}/>
|
||||||
|
<Hands {stats}/>
|
||||||
|
<Grid accGrid={stats?.gridAcc}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="note">Average calculated from {stats.total} run(s).</p>
|
||||||
|
<div class="switcher">
|
||||||
|
<Switcher values={filters} value={selectedType} on:change={e => selectedType = e?.detail ?? filters[0]}/>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<p>Calculating...</p>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
No matching scores.
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<p>No data.</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
h3 {
|
||||||
|
padding: .25em 0;
|
||||||
|
margin-bottom: .75em !important;
|
||||||
|
font-size: 1.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 > a {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 .beatsavior-icon {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1.25em;
|
||||||
|
height: 1.25em;
|
||||||
|
margin-right: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats {
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
grid-gap: 1.5em;
|
||||||
|
align-items: center;
|
||||||
|
justify-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats :global(>*:first-child) {
|
||||||
|
grid-column: 1 / span 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.note {
|
||||||
|
margin-top: 1rem;
|
||||||
|
font-size: .875em;
|
||||||
|
color: var(--faded);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switcher {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
h3 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767px) {
|
||||||
|
.stats {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-gap: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats :global(>*:first-child) {
|
||||||
|
grid-column: 1 / 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
43
src/components/Player/ProfileCards/MiniRanking.svelte
Normal file
43
src/components/Player/ProfileCards/MiniRanking.svelte
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<script>
|
||||||
|
import {opt} from '../../../utils/js'
|
||||||
|
import MiniRanking from '../../Ranking/Mini.svelte'
|
||||||
|
|
||||||
|
export let playerInfo = null;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="mini-ranking">
|
||||||
|
<div>
|
||||||
|
<MiniRanking rank={opt(playerInfo, 'rank')} numOfPlayers={5} on:height-changed />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#each opt(playerInfo, 'countries', []) as countryInfo (countryInfo.country)}
|
||||||
|
<div>
|
||||||
|
<MiniRanking rank={countryInfo.rank} country={countryInfo.country} numOfPlayers={5} on:height-changed />
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mini-ranking {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
grid-gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mini-ranking :global(section) {
|
||||||
|
padding-left: 0!important;
|
||||||
|
padding-right: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mini-ranking :global(section > h3) {
|
||||||
|
padding-left: 0!important;
|
||||||
|
padding-right: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1023px) {
|
||||||
|
.mini-ranking {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
219
src/components/Player/ProfileCards/PpCalc.svelte
Normal file
219
src/components/Player/ProfileCards/PpCalc.svelte
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
<script>
|
||||||
|
import {onMount} from 'svelte'
|
||||||
|
import {debounce} from '../../../utils/debounce'
|
||||||
|
import {formatNumber} from '../../../utils/format'
|
||||||
|
import createRankedService from '../../../services/scoresaber/rankeds'
|
||||||
|
import createPpService from '../../../services/scoresaber/pp'
|
||||||
|
import Badge from '../../Common/Badge.svelte'
|
||||||
|
import Value from '../../Common/Value.svelte'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let worker = null;
|
||||||
|
|
||||||
|
const DEBOUNCE_THRESHOLD = 300;
|
||||||
|
const ACC_THRESHOLDS = [90, 91, 92, 93, 94, 95, 96, 97];
|
||||||
|
|
||||||
|
const rankedService = createRankedService();
|
||||||
|
const ppService = createPpService();
|
||||||
|
|
||||||
|
let maxStars = 15;
|
||||||
|
let maxPp = 100;
|
||||||
|
|
||||||
|
let ppValue = 1;
|
||||||
|
let stars = 10;
|
||||||
|
let accuracy = ACC_THRESHOLDS[0];
|
||||||
|
let lastCalculatedPpValue = 0;
|
||||||
|
let rawPp = null;
|
||||||
|
let isCalculating = false;
|
||||||
|
let rankeds = null;
|
||||||
|
|
||||||
|
async function calcOnePpBoundary(playerId, ppValue) {
|
||||||
|
if (!playerId || !Number.isFinite(ppValue)) {
|
||||||
|
rawPp = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isCalculating = true;
|
||||||
|
rawPp = await worker.calcPpBoundary(playerId, ppValue);
|
||||||
|
isCalculating = false;
|
||||||
|
|
||||||
|
lastCalculatedPpValue = ppValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function calcPpFromStars(stars, acc) {
|
||||||
|
const newRawPpFromStars = ppService.PP_PER_STAR * stars * ppService.ppFactorFromAcc(acc);
|
||||||
|
const whatIf = (await ppService.getWhatIfScore(playerId, -1, newRawPpFromStars));
|
||||||
|
|
||||||
|
if (!whatIf) return;
|
||||||
|
|
||||||
|
ppValue = whatIf.diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStarsForAcc(rawPp, acc) {
|
||||||
|
return rawPp / ppService.PP_PER_STAR / ppService.ppFactorFromAcc(acc);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAccForStars(rawPp, stars) {
|
||||||
|
return ppService.accFromPpFactor(rawPp / ppService.PP_PER_STAR / stars);
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcStarsAndAccFromRawPp(rawPp) {
|
||||||
|
let newStars = getStarsForAcc(rawPp, accuracy);
|
||||||
|
if (newStars > maxStars) {
|
||||||
|
newStars = maxStars;
|
||||||
|
accuracy = getAccForStars(rawPp, newStars);
|
||||||
|
}
|
||||||
|
|
||||||
|
stars = newStars;
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedPpCalc = debounce((playerId, ppValue) => calcOnePpBoundary(playerId, ppValue), DEBOUNCE_THRESHOLD);
|
||||||
|
const onStarsPercentChange = debounce(() => calcPpFromStars(stars, accuracy), DEBOUNCE_THRESHOLD)
|
||||||
|
|
||||||
|
async function resetCalc(playerId) {
|
||||||
|
if (!playerId || !maxStars) return;
|
||||||
|
|
||||||
|
ppValue = 1;
|
||||||
|
accuracy = ACC_THRESHOLDS[0];
|
||||||
|
|
||||||
|
const whatIf = (await ppService.getWhatIfScore(playerId, -1, ppService.PP_PER_STAR * maxStars * ppService.ppFactorFromAcc(100)));
|
||||||
|
if (whatIf) maxPp = whatIf.diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
rankeds = await rankedService.get();
|
||||||
|
maxStars = Math.ceil(Object.values(rankeds).reduce((max, r) => r.stars > max ? r.stars : max, 0) + 1);
|
||||||
|
})
|
||||||
|
|
||||||
|
$: resetCalc(playerId)
|
||||||
|
$: debouncedPpCalc(playerId, ppValue);
|
||||||
|
$: calcStarsAndAccFromRawPp(rawPp);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<section>
|
||||||
|
{#if Number.isFinite(rawPp)}
|
||||||
|
<Badge
|
||||||
|
label={`+ ${formatNumber(ppValue)}pp`}
|
||||||
|
title={`Determines how many raw PPs in the new play you need to achieve to increase your total PP by ${formatNumber(ppValue)}pp`}
|
||||||
|
value={isCalculating || lastCalculatedPpValue !== ppValue ? 'Calculating...' : rawPp}
|
||||||
|
type={isCalculating || lastCalculatedPpValue !== ppValue ? 'text' : 'number'}
|
||||||
|
digits={2}
|
||||||
|
suffix=" raw pp new play"
|
||||||
|
fluid={true}
|
||||||
|
bgColor="var(--ppColour)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="columns is-desktop">
|
||||||
|
<div class="column">
|
||||||
|
<div>
|
||||||
|
<label>Desired +PP</label>
|
||||||
|
|
||||||
|
<div class="range">
|
||||||
|
<input type="range" min="1" max={maxPp} step="0.5" bind:value={ppValue}/>
|
||||||
|
<span><Value value={ppValue} suffix="pp" withZeroSuffix={true}/></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Accuracy</label>
|
||||||
|
|
||||||
|
<div class="range">
|
||||||
|
<input type="range" min="70" max="100" step="0.1" bind:value={accuracy} on:input={onStarsPercentChange}/>
|
||||||
|
<span><Value value={accuracy} suffix="%" withZeroSuffix={true}/></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Stars</label>
|
||||||
|
|
||||||
|
<div class="range">
|
||||||
|
<input type="range" min="0.1" max={maxStars} step="0.01" bind:value={stars}
|
||||||
|
on:input={onStarsPercentChange}/>
|
||||||
|
<span><Value value={stars} suffix="*" withZeroSuffix={true}/></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{#each ACC_THRESHOLDS as threshold (threshold)}
|
||||||
|
<th>{threshold}%</th>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
{#each ACC_THRESHOLDS as threshold (threshold)}
|
||||||
|
<td><Value value={ getStarsForAcc(rawPp, threshold) } suffix="*" /></td>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{:else}
|
||||||
|
<p>No PP data.</p>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.range {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range > *:first-child {
|
||||||
|
margin-right: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
font-size: .875em;
|
||||||
|
font-weight: normal;
|
||||||
|
color: var(--faded) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 20em;
|
||||||
|
max-width: 23em;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table thead {
|
||||||
|
border-bottom: solid 2px var(--dimmed);
|
||||||
|
}
|
||||||
|
|
||||||
|
table th, table td {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(section) {
|
||||||
|
padding-left: 0 !important;
|
||||||
|
padding-right: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(section > h3) {
|
||||||
|
padding-left: 0 !important;
|
||||||
|
padding-right: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767px) {
|
||||||
|
section {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 449px) {
|
||||||
|
table tbody {
|
||||||
|
font-size: .875em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
199
src/components/Player/ProfileCards/ScoreSaberStats.svelte
Normal file
199
src/components/Player/ProfileCards/ScoreSaberStats.svelte
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import createPlayerService from '../../../services/scoresaber/player'
|
||||||
|
import {addToDate, DAY, formatDateRelative, toSsMidnight} from '../../../utils/date'
|
||||||
|
import {debounce} from '../../../utils/debounce'
|
||||||
|
import ScoresStats from '../ScoresStats.svelte'
|
||||||
|
import SsBadges from '../SsBadges.svelte'
|
||||||
|
import SsChart from '../Charts/SsChart.svelte'
|
||||||
|
import AccHistoryChart from '../Charts/AccHistoryChart.svelte'
|
||||||
|
import AccMapsChart from '../Charts/AccMapsChart.svelte'
|
||||||
|
import Switcher from '../../Common/Switcher.svelte'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let scoresStats = null;
|
||||||
|
export let accStats = null;
|
||||||
|
export let accBadges = null;
|
||||||
|
export let ssBadges = null;
|
||||||
|
export let skeleton = false;
|
||||||
|
export let isCached = false;
|
||||||
|
export let rankHistory = null;
|
||||||
|
|
||||||
|
const HISTORY_GAIN_DEBOUNCE = 500;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
const playerService = createPlayerService();
|
||||||
|
|
||||||
|
let playerHistory = null;
|
||||||
|
let playerHistoryGain = null;
|
||||||
|
|
||||||
|
let gainDaysAgo = 1;
|
||||||
|
|
||||||
|
const allSwitcherOptions = [
|
||||||
|
{id: 'rank', label: 'Rank & PP', iconFa: 'fas fa-chart-line'},
|
||||||
|
{id: 'accmaps', label: 'Maps Acc', iconFa: 'fas fa-music'},
|
||||||
|
{id: 'acchistory', label: 'Acc history', iconFa: 'fas fa-crosshairs'},
|
||||||
|
];
|
||||||
|
|
||||||
|
let switcherOptions = allSwitcherOptions;
|
||||||
|
|
||||||
|
let selectedOption = switcherOptions[0];
|
||||||
|
let chartComponent = null;
|
||||||
|
let chartComponentProps = null;
|
||||||
|
|
||||||
|
function updateChartComponent(option) {
|
||||||
|
switch (option?.id) {
|
||||||
|
case 'rank':
|
||||||
|
chartComponent = SsChart;
|
||||||
|
chartComponentProps = {playerId, rankHistory, playerHistory}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'accmaps':
|
||||||
|
chartComponent = AccMapsChart;
|
||||||
|
chartComponentProps = {playerId, medianAcc, averageAcc}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'acchistory':
|
||||||
|
chartComponent = AccHistoryChart;
|
||||||
|
chartComponentProps = {playerId, rankHistory}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
chartComponent = null;
|
||||||
|
chartComponentProps = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAvailableSwitcherOptions(isCached) {
|
||||||
|
const currentSelection = selectedOption?.id ?? 'rank';
|
||||||
|
|
||||||
|
switcherOptions = allSwitcherOptions.filter(o => o?.id !== 'accmaps' || isCached);
|
||||||
|
selectedOption = switcherOptions.find(o => o.id === currentSelection) ?? switcherOptions[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSwitcherChanged(event) {
|
||||||
|
if(!event?.detail?.id) return;
|
||||||
|
|
||||||
|
selectedOption = event.detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshPlayerHistory(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
playerHistory = await playerService.getPlayerHistory(playerId) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshHistoryGain(playerId, playerHistory, rankHistory, daysAgo = 1) {
|
||||||
|
playerHistoryGain = null;
|
||||||
|
|
||||||
|
if (!playerId || (!playerHistory?.length && !rankHistory?.length)) return;
|
||||||
|
|
||||||
|
const todaySsDate = toSsMidnight(new Date());
|
||||||
|
let gainDaysAgo = null;
|
||||||
|
let playerHistoryItem = playerService.getPlayerGain(playerHistory, daysAgo, daysAgo + 7 - 1);
|
||||||
|
if (playerHistoryItem) {
|
||||||
|
gainDaysAgo = Math.floor((todaySsDate - playerHistoryItem.ssDate) / DAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rankHistory?.length) {
|
||||||
|
const reversedRankHistory = rankHistory.map(r => r).reverse();
|
||||||
|
if (!reversedRankHistory?.[daysAgo]) return;
|
||||||
|
|
||||||
|
if (!playerHistoryItem) playerHistoryItem = {playerId, rank: reversedRankHistory[daysAgo], ssDate: addToDate(-DAY, todaySsDate)};
|
||||||
|
else {
|
||||||
|
playerHistoryItem.rank = reversedRankHistory[gainDaysAgo];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!playerHistoryItem) return;
|
||||||
|
|
||||||
|
playerHistoryGain = {...playerHistoryItem, gainDaysAgo, gainType: 'scoresaber'};
|
||||||
|
|
||||||
|
dispatch('player-gain-changed', playerHistoryGain);
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedRefreshHistoryGain = debounce(
|
||||||
|
(playerId, playerHistory, rankHistory, gainDaysAgo) =>
|
||||||
|
refreshHistoryGain(playerId, playerHistory, rankHistory, gainDaysAgo), HISTORY_GAIN_DEBOUNCE,
|
||||||
|
);
|
||||||
|
|
||||||
|
let accStatsWithGain = null;
|
||||||
|
function updateAccStatsWithGain(accStats, playerGain) {
|
||||||
|
accStatsWithGain = accStats?.map(s => ({
|
||||||
|
...s,
|
||||||
|
prevValue: playerGain?.[s?.key] ?? null,
|
||||||
|
prevLabel: Number.isFinite(playerGain?.gainDaysAgo) ? formatDateRelative(addToDate(-playerGain.gainDaysAgo * DAY)) : null,
|
||||||
|
inline: true,
|
||||||
|
}))
|
||||||
|
?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedUpdateAccStatsWithGain = debounce((accStats, playerHistoryGain) => updateAccStatsWithGain(accStats, playerHistoryGain), HISTORY_GAIN_DEBOUNCE)
|
||||||
|
|
||||||
|
$: avgStat = accStats?.find(s => s.key === 'avgAcc') ?? null
|
||||||
|
$: medianStat = accStats?.find(s => s.key === 'medianAcc') ?? null
|
||||||
|
$: avgAccTween = avgStat?.value ?? null
|
||||||
|
$: medianAccTween = medianStat?.value ?? null
|
||||||
|
$: averageAcc = $avgAccTween
|
||||||
|
$: medianAcc = $medianAccTween
|
||||||
|
|
||||||
|
$: refreshPlayerHistory(playerId);
|
||||||
|
$: debouncedRefreshHistoryGain(playerId, playerHistory, rankHistory, gainDaysAgo)
|
||||||
|
$: updateAvailableSwitcherOptions(isCached)
|
||||||
|
$: updateChartComponent(selectedOption, rankHistory, averageAcc, medianAcc, playerHistory)
|
||||||
|
$: debouncedUpdateAccStatsWithGain(accStats, playerHistoryGain)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if scoresStats || ssBadges || skeleton}
|
||||||
|
<div class="stats" class:enhanced={isCached}>
|
||||||
|
{#if scoresStats}<ScoresStats stats={scoresStats} {skeleton}/>{/if}
|
||||||
|
<div>
|
||||||
|
{#if accStats || accStatsWithGain}<ScoresStats stats={accStatsWithGain ?? accStats} />{/if}
|
||||||
|
{#if accBadges}<ScoresStats stats={accBadges}/>{/if}
|
||||||
|
</div>
|
||||||
|
{#if ssBadges}
|
||||||
|
<div class="up-to-tablet">
|
||||||
|
<SsBadges badges={ssBadges}/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if selectedOption}
|
||||||
|
<div class="chart">
|
||||||
|
<svelte:component this={chartComponent} {...chartComponentProps} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chart-switcher">
|
||||||
|
<Switcher values={switcherOptions} value={selectedOption} on:change={onSwitcherChanged}/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.chart {
|
||||||
|
min-height: calc(350px + 1rem);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-switcher {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 1200px) {
|
||||||
|
.stats.enhanced {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto auto;
|
||||||
|
grid-gap: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 599px) {
|
||||||
|
.stats {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats :global(.badges) {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
25
src/components/Player/ProfileCards/TwitchVideos.svelte
Normal file
25
src/components/Player/ProfileCards/TwitchVideos.svelte
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<script>
|
||||||
|
import TwitchVideos from '../TwitchVideos.svelte'
|
||||||
|
|
||||||
|
export let videos = null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<TwitchVideos {videos} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div :global(section) {
|
||||||
|
padding-left: 0!important;
|
||||||
|
padding-right: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(section > h3) {
|
||||||
|
padding-left: 0!important;
|
||||||
|
padding-right: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(.videos a) {
|
||||||
|
pointer-events: fill;
|
||||||
|
}
|
||||||
|
</style>
|
88
src/components/Player/ScoreFilters/GenericFilter.svelte
Normal file
88
src/components/Player/ScoreFilters/GenericFilter.svelte
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
|
||||||
|
export let filter;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let filterOpen = false;
|
||||||
|
|
||||||
|
function dispatchValue(value) {
|
||||||
|
if (filter?.props?.id?.length) dispatch('change', {id: filter.props.id, value})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFilterChanged(event) {
|
||||||
|
const value = event?.detail ?? null;
|
||||||
|
|
||||||
|
dispatchValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onButtonClick() {
|
||||||
|
filterOpen = !filterOpen;
|
||||||
|
|
||||||
|
if (!filterOpen) dispatchValue(null);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if filter?.component && filter?.props}
|
||||||
|
<div class="filter" class:open={filterOpen} title={filter?.props?.title}>
|
||||||
|
<span class="filter-component">
|
||||||
|
<svelte:component this={filter.component} {...filter.props} open={filterOpen} on:change={onFilterChanged}/>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<i class={`fa filter-btn ${!filterOpen ? (filter?.props?.iconFa ?? '') : ''}`} class:fa-times={filterOpen}
|
||||||
|
title={filterOpen ? 'Click to close and clear filter' : filter?.props?.title}
|
||||||
|
on:click={onButtonClick}
|
||||||
|
></i>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.filter {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
width: 1.75em;
|
||||||
|
height: calc(1em + .5em + 2px + 2px);
|
||||||
|
overflow: hidden;
|
||||||
|
transition: all 300ms ease-out;
|
||||||
|
margin-right: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter.open {
|
||||||
|
width: 10em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter > .filter-component {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: calc(100% - 1.4em);
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: transparent;
|
||||||
|
transition: all 300ms ease-out;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
width: 1.75em;
|
||||||
|
text-align: center;
|
||||||
|
padding: .4em;
|
||||||
|
transition: all 300ms ease-out;
|
||||||
|
background-color: var(--dimmed);
|
||||||
|
z-index: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: .2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter.open .filter-btn {
|
||||||
|
width: auto;
|
||||||
|
background-color: var(--error);
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
</style>
|
44
src/components/Player/ScoreFilters/SelectFilter.svelte
Normal file
44
src/components/Player/ScoreFilters/SelectFilter.svelte
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher, tick} from 'svelte'
|
||||||
|
|
||||||
|
export let open = false;
|
||||||
|
export let values = [];
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let value = values?.length ? values[0]?.id : null;
|
||||||
|
|
||||||
|
async function onChanged() {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
dispatch('change', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (!open) value = values?.length ? values[0]?.id : null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if values?.length}
|
||||||
|
<select class:open={open} bind:value on:change={onChanged}>
|
||||||
|
{#each values as option}
|
||||||
|
<option value={option.id}>{option.name}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--foreground);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: calc(.25em - 1px) .5em calc(.25em - 1px) .5em;
|
||||||
|
transition: all 300ms ease-out;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
select.open {
|
||||||
|
border-color: var(--faded);
|
||||||
|
}
|
||||||
|
</style>
|
48
src/components/Player/ScoreFilters/TextFilter.svelte
Normal file
48
src/components/Player/ScoreFilters/TextFilter.svelte
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
|
||||||
|
export let open = false;
|
||||||
|
export let placeholder = null;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let filterEl = null;
|
||||||
|
|
||||||
|
function onKeyUp(e) {
|
||||||
|
const value = e?.target?.value ?? null;
|
||||||
|
if (!value?.length) return;
|
||||||
|
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
dispatch('change', value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (open && filterEl) filterEl.focus();
|
||||||
|
$: if (!open && filterEl) filterEl.value = '';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input type="text" {placeholder} class:open={open} bind:this={filterEl} on:keyup={onKeyUp} />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: transparent;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: calc(.25em - 1px) .5em calc(.25em - 1px) .5em;
|
||||||
|
transition: all 300ms ease-out;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
input::placeholder {
|
||||||
|
color: var(--faded)!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.open {
|
||||||
|
border-color: var(--faded);
|
||||||
|
}
|
||||||
|
</style>
|
58
src/components/Player/ScoreRank.svelte
Normal file
58
src/components/Player/ScoreRank.svelte
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<script>
|
||||||
|
import {tweened} from 'svelte/motion';
|
||||||
|
import {cubicOut} from 'svelte/easing';
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
import {SS_HOST} from '../../network/queues/scoresaber/page-queue'
|
||||||
|
|
||||||
|
export let rank;
|
||||||
|
export let country;
|
||||||
|
export let countryRank;
|
||||||
|
export let countryRankTotal;
|
||||||
|
export let showCountryTotal = false;
|
||||||
|
export let inline = true;
|
||||||
|
|
||||||
|
const currentRank = tweened(rank, {
|
||||||
|
duration: 500,
|
||||||
|
easing: cubicOut,
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentCountryRank = tweened(countryRank, {
|
||||||
|
duration: 500,
|
||||||
|
easing: cubicOut,
|
||||||
|
});
|
||||||
|
|
||||||
|
$: {
|
||||||
|
currentRank.set(rank);
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
currentCountryRank.set(countryRank);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class="val">
|
||||||
|
<i class="fas fa-globe-americas"></i>
|
||||||
|
<span class="value"><Value value={$currentRank} prefix="#" zero="-" digits={0}/></span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{#if country}
|
||||||
|
<span class="val" style="display:{inline ? 'inline' : 'block'};">
|
||||||
|
<img src={`${SS_HOST}/imports/images/flags/${country}.png`} alt=""/>
|
||||||
|
<span class="value"
|
||||||
|
title={!showCountryTotal && country && $currentCountryRank && countryRankTotal ? `#${$currentCountryRank} / ${countryRankTotal}` : ''}>
|
||||||
|
<Value value={$currentCountryRank} prefix="#" zero="-" digits={0}/>
|
||||||
|
{#if showCountryTotal}<Value value={countryRankTotal} prefix="/" zero="-" digits={0}/>{/if}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.val {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.val > *:not(:last-child) {
|
||||||
|
margin-right: .25em;
|
||||||
|
}
|
||||||
|
</style>
|
32
src/components/Player/ScoreServiceFilters.svelte
Normal file
32
src/components/Player/ScoreServiceFilters.svelte
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import stringify from 'json-stable-stringify'
|
||||||
|
import GenericFilter from './ScoreFilters/GenericFilter.svelte'
|
||||||
|
|
||||||
|
export let filters = null;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let currentFilterValues = {}
|
||||||
|
let lastFilterValues = {}
|
||||||
|
|
||||||
|
function onFilterChanged(event) {
|
||||||
|
const key = event?.detail?.id ?? null;
|
||||||
|
if (!key) return;
|
||||||
|
|
||||||
|
currentFilterValues[key] = event.detail.value;
|
||||||
|
|
||||||
|
if (stringify(currentFilterValues) !== stringify(lastFilterValues))
|
||||||
|
dispatch('change', currentFilterValues)
|
||||||
|
|
||||||
|
lastFilterValues = {...currentFilterValues}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if filters?.length}
|
||||||
|
<section>
|
||||||
|
{#each filters as filter}
|
||||||
|
<GenericFilter {filter} on:change={onFilterChanged}/>
|
||||||
|
{/each}
|
||||||
|
</section>
|
||||||
|
{/if}
|
313
src/components/Player/ScoreServiceSwitcher.svelte
Normal file
313
src/components/Player/ScoreServiceSwitcher.svelte
Normal file
@ -0,0 +1,313 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import createScoresService from '../../services/scoresaber/scores'
|
||||||
|
import createBeatSaviorService from '../../services/beatsavior'
|
||||||
|
import createAccSaberService from '../../services/accsaber'
|
||||||
|
import Switcher from '../Common/Switcher.svelte'
|
||||||
|
import ScoreServiceFilters from './ScoreServiceFilters.svelte'
|
||||||
|
import TextFilter from './ScoreFilters/TextFilter.svelte'
|
||||||
|
import SelectFilter from './ScoreFilters/SelectFilter.svelte'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let service = 'scoresaber';
|
||||||
|
export let serviceParams = {sort: 'recent', order: 'desc'}
|
||||||
|
export let loadingService = null;
|
||||||
|
export let loadingServiceParams = null;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
const scoresService = createScoresService();
|
||||||
|
const beatSaviorService = createBeatSaviorService();
|
||||||
|
const accSaberService = createAccSaberService();
|
||||||
|
|
||||||
|
let availableServiceNames = ['scoresaber'];
|
||||||
|
let accSaberCategories = null;
|
||||||
|
|
||||||
|
const allServices = [
|
||||||
|
{
|
||||||
|
id: 'scoresaber',
|
||||||
|
label: 'Score Saber',
|
||||||
|
icon: '<div class="scoresaber-icon"></div>',
|
||||||
|
url: `/u/${playerId}/scoresaber/recent/1`,
|
||||||
|
switcherComponents: [
|
||||||
|
{
|
||||||
|
component: Switcher,
|
||||||
|
props: {
|
||||||
|
values: [
|
||||||
|
{id: 'recent', 'label': 'Recent', iconFa: 'fa fa-clock', url: `/u/${playerId}/scoresaber/recent/1`},
|
||||||
|
{id: 'top', 'label': 'PP', iconFa: 'fa fa-cubes', url: `/u/${playerId}/scoresaber/top/1`},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
key: 'sort',
|
||||||
|
onChange: event => {
|
||||||
|
if (!event?.detail?.id) return null;
|
||||||
|
|
||||||
|
dispatch('service-params-change', {sort: event?.detail?.id})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'beatsavior',
|
||||||
|
label: 'Beat Savior',
|
||||||
|
icon: '<div class="beatsavior-icon"></div>',
|
||||||
|
url: `/u/${playerId}/beatsavior/recent/1`,
|
||||||
|
switcherComponents: [
|
||||||
|
{
|
||||||
|
component: Switcher,
|
||||||
|
props: {
|
||||||
|
values: [
|
||||||
|
{id: 'recent', 'label': 'Recent', iconFa: 'fa fa-clock', url: `/u/${playerId}/beatsavior/recent/1`},
|
||||||
|
{id: 'acc', 'label': 'Acc', iconFa: 'fa fa-crosshairs', url: `/u/${playerId}/beatsavior/acc/1`},
|
||||||
|
{id: 'mistakes', 'label': 'Mistakes', iconFa: 'fa fa-times', url: `/u/${playerId}/beatsavior/mistake/1`},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
key: 'sort',
|
||||||
|
onChange: event => {
|
||||||
|
if (!event?.detail?.id) return null;
|
||||||
|
|
||||||
|
dispatch('service-params-change', {sort: event?.detail?.id})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'accsaber',
|
||||||
|
label: 'AccSaber',
|
||||||
|
icon: '<div class="accsaber-icon"></div>',
|
||||||
|
url: `/u/${playerId}/accsaber/recent/1`,
|
||||||
|
switcherComponents: [
|
||||||
|
{
|
||||||
|
component: Switcher,
|
||||||
|
key: 'type',
|
||||||
|
onChange: event => {
|
||||||
|
if (!event?.detail?.id) return null;
|
||||||
|
|
||||||
|
dispatch('service-params-change', {type: event?.detail?.id})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: Switcher,
|
||||||
|
key: 'sort',
|
||||||
|
props: {
|
||||||
|
values: [
|
||||||
|
{id: 'ap', 'label': 'AP', iconFa: 'fa fa-cubes'},
|
||||||
|
{id: 'recent', 'label': 'Recent', iconFa: 'fa fa-clock'},
|
||||||
|
{id: 'acc', 'label': 'Acc', iconFa: 'fa fa-crosshairs'},
|
||||||
|
{id: 'rank', 'label': 'Rank', iconFa: 'fa fa-list-ol'},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
onChange: event => {
|
||||||
|
if (!event?.detail?.id) return null;
|
||||||
|
|
||||||
|
dispatch('service-params-change', {sort: event?.detail?.id})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
async function updateAvailableServiceNames(playerId) {
|
||||||
|
accSaberCategories = null;
|
||||||
|
|
||||||
|
const additionalServices = (await Promise.all([
|
||||||
|
scoresService.isDataForPlayerAvailable(playerId).then(r => r ? 'scoresaber-cached' : null),
|
||||||
|
beatSaviorService.isDataForPlayerAvailable(playerId).then(r => r ? 'beatsavior' : null),
|
||||||
|
accSaberService.isDataForPlayerAvailable(playerId).then(r => r ? 'accsaber' : null),
|
||||||
|
])
|
||||||
|
).filter(s => s);
|
||||||
|
|
||||||
|
if (additionalServices?.length) availableServiceNames = ['scoresaber'].concat(additionalServices);
|
||||||
|
|
||||||
|
if (additionalServices.includes('accsaber')) accSaberCategories = await accSaberService.getCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAvailableServices(avaiableServiceNames, service, loadingService, serviceParams, loadingServiceParams, accSaberCategories) {
|
||||||
|
const commonFilters = [
|
||||||
|
{
|
||||||
|
component: TextFilter,
|
||||||
|
props: {
|
||||||
|
id: 'search',
|
||||||
|
iconFa: 'fa fa-search',
|
||||||
|
title: 'Search by song/artist/mapper name',
|
||||||
|
placeholder: 'Enter song name...'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: SelectFilter,
|
||||||
|
props: {
|
||||||
|
id: 'diff',
|
||||||
|
iconFa: 'fa fa-chart-line',
|
||||||
|
title: 'Filter by map difficulty',
|
||||||
|
values: [
|
||||||
|
{id: null, name: 'All'},
|
||||||
|
{id: 'easy', name: 'Easy'},
|
||||||
|
{id: 'normal', name: 'Normal'},
|
||||||
|
{id: 'hard', name: 'Hard'},
|
||||||
|
{id: 'expert', name: 'Expert'},
|
||||||
|
{id: 'expertplus', name: 'Expert+'},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return allServices
|
||||||
|
.filter(s => availableServiceNames.includes(s?.id))
|
||||||
|
.map(s => {
|
||||||
|
if (s?.id !== service || !s?.switcherComponents?.length) return s;
|
||||||
|
|
||||||
|
const serviceDef = {...s};
|
||||||
|
serviceDef.switcherComponents = serviceDef.switcherComponents.map(c => ({...c}));
|
||||||
|
|
||||||
|
switch (service) {
|
||||||
|
case 'scoresaber':
|
||||||
|
if (availableServiceNames.includes('scoresaber-cached')) {
|
||||||
|
const sortComponent = serviceDef.switcherComponents.find(c => c.key === 'sort');
|
||||||
|
if (sortComponent?.props?.values) {
|
||||||
|
if (!sortComponent.props.values.find(v => v.id === 'rank'))
|
||||||
|
sortComponent.props.values.push({
|
||||||
|
id: 'rank',
|
||||||
|
label: 'Rank',
|
||||||
|
iconFa: 'fa fa-list-ol',
|
||||||
|
title: 'May be inaccurate - rank is from last score refresh',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!sortComponent.props.values.find(v => v.id === 'acc'))
|
||||||
|
sortComponent.props.values.push({
|
||||||
|
id: 'acc',
|
||||||
|
label: 'Acc',
|
||||||
|
iconFa: 'fa fa-crosshairs',
|
||||||
|
title: 'Accurate for ranked maps only',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!sortComponent.props.values.find(v => v.id === 'stars'))
|
||||||
|
sortComponent.props.values.push({
|
||||||
|
id: 'stars',
|
||||||
|
label: 'Stars',
|
||||||
|
iconFa: 'fa fa-star',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceDef.filters = [...commonFilters]
|
||||||
|
.concat([
|
||||||
|
{
|
||||||
|
component: SelectFilter,
|
||||||
|
props: {
|
||||||
|
id: 'songType',
|
||||||
|
iconFa: 'fa fa-cubes',
|
||||||
|
title: 'Filter by map type',
|
||||||
|
values: [
|
||||||
|
{id: null, name: 'All'},
|
||||||
|
{id: 'ranked', name: 'Ranked only'},
|
||||||
|
{id: 'unranked', name: 'Unranked only'},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'beatsavior':
|
||||||
|
serviceDef.filters = [...commonFilters];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'accsaber':
|
||||||
|
serviceDef.filters = [...commonFilters];
|
||||||
|
|
||||||
|
if (accSaberCategories?.length) {
|
||||||
|
const typeComponent = serviceDef.switcherComponents.find(c => c?.key === 'type');
|
||||||
|
if (typeComponent)
|
||||||
|
typeComponent.props = {
|
||||||
|
values: accSaberCategories.map(c => ({
|
||||||
|
id: c.name,
|
||||||
|
'label': c.displayName ?? c.name,
|
||||||
|
url: `/u/${playerId}/${service}/${c.name}/recent/1`,
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceDef.switcherComponents = serviceDef.switcherComponents
|
||||||
|
.filter(c => c?.props)
|
||||||
|
.map(c => {
|
||||||
|
const key = c?.key ?? 'sort';
|
||||||
|
|
||||||
|
[
|
||||||
|
{propKey: 'value', compareObj: serviceParams},
|
||||||
|
{propKey: 'loadingValue', compareObj: loadingServiceParams},
|
||||||
|
].forEach(o => c.props[o.propKey] = c.props?.values?.find(v => v?.id === o.compareObj?.[key]) ?? null)
|
||||||
|
|
||||||
|
return c;
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!serviceDef?.switcherComponents?.length) return null;
|
||||||
|
|
||||||
|
return serviceDef;
|
||||||
|
})
|
||||||
|
.filter(s => s)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onServiceChanged(event) {
|
||||||
|
if (!event?.detail?.id) return;
|
||||||
|
|
||||||
|
dispatch('service-change', event.detail.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFiltersChanged(event) {
|
||||||
|
const newFilters = event?.detail ?? {}
|
||||||
|
|
||||||
|
const {sort, order, ...filters} = newFilters;
|
||||||
|
|
||||||
|
const changesToPush = {
|
||||||
|
...(sort? {sort} : null),
|
||||||
|
...(order? {order} : null),
|
||||||
|
...(filters ? {filters} : {filters: {}})
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch('service-params-change', changesToPush)
|
||||||
|
}
|
||||||
|
|
||||||
|
$: updateAvailableServiceNames(playerId)
|
||||||
|
$: availableServices = updateAvailableServices(availableServiceNames, service, loadingService, serviceParams, loadingServiceParams, accSaberCategories)
|
||||||
|
|
||||||
|
$: serviceObj = availableServices.find(s => s.id === service);
|
||||||
|
$: loadingServiceObj = availableServices.find(s => s.id === loadingService)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<Switcher values={availableServices} value={serviceObj} on:change={onServiceChanged}
|
||||||
|
loadingValue={loadingServiceObj}/>
|
||||||
|
|
||||||
|
{#if serviceObj?.switcherComponents?.length}
|
||||||
|
{#each serviceObj.switcherComponents as component (`${serviceObj?.id ?? ''}${component.key ?? 'sort'}`)}
|
||||||
|
<svelte:component this={component.component} {...component.props}
|
||||||
|
on:change={component.onChange ?? null}
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if serviceObj?.filters}
|
||||||
|
{#key `${playerId}${service}`}
|
||||||
|
<ScoreServiceFilters filters={serviceObj.filters} on:change={onFiltersChanged}/>
|
||||||
|
{/key}
|
||||||
|
{/if}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
nav {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(> *) {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-right: .75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav :global(> *:last-child) {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
</style>
|
135
src/components/Player/Scores.svelte
Normal file
135
src/components/Player/Scores.svelte
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import createScoresStore from '../../stores/http/http-scores-store.js';
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import {scrollToTargetAdjusted} from '../../utils/browser'
|
||||||
|
import SongScore from './SongScore.svelte'
|
||||||
|
import Error from '../Common/Error.svelte'
|
||||||
|
import ScoreServiceSwitcher from './ScoreServiceSwitcher.svelte'
|
||||||
|
import ScoresPager from './ScoresPager.svelte'
|
||||||
|
import stringify from 'json-stable-stringify'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let initialState = null;
|
||||||
|
export let initialStateType = null;
|
||||||
|
export let initialService = 'scoresaber';
|
||||||
|
export let initialServiceParams = {};
|
||||||
|
export let numOfScores = null;
|
||||||
|
export let fixedBrowserTitle = null;
|
||||||
|
|
||||||
|
let scoresStore = createScoresStore(
|
||||||
|
playerId,
|
||||||
|
initialService,
|
||||||
|
initialServiceParams,
|
||||||
|
initialState,
|
||||||
|
initialStateType
|
||||||
|
);
|
||||||
|
|
||||||
|
let scoresBoxEl = null;
|
||||||
|
|
||||||
|
function changeParams(newPlayerId, newService, newServiceParams) {
|
||||||
|
if (!newPlayerId) return null;
|
||||||
|
|
||||||
|
scoresStore.fetch(newServiceParams, newService, newPlayerId);
|
||||||
|
|
||||||
|
return {playerId: newPlayerId, service: newService, serviceParams: newServiceParams}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPageChanged(event) {
|
||||||
|
if (!(event?.detail?.initial ?? false)) scrollToTop();
|
||||||
|
|
||||||
|
const page = (event?.detail?.page ?? 0) + 1
|
||||||
|
|
||||||
|
dispatch('page-changed', page);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onServiceParamsChanged(event) {
|
||||||
|
if (!event?.detail) return;
|
||||||
|
|
||||||
|
dispatch('service-params-changed', event.detail)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onServiceChanged(event) {
|
||||||
|
if (!event?.detail) return;
|
||||||
|
|
||||||
|
scrollToTop();
|
||||||
|
|
||||||
|
dispatch('service-changed', event.detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToTop() {
|
||||||
|
if (scoresBoxEl) scrollToTargetAdjusted(scoresBoxEl, 44)
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentService = null;
|
||||||
|
let lastService = '';
|
||||||
|
function updateService(scoresStore) {
|
||||||
|
if (!scoresStore) return;
|
||||||
|
|
||||||
|
const newService = scoresStore.getService();
|
||||||
|
if (lastService !== newService) currentService = newService;
|
||||||
|
|
||||||
|
lastService = newService;
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentServiceParams = null;
|
||||||
|
let lastServiceParams = '';
|
||||||
|
function updateServiceParams(scoresStore) {
|
||||||
|
if (!scoresStore) return;
|
||||||
|
|
||||||
|
const newServiceParams = stringify(scoresStore.getServiceParams());
|
||||||
|
if (lastServiceParams !== newServiceParams) currentServiceParams = scoresStore.getServiceParams();
|
||||||
|
|
||||||
|
lastServiceParams = newServiceParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$: changeParams(playerId, initialService, initialServiceParams, initialState, initialStateType)
|
||||||
|
$: $scoresStore, updateService(scoresStore);
|
||||||
|
$: $scoresStore, updateServiceParams(scoresStore);
|
||||||
|
$: page = currentServiceParams?.page ?? null;
|
||||||
|
$: totalScores = ((scoresStore) => scoresStore && scoresStore.getTotalScores ? scoresStore.getTotalScores() : null)(scoresStore, $scoresStore);
|
||||||
|
$: isLoading = scoresStore ? scoresStore.isLoading : false;
|
||||||
|
$: pending = scoresStore ? scoresStore.pending : null;
|
||||||
|
$: error = scoresStore ? scoresStore.error : null;
|
||||||
|
|
||||||
|
$: scoresStore && scoresStore.fetch(currentServiceParams, currentService)
|
||||||
|
$: pagerTotalScores = totalScores !== null && totalScores !== undefined ? totalScores : numOfScores
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="box has-shadow" bind:this={scoresBoxEl}>
|
||||||
|
{#if $error}
|
||||||
|
<div><Error error={$error} /></div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<ScoreServiceSwitcher {playerId} service={currentService} serviceParams={currentServiceParams}
|
||||||
|
loadingService={$pending?.service} loadingServiceParams={$pending?.serviceParams}
|
||||||
|
on:service-change={onServiceChanged} on:service-params-change={onServiceParamsChanged}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if $scoresStore && $scoresStore.length}
|
||||||
|
<div class="song-scores grid-transition-helper">
|
||||||
|
{#each $scoresStore as songScore, idx (opt(songScore, 'leaderboard.leaderboardId'))}
|
||||||
|
<SongScore {playerId} {songScore} {fixedBrowserTitle} {idx} service={currentService} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<p>No scores.</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if Number.isFinite(page) && (!Number.isFinite(pagerTotalScores) || pagerTotalScores > 0)}
|
||||||
|
<ScoresPager {playerId} service={currentService} serviceParams={currentServiceParams}
|
||||||
|
totalItems={pagerTotalScores} currentPage={page-1}
|
||||||
|
loadingPage={$pending?.serviceParams?.page ? $pending.serviceParams.page - 1 : null}
|
||||||
|
on:page-changed={onPageChanged}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.song-scores :global(> *:last-child) {
|
||||||
|
border-bottom: none !important;
|
||||||
|
}
|
||||||
|
</style>
|
208
src/components/Player/ScoresPager.svelte
Normal file
208
src/components/Player/ScoresPager.svelte
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
<script>
|
||||||
|
import {formatDate, formatDateWithOptions, truncateDate} from '../../utils/date'
|
||||||
|
import {PLAYER_SCORES_PER_PAGE} from '../../utils/scoresaber/consts'
|
||||||
|
import {PLAYER_SCORES_PER_PAGE as ACCSABER_PLAYER_SCORES_PER_PAGE} from '../../utils/accsaber/consts'
|
||||||
|
import {formatNumber} from '../../utils/format'
|
||||||
|
import createScoresService from '../../services/scoresaber/scores'
|
||||||
|
import createBeatSaviorService from '../../services/beatsavior'
|
||||||
|
import createAccSaberService from '../../services/accsaber'
|
||||||
|
import ChartBrowser from '../Common/ChartBrowser.svelte'
|
||||||
|
import Pager from '../Common/Pager.svelte'
|
||||||
|
import {debounce} from '../../utils/debounce'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let service = null;
|
||||||
|
export let serviceParams = null;
|
||||||
|
export let totalItems = null;
|
||||||
|
export let currentPage = 0;
|
||||||
|
export let loadingPage = null;
|
||||||
|
|
||||||
|
const DEBOUNCE_THRESHOLD = 500;
|
||||||
|
|
||||||
|
const scoresService = createScoresService();
|
||||||
|
const beatSaviorService = createBeatSaviorService();
|
||||||
|
const accSaberService = createAccSaberService();
|
||||||
|
|
||||||
|
let playerScores = null;
|
||||||
|
let groupedPlayerScores = null;
|
||||||
|
let playerScoresHistogram = null;
|
||||||
|
let playerScoresHistogramBucketSize = null;
|
||||||
|
let playerScoresHistogramBucketSizeHash = null;
|
||||||
|
|
||||||
|
const getHistogramBucketSizeHash = (playerId, service, serviceParams) => `${playerId ?? ''}::${service ?? ''}::${serviceParams?.sort ?? ''}`
|
||||||
|
|
||||||
|
const groupScores = (scores, keyFunc = score => truncateDate(score?.timeSet)?.getTime(), order = 'desc') =>
|
||||||
|
Object.values(
|
||||||
|
scores
|
||||||
|
.reduce((scores, score) => {
|
||||||
|
const key = keyFunc(score);
|
||||||
|
if (key === null || key === undefined) return scores;
|
||||||
|
|
||||||
|
if (!scores[key]) scores[key] = [];
|
||||||
|
|
||||||
|
scores[key].push({key, score});
|
||||||
|
|
||||||
|
return scores;
|
||||||
|
}, {}),
|
||||||
|
)
|
||||||
|
.sort((a, b) => order === 'asc' ? a?.[0]?.key - b?.[0]?.key : b?.[0].key - a?.[0].key)
|
||||||
|
.reduce((cum, values) => {
|
||||||
|
if (!values?.length) return cum;
|
||||||
|
|
||||||
|
const x = values[0].key;
|
||||||
|
const y = values.length;
|
||||||
|
|
||||||
|
const prevTotal = cum.length ? cum[cum.length - 1].total : 0;
|
||||||
|
const page = Math.floor(prevTotal / (service === 'accsaber' ? ACCSABER_PLAYER_SCORES_PER_PAGE : PLAYER_SCORES_PER_PAGE));
|
||||||
|
const total = prevTotal + y;
|
||||||
|
|
||||||
|
cum.push({
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
firstScore: values[0].score,
|
||||||
|
page,
|
||||||
|
total,
|
||||||
|
})
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, [])
|
||||||
|
.sort((a, b) => order === 'asc' ? a.x - b. x : b.x - a.x);
|
||||||
|
|
||||||
|
async function refreshAllPlayerServiceScores(playerId, service, serviceParams) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
let serviceObj = null;
|
||||||
|
switch (service) {
|
||||||
|
case 'scoresaber':
|
||||||
|
serviceObj = scoresService;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'beatsavior':
|
||||||
|
serviceObj = beatSaviorService;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'accsaber':
|
||||||
|
serviceObj = accSaberService;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serviceObj) return;
|
||||||
|
|
||||||
|
playerScoresHistogram = serviceObj.getScoresHistogramDefinition(serviceParams);
|
||||||
|
|
||||||
|
const currentHistogramBucketSizeHash = getHistogramBucketSizeHash(playerId, service, serviceParams)
|
||||||
|
if (playerScoresHistogramBucketSizeHash !== currentHistogramBucketSizeHash) {
|
||||||
|
playerScoresHistogramBucketSize = playerScoresHistogram.bucketSize;
|
||||||
|
playerScoresHistogramBucketSizeHash = currentHistogramBucketSizeHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
playerScores = (await serviceObj.getPlayerScores(playerId))
|
||||||
|
.filter(playerScoresHistogram.filter)
|
||||||
|
.sort(playerScoresHistogram.sort)
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetCurrentValues() {
|
||||||
|
playerScores = null;
|
||||||
|
groupedPlayerScores = null;
|
||||||
|
playerScoresHistogram = null;
|
||||||
|
|
||||||
|
if (playerScoresHistogramBucketSizeHash !== getHistogramBucketSizeHash(playerId, service, serviceParams))
|
||||||
|
playerScoresHistogramBucketSize = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshGroupedScores() {
|
||||||
|
groupedPlayerScores = playerScores?.length && playerScoresHistogram
|
||||||
|
? groupScores(
|
||||||
|
playerScores,
|
||||||
|
playerScoresHistogram.getRoundedValue(playerScoresHistogramBucketSize),
|
||||||
|
playerScoresHistogram.order,
|
||||||
|
)
|
||||||
|
.filter(playerScoresHistogram.histogramFilter)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedRefreshGroupedScores = debounce(() => refreshGroupedScores(), DEBOUNCE_THRESHOLD)
|
||||||
|
|
||||||
|
const chartBrowserTooltipTitle = ctx => playerScoresHistogram?.type === 'time'
|
||||||
|
? formatDate(new Date(ctx?.raw?.x), 'long', ['hour', 'minute'].includes(playerScoresHistogramBucketSize) ? 'short' : null)
|
||||||
|
: `${playerScoresHistogram.prefixLong ?? playerScoresHistogram.prefix}${formatNumber(ctx?.raw?.x, playerScoresHistogram.round)}${` - ${formatNumber(ctx?.raw?.x + playerScoresHistogramBucketSize, playerScoresHistogram.round)}`}${playerScoresHistogram.suffixLong ?? playerScoresHistogram.suffix}`;
|
||||||
|
|
||||||
|
const chartBrowserTooltipLabel = ctx => (ctx?.raw?.page ?? null) !== null
|
||||||
|
? [`${formatNumber(ctx?.raw?.y, 0)} score(s)`, '', `Click to go to page ${ctx.raw.page + 1}`]
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const chartBrowserTickFormat = (val, idx, ticks) => playerScoresHistogram?.type === 'time'
|
||||||
|
? formatDateWithOptions(new Date(ticks?.[idx]?.value), {
|
||||||
|
localeMatcher: 'best fit',
|
||||||
|
year: ['year'].includes(playerScoresHistogramBucketSize) ? 'numeric' : '2-digit',
|
||||||
|
month: ['month', 'day', 'hour', 'minute'].includes(playerScoresHistogramBucketSize) ? 'short' : undefined,
|
||||||
|
day: ['hour', 'minute'].includes(playerScoresHistogramBucketSize) ? 'numeric' : undefined,
|
||||||
|
})
|
||||||
|
: `${playerScoresHistogram.prefix}${formatNumber(ticks?.[idx]?.value, playerScoresHistogram.round)}${playerScoresHistogram.suffix}`
|
||||||
|
|
||||||
|
$: playerId, service, serviceParams, resetCurrentValues();
|
||||||
|
$: refreshAllPlayerServiceScores(playerId, service, serviceParams);
|
||||||
|
$: debouncedRefreshGroupedScores(playerScores, playerScoresHistogram, playerScoresHistogramBucketSize);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Pager {totalItems} itemsPerPage={service === 'accsaber' ? ACCSABER_PLAYER_SCORES_PER_PAGE : PLAYER_SCORES_PER_PAGE} itemsPerPageValues={null}
|
||||||
|
{currentPage} {loadingPage}
|
||||||
|
mode={totalItems ? 'pages' : 'simple'}
|
||||||
|
on:page-changed
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if groupedPlayerScores?.length}
|
||||||
|
<section class="scores-date-browse">
|
||||||
|
<ChartBrowser data={groupedPlayerScores} type={playerScoresHistogram?.type} order={playerScoresHistogram?.order ?? 'desc'}
|
||||||
|
tooltipTitleFunc={chartBrowserTooltipTitle}
|
||||||
|
tooltipLabelFunc={chartBrowserTooltipLabel}
|
||||||
|
tickFormatFunc={chartBrowserTickFormat}
|
||||||
|
on:page-changed
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{#if playerScoresHistogramBucketSize && playerScoresHistogram?.minBucketSize && playerScoresHistogram?.maxBucketSize && playerScoresHistogram?.bucketSizeStep}
|
||||||
|
<div class="histogram-controls">
|
||||||
|
<div class="range" title="Change histogram bucket size">
|
||||||
|
<input type="range" bind:value={playerScoresHistogramBucketSize}
|
||||||
|
min={playerScoresHistogram.minBucketSize}
|
||||||
|
max={playerScoresHistogram.maxBucketSize}
|
||||||
|
step={playerScoresHistogram.bucketSizeStep}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span>{`${formatNumber(playerScoresHistogramBucketSize, playerScoresHistogram?.round ?? 2)}${playerScoresHistogram.suffixLong ?? playerScoresHistogram.suffix}`}</span>
|
||||||
|
|
||||||
|
<i class="fa fa-undo" title="Reset bucket size to default value"
|
||||||
|
on:click={() => playerScoresHistogramBucketSize = playerScoresHistogram.bucketSize}
|
||||||
|
></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.scores-date-browse {
|
||||||
|
margin-top: 1rem;
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.histogram-controls {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range > *:not(:last-child) {
|
||||||
|
margin-right: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range i.fa {
|
||||||
|
cursor: pointer;
|
||||||
|
padding-top: .25em;
|
||||||
|
}
|
||||||
|
</style>
|
37
src/components/Player/ScoresStats.svelte
Normal file
37
src/components/Player/ScoresStats.svelte
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<script>
|
||||||
|
import Badge from '../Common/Badge.svelte'
|
||||||
|
import Skeleton from '../Common/Skeleton.svelte'
|
||||||
|
|
||||||
|
export let stats;
|
||||||
|
export let skeleton = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if stats}
|
||||||
|
<div class="badges has-text-centered-mobile">
|
||||||
|
{#each stats as stat}
|
||||||
|
{#key stat.label}
|
||||||
|
<Badge {...stat}/>
|
||||||
|
{/key}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{:else if skeleton}
|
||||||
|
<div class="badges has-text-centered-mobile skeleton">
|
||||||
|
{#each Array(5).fill(0) as stat}
|
||||||
|
<span class="badge"><Skeleton height="1.5em" /></span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.badges.skeleton .badge {
|
||||||
|
display: inline-block;
|
||||||
|
width: 12em;
|
||||||
|
margin-right: .5em;
|
||||||
|
margin-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badges :global(.badge .value .prev.inc),
|
||||||
|
.badges :global(.badge .value .prev.dec) {
|
||||||
|
color: inherit!important;
|
||||||
|
}
|
||||||
|
</style>
|
93
src/components/Player/Search.svelte
Normal file
93
src/components/Player/Search.svelte
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher, onMount} from 'svelte';
|
||||||
|
import createPlayerService from '../../services/scoresaber/player'
|
||||||
|
import {SsrHttpNotFoundError} from '../../network/errors'
|
||||||
|
import Autocomplete from '../Common/Autocomplete.svelte'
|
||||||
|
import MenuLine from './MenuLine.svelte'
|
||||||
|
import queues from '../../network/queues/queues'
|
||||||
|
import {MINUTE} from '../../utils/date'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let value = "";
|
||||||
|
let items = [];
|
||||||
|
|
||||||
|
const playerService = createPlayerService();
|
||||||
|
|
||||||
|
async function search(query) {
|
||||||
|
const matches = query.match(/^(?:\s*https:\/\/(?:new\.)?scoresaber.com\/u\/(\d+))|\s*(\d+)\s*/);
|
||||||
|
if (matches && (matches[1] || matches[2])) {
|
||||||
|
dispatch('selected', matches[1] ? matches[1] : matches[2])
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerService.findPlayer(query, queues.PRIORITY.FG_HIGH, {cacheTtl: 5 * MINUTE});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function searchFunc(value) {
|
||||||
|
if (!value || !value.length || value.trim().length < 4) throw 'Please enter at least 4 characters'
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await search(value);
|
||||||
|
|
||||||
|
return data ? data : [];
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof SsrHttpNotFoundError) return [];
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onItemSelected(item) {
|
||||||
|
value = item.playerName;
|
||||||
|
|
||||||
|
dispatch('selected', item.playerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
playerService.destroyService();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<Autocomplete bind:value {searchFunc}
|
||||||
|
noItemsFound="No players found."
|
||||||
|
placeholder="Enter a name or ScoreSaber profile..."
|
||||||
|
on:selected={e => onItemSelected(e.detail)}
|
||||||
|
>
|
||||||
|
<svelte:fragment slot="row" let:item>
|
||||||
|
<MenuLine player={item} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</Autocomplete>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div.player {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.player span.rank {
|
||||||
|
width: 4rem;
|
||||||
|
min-width: max-content;
|
||||||
|
text-align: right;
|
||||||
|
padding-right: .5rem;
|
||||||
|
flex-basis: 4rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
flex-grow: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.player span.player {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.player span.player img {
|
||||||
|
margin-right: .125rem;
|
||||||
|
}
|
||||||
|
</style>
|
83
src/components/Player/SongCover.svelte
Normal file
83
src/components/Player/SongCover.svelte
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<script>
|
||||||
|
import {SS_HOST} from '../../network/queues/scoresaber/page-queue'
|
||||||
|
import {navigate} from 'svelte-routing'
|
||||||
|
import Difficulty from '../Song/Difficulty.svelte'
|
||||||
|
|
||||||
|
export let leaderboard = null;
|
||||||
|
export let url = null;
|
||||||
|
export let notClickable = false;
|
||||||
|
|
||||||
|
const DEFAULT_IMG = '/assets/song-default.png';
|
||||||
|
|
||||||
|
let preloadCache = {};
|
||||||
|
let loadedImages = [];
|
||||||
|
|
||||||
|
function preloadImages(images) {
|
||||||
|
if (!images.some(img => img?.url?.length)) return;
|
||||||
|
|
||||||
|
images.forEach(imgObj => {
|
||||||
|
if (!imgObj?.url?.length || preloadCache[imgObj?.url]) return;
|
||||||
|
|
||||||
|
const url = imgObj.url;
|
||||||
|
|
||||||
|
preloadCache[url] = imgObj;
|
||||||
|
|
||||||
|
const img = new Image();
|
||||||
|
img.src = url;
|
||||||
|
img.onload = e => {
|
||||||
|
if (preloadCache[url]) loadedImages = [...loadedImages, imgObj]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$: hash = leaderboard?.song?.hash ?? null;
|
||||||
|
$: ssCoverUrl = hash ? `${SS_HOST}/imports/images/songs/${encodeURIComponent(hash)}.png` : null;
|
||||||
|
$: beatSaverCoverUrl = leaderboard?.beatMaps?.versions?.[0]?.coverURL ?? null;
|
||||||
|
|
||||||
|
$: preloadImages([{url: ssCoverUrl, priority: 10}, {url: beatSaverCoverUrl, priority: 5}]);
|
||||||
|
|
||||||
|
$: coverUrl = loadedImages.length ? (loadedImages.sort((a, b) => a?.priority - b?.priority))[0].url : DEFAULT_IMG;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="cover-difficulty">
|
||||||
|
{#if leaderboard}
|
||||||
|
{#if notClickable}
|
||||||
|
<img src={coverUrl} alt=""/>
|
||||||
|
{:else}
|
||||||
|
<a href={url} on:click|preventDefault={() => navigate(url)}>
|
||||||
|
<img src={coverUrl} alt=""/>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="difficulty">
|
||||||
|
<Difficulty diff={leaderboard.diffInfo} useShortName={true} reverseColors={true}
|
||||||
|
stars={leaderboard.complexity ?? leaderboard.stars} starsSuffix={leaderboard.complexity ? '' : '★'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<img src={DEFAULT_IMG} alt=""/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.cover-difficulty {
|
||||||
|
position: relative;
|
||||||
|
min-width: 4em;
|
||||||
|
width: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.difficulty {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 1em;
|
||||||
|
right: 0;
|
||||||
|
font-size: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 3.5em;
|
||||||
|
height: 3.5em;
|
||||||
|
border-radius: 15%;
|
||||||
|
}
|
||||||
|
</style>
|
117
src/components/Player/SongInfo.svelte
Normal file
117
src/components/Player/SongInfo.svelte
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<script>
|
||||||
|
import {navigate} from 'svelte-routing'
|
||||||
|
import {LEADERBOARD_SCORES_PER_PAGE} from '../../utils/scoresaber/consts'
|
||||||
|
import {LEADERBOARD_SCORES_PER_PAGE as ACCSABER_LEADERBOARD_SCORES_PER_PAGE} from '../../utils/accsaber/consts'
|
||||||
|
import Icons from '../Song/Icons.svelte'
|
||||||
|
import Badge from '../Common/Badge.svelte'
|
||||||
|
import SongCover from './SongCover.svelte'
|
||||||
|
|
||||||
|
export let leaderboard = null;
|
||||||
|
export let rank = null;
|
||||||
|
export let hash = null;
|
||||||
|
export let twitchUrl = null
|
||||||
|
export let notClickable = false;
|
||||||
|
export let category = null;
|
||||||
|
export let service = 'scoresaber';
|
||||||
|
|
||||||
|
$: song = leaderboard?.song ?? null;
|
||||||
|
$: scoresPerPage = service === 'accsaber' ? ACCSABER_LEADERBOARD_SCORES_PER_PAGE : LEADERBOARD_SCORES_PER_PAGE
|
||||||
|
$: page = rank && Number.isFinite(rank) ? Math.floor((rank - 1) / scoresPerPage) + 1 : 1;
|
||||||
|
$: diffInfo = leaderboard?.diffInfo ?? null;
|
||||||
|
$: leaderboardUrl = `/leaderboard/${service === 'accsaber' ? 'accsaber' : 'global'}/${leaderboard?.leaderboardId ?? ''}/${page ?? ''}`;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if song}
|
||||||
|
<section>
|
||||||
|
<SongCover {leaderboard} {notClickable} url={leaderboardUrl} />
|
||||||
|
|
||||||
|
<div class="songinfo">
|
||||||
|
{#if notClickable}
|
||||||
|
<span class="name">{song.name} {song.subName}</span>
|
||||||
|
<div class="author">{song.authorName} <small>{song.levelAuthorName}</small></div>
|
||||||
|
{:else}
|
||||||
|
<a href={leaderboardUrl} on:click|preventDefault={() => navigate(leaderboardUrl)}>
|
||||||
|
<span class="name">{song.name} {song.subName}</span>
|
||||||
|
<div class="author">{song.authorName} <small>{song.levelAuthorName}</small></div>
|
||||||
|
|
||||||
|
{#if category}
|
||||||
|
<span class="category">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--dimmed)" label={category} fluid={true} />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if hash && hash.length}
|
||||||
|
<div class="icons desktop-and-up" class:wide={twitchUrl && twitchUrl.length}>
|
||||||
|
<Icons {hash} {twitchUrl} {diffInfo} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
section :global(> *) {
|
||||||
|
margin-right: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.songinfo {
|
||||||
|
text-align: left;
|
||||||
|
font-size: .95rem;
|
||||||
|
font-weight: 500;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.songinfo {
|
||||||
|
color: var(--alternate);
|
||||||
|
}
|
||||||
|
|
||||||
|
.songinfo small {
|
||||||
|
font-size: 0.75em;
|
||||||
|
color: var(--ppColour);
|
||||||
|
}
|
||||||
|
|
||||||
|
.category {
|
||||||
|
font-size: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.songinfo .category :global(.badge) {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-end;
|
||||||
|
font-size: .65em;
|
||||||
|
min-width: 4.66em;
|
||||||
|
width: 4.66em;
|
||||||
|
margin-right: 0;
|
||||||
|
align-self: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons.wide :global(> *:not(:first-child)) {
|
||||||
|
margin-left: .25em;
|
||||||
|
margin-bottom: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons:not(.wide) :global(> *:not(:nth-child(2n + 1))) {
|
||||||
|
margin-left: .25em;
|
||||||
|
margin-bottom: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons.wide {
|
||||||
|
min-width: 6.85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons:empty {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
</style>
|
516
src/components/Player/SongScore.svelte
Normal file
516
src/components/Player/SongScore.svelte
Normal file
@ -0,0 +1,516 @@
|
|||||||
|
<script>
|
||||||
|
import {formatNumber, padNumber} from '../../utils/format'
|
||||||
|
import {fade, fly, slide} from 'svelte/transition'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import {formatDate} from '../../utils/date'
|
||||||
|
import ssrConfig from '../../ssr-config'
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import Badge from '../Common/Badge.svelte'
|
||||||
|
import Accuracy from '../Common/Accuracy.svelte'
|
||||||
|
import SongInfo from './SongInfo.svelte'
|
||||||
|
import ScoreRank from './ScoreRank.svelte'
|
||||||
|
import FormattedDate from '../Common/FormattedDate.svelte'
|
||||||
|
import Pp from '../Score/Pp.svelte'
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
import SongScoreDetails from './SongScoreDetails.svelte'
|
||||||
|
import Icons from '../Song/Icons.svelte'
|
||||||
|
|
||||||
|
export let playerId = null;
|
||||||
|
export let songScore = null;
|
||||||
|
export let fixedBrowserTitle = null;
|
||||||
|
export let idx = 0;
|
||||||
|
export let service = null;
|
||||||
|
|
||||||
|
let showDetails = false;
|
||||||
|
|
||||||
|
function formatFailedAt(beatSavior) {
|
||||||
|
const endTime = opt(beatSavior, 'trackers.winTracker.endTime');
|
||||||
|
const won = opt(beatSavior, 'trackers.winTracker.won', false);
|
||||||
|
if (!endTime || won) return null;
|
||||||
|
|
||||||
|
let failedAt = null;
|
||||||
|
if (endTime) {
|
||||||
|
let minutes = padNumber(Math.floor(endTime / 60));
|
||||||
|
let seconds = padNumber(Math.round(endTime - minutes * 60));
|
||||||
|
if (seconds >= 60) {
|
||||||
|
minutes = padNumber(minutes + 1)
|
||||||
|
seconds = padNumber(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
failedAt = `${minutes}:${seconds}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return failedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
$: leaderboard = opt(songScore, 'leaderboard', null);
|
||||||
|
$: score = opt(songScore, 'score', null);
|
||||||
|
$: prevScore = opt(songScore, 'prevScore', null);
|
||||||
|
$: beatSavior = opt(songScore, 'beatSavior', null)
|
||||||
|
$: comparePlayers = opt(songScore, 'comparePlayers', null)
|
||||||
|
$: hash = opt(leaderboard, 'song.hash')
|
||||||
|
$: twitchUrl = opt(songScore, 'twitchVideo.url', null)
|
||||||
|
$: diffInfo = opt(leaderboard, 'diffInfo')
|
||||||
|
$: failedAt = formatFailedAt(beatSavior)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if songScore}
|
||||||
|
<div class={`song-score row-${idx}`}
|
||||||
|
in:fly={{x: 300, delay: idx * 30, duration:500}} out:fade={{duration:100}}
|
||||||
|
class:with-details={showDetails}
|
||||||
|
>
|
||||||
|
<div class="icons up-to-tablet">
|
||||||
|
<Icons {hash} {twitchUrl} {diffInfo} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main" class:beat-savior={service === 'beatsavior'} class:accsaber={service === 'accsaber'}>
|
||||||
|
<span class="rank">
|
||||||
|
{#if service !== 'beatsavior'}
|
||||||
|
<ScoreRank rank={score.rank}
|
||||||
|
countryRank={score.ssplCountryRank}
|
||||||
|
countryRankTotal={null}
|
||||||
|
country={score.country}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="timeset tablet-and-up">
|
||||||
|
<FormattedDate date={score.timeSet} prevPrefix="vs " prevDate={prevScore ? prevScore.timeSet : null} absolute={service === 'beatsavior'}/>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span class="timeset mobile-only">
|
||||||
|
<FormattedDate date={score.timeSet} prevPrefix="vs " prevDate={prevScore ? prevScore.timeSet : null} absolute={service === 'beatsavior'}/>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span class="song">
|
||||||
|
<SongInfo {leaderboard} rank={score.rank} {hash} {twitchUrl} notClickable={['beatsavior'].includes(service)}
|
||||||
|
category={leaderboard?.categoryDisplayName ?? null} {service}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<section class="stats">
|
||||||
|
{#if !beatSavior || !beatSavior.stats}
|
||||||
|
<span class="beat-savior-reveal clickable" class:opened={showDetails} on:click={() => showDetails = !showDetails} title="Show leaderboard">
|
||||||
|
<i class="fas fa-chevron-down"></i>
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span></span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if score.pp}
|
||||||
|
<span class="pp with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--ppColour)">
|
||||||
|
<span slot="label">
|
||||||
|
<Pp playerId={score.playerId} leaderboardId={leaderboard.leaderboardId}
|
||||||
|
pp="{score.pp}" weighted={score.ppWeighted} attribution={score.ppAttribution} whatIf={score.whatIfPp}
|
||||||
|
zero={(configStore, $configStore, formatNumber(0))} withZeroSuffix={true} inline={false}
|
||||||
|
color="white"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{:else if service === 'beatsavior' && beatSavior && !opt(beatSavior, 'trackers.winTracker.won', false)}
|
||||||
|
<span class="pp with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--decrease)" label="FAIL" title={failedAt ? `Failed at ${failedAt}` : null} />
|
||||||
|
</span>
|
||||||
|
{:else if service === 'accsaber' && score.ap}
|
||||||
|
<span class="pp with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--ppColour)">
|
||||||
|
<span slot="label">
|
||||||
|
<Pp playerId={score.playerId} leaderboardId={leaderboard.leaderboardId}
|
||||||
|
pp="{score.ap}" weighted={score.weightedAp}
|
||||||
|
zero={formatNumber(0)} withZeroSuffix={true} inline={false}
|
||||||
|
suffix="AP"
|
||||||
|
color="white"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="pp with-badge"></span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if score.acc}
|
||||||
|
<span class="acc with-badge">
|
||||||
|
<Accuracy {score} {prevScore} noSecondMetric={true} />
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="acc with-badge"></span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if score.score}
|
||||||
|
<span class="score with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--dimmed)">
|
||||||
|
<span slot="label">
|
||||||
|
<Value value="{score.score}" prevValue={opt(prevScore, 'score')}
|
||||||
|
inline={false} digits={0} prefix={score.scoreApproximate ? '~' : ''}
|
||||||
|
prevTitle={"${value} on " + (configStore, $configStore, formatDate(opt(prevScore, 'timeSet'), 'short', 'short'))}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if beatSavior && beatSavior.stats}
|
||||||
|
<span class="beat-savior-reveal clickable" class:opened={showDetails} on:click={() => showDetails = !showDetails} title="Show details">
|
||||||
|
<i class="fas fa-chevron-down"></i>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{#if beatSavior.stats.accLeft}
|
||||||
|
<span class="beatSavior with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor={ssrConfig.leftSaberColor}>
|
||||||
|
<span slot="label">
|
||||||
|
<Value
|
||||||
|
title={`Left accuracy: ${beatSavior.stats.leftAverageCut ? beatSavior.stats.leftAverageCut.map(v => (configStore, $configStore, formatNumber(v))).join('/') : ''}`}
|
||||||
|
value="{beatSavior.stats.accLeft}"
|
||||||
|
inline={false} digits={2}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if beatSavior.stats.accRight}
|
||||||
|
<span class="beatSavior with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor={ssrConfig.rightSaberColor}>
|
||||||
|
<span slot="label">
|
||||||
|
<Value
|
||||||
|
title={`Right accuracy: ${beatSavior.stats.rightAverageCut ? beatSavior.stats.rightAverageCut.map(v => (configStore, $configStore, formatNumber(v))).join('/') : ''}`}
|
||||||
|
value="{beatSavior.stats.accRight}" inline={false} digits={2}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if beatSavior.stats.miss !== undefined}
|
||||||
|
<span class="beatSavior with-badge">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--dimmed)">
|
||||||
|
<span slot="label" title={`Missed notes: ${beatSavior.stats.missedNotes}, Bad cuts: ${beatSavior.stats.badCuts}, Bomb hit: ${beatSavior.stats.bombHit}, Wall hit: ${beatSavior.stats.wallHit}`}>
|
||||||
|
{#if beatSavior.stats.miss || beatSavior.stats.bombHit || beatSavior.stats.wallHit}
|
||||||
|
<i class="fas fa-times"></i>
|
||||||
|
<Value
|
||||||
|
title={`Missed notes: ${beatSavior.stats.missedNotes}, Bad cuts: ${beatSavior.stats.badCuts}, Bomb hit: ${beatSavior.stats.bombHit}, Wall hit: ${beatSavior.stats.wallHit}`}
|
||||||
|
value="{beatSavior.stats.miss + beatSavior.stats.wallHit + beatSavior.stats.bombHit}"
|
||||||
|
inline={false} digits={0}
|
||||||
|
/>
|
||||||
|
{:else if (!beatSavior.stats.wallHit && !beatSavior.stats.bombHit)}
|
||||||
|
FC
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if (showDetails || (configStore && opt($configStore, 'scoreComparison.method') === 'in-place') ) && comparePlayers && Array.isArray(comparePlayers)}
|
||||||
|
{#each comparePlayers as comparePlayer (comparePlayer.playerId)}
|
||||||
|
<span></span>
|
||||||
|
<span class="compare-player-name"><span>vs {comparePlayer.playerName} (<FormattedDate date={opt(comparePlayer, 'score.timeSet')}/>)</span></span>
|
||||||
|
|
||||||
|
<span></span>
|
||||||
|
{#if comparePlayer.score && comparePlayer.score.pp}
|
||||||
|
<span class="pp with-badge compare">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--ppColour)">
|
||||||
|
<span slot="label">
|
||||||
|
<Pp playerId={comparePlayer.playerId} leaderboardId={leaderboard.leaderboardId}
|
||||||
|
pp="{comparePlayer.score.pp}" withZeroSuffix={true} inline={false}
|
||||||
|
color="white"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="pp with-badge"></span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if comparePlayer.score.acc}
|
||||||
|
<span class="acc with-badge compare">
|
||||||
|
<Accuracy score={comparePlayer.score} noSecondMetric={true} />
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="acc with-badge"></span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if comparePlayer.score.score}
|
||||||
|
<span class="score with-badge compare">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--dimmed)">
|
||||||
|
<span slot="label">
|
||||||
|
<Value value={comparePlayer.score.score}
|
||||||
|
inline={false} digits={0}
|
||||||
|
title={comparePlayer.score.mods && comparePlayer.score.mods.length ? `Mods: ${comparePlayer.score.mods.join(', ')}` : ''}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if comparePlayer.beatSavior && comparePlayer.beatSavior.stats}
|
||||||
|
<span></span>
|
||||||
|
|
||||||
|
{#if comparePlayer.beatSavior.stats.accLeft}
|
||||||
|
<span class="beatSavior with-badge compare">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor={ssrConfig.leftSaberColor}>
|
||||||
|
<span slot="label">
|
||||||
|
<Value
|
||||||
|
title={`Left accuracy: ${comparePlayer.beatSavior.stats.leftAverageCut ? comparePlayer.beatSavior.stats.leftAverageCut.map(v => (configStore, $configStore, formatNumber(v))).join('/') : ''}`}
|
||||||
|
value="{comparePlayer.beatSavior.stats.accLeft}"
|
||||||
|
inline={false} digits={2}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if comparePlayer.beatSavior.stats.accRight}
|
||||||
|
<span class="beatSavior with-badge compare">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor={ssrConfig.rightSaberColor}>
|
||||||
|
<span slot="label">
|
||||||
|
<Value
|
||||||
|
title={`Right accuracy: ${comparePlayer.beatSavior.stats.rightAverageCut ? comparePlayer.beatSavior.stats.rightAverageCut.map(v => (configStore, $configStore, formatNumber(v))).join('/') : ''}`}
|
||||||
|
value="{comparePlayer.beatSavior.stats.accRight}" inline={false} digits={2}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if comparePlayer.beatSavior.stats.miss !== undefined}
|
||||||
|
<span class="beatSavior with-badge compare">
|
||||||
|
<Badge onlyLabel={true} color="white" bgColor="var(--dimmed)">
|
||||||
|
<span slot="label" title={`Missed notes: ${comparePlayer.beatSavior.stats.missedNotes}, Bad cuts: ${comparePlayer.beatSavior.stats.badCuts}, Bomb hit: ${comparePlayer.beatSavior.stats.bombHit}, Wall hit: ${comparePlayer.beatSavior.stats.wallHit}`}>
|
||||||
|
{#if comparePlayer.beatSavior.stats.miss || comparePlayer.beatSavior.stats.bombHit || comparePlayer.beatSavior.stats.wallHit}
|
||||||
|
<i class="fas fa-times"></i>
|
||||||
|
<Value
|
||||||
|
title={`Missed notes: ${comparePlayer.beatSavior.stats.missedNotes}, Bad cuts: ${comparePlayer.beatSavior.stats.badCuts}, Bomb hit: ${comparePlayer.beatSavior.stats.bombHit}, Wall hit: ${comparePlayer.beatSavior.stats.wallHit}`}
|
||||||
|
value="{comparePlayer.beatSavior.stats.miss}" inline={false} digits={0}
|
||||||
|
/>
|
||||||
|
{:else if (!comparePlayer.beatSavior.stats.wallHit && !comparePlayer.beatSavior.stats.bombHit)}
|
||||||
|
FC
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if showDetails}
|
||||||
|
<div transition:slide>
|
||||||
|
<SongScoreDetails {playerId} {songScore} {fixedBrowserTitle}
|
||||||
|
noSsLeaderboard={['beatsavior', 'accsaber'].includes(service)}
|
||||||
|
showAccSaberLeaderboard={'accsaber' === service}
|
||||||
|
noBeatSaviorHistory={service === 'beatsavior'}/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.song-score {
|
||||||
|
border-bottom: 1px solid var(--dimmed);
|
||||||
|
padding: .5em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .icons.up-to-tablet + .main {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score.with-details .main {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main > * {
|
||||||
|
margin-right: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main > *:last-child {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main :global(.badge) {
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: .125em .25em !important;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main :global(.badge small) {
|
||||||
|
font-size: .7em;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-top: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main :global(.inc), .song-score :global(.dec) {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
section.stats, .beat-savior-data {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1rem repeat(3, minmax(0, 1fr));
|
||||||
|
grid-template-rows: min-content;
|
||||||
|
grid-column-gap: .75em;
|
||||||
|
grid-row-gap: .25em;
|
||||||
|
min-width: 20rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior-data {
|
||||||
|
grid-template-columns: 1rem repeat(3, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.beatSavior {
|
||||||
|
font-size: .85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rank {
|
||||||
|
width: 5.5em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song {
|
||||||
|
flex-grow: 1;
|
||||||
|
min-width: 15.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeset {
|
||||||
|
width: 8.5em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main.beat-savior .timeset {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeset :global(small) {
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rank .timeset {
|
||||||
|
width: auto;
|
||||||
|
min-width: 7em;
|
||||||
|
font-size: .8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pp {
|
||||||
|
min-width: 5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pp.with-badge {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.acc {
|
||||||
|
min-width :4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.score {
|
||||||
|
min-width: 5.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.with-badge {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.with-badge :global(.badge) {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beatSavior.with-badge i {
|
||||||
|
font-size: .875em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beatSavior.with-badge :global(.label) {
|
||||||
|
font-size: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior-data {
|
||||||
|
grid-column: 1/-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.beat-savior-reveal {
|
||||||
|
align-self: end;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 500ms;
|
||||||
|
transform-origin: .5em .5em;
|
||||||
|
}
|
||||||
|
.beat-savior-reveal.opened {
|
||||||
|
transform: rotateZ(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.compare-player-name {
|
||||||
|
grid-column: 2 / span 3;
|
||||||
|
color: var(--faded);
|
||||||
|
text-align: center;
|
||||||
|
font-size: .875em;
|
||||||
|
line-height: 1;
|
||||||
|
border-bottom: 1px solid var(--faded);
|
||||||
|
margin-bottom: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compare-player-name > span {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
top: .5em;
|
||||||
|
background-color: var(--foreground);
|
||||||
|
padding: 0 .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats .compare {
|
||||||
|
opacity: .7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons {
|
||||||
|
width: 100%;
|
||||||
|
font-size: .75em;
|
||||||
|
text-align: right;
|
||||||
|
margin-right: 0;
|
||||||
|
margin-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons:empty {
|
||||||
|
margin-bottom: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767px) {
|
||||||
|
.song-score {
|
||||||
|
padding: .75em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song-score .main {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rank, .timeset {
|
||||||
|
padding-bottom: .5em !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.song {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
margin-right: 0;
|
||||||
|
padding-bottom: .75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icons {
|
||||||
|
margin-bottom: .5em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
125
src/components/Player/SongScoreDetails.svelte
Normal file
125
src/components/Player/SongScoreDetails.svelte
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<script>
|
||||||
|
import {LEADERBOARD_SCORES_PER_PAGE} from '../../utils/scoresaber/consts'
|
||||||
|
import {LEADERBOARD_SCORES_PER_PAGE as ACCSABER_LEADERBOARD_SCORES_PER_PAGE} from '../../utils/accsaber/consts'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import BeatSaviorDetails from '../BeatSavior/Details.svelte'
|
||||||
|
import LeaderboardPage from '../../pages/Leaderboard.svelte'
|
||||||
|
import Switcher from '../Common/Switcher.svelte'
|
||||||
|
|
||||||
|
export let playerId;
|
||||||
|
export let songScore;
|
||||||
|
export let fixedBrowserTitle = null;
|
||||||
|
export let noBeatSaviorHistory = false;
|
||||||
|
export let noSsLeaderboard = false;
|
||||||
|
export let showAccSaberLeaderboard = false;
|
||||||
|
|
||||||
|
const switcherOptions = [];
|
||||||
|
switcherOptions.push({id: 'beatsavior', label: 'Beat Savior', icon: '<div class="beatsavior-icon"></div>'});
|
||||||
|
if (showAccSaberLeaderboard) switcherOptions.push({id: 'accsaber', label: 'Leaderboard', icon: '<div class="accsaber-icon"></div>'})
|
||||||
|
if (!noSsLeaderboard) switcherOptions.push({id: 'leaderboard', label: 'Leaderboard', iconFa: 'fas fa-cubes'})
|
||||||
|
|
||||||
|
let selectedOption = switcherOptions[0];
|
||||||
|
let inBuiltLeaderboardPage = null;
|
||||||
|
|
||||||
|
function getAvailableOptions(songScore) {
|
||||||
|
if (!songScore) return null;
|
||||||
|
|
||||||
|
const options = switcherOptions.filter(o => o.id !== 'beatsavior' || songScore.beatSavior);
|
||||||
|
|
||||||
|
if (!options.includes(selectedOption)) {
|
||||||
|
selectedOption = options.length ? options[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onOptionChanged(event) {
|
||||||
|
selectedOption = event.detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateInBuiltLeaderboardPage(rank, type) {
|
||||||
|
if (!rank) {
|
||||||
|
inBuiltLeaderboardPage = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inBuiltLeaderboardPage = Math.floor((rank - 1) / (type === 'accsaber' ? ACCSABER_LEADERBOARD_SCORES_PER_PAGE : LEADERBOARD_SCORES_PER_PAGE)) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInBuiltLeaderboardPageChanged(event) {
|
||||||
|
const newPage = opt(event, 'detail.page');
|
||||||
|
if (!Number.isFinite(newPage)) return;
|
||||||
|
|
||||||
|
inBuiltLeaderboardPage = newPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: leaderboard = opt(songScore, 'leaderboard', null);
|
||||||
|
$: score = opt(songScore, 'score', null);
|
||||||
|
$: prevScore = opt(songScore, 'prevScore', null);
|
||||||
|
$: beatSavior = opt(songScore, 'beatSavior', null)
|
||||||
|
|
||||||
|
$: filteredOptions = getAvailableOptions(songScore);
|
||||||
|
$: updateInBuiltLeaderboardPage(score && score.rank ? score.rank : null, selectedOption?.id ?? 'leaderboard')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<section class="details">
|
||||||
|
{#if songScore}
|
||||||
|
{#if filteredOptions && filteredOptions.length > 1}
|
||||||
|
<nav>
|
||||||
|
<Switcher values={filteredOptions} value={selectedOption} on:change={onOptionChanged}/>
|
||||||
|
</nav>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="tab">
|
||||||
|
{#if selectedOption && selectedOption.id === 'beatsavior'}
|
||||||
|
<BeatSaviorDetails {playerId} {beatSavior} {leaderboard} noHistory={noBeatSaviorHistory}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if selectedOption && selectedOption.id === 'accsaber'}
|
||||||
|
<LeaderboardPage leaderboardId={leaderboard.leaderboardId}
|
||||||
|
type="accsaber"
|
||||||
|
page={inBuiltLeaderboardPage}
|
||||||
|
scrollOffset={176}
|
||||||
|
dontNavigate={true} withoutDiffSwitcher={true} withoutHeader={true}
|
||||||
|
on:page-changed={onInBuiltLeaderboardPageChanged}
|
||||||
|
{fixedBrowserTitle}
|
||||||
|
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if selectedOption && selectedOption.id === 'leaderboard'}
|
||||||
|
<LeaderboardPage leaderboardId={leaderboard.leaderboardId}
|
||||||
|
type="global"
|
||||||
|
page={inBuiltLeaderboardPage}
|
||||||
|
scrollOffset={176}
|
||||||
|
dontNavigate={true} withoutDiffSwitcher={true} withoutHeader={true}
|
||||||
|
on:page-changed={onInBuiltLeaderboardPageChanged}
|
||||||
|
{fixedBrowserTitle}
|
||||||
|
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.details {
|
||||||
|
padding: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: 1fr;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab > :global(*) {
|
||||||
|
grid-area: 1 / 1 / 1 / 1;
|
||||||
|
}
|
||||||
|
</style>
|
32
src/components/Player/SsBadges.svelte
Normal file
32
src/components/Player/SsBadges.svelte
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<script>
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
|
||||||
|
export let badges;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if badges}
|
||||||
|
<div class="ss-badges" transition:fade={{ duration: 500 }}>
|
||||||
|
{#each badges as badge (badge.src)}
|
||||||
|
<img src={badge.src} alt={badge.title} title={badge.title}/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.ss-badges {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ss-badges img {
|
||||||
|
margin-right: .5rem;
|
||||||
|
margin-bottom: .25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media(max-width: 768px) {
|
||||||
|
.ss-badges {
|
||||||
|
margin-top: .5rem;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
22
src/components/Player/Status.svelte
Normal file
22
src/components/Player/Status.svelte
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
export let playerInfo;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if playerInfo.banned}<span class="status banned">Banned</span>{/if}
|
||||||
|
{#if playerInfo.inactive}<span class="status inactive">Inactive</span>{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.status {
|
||||||
|
border-left: 1px solid var(--dimmed);
|
||||||
|
padding-left: .75rem;
|
||||||
|
margin-left: .5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banned {
|
||||||
|
color: var(--decrease);
|
||||||
|
}
|
||||||
|
|
||||||
|
.inactive {
|
||||||
|
color: var(--faded);
|
||||||
|
}
|
||||||
|
</style>
|
161
src/components/Player/TwitchLinkModal.svelte
Normal file
161
src/components/Player/TwitchLinkModal.svelte
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import createTwitchService from '../../services/twitch'
|
||||||
|
import Button from '../Common/Button.svelte'
|
||||||
|
import Dialog from '../Common/Dialog.svelte'
|
||||||
|
import {delay} from '../../utils/promise'
|
||||||
|
import {SsrHttpUnauthenticatedError, SsrHttpUnauthorizedError} from '../../network/errors'
|
||||||
|
|
||||||
|
export let playerId;
|
||||||
|
export let show = false;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
const twitchService = createTwitchService();
|
||||||
|
|
||||||
|
let twitchProfile = null;
|
||||||
|
|
||||||
|
let twitchUserName = "";
|
||||||
|
let alreadySearched = false;
|
||||||
|
let isSearching = false;
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
async function onPlayerChanged(playerId) {
|
||||||
|
if (!playerId) return;
|
||||||
|
|
||||||
|
twitchProfile = await twitchService.getPlayerProfile(playerId)
|
||||||
|
if (twitchProfile && twitchProfile.login) {
|
||||||
|
twitchUserName = twitchProfile.login;
|
||||||
|
|
||||||
|
if (!twitchProfile.id) onFindUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCancel() {
|
||||||
|
dispatch('cancel')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onFindUser() {
|
||||||
|
if (!twitchUserName || !twitchUserName.length) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
isSearching = true
|
||||||
|
alreadySearched = false;
|
||||||
|
twitchProfile = null;
|
||||||
|
error = null;
|
||||||
|
|
||||||
|
await delay(100);
|
||||||
|
twitchProfile = await twitchService.fetchProfile(twitchUserName);
|
||||||
|
|
||||||
|
alreadySearched = true;
|
||||||
|
} catch(err) {
|
||||||
|
if (err instanceof SsrHttpUnauthenticatedError || err instanceof SsrHttpUnauthorizedError) {
|
||||||
|
error = 'Twitch authentication error. It is likely that your Twitch token is invalid. Go to Settings and reconnect service with your Twitch account.';
|
||||||
|
} else {
|
||||||
|
error = 'An error occurred while trying to connect to Twitch.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
isSearching = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTwitchUserNameKeyUp(e) {
|
||||||
|
if (e.code === 'Enter') {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
onFindUser();
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: onPlayerChanged(playerId)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if show}
|
||||||
|
<Dialog closeable={true} on:confirm={onCancel}>
|
||||||
|
<svelte:fragment slot="header">
|
||||||
|
<div class="header-title">Set up a Twitch profile</div>
|
||||||
|
</svelte:fragment>
|
||||||
|
|
||||||
|
<svelte:fragment slot="content">
|
||||||
|
<div class="search">
|
||||||
|
<input type="text" bind:value={twitchUserName} placeholder="Enter Twitch username..." on:keyup={onTwitchUserNameKeyUp}/>
|
||||||
|
<Button iconFa="fas fa-search" type="primary" label="Search" on:click={onFindUser} loading={isSearching}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if twitchProfile && twitchProfile.id}
|
||||||
|
<div class="results">
|
||||||
|
<img src={twitchProfile.profile_image_url}/>
|
||||||
|
<div>
|
||||||
|
<h1 class="title is-4">{twitchProfile.display_name}</h1>
|
||||||
|
<h2 class="subtitle is-6"><a href="https://twitch.tv/{encodeURIComponent(twitchProfile.login)}" target="_blank" rel="noreferrer">https://twitch.tv/{twitchProfile.login}</a></h2>
|
||||||
|
<p>{twitchProfile.description}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else if error}
|
||||||
|
<p class="error">{error}</p>
|
||||||
|
{:else if alreadySearched}
|
||||||
|
<p>Twitch user not found.</p>
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
|
||||||
|
<svelte:fragment slot="footer-right">
|
||||||
|
<Button iconFa="fab fa-twitch" label="Link" type="twitch" on:click={() => dispatch('link', twitchProfile)} disabled={!twitchProfile}/>
|
||||||
|
<Button label="Cancel" on:click={onCancel}/>
|
||||||
|
</svelte:fragment>
|
||||||
|
</Dialog>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.header-title {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
padding: calc(0.65em - 1px) 1em;
|
||||||
|
margin: 0 0 0.45em 0;
|
||||||
|
outline: none;
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--faded);
|
||||||
|
border: 2px solid var(--faded);
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search :global(.button) {
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 30%;
|
||||||
|
height: auto;
|
||||||
|
margin-right: 1.5em;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #9146ff !important;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: var(--error);
|
||||||
|
}
|
||||||
|
</style>
|
58
src/components/Player/TwitchVideos.svelte
Normal file
58
src/components/Player/TwitchVideos.svelte
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<script>
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
import {dateFromString} from '../../utils/date'
|
||||||
|
import FormattedDate from '../Common/FormattedDate.svelte'
|
||||||
|
|
||||||
|
export let videos = null;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if videos && videos.length}
|
||||||
|
<section transition:fade>
|
||||||
|
<h3 class="title is-6"><i class="fab fa-twitch"></i> Twitch VODs</h3>
|
||||||
|
|
||||||
|
<div class="videos">
|
||||||
|
<span>Date</span>
|
||||||
|
<span>Video</span>
|
||||||
|
<span>Duration</span>
|
||||||
|
|
||||||
|
{#each videos as video}
|
||||||
|
<span><FormattedDate date={dateFromString(video.created_at)} /></span>
|
||||||
|
|
||||||
|
<a href={video.url} target="_blank" rel="noreferrer">{video.title}</a>
|
||||||
|
|
||||||
|
<span>{video.duration}</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
width: 100%;
|
||||||
|
padding: .5em;
|
||||||
|
font-size: .875em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
padding: .25em;
|
||||||
|
margin-bottom: .75em !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 i {
|
||||||
|
margin-right: .25em;
|
||||||
|
padding: .25em;
|
||||||
|
color: white;
|
||||||
|
background-color: #9146ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.videos {
|
||||||
|
display: inline-grid;
|
||||||
|
grid-template-columns: auto 1fr auto;
|
||||||
|
grid-row-gap: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.videos :global(> *) {
|
||||||
|
border-bottom: 1px solid var(--dimmed);
|
||||||
|
padding: .125em .25em;
|
||||||
|
}
|
||||||
|
</style>
|
184
src/components/Player/utils/profile.js
Normal file
184
src/components/Player/utils/profile.js
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
import {SS_HOST} from '../../../network/queues/scoresaber/page-queue'
|
||||||
|
import tweened from '../../../svelte-utils/tweened';
|
||||||
|
import {opt} from '../../../utils/js'
|
||||||
|
|
||||||
|
const TWEEN_DURATION = 300;
|
||||||
|
|
||||||
|
const scoresStatsTweened = {};
|
||||||
|
function updateScoresStats(playerData, playerStats) {
|
||||||
|
if (!playerData) return null;
|
||||||
|
|
||||||
|
const scoreStats = opt(playerData, 'scoreStats');
|
||||||
|
|
||||||
|
const statsDef = scoreStats
|
||||||
|
? [
|
||||||
|
{key: "totalPlayCount", label: 'Total play count', bgColor: 'var(--selected)'},
|
||||||
|
{key: "totalScore", label: 'Total score', bgColor: 'var(--selected)'},
|
||||||
|
{key: "rankedPlayCount", label: 'Ranked play count', bgColor: 'var(--ppColour)'},
|
||||||
|
{key: "totalRankedScore", label: 'Total ranked score', bgColor: 'var(--ppColour)'},
|
||||||
|
{key: "averageRankedAccuracy", label: 'Average', title: 'Average ranked accuracy', digits: 2, suffix: '%', bgColor: 'var(--selected)'}
|
||||||
|
]
|
||||||
|
: [];
|
||||||
|
|
||||||
|
return statsDef
|
||||||
|
.map(s => {
|
||||||
|
const value = scoreStats && scoreStats[s.key] ? scoreStats[s.key] : null;
|
||||||
|
if (!value && !Number.isFinite(value)) return null;
|
||||||
|
|
||||||
|
if (!scoresStatsTweened.hasOwnProperty(s.key)) scoresStatsTweened[s.key] = tweened(value, TWEEN_DURATION);
|
||||||
|
else scoresStatsTweened[s.key].set(value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
label: s.label,
|
||||||
|
title: opt(s, 'title', ''),
|
||||||
|
value: scoresStatsTweened[s.key],
|
||||||
|
digits: opt(s, 'digits', 0),
|
||||||
|
suffix: opt(s, 'suffix', ''),
|
||||||
|
fluid: true,
|
||||||
|
bgColor: opt(s, 'bgColor', 'var(--dimmed)'),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.concat(
|
||||||
|
(playerStats && playerStats.topPp && Number.isFinite(playerStats.topPp) ? [{
|
||||||
|
label: 'Best PP',
|
||||||
|
title: null,
|
||||||
|
value: playerStats.topPp,
|
||||||
|
digits: 2,
|
||||||
|
suffix: 'pp',
|
||||||
|
fluid: true,
|
||||||
|
bgColor: 'var(--ppColour)',
|
||||||
|
}] : [])
|
||||||
|
)
|
||||||
|
.filter(s => s && (!playerStats || s.label !== 'Average'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAccStats(playerStats) {
|
||||||
|
if (!playerStats) return null;
|
||||||
|
|
||||||
|
return (playerStats ? ['topAcc', 'avgAcc', 'medianAcc', 'stdDeviation'] : [])
|
||||||
|
.reduce((cum, key) => {
|
||||||
|
const value = playerStats[key] ? playerStats[key] : null;
|
||||||
|
if (!value && !Number.isFinite(value)) return cum;
|
||||||
|
|
||||||
|
const tweenKey = key === 'avgAcc' ? 'averageRankedAccuracy' : key
|
||||||
|
if (!scoresStatsTweened.hasOwnProperty(tweenKey)) scoresStatsTweened[tweenKey] = tweened(value, TWEEN_DURATION);
|
||||||
|
else scoresStatsTweened[tweenKey].set(value);
|
||||||
|
|
||||||
|
let metricData = null;
|
||||||
|
|
||||||
|
switch(key) {
|
||||||
|
case 'avgAcc':
|
||||||
|
metricData = {
|
||||||
|
key,
|
||||||
|
label: 'Average',
|
||||||
|
title: 'Average ranked accuracy',
|
||||||
|
bgColor: 'var(--selected)'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'medianAcc':
|
||||||
|
metricData = {
|
||||||
|
key,
|
||||||
|
label: 'Median',
|
||||||
|
title: 'Median ranked accuracy',
|
||||||
|
bgColor: 'var(--ppColour)'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'stdDeviation':
|
||||||
|
metricData = {
|
||||||
|
key,
|
||||||
|
label: 'Std deviation',
|
||||||
|
title: 'Standard deviation ranked accuracy',
|
||||||
|
bgColor: 'var(--decrease)'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'topAcc':
|
||||||
|
metricData = {
|
||||||
|
key,
|
||||||
|
label: 'Best',
|
||||||
|
title: 'Best ranked accuracy',
|
||||||
|
bgColor: 'rgba(60,179,113,.75)'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metricData)
|
||||||
|
cum.push({
|
||||||
|
...metricData,
|
||||||
|
value: scoresStatsTweened[tweenKey],
|
||||||
|
digits: 2,
|
||||||
|
suffix: '%',
|
||||||
|
fluid: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
return cum;
|
||||||
|
}, [])
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAccBadges(playerStats) {
|
||||||
|
if (!playerStats || !playerStats.badges) return null;
|
||||||
|
|
||||||
|
return playerStats.badges
|
||||||
|
.map(badge => {
|
||||||
|
const value = badge.value;
|
||||||
|
|
||||||
|
if (!scoresStatsTweened.hasOwnProperty(badge.label)) scoresStatsTweened[badge.label] = tweened(value, TWEEN_DURATION);
|
||||||
|
else scoresStatsTweened[badge.label].set(value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...badge,
|
||||||
|
value: scoresStatsTweened[badge.label],
|
||||||
|
title: !badge.min ? `< ${badge.max}%` : (!badge.max ? `> ${badge.min}%` : `${badge.min}% - ${badge.max}%`),
|
||||||
|
fluid: true,
|
||||||
|
digits: 0,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSsBadges(playerData) {
|
||||||
|
if (!opt(playerData, 'playerInfo.badges.length')) return null;
|
||||||
|
|
||||||
|
return playerData.playerInfo.badges.map(b => ({src: `${SS_HOST}/imports/images/badges/${b.image}`, title: b.description}));
|
||||||
|
}
|
||||||
|
|
||||||
|
const playerInfoTweened = {};
|
||||||
|
export default (playerData, playerStats) => {
|
||||||
|
if (!playerData && !playerStats) return {};
|
||||||
|
|
||||||
|
const playerInfo = {...opt(playerData, 'playerInfo', null)};
|
||||||
|
|
||||||
|
['pp', 'rank'].forEach(key => {
|
||||||
|
const value = playerInfo && playerInfo[key] ? playerInfo[key] : 0;
|
||||||
|
if (!playerInfoTweened.hasOwnProperty(key)) playerInfoTweened[key] = tweened(value, TWEEN_DURATION);
|
||||||
|
else playerInfoTweened[key].set(value);
|
||||||
|
|
||||||
|
if (playerInfo) {
|
||||||
|
playerInfo[key + 'Value'] = playerInfo[key];
|
||||||
|
playerInfo[key] = playerInfoTweened[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const firstCountryRank = opt(playerInfo, 'countries.0.rank')
|
||||||
|
if (Number.isFinite(firstCountryRank)) {
|
||||||
|
playerInfo.countries = playerInfo.countries.map(c => ({...c}))
|
||||||
|
const key = 'countryRank'
|
||||||
|
const value = playerInfo.countries[0].rank;
|
||||||
|
|
||||||
|
if (!playerInfoTweened.hasOwnProperty(key)) playerInfoTweened[key] = tweened(value, TWEEN_DURATION);
|
||||||
|
else playerInfoTweened[key].set(value);
|
||||||
|
|
||||||
|
playerInfo.countries[0].rankValue = value;
|
||||||
|
playerInfo.countries[0].rank = playerInfoTweened[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
playerInfo,
|
||||||
|
prevInfo: opt(playerData, 'prevInfo', null),
|
||||||
|
scoresStats: updateScoresStats(playerData, playerStats),
|
||||||
|
accStats: updateAccStats(playerStats),
|
||||||
|
accBadges: updateAccBadges(playerStats),
|
||||||
|
ssBadges: updateSsBadges(playerData),
|
||||||
|
}
|
||||||
|
}
|
126
src/components/Player/utils/service-param-manager.js
Normal file
126
src/components/Player/utils/service-param-manager.js
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
export default () => {
|
||||||
|
let currentService = null;
|
||||||
|
let currentServiceParams = {};
|
||||||
|
|
||||||
|
const getAllServices = () => ['scoresaber', 'beatsavior', 'accsaber'];
|
||||||
|
|
||||||
|
const get = () => ({service: currentService, params: currentServiceParams});
|
||||||
|
|
||||||
|
const getDefaultParams = service => {
|
||||||
|
switch (service) {
|
||||||
|
case 'beatsavior':
|
||||||
|
return {sort: 'recent', order: 'desc', page: 1, filters: {}};
|
||||||
|
|
||||||
|
case 'accsaber':
|
||||||
|
return {type: 'overall', order: 'desc', sort: 'ap', page: 1, filters: {}}
|
||||||
|
|
||||||
|
case 'scoresaber':
|
||||||
|
default:
|
||||||
|
return {sort: 'recent', order: 'desc', page: 1, filters: {}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const update = (serviceParams = {}, service = currentService) => {
|
||||||
|
const availableServices = getAllServices();
|
||||||
|
if (!availableServices.includes(service)) service = availableServices?.[0] ?? 'scoresaber';
|
||||||
|
|
||||||
|
const defaultServiceParams = getDefaultParams(service);
|
||||||
|
|
||||||
|
if (defaultServiceParams?.page && !Number.isFinite(serviceParams?.page)) {
|
||||||
|
const val = parseInt(serviceParams?.page, 10);
|
||||||
|
serviceParams.page = !isNaN(val) ? val : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// preserve old filters
|
||||||
|
serviceParams = {...serviceParams}
|
||||||
|
serviceParams.filters = {
|
||||||
|
...(currentServiceParams?.filters ?? {}),
|
||||||
|
...(serviceParams?.filters ?? {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
currentService = service;
|
||||||
|
currentServiceParams = {...defaultServiceParams, ...currentServiceParams, ...serviceParams}
|
||||||
|
|
||||||
|
return get();
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearServiceParams = () => currentServiceParams = {}
|
||||||
|
|
||||||
|
const initFromUrl = (url = null) => {
|
||||||
|
const availableServices = getAllServices();
|
||||||
|
const defaultService = availableServices?.[0] ?? 'scoresaber';
|
||||||
|
const paramsArr = url ? url.split('/') : [defaultService];
|
||||||
|
|
||||||
|
const service = paramsArr[0] ?? 'scoresaber';
|
||||||
|
|
||||||
|
const serviceDefaultParams = getDefaultParams(service);
|
||||||
|
|
||||||
|
switch (service) {
|
||||||
|
case 'beatsavior':
|
||||||
|
return update(
|
||||||
|
{
|
||||||
|
sort: paramsArr[1] ?? serviceDefaultParams?.sort,
|
||||||
|
order: 'desc',
|
||||||
|
page: paramsArr[2] ?? serviceDefaultParams?.page,
|
||||||
|
},
|
||||||
|
service,
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'accsaber':
|
||||||
|
return update(
|
||||||
|
{
|
||||||
|
type: paramsArr[1] ?? serviceDefaultParams?.type,
|
||||||
|
sort: paramsArr[2] ?? serviceDefaultParams?.sort,
|
||||||
|
order: (paramsArr[2] ?? serviceDefaultParams?.sort) === 'rank' ? 'asc' : 'desc',
|
||||||
|
page: paramsArr[3] ?? serviceDefaultParams?.page,
|
||||||
|
},
|
||||||
|
service,
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'scoresaber':
|
||||||
|
default:
|
||||||
|
return update(
|
||||||
|
{
|
||||||
|
sort: paramsArr[1] ?? serviceDefaultParams?.sort,
|
||||||
|
order: (paramsArr[1] ?? serviceDefaultParams?.sort) === 'rank' ? 'asc' : 'desc',
|
||||||
|
page: paramsArr[2] ?? serviceDefaultParams?.page,
|
||||||
|
},
|
||||||
|
service,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUrl = (service, params = {}, noPage = false) => {
|
||||||
|
if (!service) return '';
|
||||||
|
|
||||||
|
const serviceDefaultParams = getDefaultParams(service);
|
||||||
|
|
||||||
|
switch (service) {
|
||||||
|
case 'beatsavior':
|
||||||
|
return `${service}/${params?.sort ?? serviceDefaultParams?.sort}${noPage ? '' : `/${params?.page ?? serviceDefaultParams?.page}`}`;
|
||||||
|
|
||||||
|
case 'accsaber':
|
||||||
|
return `${service}/${params?.type ?? serviceDefaultParams?.type}/${params?.sort ?? serviceDefaultParams?.sort}${noPage ? '' : `/${params?.page ?? serviceDefaultParams?.page}`}`;
|
||||||
|
|
||||||
|
case 'scoresaber':
|
||||||
|
return `${service}/${params?.sort ?? serviceDefaultParams?.sort}${noPage ? '' : `/${params?.page ?? serviceDefaultParams?.page}`}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCurrentServiceUrl = () => getUrl(currentService, currentServiceParams);
|
||||||
|
const getCurrentServiceUrlWithoutPage = () => getUrl(currentService, currentServiceParams, true);
|
||||||
|
const getDefaultServiceUrl = (service = currentService) => getUrl(service, {});
|
||||||
|
|
||||||
|
return {
|
||||||
|
getAvailableServices: getAllServices,
|
||||||
|
initFromUrl,
|
||||||
|
getDefaultServiceUrl,
|
||||||
|
getCurrentServiceUrl,
|
||||||
|
getCurrentServiceUrlWithoutPage,
|
||||||
|
get,
|
||||||
|
getService: () => currentService,
|
||||||
|
getParams: () => currentServiceParams,
|
||||||
|
update,
|
||||||
|
clearServiceParams,
|
||||||
|
}
|
||||||
|
}
|
130
src/components/Ranking/Mini.svelte
Normal file
130
src/components/Ranking/Mini.svelte
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<script>
|
||||||
|
import {createEventDispatcher} from 'svelte'
|
||||||
|
import createRankingService from '../../services/scoresaber/ranking'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import {navigate} from 'svelte-routing'
|
||||||
|
import PlayerNameWithFlag from '../Common/PlayerNameWithFlag.svelte'
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
import Spinner from '../Common/Spinner.svelte'
|
||||||
|
import Flag from '../Common/Flag.svelte'
|
||||||
|
import {fade} from 'svelte/transition'
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export let rank = null;
|
||||||
|
export let country = null;
|
||||||
|
export let numOfPlayers = 5;
|
||||||
|
|
||||||
|
let rankingService = createRankingService();
|
||||||
|
let miniRanking = null;
|
||||||
|
|
||||||
|
let isLoading = false;
|
||||||
|
let comparePp = null;
|
||||||
|
|
||||||
|
const prevTitle = "vs ${value}"
|
||||||
|
|
||||||
|
async function onParamsChanged(rank, country, numOfPlayers) {
|
||||||
|
try {
|
||||||
|
miniRanking = null;
|
||||||
|
comparePp = null;
|
||||||
|
|
||||||
|
if (!rank) return;
|
||||||
|
|
||||||
|
isLoading = true;
|
||||||
|
|
||||||
|
const ranking = await rankingService.getMiniRanking(rank, country, numOfPlayers);
|
||||||
|
if (!ranking) return;
|
||||||
|
|
||||||
|
comparePp = opt(ranking.find(p => opt(p, 'playerInfo.rank') === rank), 'playerInfo.pp')
|
||||||
|
miniRanking = ranking
|
||||||
|
|
||||||
|
dispatch('height-changed');
|
||||||
|
} finally {
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: onParamsChanged(rank, country, numOfPlayers)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if miniRanking || isLoading}
|
||||||
|
<section transition:fade>
|
||||||
|
<h3 class="title is-6">
|
||||||
|
{#if country}
|
||||||
|
<Flag {country}/>
|
||||||
|
{:else}
|
||||||
|
<i class="fas fa-globe-americas svelte-1pb1u1r"></i>
|
||||||
|
{/if}
|
||||||
|
<span>{country ? 'Country' : 'Global'} ranking</span>
|
||||||
|
{#if isLoading}
|
||||||
|
<Spinner/>
|
||||||
|
{/if}
|
||||||
|
</h3>
|
||||||
|
{#if miniRanking}
|
||||||
|
<div class="players">
|
||||||
|
{#each miniRanking as player}
|
||||||
|
<div class="rank">
|
||||||
|
<Value value={opt(player, 'playerInfo.rank')} zero="" digits={0} prefix="#"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<PlayerNameWithFlag {player} on:click={() => navigate(`/u/${player.playerId}/scoresaber/recent/1`)}/>
|
||||||
|
|
||||||
|
<div class="pp">
|
||||||
|
<Value value={opt(player, 'playerInfo.pp')} prevValue={comparePp} zero="" suffix="pp" {prevTitle} />
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
padding: .5em;
|
||||||
|
font-size: .875em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
padding: .25em;
|
||||||
|
margin-bottom: .75em !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 > span {
|
||||||
|
margin-left: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.players {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto 1fr auto;
|
||||||
|
grid-row-gap: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.players :global(> *) {
|
||||||
|
border-bottom: 1px solid var(--dimmed);
|
||||||
|
padding: .125em .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.rank {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.players :global(.player-name) {
|
||||||
|
overflow-x: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pp {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 10.75em;
|
||||||
|
color: var(--ppColour);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pp :global(> :nth-child(2)) {
|
||||||
|
margin-left: .5em;
|
||||||
|
}
|
||||||
|
</style>
|
114
src/components/Score/Pp.svelte
Normal file
114
src/components/Score/Pp.svelte
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<script>
|
||||||
|
import {configStore} from '../../stores/config'
|
||||||
|
import {opt} from '../../utils/js'
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
import {formatNumber} from '../../utils/format'
|
||||||
|
import {hoverable} from '../../svelte-utils/actions/hoverable'
|
||||||
|
|
||||||
|
export let pp = 0;
|
||||||
|
export let zero = '-';
|
||||||
|
export let withZeroSuffix = false;
|
||||||
|
export let weighted = null;
|
||||||
|
export let attribution = null;
|
||||||
|
export let playerId = null;
|
||||||
|
export let color = "var(--ppColour)"
|
||||||
|
export let leaderboardId = null;
|
||||||
|
export let whatIf = null;
|
||||||
|
export let suffix = "pp";
|
||||||
|
|
||||||
|
let tooltipOpacity = 0;
|
||||||
|
let tooltipX = null;
|
||||||
|
let tooltipY = null;
|
||||||
|
|
||||||
|
const onHover = event => {
|
||||||
|
tooltipY = event.detail.rect.top + 24;
|
||||||
|
tooltipX = event.detail.rect.left - 8;
|
||||||
|
tooltipOpacity = 1;
|
||||||
|
}
|
||||||
|
const onUnhover = () => tooltipOpacity = 0;
|
||||||
|
|
||||||
|
$: secondaryMetricsPref = opt($configStore, 'preferences.secondaryPp', 'attribution')
|
||||||
|
$: secondaryMetricsType = secondaryMetricsPref === 'attribution' && attribution !== null && attribution !== undefined ? 'attribution' : 'weighted'
|
||||||
|
$: secondaryMetrics = secondaryMetricsType === 'attribution' ? attribution : weighted
|
||||||
|
$: secondaryMetricsTitle = secondaryMetricsType === 'attribution' ? `Actual contribution of the score to the total ${suffix.toUpperCase()}` : `Weighted ${suffix.toUpperCase()}`
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class="pp" style="--color: {color}">
|
||||||
|
{#if whatIf}<span class="whatif-tooltip" style="--opacity: {tooltipOpacity}; --x: {tooltipX+'px'}; --y: {tooltipY+'px'}">
|
||||||
|
If you play like this:
|
||||||
|
<span class="whatif-value">
|
||||||
|
{formatNumber(whatIf.currentTotalPp)} + <strong>{formatNumber(whatIf.diff)}</strong> =<strong class="total">{formatNumber(whatIf.newTotalPp)}pp</strong>
|
||||||
|
</span>
|
||||||
|
</span>{/if}
|
||||||
|
|
||||||
|
<span class="value">
|
||||||
|
<Value value="{pp}" {zero} {withZeroSuffix} prevValue={secondaryMetrics}
|
||||||
|
prevWithSign={secondaryMetricsType === 'attribution'} prevTitle={secondaryMetricsTitle}
|
||||||
|
prevAbsolute={secondaryMetrics !== null} {suffix} {...$$restProps}
|
||||||
|
forcePrev={pp === weighted}
|
||||||
|
>
|
||||||
|
<span slot="value" let:formatted class="main-value" class:whatIfAvailable={whatIf} use:hoverable on:hover={onHover} on:unhover={onUnhover}>
|
||||||
|
{formatted} <i class="fas fa-question"></i>
|
||||||
|
</span>
|
||||||
|
<svelte:fragment slot="prev" let:formatted let:value>
|
||||||
|
{#if secondaryMetricsType === 'attribution'}
|
||||||
|
[ {value === 0 ? `+${formatNumber(Math.abs(value))}pp` : formatted} ]
|
||||||
|
{:else}
|
||||||
|
( {formatted} )
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Value>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.pp {
|
||||||
|
color: var(--color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value :global(.prev) {
|
||||||
|
min-width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.whatIfAvailable {
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-value > i {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.whatIfAvailable > i {
|
||||||
|
display: inline;
|
||||||
|
position: absolute;
|
||||||
|
top: .45em;
|
||||||
|
right: .25em;
|
||||||
|
font-size: .55em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.whatif-tooltip {
|
||||||
|
position: fixed;
|
||||||
|
top: var(--y);
|
||||||
|
left: var(--x);
|
||||||
|
z-index: 10;
|
||||||
|
width: 18em!important;
|
||||||
|
padding: .25em;
|
||||||
|
font-size: .875em;
|
||||||
|
font-weight: normal;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--textColor);
|
||||||
|
background-color: var(--foreground);
|
||||||
|
border: 1px solid var(--faded);
|
||||||
|
opacity: var(--opacity);
|
||||||
|
transition: opacity 300ms;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.whatif-tooltip .whatif-value {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.whatif-value .total {
|
||||||
|
color: var(--increase)!important;
|
||||||
|
}
|
||||||
|
</style>
|
39
src/components/Song/Difficulty.svelte
Normal file
39
src/components/Song/Difficulty.svelte
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<script>
|
||||||
|
import {getHumanDiffInfo} from '../../utils/scoresaber/format'
|
||||||
|
import Value from '../Common/Value.svelte'
|
||||||
|
|
||||||
|
export let diff;
|
||||||
|
export let useShortName = false;
|
||||||
|
export let reverseColors = false;
|
||||||
|
export let stars = null;
|
||||||
|
export let starsSuffix = "*"
|
||||||
|
|
||||||
|
$: diffInfo = diff ? getHumanDiffInfo(diff) : null;
|
||||||
|
$: title = useShortName && diffInfo.type !== 'Standard' ? diffInfo.name: diffInfo.fullName;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if diffInfo}
|
||||||
|
<span class="{'diff ' + (reverseColors ? 'reversed' : '')}"
|
||||||
|
style="color: {reverseColors ? 'white' : diffInfo.color}; background-color: {reverseColors ? diffInfo.color : 'transparent'}"
|
||||||
|
{title}>
|
||||||
|
{#if stars}
|
||||||
|
<Value value={stars} suffix={starsSuffix} zero="" {title}/>
|
||||||
|
{:else}
|
||||||
|
{useShortName ? diffInfo.shortName : diffInfo.fullName}
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.diff {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reversed {
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 0 2px;
|
||||||
|
min-width: 1.5em;
|
||||||
|
max-height: 1.5em;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
</style>
|
16
src/components/Song/Duration.svelte
Normal file
16
src/components/Song/Duration.svelte
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
import {padNumber} from '../../utils/format'
|
||||||
|
|
||||||
|
export let value = 0;
|
||||||
|
export let zero = "-";
|
||||||
|
export let suffix = "";
|
||||||
|
export let withZeroSuffix = false;
|
||||||
|
export let inline = false;
|
||||||
|
|
||||||
|
$: formatted = value ? (Math.floor(value/60) + ':' + padNumber(Math.round(value % 60))) + suffix : zero + (withZeroSuffix ? suffix : '');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span>{formatted}</span>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
63
src/components/Song/Icons.svelte
Normal file
63
src/components/Song/Icons.svelte
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<script>
|
||||||
|
import createBeatSaverService from '../../services/beatmaps'
|
||||||
|
import {copyToClipboard} from '../../utils/clipboard';
|
||||||
|
import beatSaverSvg from "../../resources/beatsaver.svg";
|
||||||
|
import Button from "../Common/Button.svelte";
|
||||||
|
import {capitalize} from '../../utils/js'
|
||||||
|
|
||||||
|
export let hash;
|
||||||
|
export let diffInfo = null;
|
||||||
|
export let twitchUrl = null;
|
||||||
|
|
||||||
|
let songKey;
|
||||||
|
let shownIcons = ["bsr", "bs", "preview", "oneclick", "twitch"];
|
||||||
|
|
||||||
|
let beatSaverService = createBeatSaverService();
|
||||||
|
|
||||||
|
async function updateSongKey(hash) {
|
||||||
|
if (!hash) {
|
||||||
|
songKey = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const songInfo = await beatSaverService.byHash(hash);
|
||||||
|
if (songInfo && songInfo.key) {
|
||||||
|
songKey = songInfo.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: updateSongKey(hash)
|
||||||
|
$: diffName = diffInfo && diffInfo.diff ? capitalize(diffInfo.diff) : null
|
||||||
|
$: charName = diffInfo && diffInfo.type ? diffInfo.type : null
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if shownIcons.includes('twitch') && twitchUrl && twitchUrl.length}
|
||||||
|
<a class="video" href="{twitchUrl}" target="_blank" rel="noreferrer">
|
||||||
|
<Button iconFa="fab fa-twitch" type="twitch" title="Twitch VOD preview" noMargin={true}/>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if songKey && songKey.length}
|
||||||
|
{#if shownIcons.includes('bsr')}
|
||||||
|
<Button iconFa="fas fa-exclamation" title="Copy !bsr" noMargin={true}
|
||||||
|
on:click={copyToClipboard('!bsr ' + songKey)}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if shownIcons.includes('bs')}
|
||||||
|
<a href="https://beatsaver.com/maps/{songKey}" target="_blank" rel="noreferrer">
|
||||||
|
<Button icon={beatSaverSvg} title="Go to Beat Saver" noMargin={true}/>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if shownIcons.includes('oneclick')}
|
||||||
|
<a href="beatsaver://{songKey}">
|
||||||
|
<Button iconFa="far fa-hand-pointer" title="One click install" noMargin={true}/>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if shownIcons.includes('preview')}
|
||||||
|
<a href={`https://skystudioapps.com/bs-viewer/?id=${songKey}${diffName ? `&diffName=${diffName}` : ''}${charName ? `&charName=${charName}` : ''}`} target="_blank" rel="noreferrer">
|
||||||
|
<Button iconFa="fa fa-play-circle" title="Map preview" noMargin={true}/>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
106
src/db/cache.js
Normal file
106
src/db/cache.js
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
import eventBus from '../utils/broadcast-channel-pubsub'
|
||||||
|
|
||||||
|
export default (name, getObjKey) => {
|
||||||
|
let cache = {};
|
||||||
|
|
||||||
|
// update data cached on another node
|
||||||
|
eventBus.on('cache-key-set-' + name, ({key, value}, isLocal) => !isLocal ? set(key, value, false) : null);
|
||||||
|
eventBus.on('cache-all-set' + name, ({data}, isLocal) => !isLocal ? setAll(data, false) : null);
|
||||||
|
eventBus.on('cache-merge-' + name, ({data}, isLocal) => !isLocal ? merge(data, false) : null);
|
||||||
|
eventBus.on('cache-key-forget-' + name, ({key}, isLocal) => !isLocal ? forget(key, false) : null);
|
||||||
|
eventBus.on('cache-flush-' + name, (_, isLocal) => !isLocal ? flush(false) : null);
|
||||||
|
|
||||||
|
const set = (key, value, emitEvent = true) => {
|
||||||
|
cache[key] = value;
|
||||||
|
|
||||||
|
if (emitEvent) eventBus.publish('cache-key-set-' + name, {key, value});
|
||||||
|
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
const setAll = (data, emitEvent = true) => {
|
||||||
|
cache = data;
|
||||||
|
|
||||||
|
if (emitEvent) eventBus.publish('cache-all-set-' + name, {data});
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
const merge = (data, emitEvent = true) => {
|
||||||
|
cache = {...cache, ...data}
|
||||||
|
|
||||||
|
if (emitEvent) eventBus.publish('cache-merge-' + name, {data});
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
const get = async (key, fetchFunc) => {
|
||||||
|
if (cache.hasOwnProperty(key)) return cache[key];
|
||||||
|
|
||||||
|
const value = await fetchFunc();
|
||||||
|
|
||||||
|
return set(key, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getByFilter = async (fetchFunc, filterFunc) => {
|
||||||
|
if (filterFunc) {
|
||||||
|
const obj = Object.values(cache).find(filterFunc);
|
||||||
|
if (obj) return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = await fetchFunc();
|
||||||
|
if (value === undefined) return value;
|
||||||
|
|
||||||
|
const key = getObjKey(value);
|
||||||
|
|
||||||
|
return set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAll = () => cache;
|
||||||
|
|
||||||
|
const has = key => cache[key] !== undefined;
|
||||||
|
|
||||||
|
const getKeys = () => Object.keys(cache);
|
||||||
|
|
||||||
|
const forget = (key, emitEvent = true) => {
|
||||||
|
delete cache[key];
|
||||||
|
|
||||||
|
if (emitEvent) eventBus.publish('cache-key-forget-' + name, {key});
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
const forgetByFilter = (filterFunc, emitEvent = true) => {
|
||||||
|
if (!filterFunc) return false;
|
||||||
|
|
||||||
|
Object.keys(cache).filter(key => filterFunc(cache[key]))
|
||||||
|
.forEach(key => {
|
||||||
|
delete cache[key]
|
||||||
|
|
||||||
|
if (emitEvent) eventBus.publish('cache-key-forget-' + name, {key});
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const flush = (emitEvent = true) => {
|
||||||
|
cache = {};
|
||||||
|
|
||||||
|
if (emitEvent) eventBus.publish('cache-flush-' + name, {});
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
has,
|
||||||
|
get,
|
||||||
|
getByFilter,
|
||||||
|
getAll,
|
||||||
|
set,
|
||||||
|
setAll,
|
||||||
|
merge,
|
||||||
|
getKeys,
|
||||||
|
forget,
|
||||||
|
forgetByFilter,
|
||||||
|
flush,
|
||||||
|
}
|
||||||
|
}
|
243
src/db/db.js
Normal file
243
src/db/db.js
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
import {openDB} from 'idb'
|
||||||
|
import log from '../utils/logger'
|
||||||
|
import {isDateObject} from '../utils/js'
|
||||||
|
import eventBus from '../utils/broadcast-channel-pubsub'
|
||||||
|
|
||||||
|
const SSR_DB_VERSION = 12;
|
||||||
|
export let db = null;
|
||||||
|
|
||||||
|
export default async () => {
|
||||||
|
IDBKeyRange.prototype.toString = function () {
|
||||||
|
return "IDBKeyRange-" + (isDateObject(this.lower) ? this.lower.getTime() : this.lower) + '-' + (isDateObject(this.upper) ? this.upper : this.upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await openDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openDatabase() {
|
||||||
|
try {
|
||||||
|
let dbNewVersion = 0, dbOldVersion = 0;
|
||||||
|
|
||||||
|
db = await openDB('ssr', SSR_DB_VERSION, {
|
||||||
|
async upgrade(db, oldVersion, newVersion, transaction) {
|
||||||
|
log.info(`Converting database from version ${oldVersion} to version ${newVersion}`);
|
||||||
|
|
||||||
|
dbNewVersion = newVersion;
|
||||||
|
dbOldVersion = oldVersion;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case newVersion >= 1 && oldVersion <= 0:
|
||||||
|
db.createObjectStore('players', {
|
||||||
|
keyPath: 'id',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const playersHistory = db.createObjectStore('players-history', {
|
||||||
|
keyPath: '_idbId',
|
||||||
|
autoIncrement: true,
|
||||||
|
});
|
||||||
|
playersHistory.createIndex('players-history-playerId', 'playerId', {unique: false});
|
||||||
|
playersHistory.createIndex('players-history-timestamp', 'timestamp', {unique: false});
|
||||||
|
|
||||||
|
const scoresStore = db.createObjectStore('scores', {
|
||||||
|
keyPath: 'id',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
scoresStore.createIndex('scores-leaderboardId', 'leaderboardId', {unique: false});
|
||||||
|
scoresStore.createIndex('scores-playerId', 'playerId', {unique: false});
|
||||||
|
scoresStore.createIndex('scores-timeset', 'timeset', {unique: false});
|
||||||
|
scoresStore.createIndex('scores-pp', 'pp', {unique: false});
|
||||||
|
|
||||||
|
db.createObjectStore('rankeds', {
|
||||||
|
keyPath: 'leaderboardId',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const songsStore = db.createObjectStore('songs', {
|
||||||
|
keyPath: 'hash',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
songsStore.createIndex('songs-key', 'key', {unique: true});
|
||||||
|
|
||||||
|
db.createObjectStore('twitch', {
|
||||||
|
keyPath: 'playerId',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const rankedsChangesStore = db.createObjectStore('rankeds-changes', {
|
||||||
|
keyPath: '_idbId',
|
||||||
|
autoIncrement: true,
|
||||||
|
});
|
||||||
|
rankedsChangesStore.createIndex('rankeds-changes-timestamp', 'timestamp', {unique: false});
|
||||||
|
rankedsChangesStore.createIndex('rankeds-changes-leaderboardId', 'leaderboardId', {unique: false});
|
||||||
|
|
||||||
|
// no autoIncrement, no keyPath - key must be provided
|
||||||
|
db.createObjectStore('key-value');
|
||||||
|
|
||||||
|
db.createObjectStore('cache');
|
||||||
|
|
||||||
|
const groups = db.createObjectStore('groups', {keyPath: '_idbId', autoIncrement: true});
|
||||||
|
groups.createIndex('groups-name', 'name', {unique: false});
|
||||||
|
groups.createIndex('groups-playerId', 'playerId', {unique: false});
|
||||||
|
|
||||||
|
const beatSaviorFiles = db.createObjectStore('beat-savior-files', {
|
||||||
|
keyPath: 'fileId',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const beatSavior = db.createObjectStore('beat-savior', {
|
||||||
|
keyPath: 'beatSaviorId',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
beatSavior.createIndex('beat-savior-playerId', 'playerId', {unique: false});
|
||||||
|
beatSavior.createIndex('beat-savior-songId', 'songId', {unique: false});
|
||||||
|
beatSavior.createIndex('beat-savior-fileId', 'fileId', {unique: false});
|
||||||
|
|
||||||
|
// NO break here!
|
||||||
|
|
||||||
|
case newVersion >=2 && oldVersion <= 1:
|
||||||
|
db.createObjectStore('beat-savior-players', {
|
||||||
|
keyPath: 'playerId',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// NO break here!
|
||||||
|
|
||||||
|
case newVersion >= 3 && oldVersion <=2:
|
||||||
|
db.deleteObjectStore('players');
|
||||||
|
|
||||||
|
db.createObjectStore('players', {
|
||||||
|
keyPath: 'playerId',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const scoresStore4 = transaction.objectStore('scores');
|
||||||
|
scoresStore4.deleteIndex('scores-timeset');
|
||||||
|
scoresStore4.createIndex('scores-timeSet', 'timeSet', {unique: false});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 4 && oldVersion <=3:
|
||||||
|
db.deleteObjectStore('beat-savior-files');
|
||||||
|
|
||||||
|
const beatSaviorStore = transaction.objectStore('beat-savior');
|
||||||
|
beatSaviorStore.deleteIndex('beat-savior-fileId');
|
||||||
|
beatSaviorStore.deleteIndex('beat-savior-songId');
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 5 && oldVersion <=4:
|
||||||
|
const songsBeatMapsStore = db.createObjectStore('songs-beatmaps', {
|
||||||
|
keyPath: 'hash',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
songsBeatMapsStore.createIndex('songs-beatmaps--key', 'key', {unique: true});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 6 && oldVersion <=5:
|
||||||
|
const songsBeatMapsStorev6 = transaction.objectStore('songs-beatmaps');
|
||||||
|
songsBeatMapsStorev6.deleteIndex('songs-beatmaps--key');
|
||||||
|
songsBeatMapsStorev6.createIndex('songs-beatmaps-key', 'key', {unique: true});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 7 && oldVersion <=6:
|
||||||
|
const scoresUpdateQueue = db.createObjectStore('scores-update-queue', {
|
||||||
|
keyPath: 'id',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
scoresUpdateQueue.createIndex('scores-update-queue-fetchedAt', 'fetchedAt', {unique: false});
|
||||||
|
|
||||||
|
case newVersion >= 8 && oldVersion <= 7:
|
||||||
|
const beatSaviorStorev8 = transaction.objectStore('beat-savior');
|
||||||
|
beatSaviorStorev8.createIndex('beat-savior-hash', 'hash', {unique: false});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 9 && oldVersion <= 8:
|
||||||
|
const playersHistoryStorev9 = transaction.objectStore('players-history');
|
||||||
|
playersHistoryStorev9.deleteIndex('players-history-timestamp');
|
||||||
|
playersHistoryStorev9.createIndex('players-history-playerIdSsTimestamp', 'playerIdSsTimestamp', {unique: true});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 10 && oldVersion <= 9:
|
||||||
|
const songsBeatMapsStoreV10 = transaction.objectStore('songs-beatmaps');
|
||||||
|
songsBeatMapsStoreV10.deleteIndex('songs-beatmaps-key');
|
||||||
|
songsBeatMapsStoreV10.createIndex('songs-beatmaps-key', 'key', {unique: false});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 11 && oldVersion <= 10:
|
||||||
|
db.createObjectStore('accsaber-categories', {
|
||||||
|
keyPath: 'name',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const accSaberPlayersStore = db.createObjectStore('accsaber-players', {
|
||||||
|
keyPath: 'id',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
accSaberPlayersStore.createIndex('accsaber-players-playerId', 'playerId', {unique: false});
|
||||||
|
accSaberPlayersStore.createIndex('accsaber-players-category', 'category', {unique: false});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
|
||||||
|
case newVersion >= 12 && oldVersion <= 11:
|
||||||
|
const accSaberPlayersHistoryStore = db.createObjectStore('accsaber-players-history', {
|
||||||
|
keyPath: 'playerIdTimestamp',
|
||||||
|
autoIncrement: false,
|
||||||
|
});
|
||||||
|
accSaberPlayersHistoryStore.createIndex('accsaber-players-history-playerId', 'playerId', {unique: false});
|
||||||
|
|
||||||
|
// NO break here
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Database converted");
|
||||||
|
},
|
||||||
|
|
||||||
|
blocked() {
|
||||||
|
console.warn('DB blocked')
|
||||||
|
},
|
||||||
|
blocking() {
|
||||||
|
// other tab tries to open newer db version - close connection
|
||||||
|
console.warn('DB blocking... will be closed')
|
||||||
|
db.close();
|
||||||
|
|
||||||
|
eventBus.publish('dl-manager-pause-cmd');
|
||||||
|
|
||||||
|
// TODO: should be reopened with new version: event.newVersion
|
||||||
|
// TODO: or rather notify user / auto reload page
|
||||||
|
},
|
||||||
|
terminated() {
|
||||||
|
console.warn('DB terminated');
|
||||||
|
|
||||||
|
eventBus.publish('dl-manager-pause-cmd');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Closure code should awaits DB operations ONLY or fail
|
||||||
|
// https://github.com/jakearchibald/idb#user-content-transaction-lifetime
|
||||||
|
db.runInTransaction = async (objectStores, closure, mode = 'readwrite', options = {durability: 'strict'}) => {
|
||||||
|
try {
|
||||||
|
const tx = db.transaction(objectStores, mode, options);
|
||||||
|
|
||||||
|
const result = await closure(tx);
|
||||||
|
|
||||||
|
await tx.done;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
log.error('Can not open DB.');
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
189
src/db/fix-data.js
Normal file
189
src/db/fix-data.js
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
import keyValueRepository from './repository/key-value';
|
||||||
|
import createBeatMapsService from '../services/beatmaps'
|
||||||
|
import log from '../utils/logger';
|
||||||
|
import {db} from './db'
|
||||||
|
import {isDateObject} from '../utils/js'
|
||||||
|
import twitchRepository from './repository/twitch'
|
||||||
|
import {correctOldSsDate} from '../utils/date'
|
||||||
|
|
||||||
|
const FIXES_KEY = 'data-fix';
|
||||||
|
|
||||||
|
const getAppliedFixes = async () => keyValueRepository().get(FIXES_KEY, true);
|
||||||
|
const setAppliedFixes = async fixes => keyValueRepository().set(fixes, FIXES_KEY);
|
||||||
|
const addAppliedFix = async fixName => {
|
||||||
|
let allAppliedFixes = await getAppliedFixes();
|
||||||
|
allAppliedFixes = allAppliedFixes && Array.isArray(allAppliedFixes) ? allAppliedFixes : [];
|
||||||
|
allAppliedFixes.push(fixName);
|
||||||
|
await setAppliedFixes(allAppliedFixes);
|
||||||
|
}
|
||||||
|
|
||||||
|
const allFixes = {
|
||||||
|
'rankeds-20210725': {
|
||||||
|
apply: async fixName => {
|
||||||
|
log.info('Apply rankeds refresh fix (20210725)')
|
||||||
|
|
||||||
|
return db.runInTransaction(['rankeds-changes', 'rankeds', 'key-value'], async tx => {
|
||||||
|
await tx.objectStore('rankeds-changes').clear();
|
||||||
|
await tx.objectStore('rankeds').clear();
|
||||||
|
|
||||||
|
const keyValueStore = tx.objectStore('key-value')
|
||||||
|
|
||||||
|
keyValueStore.delete('rankedsLastUpdated');
|
||||||
|
|
||||||
|
let allAppliedFixes = await keyValueStore.get(FIXES_KEY);
|
||||||
|
allAppliedFixes = allAppliedFixes && Array.isArray(allAppliedFixes) ? allAppliedFixes : [];
|
||||||
|
allAppliedFixes.push(fixName);
|
||||||
|
await keyValueStore.put(allAppliedFixes, FIXES_KEY);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
'beatsaver-20210804': {
|
||||||
|
apply: async fixName => {
|
||||||
|
log.info('Converting BeatSaver songs to a new format...', 'DBFix')
|
||||||
|
|
||||||
|
return db.runInTransaction(['songs', 'songs-beatmaps', 'key-value'], async tx => {
|
||||||
|
const songsBeatMapsStore = tx.objectStore('songs-beatmaps');
|
||||||
|
|
||||||
|
let cursor = await tx.objectStore('songs').openCursor();
|
||||||
|
|
||||||
|
let songCount = 0;
|
||||||
|
|
||||||
|
const beatmapsService = createBeatMapsService();
|
||||||
|
|
||||||
|
while (cursor) {
|
||||||
|
const beatSaverSong = cursor.value;
|
||||||
|
|
||||||
|
if (beatSaverSong?.metadata?.characteristics) {
|
||||||
|
const beatMapsSong = beatmapsService.convertOldBeatSaverToBeatMaps(beatSaverSong);
|
||||||
|
if (beatMapsSong) {
|
||||||
|
songsBeatMapsStore.put(beatMapsSong)
|
||||||
|
|
||||||
|
songCount++;
|
||||||
|
} else {
|
||||||
|
log.info(`Unable to convert, deleting a song`, 'DBFix', beatSaverSong);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info(`No metadata characteristics, skipping a song`, 'DBFix', beatSaverSong);
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = await cursor.continue();
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyValueStore = tx.objectStore('key-value')
|
||||||
|
let allAppliedFixes = await keyValueStore.get(FIXES_KEY);
|
||||||
|
allAppliedFixes = allAppliedFixes && Array.isArray(allAppliedFixes) ? allAppliedFixes : [];
|
||||||
|
allAppliedFixes.push(fixName);
|
||||||
|
await keyValueStore.put(allAppliedFixes, FIXES_KEY);
|
||||||
|
|
||||||
|
log.info(`${songCount} BeatSaver song(s) converted`, 'DBFix')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'twitch-20210808': {
|
||||||
|
apply: async fixName => {
|
||||||
|
const predefinedProfiles = {
|
||||||
|
'76561198059659922': 'patian25',
|
||||||
|
'1994101560659098': 'xoxobluff',
|
||||||
|
'76561198138327464': 'altrowilddog',
|
||||||
|
'76561198855288628': 'inbourne',
|
||||||
|
'76561198136177445': 'riviengt',
|
||||||
|
'76561199004224834': 'nyaanos',
|
||||||
|
'76561198023909718': 'danielduel',
|
||||||
|
'76561198212019365': 'fnyt',
|
||||||
|
'76561197966674102': 'maciekvr',
|
||||||
|
'76561198025451538': 'drakonno',
|
||||||
|
'76561197994110158': 'sanorek',
|
||||||
|
'76561198034203862': 'vr_agent',
|
||||||
|
'3702342373170767': 'xjedam',
|
||||||
|
'76561197995161445': 'mediekore',
|
||||||
|
'76561198087710981': 'shreddyfreddy',
|
||||||
|
'76561198999385463': 'woltixo',
|
||||||
|
'76561198035381239': 'motzel',
|
||||||
|
'76561198178407566' : 'acetari',
|
||||||
|
'76561198045386379': 'duhhello',
|
||||||
|
'76561198835772160': 'tornadoef6',
|
||||||
|
'76561198187936410': 'garsh_',
|
||||||
|
'76561198362923485': 'tseska_',
|
||||||
|
'76561198154190170': 'tieeli',
|
||||||
|
'76561198333869741': 'cerret07',
|
||||||
|
'76561197995162898': 'electrostats',
|
||||||
|
'76561198166289091': 'rocker1904',
|
||||||
|
'2538637699496776': 'astrella_',
|
||||||
|
'76561198171842815': 'coolpickb',
|
||||||
|
'76561198145281261': 'harbgy'
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info('Adding predefined Twitch profiles...', 'DBFix')
|
||||||
|
|
||||||
|
const updatePlayerTwitchProfile = async (twitchProfile) => twitchRepository().set(twitchProfile);
|
||||||
|
|
||||||
|
await Promise.all(Object.entries(predefinedProfiles).map(async ([playerId, twitchLogin]) => updatePlayerTwitchProfile(
|
||||||
|
{
|
||||||
|
lastUpdated: null,
|
||||||
|
login: twitchLogin,
|
||||||
|
playerId
|
||||||
|
}
|
||||||
|
)))
|
||||||
|
|
||||||
|
await addAppliedFix(fixName);
|
||||||
|
|
||||||
|
log.info('Twitch profiles added.', 'DBFix')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'player-history-20211022': {
|
||||||
|
apply: async fixName => {
|
||||||
|
log.info('Apply player ss history fix (20211022)')
|
||||||
|
|
||||||
|
return db.runInTransaction(['players-history', 'key-value'], async tx => {
|
||||||
|
const playersHistoryStore = tx.objectStore('players-history');
|
||||||
|
|
||||||
|
let cursor = await playersHistoryStore.openCursor();
|
||||||
|
|
||||||
|
while (cursor) {
|
||||||
|
const history = cursor.value;
|
||||||
|
|
||||||
|
if (!history?.playerId || !isDateObject(history?.ssDate)) {
|
||||||
|
await cursor.delete();
|
||||||
|
cursor = await cursor.continue();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const playerId = history.playerId;
|
||||||
|
const ssDate = correctOldSsDate(history.ssDate);
|
||||||
|
const playerIdSsTimestamp = `${playerId}_${ssDate.getTime()}`;
|
||||||
|
|
||||||
|
await cursor.delete();
|
||||||
|
playersHistoryStore.put({...history, ssDate, playerIdSsTimestamp});
|
||||||
|
|
||||||
|
cursor = await cursor.continue();
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyValueStore = tx.objectStore('key-value')
|
||||||
|
let allAppliedFixes = await keyValueStore.get(FIXES_KEY);
|
||||||
|
allAppliedFixes = allAppliedFixes && Array.isArray(allAppliedFixes) ? allAppliedFixes : [];
|
||||||
|
allAppliedFixes.push(fixName);
|
||||||
|
await keyValueStore.put(allAppliedFixes, FIXES_KEY);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async () => {
|
||||||
|
let appliedDbFixes = await getAppliedFixes();
|
||||||
|
const appliedFixes = appliedDbFixes && Array.isArray(appliedDbFixes) ? appliedDbFixes : [];
|
||||||
|
const neededFixes = Object.keys(allFixes).filter(f => !appliedFixes.includes(f) && (!allFixes[f].validTo || allFixes[f].validTo > new Date()));
|
||||||
|
|
||||||
|
if (!neededFixes.length) return;
|
||||||
|
|
||||||
|
document.body.innerHTML = '<p>Database conversion. Please wait...</p>';
|
||||||
|
|
||||||
|
for (let key of neededFixes) {
|
||||||
|
await allFixes[key].apply(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.innerHTML = '';
|
||||||
|
}
|
19
src/db/repositories-init.js
Normal file
19
src/db/repositories-init.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import cacheRepository from './repository/cache';
|
||||||
|
import groupsRepository from './repository/groups';
|
||||||
|
import keyValueRepository from './repository/key-value';
|
||||||
|
import playersRepository from './repository/players';
|
||||||
|
import playersHistoryRepository from './repository/players-history';
|
||||||
|
import rankedsRepository from './repository/rankeds';
|
||||||
|
import rankedsChangesRepository from './repository/rankeds-changes';
|
||||||
|
import scoresRepository from './repository/scores';
|
||||||
|
import songsRepository from './repository/songs';
|
||||||
|
import twitchRepository from './repository/twitch';
|
||||||
|
import log from '../utils/logger';
|
||||||
|
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
log.debug('Initialize DB repositories');
|
||||||
|
|
||||||
|
// initialize all repositories in order to create cache to sync
|
||||||
|
[cacheRepository, groupsRepository, keyValueRepository, playersRepository, playersHistoryRepository, rankedsRepository, rankedsChangesRepository, scoresRepository, songsRepository, twitchRepository].map(repository => repository());
|
||||||
|
}
|
3
src/db/repository/accsaber-categories.js
Normal file
3
src/db/repository/accsaber-categories.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import createRepository from './generic';
|
||||||
|
|
||||||
|
export default () => createRepository('accsaber-categories', 'name');
|
6
src/db/repository/accsaber-players-history.js
Normal file
6
src/db/repository/accsaber-players-history.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import createRepository from './generic';
|
||||||
|
|
||||||
|
export default () => createRepository('accsaber-players-history', 'playerIdTimestamp', {
|
||||||
|
'accsaber-players-history-playerId': 'playerId',
|
||||||
|
'accsaber-players-history-playerIdTimestamp': 'playerIdTimestamp'
|
||||||
|
});
|
10
src/db/repository/accsaber-players.js
Normal file
10
src/db/repository/accsaber-players.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import createRepository from './generic';
|
||||||
|
|
||||||
|
export default () => createRepository(
|
||||||
|
'accsaber-players',
|
||||||
|
'id',
|
||||||
|
{
|
||||||
|
'accsaber-players-playerId': 'playerId',
|
||||||
|
'accsaber-players-category': 'category',
|
||||||
|
},
|
||||||
|
);
|
3
src/db/repository/beat-savior-files.js
Normal file
3
src/db/repository/beat-savior-files.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import createRepository from './generic';
|
||||||
|
|
||||||
|
export default () => createRepository('beat-savior-files', 'fileId');
|
3
src/db/repository/beat-savior-players.js
Normal file
3
src/db/repository/beat-savior-players.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import createRepository from './generic';
|
||||||
|
|
||||||
|
export default () => createRepository('beat-savior-players', 'playerId');
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user