Compare commits
146 Commits
449d46479c
...
9ba402d54f
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | 9ba402d54f | |
Savanni D'Gerinel | 58d9a12e9f | |
Savanni D'Gerinel | 08029a2afd | |
Savanni D'Gerinel | d4fc937613 | |
Savanni D'Gerinel | 9130aa5c77 | |
Savanni D'Gerinel | 5a471a3dbf | |
Savanni D'Gerinel | 92ca170a24 | |
Savanni D'Gerinel | d79598eaa3 | |
Savanni D'Gerinel | 9533934e05 | |
Savanni D'Gerinel | b9808a1862 | |
Savanni D'Gerinel | c51fced23a | |
Savanni D'Gerinel | 23011aacc0 | |
Savanni D'Gerinel | bce5659ceb | |
Savanni D'Gerinel | 084a558740 | |
Savanni D'Gerinel | 744511a552 | |
Savanni D'Gerinel | c8d21d0e25 | |
Savanni D'Gerinel | 1b9a8eee67 | |
Savanni D'Gerinel | 741f963606 | |
Savanni D'Gerinel | 82deabce48 | |
Savanni D'Gerinel | 4b30bf288a | |
Savanni D'Gerinel | 96c6f2dfbf | |
Savanni D'Gerinel | 90b0f830e0 | |
Savanni D'Gerinel | e3957a5dbe | |
Savanni D'Gerinel | ba814fd899 | |
Savanni D'Gerinel | 9137909a64 | |
Savanni D'Gerinel | 12f4f9dde6 | |
Savanni D'Gerinel | fd4c6ff935 | |
Savanni D'Gerinel | 3cca3a7f89 | |
Savanni D'Gerinel | 4fd07b240e | |
Savanni D'Gerinel | 2469cd78fa | |
Savanni D'Gerinel | f24fb5eae9 | |
Savanni D'Gerinel | 798566d01c | |
Savanni D'Gerinel | 6fd4d9df96 | |
savanni | d9531c69ad | |
Savanni D'Gerinel | b15658dd0c | |
Savanni D'Gerinel | 9266387833 | |
Savanni D'Gerinel | ebb7062041 | |
Savanni D'Gerinel | d0db274110 | |
Savanni D'Gerinel | 32ed1a2464 | |
Savanni D'Gerinel | 6456389eef | |
Savanni D'Gerinel | ef045117be | |
Savanni D'Gerinel | 6f6579b7a7 | |
Savanni D'Gerinel | b7f5f4ba34 | |
Savanni D'Gerinel | 7546a81876 | |
Savanni D'Gerinel | d4a55ccb17 | |
Savanni D'Gerinel | 587c1d763d | |
Savanni D'Gerinel | a779220173 | |
Savanni D'Gerinel | 343969a898 | |
Savanni D'Gerinel | 6c87d23537 | |
Savanni D'Gerinel | 140ad0f22c | |
Savanni D'Gerinel | 6c4226ec66 | |
Savanni D'Gerinel | b86a618b34 | |
Savanni D'Gerinel | 297e7f70c4 | |
Savanni D'Gerinel | 68cec8bc12 | |
Savanni D'Gerinel | ef396f3bfb | |
Savanni D'Gerinel | 1e65219401 | |
Savanni D'Gerinel | 0b0bd1e14b | |
Savanni D'Gerinel | b321c03297 | |
Savanni D'Gerinel | c87ab6da7f | |
Savanni D'Gerinel | ab97f266bb | |
Savanni D'Gerinel | fdbde131e8 | |
Savanni D'Gerinel | 9a6da002e2 | |
Savanni D'Gerinel | 60b0f1b736 | |
Savanni D'Gerinel | 0dd7344a09 | |
Savanni D'Gerinel | 904a866de0 | |
Savanni D'Gerinel | 17050ed4d6 | |
Savanni D'Gerinel | 97c52de2cf | |
Savanni D'Gerinel | fee2e598d3 | |
Savanni D'Gerinel | 889c3cec94 | |
Savanni D'Gerinel | 06157604b9 | |
Savanni D'Gerinel | d68e088500 | |
Savanni D'Gerinel | 27d87fcd02 | |
Savanni D'Gerinel | edcf20cc25 | |
Savanni D'Gerinel | 78af31f6f9 | |
Savanni D'Gerinel | 52e27318fe | |
Savanni D'Gerinel | e746190a4a | |
Savanni D'Gerinel | 300704297f | |
Savanni D'Gerinel | 3cd39af060 | |
Savanni D'Gerinel | 037484e7b4 | |
Savanni D'Gerinel | 6d51ae8479 | |
Savanni D'Gerinel | d74c9ebcad | |
Savanni D'Gerinel | ad6b006e1c | |
Savanni D'Gerinel | 70b34f41b5 | |
Savanni D'Gerinel | 78acebbf06 | |
Savanni D'Gerinel | dad38590f4 | |
Savanni D'Gerinel | 0d6cd2a247 | |
Savanni D'Gerinel | a2eec878a2 | |
Savanni D'Gerinel | d8ac8fba01 | |
Savanni D'Gerinel | ea5c8cdb78 | |
Savanni D'Gerinel | d1b257e631 | |
Savanni D'Gerinel | 268acb615f | |
Savanni D'Gerinel | 4590bc6688 | |
Savanni D'Gerinel | 26db170c79 | |
Savanni D'Gerinel | 59a8f252da | |
Savanni D'Gerinel | 8df649d6cd | |
Savanni D'Gerinel | 481226e8c6 | |
Savanni D'Gerinel | b64eda7efd | |
Savanni D'Gerinel | 553d3f8496 | |
Savanni D'Gerinel | a8a9c49f02 | |
Savanni D'Gerinel | 829b300ca0 | |
Savanni D'Gerinel | e32f103dd4 | |
Savanni D'Gerinel | 0240132153 | |
Savanni D'Gerinel | cb16d73342 | |
Savanni D'Gerinel | 35850b60b3 | |
Savanni D'Gerinel | b236ee54ab | |
Savanni D'Gerinel | c2e7399e55 | |
Savanni D'Gerinel | d430fd82e6 | |
Savanni D'Gerinel | 62a178e168 | |
Savanni D'Gerinel | cbae0f47fc | |
Savanni D'Gerinel | b8493b7fe7 | |
savanni | ea02e614dd | |
Savanni D'Gerinel | 68096ec743 | |
Savanni D'Gerinel | f23d7e9d7e | |
Savanni D'Gerinel | 44171393ef | |
Savanni D'Gerinel | db80f47e8b | |
Savanni D'Gerinel | f31f622d6f | |
Savanni D'Gerinel | da6cf800ec | |
Savanni D'Gerinel | 92393875dc | |
Savanni D'Gerinel | 1b61689de6 | |
Savanni D'Gerinel | 7c56a2907f | |
Savanni D'Gerinel | 40cce7ce00 | |
Savanni D'Gerinel | 725c96bc1b | |
Savanni D'Gerinel | 8260b4e2f3 | |
savanni | c296c742ca | |
Savanni D'Gerinel | ec13842fe4 | |
Savanni D'Gerinel | 09595b99c6 | |
Savanni D'Gerinel | 8300b84525 | |
Savanni D'Gerinel | 7fe9a68062 | |
Savanni D'Gerinel | 81779c9fc2 | |
savanni | 226329ab6d | |
savanni | 1016ba756c | |
savanni | 52ca039f45 | |
savanni | 4163ccb5c2 | |
Savanni D'Gerinel | 363a4632b1 | |
savanni | e60a2fbc30 | |
Savanni D'Gerinel | cca1b9c3ba | |
Savanni D'Gerinel | a8d8210252 | |
Savanni D'Gerinel | 214463f6b4 | |
Savanni D'Gerinel | 411e0261fc | |
Savanni D'Gerinel | 12e9067c14 | |
Savanni D'Gerinel | c5721c1e87 | |
Savanni D'Gerinel | f17dd5b89d | |
Savanni D'Gerinel | ac5d8e0c75 | |
Savanni D'Gerinel | c5528d1ceb | |
savanni | be995d2f26 | |
Savanni D'Gerinel | ebb33e915c |
|
@ -1,2 +1,5 @@
|
||||||
target
|
target
|
||||||
.direnv/
|
.direnv/
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
result
|
||||||
|
|
|
@ -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>.
|
53
Makefile
53
Makefile
|
@ -1,10 +1,34 @@
|
||||||
|
|
||||||
|
all: test bin
|
||||||
|
|
||||||
|
test: kifu-core/test-oneshot sgf/test-oneshot
|
||||||
|
|
||||||
|
bin: kifu-gtk
|
||||||
|
|
||||||
|
changeset-dev:
|
||||||
|
cd changeset && make dev
|
||||||
|
|
||||||
|
changeset-test:
|
||||||
|
cd changeset && make test
|
||||||
|
|
||||||
|
coordinates-dev:
|
||||||
|
cd coordinates && make dev
|
||||||
|
|
||||||
|
coordinates-test:
|
||||||
|
cd coordinates && make test
|
||||||
|
|
||||||
emseries-dev:
|
emseries-dev:
|
||||||
cd emseries && make dev
|
cd emseries && make dev
|
||||||
|
|
||||||
emseries-test:
|
emseries-test:
|
||||||
cd emseries && make test
|
cd emseries && make test
|
||||||
|
|
||||||
|
flow-dev:
|
||||||
|
cd flow && make dev
|
||||||
|
|
||||||
|
flow-test:
|
||||||
|
cd flow && make test
|
||||||
|
|
||||||
fluent-ergonomics-dev:
|
fluent-ergonomics-dev:
|
||||||
cd fluent-ergonomics && make dev
|
cd fluent-ergonomics && make dev
|
||||||
|
|
||||||
|
@ -17,3 +41,32 @@ ifc-dev:
|
||||||
ifc-test:
|
ifc-test:
|
||||||
cd ifc && make test
|
cd ifc && make test
|
||||||
|
|
||||||
|
kifu-core/dev:
|
||||||
|
cd kifu/core && make test
|
||||||
|
|
||||||
|
kifu-core/test:
|
||||||
|
cd kifu/core && make test
|
||||||
|
|
||||||
|
kifu-core/test-oneshot:
|
||||||
|
cd kifu/core && make test-oneshot
|
||||||
|
|
||||||
|
kifu-gtk:
|
||||||
|
cd kifu/gtk && make release
|
||||||
|
|
||||||
|
kifu-gtk/dev:
|
||||||
|
cd kifu/gtk && make dev
|
||||||
|
|
||||||
|
kifu-pwa:
|
||||||
|
cd kifu/pwa && make release
|
||||||
|
|
||||||
|
kifu-pwa/dev:
|
||||||
|
pushd kifu/pwa && make dev
|
||||||
|
|
||||||
|
kifu-pwa/server:
|
||||||
|
pushd kifu/pwa && make server
|
||||||
|
|
||||||
|
sgf/test:
|
||||||
|
pushd sgf && make test
|
||||||
|
|
||||||
|
sgf/test-oneshot:
|
||||||
|
pushd sgf && make test-oneshot
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "changeset"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.139"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuid"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "changeset"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
license-file = "../COPYING"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
uuid = { version = "*", features = [ "v4" ] }
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
dev:
|
||||||
|
cargo watch -x build
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo watch -x test
|
||||||
|
|
||||||
|
test-once:
|
||||||
|
cargo test
|
|
@ -0,0 +1,204 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
hash::Hash,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub trait Constructable {
|
||||||
|
fn new() -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub enum Change<Key: Eq + Hash, Value> {
|
||||||
|
DeleteRecord(Key),
|
||||||
|
UpdateRecord((Key, Value)),
|
||||||
|
NewRecord(Value),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Changeset<Key: Clone + Eq + Hash, Value> {
|
||||||
|
delete: HashSet<Key>,
|
||||||
|
update: HashMap<Key, Value>,
|
||||||
|
new: HashMap<Key, Value>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Key: Clone + Constructable + Eq + Hash, Value> Changeset<Key, Value> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
delete: HashSet::new(),
|
||||||
|
update: HashMap::new(),
|
||||||
|
new: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add(&mut self, r: Value) -> Key {
|
||||||
|
let k = Key::new();
|
||||||
|
self.new.insert(k.clone(), r);
|
||||||
|
k.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self, k: Key, v: Value) {
|
||||||
|
match self.new.get_mut(&k) {
|
||||||
|
Some(record) => *record = v,
|
||||||
|
None => {
|
||||||
|
let _ = self.update.insert(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete(&mut self, k: Key) {
|
||||||
|
let new_v = self.new.remove(&k);
|
||||||
|
let updated_v = self.update.remove(&k);
|
||||||
|
match (new_v.is_some(), updated_v.is_some()) {
|
||||||
|
(false, false) => {
|
||||||
|
let _ = self.delete.insert(k);
|
||||||
|
}
|
||||||
|
(true, false) => (),
|
||||||
|
(false, true) => {
|
||||||
|
let _ = self.delete.insert(k);
|
||||||
|
}
|
||||||
|
(true, true) => {
|
||||||
|
panic!("state error: key exists in the new and updtade columns at once")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Key: Clone + Eq + Hash, Value> From<Changeset<Key, Value>> for Vec<Change<Key, Value>> {
|
||||||
|
fn from(changes: Changeset<Key, Value>) -> Self {
|
||||||
|
let Changeset {
|
||||||
|
delete,
|
||||||
|
update,
|
||||||
|
new,
|
||||||
|
} = changes;
|
||||||
|
delete
|
||||||
|
.into_iter()
|
||||||
|
.map(|k| Change::DeleteRecord(k))
|
||||||
|
.chain(
|
||||||
|
update
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| Change::UpdateRecord((k, v))),
|
||||||
|
)
|
||||||
|
.chain(new.into_iter().map(|(_, v)| Change::NewRecord(v)))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
|
struct Id(Uuid);
|
||||||
|
impl Constructable for Id {
|
||||||
|
fn new() -> Self {
|
||||||
|
Id(Uuid::new_v4())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_generates_a_new_record() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
set.add("efgh".to_string());
|
||||||
|
let changes = Vec::from(set.clone());
|
||||||
|
assert_eq!(changes.len(), 1);
|
||||||
|
assert!(changes.contains(&Change::NewRecord("efgh".to_string())));
|
||||||
|
|
||||||
|
set.add("wxyz".to_string());
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 2);
|
||||||
|
assert!(changes.contains(&Change::NewRecord("efgh".to_string())));
|
||||||
|
assert!(changes.contains(&Change::NewRecord("wxyz".to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_generates_a_delete_record() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
let id1 = Id::new();
|
||||||
|
set.delete(id1.clone());
|
||||||
|
let changes = Vec::from(set.clone());
|
||||||
|
assert_eq!(changes.len(), 1);
|
||||||
|
assert!(changes.contains(&Change::DeleteRecord(id1.clone())));
|
||||||
|
|
||||||
|
let id2 = Id::new();
|
||||||
|
set.delete(id2.clone());
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 2);
|
||||||
|
assert!(changes.contains(&Change::DeleteRecord(id1)));
|
||||||
|
assert!(changes.contains(&Change::DeleteRecord(id2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_unrelated_records() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
let id1 = Id::new();
|
||||||
|
let id2 = Id::new();
|
||||||
|
set.update(id1.clone(), "abcd".to_owned());
|
||||||
|
set.update(id2.clone(), "efgh".to_owned());
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 2);
|
||||||
|
assert!(changes.contains(&Change::UpdateRecord((id1, "abcd".to_owned()))));
|
||||||
|
assert!(changes.contains(&Change::UpdateRecord((id2, "efgh".to_owned()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_cancels_new() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
let key = set.add("efgh".to_string());
|
||||||
|
set.delete(key);
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete_cancels_update() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
let id = Id::new();
|
||||||
|
set.update(id.clone(), "efgh".to_owned());
|
||||||
|
set.delete(id.clone());
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 1);
|
||||||
|
assert!(changes.contains(&Change::DeleteRecord(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_atop_new_is_new() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
let key = set.add("efgh".to_owned());
|
||||||
|
set.update(key, "wxyz".to_owned());
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 1);
|
||||||
|
assert!(changes.contains(&Change::NewRecord("wxyz".to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn updates_get_squashed() {
|
||||||
|
let mut set: Changeset<Id, String> = Changeset::new();
|
||||||
|
let id1 = Id::new();
|
||||||
|
let id2 = Id::new();
|
||||||
|
set.update(id1.clone(), "efgh".to_owned());
|
||||||
|
set.update(id2.clone(), "efgh".to_owned());
|
||||||
|
let changes = Vec::from(set.clone());
|
||||||
|
assert_eq!(changes.len(), 2);
|
||||||
|
assert!(changes.contains(&Change::UpdateRecord((id1.clone(), "efgh".to_string()))));
|
||||||
|
assert!(changes.contains(&Change::UpdateRecord((id2.clone(), "efgh".to_string()))));
|
||||||
|
|
||||||
|
set.update(id1.clone(), "wxyz".to_owned());
|
||||||
|
let changes = Vec::from(set);
|
||||||
|
assert_eq!(changes.len(), 2);
|
||||||
|
assert!(changes.contains(&Change::UpdateRecord((id1, "wxyz".to_string()))));
|
||||||
|
assert!(changes.contains(&Change::UpdateRecord((id2, "efgh".to_string()))));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,348 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-set"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
|
||||||
|
dependencies = [
|
||||||
|
"bit-vec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-vec"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "coordinates"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
"proptest",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fastrand"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
|
||||||
|
dependencies = [
|
||||||
|
"instant",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.139"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.49"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proptest"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5"
|
||||||
|
dependencies = [
|
||||||
|
"bit-set",
|
||||||
|
"bitflags",
|
||||||
|
"byteorder",
|
||||||
|
"lazy_static",
|
||||||
|
"num-traits",
|
||||||
|
"quick-error 2.0.1",
|
||||||
|
"rand",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_xorshift",
|
||||||
|
"regex-syntax",
|
||||||
|
"rusty-fork",
|
||||||
|
"tempfile",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-error"
|
||||||
|
version = "1.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-error"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_xorshift"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.6.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "remove_dir_all"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rusty-fork"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"quick-error 1.2.3",
|
||||||
|
"tempfile",
|
||||||
|
"wait-timeout",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.107"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tempfile"
|
||||||
|
version = "3.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"fastrand",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"remove_dir_all",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wait-timeout"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "coordinates"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
license-file = "../COPYING"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
proptest = "1.0"
|
||||||
|
thiserror = "1.0"
|
||||||
|
nom = { version = "7" }
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
dev:
|
||||||
|
cargo watch -x build
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo watch -x test
|
||||||
|
|
||||||
|
test-once:
|
||||||
|
cargo test
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Seeds for failure cases proptest has generated in the past. It is
|
||||||
|
# automatically read and these particular cases re-run before any
|
||||||
|
# novel cases are generated.
|
||||||
|
#
|
||||||
|
# It is recommended to check this file in to source control so that
|
||||||
|
# everyone who runs the test benefits from these saved cases.
|
||||||
|
cc a2c4f3291703eca342388b116ee0849a96e5f977c5af22a6b5bc805edecfeb5d # shrinks to (q, r) = (0, 0), idx = 0
|
||||||
|
cc f80f4dd28944bad3a39512535e38ca3db1870c6daefd5317856f70bb58a505df # shrinks to (x, y) = (0, 0), idx = 0
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use coordinates::hex_map;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct MapVal;
|
||||||
|
|
||||||
|
impl Default for MapVal {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MapVal> for String {
|
||||||
|
fn from(_val: MapVal) -> Self {
|
||||||
|
".".to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut args = std::env::args().skip(1);
|
||||||
|
|
||||||
|
let filename = args
|
||||||
|
.next()
|
||||||
|
.map(|p| PathBuf::from(p))
|
||||||
|
.expect("A filename is required");
|
||||||
|
let size = args
|
||||||
|
.next()
|
||||||
|
.and_then(|s| s.parse::<usize>().ok())
|
||||||
|
.unwrap_or(3);
|
||||||
|
let map: hex_map::Map<MapVal> = hex_map::Map::new_hexagonal(size);
|
||||||
|
hex_map::write_file(filename, map);
|
||||||
|
}
|
|
@ -0,0 +1,177 @@
|
||||||
|
/*
|
||||||
|
Copyright 2022-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// Ĉi-tiu modulo enhavas la elementojn por kub-koordinato.
|
||||||
|
///
|
||||||
|
/// This code is based on https://www.redblobgames.com/grids/hexagons/
|
||||||
|
use crate::Error;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
/// An address within the hex coordinate system
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct AxialAddr {
|
||||||
|
q: i32,
|
||||||
|
r: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AxialAddr {
|
||||||
|
/// Create a new axial coordinate address.
|
||||||
|
pub fn new(q: i32, r: i32) -> Self {
|
||||||
|
Self { q, r }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn origin() -> AxialAddr {
|
||||||
|
AxialAddr { q: 0, r: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn q(&self) -> i32 {
|
||||||
|
self.q
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn r(&self) -> i32 {
|
||||||
|
self.r
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn s(&self) -> i32 {
|
||||||
|
-self.q - self.r
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a list of coordinates adjacent to this one.
|
||||||
|
pub fn adjacencies(&self) -> impl Iterator<Item = AxialAddr> {
|
||||||
|
vec![
|
||||||
|
AxialAddr::new(self.q + 1, self.r),
|
||||||
|
AxialAddr::new(self.q, self.r + 1),
|
||||||
|
AxialAddr::new(self.q - 1, self.r + 1),
|
||||||
|
AxialAddr::new(self.q - 1, self.r),
|
||||||
|
AxialAddr::new(self.q, self.r - 1),
|
||||||
|
AxialAddr::new(self.q + 1, self.r - 1),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test whether a coordinate is adjacent to this one
|
||||||
|
pub fn is_adjacent(&self, dest: &AxialAddr) -> bool {
|
||||||
|
dest.adjacencies()
|
||||||
|
.collect::<Vec<AxialAddr>>()
|
||||||
|
.contains(&self)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Measure the distance to a destination
|
||||||
|
pub fn distance(&self, dest: &AxialAddr) -> usize {
|
||||||
|
(((self.q() - dest.q()).abs() + (self.r() - dest.r()).abs() + (self.s() - dest.s()).abs())
|
||||||
|
/ 2) as usize
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get an iteration of all of the coordinates within the specified distance of this one.
|
||||||
|
pub fn addresses(&self, distance: usize) -> impl Iterator<Item = AxialAddr> {
|
||||||
|
let item = self.clone();
|
||||||
|
let mut results: HashSet<AxialAddr> = HashSet::new();
|
||||||
|
let mut positions: Vec<AxialAddr> = Vec::new();
|
||||||
|
|
||||||
|
positions.push(item);
|
||||||
|
|
||||||
|
while positions.len() > 0 {
|
||||||
|
let elem = positions.remove(0);
|
||||||
|
for adj in elem.adjacencies() {
|
||||||
|
if self.distance(&adj) <= distance && !results.contains(&adj) {
|
||||||
|
positions.push(adj.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results.insert(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn distance_0_has_the_source() {
|
||||||
|
let addr = AxialAddr::origin();
|
||||||
|
let lst: Vec<AxialAddr> = addr.addresses(0).collect();
|
||||||
|
assert_eq!(lst.len(), 1);
|
||||||
|
assert!(lst.contains(&AxialAddr::origin()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn distance_1_has_seven_addresses() {
|
||||||
|
let hexaddr = AxialAddr::origin();
|
||||||
|
let lst: Vec<AxialAddr> = hexaddr.addresses(1).collect();
|
||||||
|
assert_eq!(lst.len(), 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn distance_2_has_19_addresses() {
|
||||||
|
let hexaddr = AxialAddr::origin();
|
||||||
|
let lst: Vec<AxialAddr> = hexaddr.addresses(2).collect();
|
||||||
|
assert_eq!(lst.len(), 19);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn address() -> (std::ops::Range<i32>, std::ops::Range<i32>) {
|
||||||
|
(-65536_i32..65535, -65536_i32..65535)
|
||||||
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn produces_adjacent_coordinates((x, y) in address(), idx in 0_usize..6) {
|
||||||
|
let coord1 = AxialAddr::new(x, y);
|
||||||
|
let lst1: HashSet<AxialAddr> = coord1.adjacencies().collect();
|
||||||
|
assert_eq!(lst1.len(), 6);
|
||||||
|
|
||||||
|
let lst1 = lst1.into_iter().collect::<Vec<_>>();
|
||||||
|
let coord2 = &lst1[idx];
|
||||||
|
let lst2: Vec<AxialAddr> = coord2.adjacencies().collect();
|
||||||
|
assert!(lst2.contains(&coord1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tests_adjacencies((q, r) in address(), idx in 0_usize..6) {
|
||||||
|
let coord1 = AxialAddr::new(q, r);
|
||||||
|
let lst1: Vec<AxialAddr> = coord1.adjacencies().collect();
|
||||||
|
assert_eq!(lst1.len(), 6);
|
||||||
|
|
||||||
|
let coord2 = &lst1[idx];
|
||||||
|
assert!(coord2.is_adjacent(&coord1));
|
||||||
|
assert!(coord1.is_adjacent(&coord2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn measures_distance((q1, r1) in address(),
|
||||||
|
(q2, r2) in address()) {
|
||||||
|
let hexaddr_1 = AxialAddr::new(q1, r1);
|
||||||
|
let hexaddr_2 = AxialAddr::new(q2, r2);
|
||||||
|
|
||||||
|
let s1 = -q1 - r1;
|
||||||
|
let s2 = -q2 - r2;
|
||||||
|
let expected = (((q1 - q2).abs() + (r1 - r2).abs() + (s1 - s2).abs()) / 2) as usize;
|
||||||
|
assert_eq!(hexaddr_1.distance(&hexaddr_2), expected);
|
||||||
|
assert_eq!(hexaddr_2.distance(&hexaddr_1), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn calculates_distance((q, r) in address(), distance in 0_usize..6) {
|
||||||
|
let hexaddr = AxialAddr::new(q, r);
|
||||||
|
let en_distancaj_hexaddr: Vec<AxialAddr> = hexaddr.addresses(distance).collect();
|
||||||
|
|
||||||
|
let expected_cnt = ((0..distance+1).map(|v| v * 6).fold(1, |acc, val| acc + val)) as usize;
|
||||||
|
assert_eq!(en_distancaj_hexaddr.len(), expected_cnt);
|
||||||
|
for c in en_distancaj_hexaddr {
|
||||||
|
assert!(c.distance(&hexaddr) <= distance as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,195 @@
|
||||||
|
/*
|
||||||
|
Copyright 2022-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Luminescent Dreams Tools. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use crate::{hex::AxialAddr, Error};
|
||||||
|
use nom::{
|
||||||
|
bytes::complete::tag,
|
||||||
|
character::complete::alphanumeric1,
|
||||||
|
error::ParseError,
|
||||||
|
multi::many1,
|
||||||
|
sequence::{delimited, separated_pair},
|
||||||
|
Finish, IResult, Parser,
|
||||||
|
};
|
||||||
|
use std::{
|
||||||
|
collections::{hash_map::Entry, HashMap},
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct Map<A> {
|
||||||
|
cells: HashMap<AxialAddr, A>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A: Default + Clone> Map<A> {
|
||||||
|
pub fn new_hexagonal(radius: usize) -> Map<A> {
|
||||||
|
let cells = vec![(AxialAddr::origin(), Default::default())]
|
||||||
|
.into_iter()
|
||||||
|
.chain(
|
||||||
|
AxialAddr::origin()
|
||||||
|
.addresses(radius)
|
||||||
|
.map(|addr| (addr, Default::default())),
|
||||||
|
)
|
||||||
|
.collect::<HashMap<AxialAddr, A>>();
|
||||||
|
Map { cells }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn contains(&self, coordinate: AxialAddr) -> bool {
|
||||||
|
self.cells.contains_key(&coordinate)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cell(&mut self, addr: AxialAddr) -> Entry<AxialAddr, A> {
|
||||||
|
self.cells.entry(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, addr: &AxialAddr) -> Option<&A> {
|
||||||
|
self.cells.get(addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_file<A: Default + From<String>>(path: PathBuf) -> Result<Map<A>, Error> {
|
||||||
|
let data = std::fs::read_to_string(path)?;
|
||||||
|
Ok(parse_data(data.lines()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_file<A: Clone>(path: PathBuf, map: Map<A>) -> Result<(), Error>
|
||||||
|
where
|
||||||
|
String: From<A>,
|
||||||
|
{
|
||||||
|
std::fs::write(path, write_data(map).join("\n")).map_err(Error::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_data<'a, A: Default + From<String>>(
|
||||||
|
data: impl Iterator<Item = &'a str> + 'a,
|
||||||
|
) -> Map<A> {
|
||||||
|
fn parse_line<A: From<String>>(input: &str) -> Result<(AxialAddr, A), nom::error::Error<&str>> {
|
||||||
|
fn parse<A: From<String>>(input: &str) -> IResult<&str, (AxialAddr, A)> {
|
||||||
|
let (input, addr) = parse_address(input)?;
|
||||||
|
let (input, value) = cell_value::<A>(input)?;
|
||||||
|
Ok((input, (addr, value)))
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(input).finish().map(|(_, pair)| pair)
|
||||||
|
}
|
||||||
|
|
||||||
|
let cells = data
|
||||||
|
.map(|line| parse_line::<A>(&line).unwrap())
|
||||||
|
.collect::<Vec<(AxialAddr, A)>>();
|
||||||
|
let cells = cells.into_iter().collect::<HashMap<AxialAddr, A>>();
|
||||||
|
Map { cells }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_data<A: Clone>(map: Map<A>) -> Vec<String>
|
||||||
|
where
|
||||||
|
String: From<A>,
|
||||||
|
{
|
||||||
|
map.cells
|
||||||
|
.iter()
|
||||||
|
.map(|(addr, val)| format!("[{}, {}] {}", addr.q(), addr.r(), String::from(val.clone())))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_address(input: &str) -> IResult<&str, AxialAddr> {
|
||||||
|
let (input, (q, r)) = delimited(
|
||||||
|
tag("["),
|
||||||
|
separated_pair(
|
||||||
|
nom::character::complete::i32,
|
||||||
|
tag(", "),
|
||||||
|
nom::character::complete::i32,
|
||||||
|
),
|
||||||
|
tag("] "),
|
||||||
|
)(input)?;
|
||||||
|
Ok((input, (AxialAddr::new(q, r))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cell_value<A: From<String>>(input: &str) -> IResult<&str, A> {
|
||||||
|
many1(alphanumeric1)
|
||||||
|
.or(tag(".").map(|v| vec![v]))
|
||||||
|
.map(|v| v.join(""))
|
||||||
|
.map(|v| A::from(v))
|
||||||
|
.parse(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
struct MapVal(char);
|
||||||
|
impl Default for MapVal {
|
||||||
|
fn default() -> MapVal {
|
||||||
|
MapVal('.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<MapVal> for String {
|
||||||
|
fn from(v: MapVal) -> String {
|
||||||
|
format!("{}", v.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<String> for MapVal {
|
||||||
|
fn from(s: String) -> MapVal {
|
||||||
|
MapVal(s.chars().next().unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_modify_a_map() {
|
||||||
|
let mut map: Map<MapVal> = Map::new_hexagonal(1);
|
||||||
|
map.cell(AxialAddr::new(0, 0))
|
||||||
|
.and_modify(|cell| *cell = MapVal('L'));
|
||||||
|
assert_eq!(map.get(&AxialAddr::new(0, 0)), Some(&MapVal('L')));
|
||||||
|
assert_eq!(map.get(&AxialAddr::new(0, 1)), Some(&MapVal('.')));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_serialize_a_map() {
|
||||||
|
let mut map: Map<MapVal> = Map::new_hexagonal(1);
|
||||||
|
map.cell(AxialAddr::new(0, 0))
|
||||||
|
.and_modify(|cell| *cell = MapVal('L'));
|
||||||
|
map.cell(AxialAddr::new(1, 0))
|
||||||
|
.and_modify(|cell| *cell = MapVal('A'));
|
||||||
|
|
||||||
|
let mut expected: HashSet<String> = HashSet::new();
|
||||||
|
expected.insert("[0, 0] L".to_owned());
|
||||||
|
expected.insert("[1, 0] A".to_owned());
|
||||||
|
expected.insert("[0, 1] .".to_owned());
|
||||||
|
expected.insert("[-1, 1] .".to_owned());
|
||||||
|
expected.insert("[-1, 0] .".to_owned());
|
||||||
|
expected.insert("[0, -1] .".to_owned());
|
||||||
|
expected.insert("[1, -1] .".to_owned());
|
||||||
|
|
||||||
|
let map_rows = write_data(map);
|
||||||
|
assert_eq!(map_rows.len(), expected.len());
|
||||||
|
map_rows
|
||||||
|
.iter()
|
||||||
|
.for_each(|row| assert!(expected.contains(row)));
|
||||||
|
expected
|
||||||
|
.iter()
|
||||||
|
.for_each(|expected| assert!(map_rows.contains(expected)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_deserialize_a_map() {
|
||||||
|
let map_data = "[0, 0] L
|
||||||
|
[1, 0] A
|
||||||
|
[0, 1] .
|
||||||
|
[-1, 1] .
|
||||||
|
[-1, 0] .
|
||||||
|
[0, -1] .
|
||||||
|
[1, -1] .";
|
||||||
|
let map: Map<MapVal> = parse_data(map_data.lines());
|
||||||
|
assert_eq!(map.get(&AxialAddr::new(0, 0)), Some(&MapVal('L')));
|
||||||
|
assert_eq!(map.get(&AxialAddr::new(1, 0)), Some(&MapVal('A')));
|
||||||
|
assert_eq!(map.get(&AxialAddr::new(0, 1)), Some(&MapVal('.')));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of Koordinatoj.
|
||||||
|
|
||||||
|
Lumeto 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.
|
||||||
|
|
||||||
|
Lumeto 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
use thiserror;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("IO error on reading or writing: {0}")]
|
||||||
|
IO(std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for Error {
|
||||||
|
fn from(err: std::io::Error) -> Self {
|
||||||
|
Self::IO(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod hex;
|
||||||
|
pub mod hex_map;
|
||||||
|
|
||||||
|
pub use hex::AxialAddr;
|
|
@ -0,0 +1,729 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.70"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cairo-rs"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8af54f5d48af1226928adc1f57edd22f5df1349e7da1fc96ae15cf43db0e871"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cairo-sys-rs",
|
||||||
|
"glib",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cairo-sys-rs"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f55382a01d30e5e53f185eee269124f5e21ab526595b872751278dfbb463594e"
|
||||||
|
dependencies = [
|
||||||
|
"glib-sys",
|
||||||
|
"libc",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-expr"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a35b255461940a32985c627ce82900867c61db1659764d3675ea81963f72a4c6"
|
||||||
|
dependencies = [
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cyberpunk-splash"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cairo-rs",
|
||||||
|
"gio",
|
||||||
|
"glib",
|
||||||
|
"gtk4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "field-offset"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3cf3a800ff6e860c863ca6d4b16fd999db8b752819c1606884047b73e468535"
|
||||||
|
dependencies = [
|
||||||
|
"memoffset",
|
||||||
|
"rustc_version",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-channel"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-core"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.13",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-task"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-util"
|
||||||
|
version = "0.3.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-task",
|
||||||
|
"pin-project-lite",
|
||||||
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gdk-pixbuf"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b023fbe0c6b407bd3d9805d107d9800da3829dc5a676653210f1d5f16d7f59bf"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"gdk-pixbuf-sys",
|
||||||
|
"gio",
|
||||||
|
"glib",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gdk-pixbuf-sys"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b41bd2b44ed49d99277d3925652a163038bd5ed943ec9809338ffb2f4391e3b"
|
||||||
|
dependencies = [
|
||||||
|
"gio-sys",
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"libc",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gdk4"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3abf96408a26e3eddf881a7f893a1e111767137136e347745e8ea6ed12731ff"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cairo-rs",
|
||||||
|
"gdk-pixbuf",
|
||||||
|
"gdk4-sys",
|
||||||
|
"gio",
|
||||||
|
"glib",
|
||||||
|
"libc",
|
||||||
|
"pango",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gdk4-sys"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bc92aa1608c089c49393d014c38ac0390d01e4841e1fedaa75dbcef77aaed64"
|
||||||
|
dependencies = [
|
||||||
|
"cairo-sys-rs",
|
||||||
|
"gdk-pixbuf-sys",
|
||||||
|
"gio-sys",
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"libc",
|
||||||
|
"pango-sys",
|
||||||
|
"pkg-config",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gio"
|
||||||
|
version = "0.17.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2261a3b4e922ec676d1c27ac466218c38cf5dcb49a759129e54bb5046e442125"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-util",
|
||||||
|
"gio-sys",
|
||||||
|
"glib",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"pin-project-lite",
|
||||||
|
"smallvec",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gio-sys"
|
||||||
|
version = "0.17.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6b1d43b0d7968b48455244ecafe41192871257f5740aa6b095eb19db78e362a5"
|
||||||
|
dependencies = [
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"libc",
|
||||||
|
"system-deps",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glib"
|
||||||
|
version = "0.17.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cfb53061756195d76969292c2d2e329e01259276524a9bae6c9b73af62854773"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
"gio-sys",
|
||||||
|
"glib-macros",
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"libc",
|
||||||
|
"memchr",
|
||||||
|
"once_cell",
|
||||||
|
"smallvec",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glib-macros"
|
||||||
|
version = "0.17.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc4cf346122086f196260783aa58987190dbd5f43bfab01946d2bf9786e8d9ef"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"heck",
|
||||||
|
"proc-macro-crate",
|
||||||
|
"proc-macro-error",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glib-sys"
|
||||||
|
version = "0.17.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49f00ad0a1bf548e61adfff15d83430941d9e1bb620e334f779edd1c745680a5"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gobject-sys"
|
||||||
|
version = "0.17.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "15e75b0000a64632b2d8ca3cf856af9308e3a970844f6e9659bd197f026793d0"
|
||||||
|
dependencies = [
|
||||||
|
"glib-sys",
|
||||||
|
"libc",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "graphene-rs"
|
||||||
|
version = "0.17.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "21cf11565bb0e4dfc2f99d4775b6c329f0d40a2cff9c0066214d31a0e1b46256"
|
||||||
|
dependencies = [
|
||||||
|
"glib",
|
||||||
|
"graphene-sys",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "graphene-sys"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf80a4849a8d9565410a8fec6fc3678e9c617f4ac7be182ca55ab75016e07af9"
|
||||||
|
dependencies = [
|
||||||
|
"glib-sys",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gsk4"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f01ef44fa7cac15e2da9978529383e6bee03e570ba5bf7036b4c10a15cc3a3c"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cairo-rs",
|
||||||
|
"gdk4",
|
||||||
|
"glib",
|
||||||
|
"graphene-rs",
|
||||||
|
"gsk4-sys",
|
||||||
|
"libc",
|
||||||
|
"pango",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gsk4-sys"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c07a84fb4dcf1323d29435aa85e2f5f58bef564342bef06775ec7bd0da1f01b0"
|
||||||
|
dependencies = [
|
||||||
|
"cairo-sys-rs",
|
||||||
|
"gdk4-sys",
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"graphene-sys",
|
||||||
|
"libc",
|
||||||
|
"pango-sys",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gtk4"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e30e124b5a605f6f5513db13958bfcd51d746607b20bc7bb718b33e303274ed"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cairo-rs",
|
||||||
|
"field-offset",
|
||||||
|
"futures-channel",
|
||||||
|
"gdk-pixbuf",
|
||||||
|
"gdk4",
|
||||||
|
"gio",
|
||||||
|
"glib",
|
||||||
|
"graphene-rs",
|
||||||
|
"gsk4",
|
||||||
|
"gtk4-macros",
|
||||||
|
"gtk4-sys",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"pango",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gtk4-macros"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f041a797fb098bfb06e432c61738133604bfa3af57f13f1da3b9d46271422ef0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"proc-macro-crate",
|
||||||
|
"proc-macro-error",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gtk4-sys"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f8283f707b07e019e76c7f2934bdd4180c277e08aa93f4c0d8dd07b7a34e22f"
|
||||||
|
dependencies = [
|
||||||
|
"cairo-sys-rs",
|
||||||
|
"gdk-pixbuf-sys",
|
||||||
|
"gdk4-sys",
|
||||||
|
"gio-sys",
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"graphene-sys",
|
||||||
|
"gsk4-sys",
|
||||||
|
"libc",
|
||||||
|
"pango-sys",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.12.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "1.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.141"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.17.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pango"
|
||||||
|
version = "0.17.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52c280b82a881e4208afb3359a8e7fde27a1b272280981f1f34610bed5770d37"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"gio",
|
||||||
|
"glib",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"pango-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pango-sys"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4293d0f0b5525eb5c24734d30b0ed02cd02aa734f216883f376b54de49625de8"
|
||||||
|
dependencies = [
|
||||||
|
"glib-sys",
|
||||||
|
"gobject-sys",
|
||||||
|
"libc",
|
||||||
|
"system-deps",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-crate"
|
||||||
|
version = "1.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"toml_edit",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error-attr",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error-attr"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.56"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_version"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||||
|
dependencies = [
|
||||||
|
"semver",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.159"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "system-deps"
|
||||||
|
version = "6.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "555fc8147af6256f3931a36bb83ad0023240ce9cf2b319dec8236fd1f220b05f"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-expr",
|
||||||
|
"heck",
|
||||||
|
"pkg-config",
|
||||||
|
"toml",
|
||||||
|
"version-compare",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.13",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_edit",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_datetime"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.19.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version-compare"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winnow"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "cyberpunk-splash"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cairo-rs = { version = "0.17" }
|
||||||
|
gio = { version = "0.17" }
|
||||||
|
glib = { version = "0.17" }
|
||||||
|
gtk = { version = "0.6", package = "gtk4" }
|
|
@ -0,0 +1,773 @@
|
||||||
|
use cairo::{
|
||||||
|
Context, FontSlant, FontWeight, Format, ImageSurface, LineCap, LinearGradient, Pattern,
|
||||||
|
TextExtents,
|
||||||
|
};
|
||||||
|
use glib::{GString, Object};
|
||||||
|
use gtk::{gdk::Key, prelude::*, subclass::prelude::*, EventControllerKey};
|
||||||
|
use std::{
|
||||||
|
cell::RefCell,
|
||||||
|
rc::Rc,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
|
||||||
|
const WIDTH: i32 = 1600;
|
||||||
|
const HEIGHT: i32 = 600;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
enum Event {
|
||||||
|
Frames(u8),
|
||||||
|
Time(Duration),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum State {
|
||||||
|
Running {
|
||||||
|
last_update: Instant,
|
||||||
|
deadline: Instant,
|
||||||
|
timeout: Option<TimeoutAnimation>,
|
||||||
|
},
|
||||||
|
Paused {
|
||||||
|
time_remaining: Duration,
|
||||||
|
timeout: Option<TimeoutAnimation>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn new(countdown: Duration) -> Self {
|
||||||
|
Self::Paused {
|
||||||
|
time_remaining: countdown,
|
||||||
|
timeout: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start(&mut self) {
|
||||||
|
if let Self::Paused {
|
||||||
|
time_remaining,
|
||||||
|
timeout,
|
||||||
|
} = self
|
||||||
|
{
|
||||||
|
*self = Self::Running {
|
||||||
|
last_update: Instant::now(),
|
||||||
|
deadline: Instant::now() + *time_remaining,
|
||||||
|
timeout: timeout.clone(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pause(&mut self) {
|
||||||
|
if let Self::Running {
|
||||||
|
deadline, timeout, ..
|
||||||
|
} = self
|
||||||
|
{
|
||||||
|
*self = Self::Paused {
|
||||||
|
time_remaining: *deadline - Instant::now(),
|
||||||
|
timeout: timeout.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_pause(&mut self) {
|
||||||
|
match self {
|
||||||
|
Self::Running { .. } => self.pause(),
|
||||||
|
Self::Paused { .. } => self.start(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&mut self, now: Instant) {
|
||||||
|
if let Self::Running {
|
||||||
|
last_update,
|
||||||
|
deadline,
|
||||||
|
timeout,
|
||||||
|
} = self
|
||||||
|
{
|
||||||
|
*last_update = now;
|
||||||
|
if let Some(ref mut timeout) = timeout {
|
||||||
|
// TODO: figure out the actual number of frames
|
||||||
|
timeout.tick(1);
|
||||||
|
}
|
||||||
|
if *last_update > *deadline && timeout.is_none() {
|
||||||
|
*timeout = Some(TimeoutAnimation {
|
||||||
|
intensity: 1.,
|
||||||
|
duration: 1.,
|
||||||
|
ascending: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct TimeoutAnimation {
|
||||||
|
intensity: f64,
|
||||||
|
duration: f64,
|
||||||
|
ascending: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TimeoutAnimation {
|
||||||
|
fn tick(&mut self, frames_elapsed: u8) {
|
||||||
|
let step_size = 1. / (self.duration * 60.);
|
||||||
|
if self.ascending {
|
||||||
|
self.intensity = self.intensity + step_size * frames_elapsed as f64;
|
||||||
|
if self.intensity > 1. {
|
||||||
|
self.intensity = 1.0;
|
||||||
|
self.ascending = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.intensity = self.intensity - step_size * frames_elapsed as f64;
|
||||||
|
if self.intensity < 0. {
|
||||||
|
self.intensity = 0.0;
|
||||||
|
self.ascending = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SplashPrivate {
|
||||||
|
text: Rc<RefCell<String>>,
|
||||||
|
background: Rc<RefCell<Pattern>>,
|
||||||
|
time_extents: Rc<RefCell<Option<TextExtents>>>,
|
||||||
|
width: Rc<RefCell<i32>>,
|
||||||
|
height: Rc<RefCell<i32>>,
|
||||||
|
|
||||||
|
state: Rc<RefCell<State>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SplashPrivate {
|
||||||
|
fn set_text(&self, text: String) {
|
||||||
|
*self.text.borrow_mut() = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_state(&self, state: State) {
|
||||||
|
*self.state.borrow_mut() = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn redraw_background(&self) {
|
||||||
|
let pen = GlowPen::new(
|
||||||
|
*self.width.borrow(),
|
||||||
|
*self.height.borrow(),
|
||||||
|
2.,
|
||||||
|
8.,
|
||||||
|
8.,
|
||||||
|
(0.7, 0., 1.),
|
||||||
|
);
|
||||||
|
|
||||||
|
let background =
|
||||||
|
ImageSurface::create(Format::Rgb24, *self.width.borrow(), *self.height.borrow())
|
||||||
|
.unwrap();
|
||||||
|
let context = Context::new(background).unwrap();
|
||||||
|
context.push_group();
|
||||||
|
context.set_source_rgb(0., 0., 0.);
|
||||||
|
let _ = context.paint();
|
||||||
|
|
||||||
|
context.select_font_face("Alegreya Sans SC", FontSlant::Normal, FontWeight::Bold);
|
||||||
|
|
||||||
|
{
|
||||||
|
context.set_source_rgb(0.7, 0., 1.);
|
||||||
|
|
||||||
|
let hashtag = "#CodingTogether";
|
||||||
|
context.set_font_size(64.);
|
||||||
|
let extents = context.text_extents(hashtag).unwrap();
|
||||||
|
|
||||||
|
context.move_to(20., extents.height() + 40.);
|
||||||
|
let _ = context.show_text(hashtag);
|
||||||
|
|
||||||
|
AsymLine {
|
||||||
|
orientation: gtk::Orientation::Horizontal,
|
||||||
|
start_x: 10.,
|
||||||
|
start_y: extents.height() + 10.,
|
||||||
|
start_length: 0.,
|
||||||
|
height: extents.height() / 2.,
|
||||||
|
total_length: extents.width() + extents.height() / 2.,
|
||||||
|
invert: false,
|
||||||
|
}
|
||||||
|
.draw(&pen);
|
||||||
|
pen.stroke();
|
||||||
|
|
||||||
|
AsymLine {
|
||||||
|
orientation: gtk::Orientation::Horizontal,
|
||||||
|
start_x: 20.,
|
||||||
|
start_y: extents.height() + 60.,
|
||||||
|
start_length: extents.width(),
|
||||||
|
height: extents.height() / 2.,
|
||||||
|
total_length: extents.width() + extents.height() / 2.,
|
||||||
|
invert: false,
|
||||||
|
}
|
||||||
|
.draw(&pen);
|
||||||
|
pen.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
context.set_font_size(128.);
|
||||||
|
|
||||||
|
let center_x = *self.width.borrow() as f64 / 2.;
|
||||||
|
let center_y = *self.height.borrow() as f64 / 2.;
|
||||||
|
|
||||||
|
let title_extents = context.text_extents(&self.text.borrow()).unwrap();
|
||||||
|
let title_width = title_extents.width();
|
||||||
|
let title_height = title_extents.height();
|
||||||
|
|
||||||
|
{
|
||||||
|
let start_length = center_x - title_width / 2. - title_height - 20.;
|
||||||
|
|
||||||
|
let title_cutout = AsymLineCutout {
|
||||||
|
orientation: gtk::Orientation::Horizontal,
|
||||||
|
start_x: 20.,
|
||||||
|
start_y: center_y - 20. - title_height / 2.,
|
||||||
|
start_length,
|
||||||
|
total_length: *self.width.borrow() as f64 - 120.,
|
||||||
|
cutout_length: title_width,
|
||||||
|
height: title_height,
|
||||||
|
invert: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
title_cutout.draw(&pen);
|
||||||
|
pen.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let title_baseline_x = center_x - title_width / 2.;
|
||||||
|
let title_baseline_y = center_y - 20.;
|
||||||
|
|
||||||
|
let gradient = LinearGradient::new(
|
||||||
|
title_baseline_x,
|
||||||
|
title_baseline_y - title_height,
|
||||||
|
title_baseline_x,
|
||||||
|
title_baseline_y,
|
||||||
|
);
|
||||||
|
gradient.add_color_stop_rgb(0.2, 0.7, 0.0, 1.0);
|
||||||
|
gradient.add_color_stop_rgb(0.8, 0.2, 0.0, 1.0);
|
||||||
|
context.move_to(title_baseline_x, title_baseline_y);
|
||||||
|
let _ = context.set_source(gradient);
|
||||||
|
let _ = context.show_text(&self.text.borrow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
AsymLine {
|
||||||
|
orientation: gtk::Orientation::Horizontal,
|
||||||
|
start_x: 100.,
|
||||||
|
start_y: *self.height.borrow() as f64 / 2. + 100.,
|
||||||
|
start_length: 400.,
|
||||||
|
height: 50.,
|
||||||
|
total_length: 650.,
|
||||||
|
invert: true,
|
||||||
|
}
|
||||||
|
.draw(&pen);
|
||||||
|
pen.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
context.set_source_rgb(0.7, 0., 1.);
|
||||||
|
AsymLine {
|
||||||
|
orientation: gtk::Orientation::Horizontal,
|
||||||
|
start_x: *self.width.borrow() as f64 / 2. + 100.,
|
||||||
|
start_y: *self.height.borrow() as f64 / 2. + 200.,
|
||||||
|
start_length: 600.,
|
||||||
|
height: 50.,
|
||||||
|
total_length: 650.,
|
||||||
|
invert: false,
|
||||||
|
}
|
||||||
|
.draw(&pen);
|
||||||
|
pen.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
let tracery = pen.finish();
|
||||||
|
let _ = context.set_source(tracery);
|
||||||
|
let _ = context.paint();
|
||||||
|
|
||||||
|
let background = context.pop_group().unwrap();
|
||||||
|
|
||||||
|
*self.background.borrow_mut() = background;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for SplashPrivate {
|
||||||
|
const NAME: &'static str = "Splash";
|
||||||
|
type Type = Splash;
|
||||||
|
type ParentType = gtk::DrawingArea;
|
||||||
|
|
||||||
|
fn new() -> SplashPrivate {
|
||||||
|
// Set up a default plain black background
|
||||||
|
let background = ImageSurface::create(Format::Rgb24, WIDTH, HEIGHT).unwrap();
|
||||||
|
let context = Context::new(background).unwrap();
|
||||||
|
context.push_group();
|
||||||
|
context.set_source_rgb(0., 0., 0.);
|
||||||
|
let _ = context.paint();
|
||||||
|
let background = context.pop_group().unwrap();
|
||||||
|
|
||||||
|
SplashPrivate {
|
||||||
|
text: Rc::new(RefCell::new(String::from(""))),
|
||||||
|
background: Rc::new(RefCell::new(background)),
|
||||||
|
time_extents: Rc::new(RefCell::new(None)),
|
||||||
|
width: Rc::new(RefCell::new(WIDTH)),
|
||||||
|
height: Rc::new(RefCell::new(HEIGHT)),
|
||||||
|
|
||||||
|
state: Rc::new(RefCell::new(State::new(Duration::ZERO))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ObjectImpl for SplashPrivate {}
|
||||||
|
impl WidgetImpl for SplashPrivate {}
|
||||||
|
impl DrawingAreaImpl for SplashPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct Splash(ObjectSubclass<SplashPrivate>) @extends gtk::DrawingArea, gtk::Widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Splash {
|
||||||
|
pub fn new(text: String, state: State) -> Self {
|
||||||
|
let s: Self = Object::builder().build();
|
||||||
|
s.set_width_request(WIDTH);
|
||||||
|
s.set_height_request(HEIGHT);
|
||||||
|
|
||||||
|
s.imp().set_text(text);
|
||||||
|
s.imp().set_state(state);
|
||||||
|
s.imp().redraw_background();
|
||||||
|
|
||||||
|
s.set_draw_func({
|
||||||
|
let s = s.clone();
|
||||||
|
move |_, context, width, height| {
|
||||||
|
let background = s.imp().background.borrow();
|
||||||
|
let _ = context.set_source(&*background);
|
||||||
|
let _ = context.paint();
|
||||||
|
|
||||||
|
let state = s.imp().state.borrow().clone();
|
||||||
|
|
||||||
|
let time = match state {
|
||||||
|
State::Running { deadline, .. } => deadline - Instant::now(),
|
||||||
|
State::Paused { time_remaining, .. } => time_remaining,
|
||||||
|
};
|
||||||
|
let minutes = time.as_secs() / 60;
|
||||||
|
let seconds = time.as_secs() % 60;
|
||||||
|
|
||||||
|
let center_x = width as f64 / 2.;
|
||||||
|
let center_y = height as f64 / 2.;
|
||||||
|
|
||||||
|
{
|
||||||
|
context.select_font_face(
|
||||||
|
"Alegreya Sans SC",
|
||||||
|
FontSlant::Normal,
|
||||||
|
FontWeight::Bold,
|
||||||
|
);
|
||||||
|
context.set_font_size(128.);
|
||||||
|
|
||||||
|
let time = format!("{:02}' {:02}\"", minutes, seconds);
|
||||||
|
|
||||||
|
let time_extents = context.text_extents(&time).unwrap();
|
||||||
|
|
||||||
|
let mut saved_extents = s.imp().time_extents.borrow_mut();
|
||||||
|
if saved_extents.is_none() {
|
||||||
|
*saved_extents = Some(time_extents.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let time_baseline_x = center_x - time_extents.width() / 2.;
|
||||||
|
let time_baseline_y = center_y + 100.;
|
||||||
|
|
||||||
|
let gradient = LinearGradient::new(
|
||||||
|
time_baseline_x,
|
||||||
|
time_baseline_y - time_extents.height(),
|
||||||
|
time_baseline_x,
|
||||||
|
time_baseline_y,
|
||||||
|
);
|
||||||
|
let (running, timeout_animation) = match state {
|
||||||
|
State::Running { timeout, .. } => (true, timeout.clone()),
|
||||||
|
State::Paused { timeout, .. } => (false, timeout.clone()),
|
||||||
|
};
|
||||||
|
match timeout_animation {
|
||||||
|
Some(ref animation) => {
|
||||||
|
gradient.add_color_stop_rgba(0.2, 0.2, 0.0, 1.0, animation.intensity);
|
||||||
|
gradient.add_color_stop_rgba(0.8, 0.7, 0.0, 1.0, animation.intensity);
|
||||||
|
let _ = context.set_source(gradient);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
if running {
|
||||||
|
gradient.add_color_stop_rgb(0.2, 0.2, 0.0, 1.0);
|
||||||
|
gradient.add_color_stop_rgb(0.8, 0.7, 0.0, 1.0);
|
||||||
|
let _ = context.set_source(gradient);
|
||||||
|
} else {
|
||||||
|
context.set_source_rgb(0.3, 0.3, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.move_to(time_baseline_x, time_baseline_y);
|
||||||
|
let _ = context.show_text(&time);
|
||||||
|
};
|
||||||
|
|
||||||
|
match *s.imp().time_extents.borrow() {
|
||||||
|
Some(extents) => {
|
||||||
|
context.set_source_rgb(0.7, 0.0, 1.0);
|
||||||
|
let time_meter = SlashMeter {
|
||||||
|
orientation: gtk::Orientation::Horizontal,
|
||||||
|
start_x: center_x + extents.width() / 2. + 50.,
|
||||||
|
start_y: center_y + 100.,
|
||||||
|
count: 5,
|
||||||
|
fill_count: minutes as u8,
|
||||||
|
height: 60.,
|
||||||
|
length: 100.,
|
||||||
|
};
|
||||||
|
time_meter.draw(&context);
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
s.connect_resize(|s, width, height| {
|
||||||
|
*s.imp().width.borrow_mut() = width;
|
||||||
|
*s.imp().height.borrow_mut() = height;
|
||||||
|
s.imp().redraw_background();
|
||||||
|
});
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_state(&self, state: State) {
|
||||||
|
self.imp().set_state(state);
|
||||||
|
self.queue_draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AsymLineCutout {
|
||||||
|
orientation: gtk::Orientation,
|
||||||
|
start_x: f64,
|
||||||
|
start_y: f64,
|
||||||
|
start_length: f64,
|
||||||
|
total_length: f64,
|
||||||
|
cutout_length: f64,
|
||||||
|
height: f64,
|
||||||
|
invert: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsymLineCutout {
|
||||||
|
fn draw(&self, pen: &impl Pen) {
|
||||||
|
let dodge = if self.invert {
|
||||||
|
self.height
|
||||||
|
} else {
|
||||||
|
-self.height
|
||||||
|
};
|
||||||
|
match self.orientation {
|
||||||
|
gtk::Orientation::Horizontal => {
|
||||||
|
pen.move_to(self.start_x, self.start_y);
|
||||||
|
pen.line_to(self.start_x + self.start_length, self.start_y);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x + self.start_length + self.height,
|
||||||
|
self.start_y + dodge,
|
||||||
|
);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x + self.start_length + self.height + self.cutout_length,
|
||||||
|
self.start_y + dodge,
|
||||||
|
);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x
|
||||||
|
+ self.start_length
|
||||||
|
+ self.height
|
||||||
|
+ self.cutout_length
|
||||||
|
+ (self.height / 2.),
|
||||||
|
self.start_y + dodge / 2.,
|
||||||
|
);
|
||||||
|
pen.line_to(self.total_length, self.start_y + dodge / 2.);
|
||||||
|
}
|
||||||
|
gtk::Orientation::Vertical => {
|
||||||
|
pen.move_to(self.start_x, self.start_y);
|
||||||
|
pen.line_to(self.start_x, self.start_y + self.start_length);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x + dodge,
|
||||||
|
self.start_y + self.start_length + self.height,
|
||||||
|
);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x + dodge,
|
||||||
|
self.start_y + self.start_length + self.height + self.cutout_length,
|
||||||
|
);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x + dodge / 2.,
|
||||||
|
self.start_y
|
||||||
|
+ self.start_length
|
||||||
|
+ self.height
|
||||||
|
+ self.cutout_length
|
||||||
|
+ (self.height / 2.),
|
||||||
|
);
|
||||||
|
pen.line_to(self.start_x + dodge / 2., self.total_length);
|
||||||
|
}
|
||||||
|
_ => panic!("unknown orientation"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AsymLine {
|
||||||
|
orientation: gtk::Orientation,
|
||||||
|
start_x: f64,
|
||||||
|
start_y: f64,
|
||||||
|
start_length: f64,
|
||||||
|
height: f64,
|
||||||
|
total_length: f64,
|
||||||
|
invert: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsymLine {
|
||||||
|
fn draw(&self, pen: &impl Pen) {
|
||||||
|
let dodge = if self.invert {
|
||||||
|
self.height
|
||||||
|
} else {
|
||||||
|
-self.height
|
||||||
|
};
|
||||||
|
match self.orientation {
|
||||||
|
gtk::Orientation::Horizontal => {
|
||||||
|
pen.move_to(self.start_x, self.start_y);
|
||||||
|
pen.line_to(self.start_x + self.start_length, self.start_y);
|
||||||
|
pen.line_to(
|
||||||
|
self.start_x + self.start_length + self.height,
|
||||||
|
self.start_y + dodge,
|
||||||
|
);
|
||||||
|
pen.line_to(self.start_x + self.total_length, self.start_y + dodge);
|
||||||
|
}
|
||||||
|
gtk::Orientation::Vertical => {}
|
||||||
|
_ => panic!("unknown orientation"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SlashMeter {
|
||||||
|
orientation: gtk::Orientation,
|
||||||
|
start_x: f64,
|
||||||
|
start_y: f64,
|
||||||
|
count: u8,
|
||||||
|
fill_count: u8,
|
||||||
|
height: f64,
|
||||||
|
length: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SlashMeter {
|
||||||
|
fn draw(&self, context: &Context) {
|
||||||
|
match self.orientation {
|
||||||
|
gtk::Orientation::Horizontal => {
|
||||||
|
let angle: f64 = 0.8;
|
||||||
|
let run = self.height / angle.tan();
|
||||||
|
let width = self.length as f64 / (self.count as f64 * 2.);
|
||||||
|
|
||||||
|
for c in 0..self.count {
|
||||||
|
context.set_line_width(1.);
|
||||||
|
|
||||||
|
let start_x = self.start_x + c as f64 * width * 2.;
|
||||||
|
context.move_to(start_x, self.start_y);
|
||||||
|
context.line_to(start_x + run, self.start_y - self.height);
|
||||||
|
context.line_to(start_x + run + width, self.start_y - self.height);
|
||||||
|
context.line_to(start_x + width, self.start_y);
|
||||||
|
context.line_to(start_x, self.start_y);
|
||||||
|
if c < self.fill_count {
|
||||||
|
let _ = context.fill();
|
||||||
|
} else {
|
||||||
|
let _ = context.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gtk::Orientation::Vertical => {}
|
||||||
|
_ => panic!("unknown orientation"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Pen {
|
||||||
|
fn move_to(&self, x: f64, y: f64);
|
||||||
|
fn line_to(&self, x: f64, y: f64);
|
||||||
|
fn stroke(&self);
|
||||||
|
|
||||||
|
fn finish(self) -> Pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GlowPen {
|
||||||
|
blur_context: Context,
|
||||||
|
draw_context: Context,
|
||||||
|
|
||||||
|
line_width: f64,
|
||||||
|
blur_line_width: f64,
|
||||||
|
blur_size: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlowPen {
|
||||||
|
fn new(
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
line_width: f64,
|
||||||
|
blur_line_width: f64,
|
||||||
|
blur_size: f64,
|
||||||
|
color: (f64, f64, f64),
|
||||||
|
) -> Self {
|
||||||
|
let blur_context =
|
||||||
|
Context::new(ImageSurface::create(Format::Rgb24, width, height).unwrap()).unwrap();
|
||||||
|
blur_context.set_line_width(blur_line_width);
|
||||||
|
blur_context.set_source_rgba(color.0, color.1, color.2, 0.5);
|
||||||
|
blur_context.push_group();
|
||||||
|
blur_context.set_line_cap(LineCap::Round);
|
||||||
|
|
||||||
|
let draw_context =
|
||||||
|
Context::new(ImageSurface::create(Format::Rgb24, width, height).unwrap()).unwrap();
|
||||||
|
draw_context.set_line_width(line_width);
|
||||||
|
draw_context.set_source_rgb(color.0, color.1, color.2);
|
||||||
|
draw_context.push_group();
|
||||||
|
draw_context.set_line_cap(LineCap::Round);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
blur_context,
|
||||||
|
draw_context,
|
||||||
|
line_width,
|
||||||
|
blur_line_width,
|
||||||
|
blur_size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pen for GlowPen {
|
||||||
|
fn move_to(&self, x: f64, y: f64) {
|
||||||
|
self.blur_context.move_to(x, y);
|
||||||
|
self.draw_context.move_to(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn line_to(&self, x: f64, y: f64) {
|
||||||
|
self.blur_context.line_to(x, y);
|
||||||
|
self.draw_context.line_to(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stroke(&self) {
|
||||||
|
self.blur_context.stroke();
|
||||||
|
self.draw_context.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finish(self) -> Pattern {
|
||||||
|
let foreground = self.draw_context.pop_group().unwrap();
|
||||||
|
self.blur_context.set_source(foreground).unwrap();
|
||||||
|
self.blur_context.paint().unwrap();
|
||||||
|
self.blur_context.pop_group().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let app = gtk::Application::builder()
|
||||||
|
.application_id("com.luminescent-dreams.cyberpunk-splash")
|
||||||
|
.flags(gio::ApplicationFlags::HANDLES_OPEN)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
app.add_main_option(
|
||||||
|
"title",
|
||||||
|
glib::char::Char::from(b't'),
|
||||||
|
glib::OptionFlags::IN_MAIN,
|
||||||
|
glib::OptionArg::String,
|
||||||
|
"",
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
app.add_main_option(
|
||||||
|
"countdown",
|
||||||
|
glib::char::Char::from(b'c'),
|
||||||
|
glib::OptionFlags::IN_MAIN,
|
||||||
|
glib::OptionArg::String,
|
||||||
|
"",
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
let state = Arc::new(RwLock::new(State::new(Duration::from_secs(5 * 60))));
|
||||||
|
let title = Arc::new(RwLock::new("".to_owned()));
|
||||||
|
|
||||||
|
app.connect_command_line(|_, _args| {
|
||||||
|
println!("connect_command_line");
|
||||||
|
1
|
||||||
|
});
|
||||||
|
app.connect_handle_local_options({
|
||||||
|
let title = title.clone();
|
||||||
|
let state = state.clone();
|
||||||
|
move |_, options| {
|
||||||
|
println!("connect_handle_local_options");
|
||||||
|
*title.write().unwrap() = options.lookup::<String>("title").unwrap().unwrap();
|
||||||
|
let countdown = match options.lookup::<String>("countdown") {
|
||||||
|
Ok(Some(countdown_str)) => {
|
||||||
|
let parts = countdown_str.split(':').collect::<Vec<&str>>();
|
||||||
|
let duration = match parts.len() {
|
||||||
|
2 => {
|
||||||
|
let minutes = parts[0].parse::<u64>().unwrap();
|
||||||
|
let seconds = parts[1].parse::<u64>().unwrap();
|
||||||
|
Duration::from_secs(minutes * 60 + seconds)
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
let seconds = parts[1].parse::<u64>().unwrap();
|
||||||
|
Duration::from_secs(seconds)
|
||||||
|
}
|
||||||
|
_ => Duration::from_secs(300),
|
||||||
|
};
|
||||||
|
duration
|
||||||
|
}
|
||||||
|
_ => Duration::from_secs(300),
|
||||||
|
};
|
||||||
|
match *state.write().unwrap() {
|
||||||
|
State::Running {
|
||||||
|
ref mut deadline, ..
|
||||||
|
} => *deadline = Instant::now() + countdown,
|
||||||
|
State::Paused {
|
||||||
|
ref mut time_remaining,
|
||||||
|
..
|
||||||
|
} => *time_remaining = countdown,
|
||||||
|
}
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.connect_open(move |app, files, args| {
|
||||||
|
println!("called open");
|
||||||
|
println!("files: {}", files.len());
|
||||||
|
println!("args: {}", args);
|
||||||
|
|
||||||
|
app.activate();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.connect_activate(move |app| {
|
||||||
|
let (gtk_tx, gtk_rx) =
|
||||||
|
gtk::glib::MainContext::channel::<State>(gtk::glib::PRIORITY_DEFAULT);
|
||||||
|
|
||||||
|
let window = gtk::ApplicationWindow::new(app);
|
||||||
|
window.present();
|
||||||
|
|
||||||
|
let splash = Splash::new(title.read().unwrap().clone(), state.read().unwrap().clone());
|
||||||
|
|
||||||
|
window.set_child(Some(&splash));
|
||||||
|
|
||||||
|
window.connect_maximized_notify(|window| {
|
||||||
|
window.fullscreen();
|
||||||
|
});
|
||||||
|
|
||||||
|
let keyboard_events = EventControllerKey::new();
|
||||||
|
keyboard_events.connect_key_released({
|
||||||
|
let window = window.clone();
|
||||||
|
let state = state.clone();
|
||||||
|
move |_, key, _, _| {
|
||||||
|
let name = key
|
||||||
|
.name()
|
||||||
|
.map(|s| s.as_str().to_owned())
|
||||||
|
.unwrap_or("".to_owned());
|
||||||
|
match name.as_ref() {
|
||||||
|
"Escape" => window.unfullscreen(),
|
||||||
|
"space" => state.write().unwrap().start_pause(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.add_controller(keyboard_events);
|
||||||
|
|
||||||
|
gtk_rx.attach(None, move |state| {
|
||||||
|
splash.set_state(state);
|
||||||
|
Continue(true)
|
||||||
|
});
|
||||||
|
|
||||||
|
std::thread::spawn({
|
||||||
|
let state = state.clone();
|
||||||
|
move || {
|
||||||
|
state.write().unwrap().start();
|
||||||
|
loop {
|
||||||
|
std::thread::sleep(Duration::from_millis(1000 / 60));
|
||||||
|
state.write().unwrap().run(Instant::now());
|
||||||
|
let _ = gtk_tx.send(state.read().unwrap().clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.run();
|
||||||
|
}
|
|
@ -36,9 +36,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono-tz"
|
name = "chrono-tz"
|
||||||
version = "0.6.1"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552"
|
checksum = "cf9cc2b23599e6d7479755f3594285efb3f74a1bdca7a7374948bc831e23a552"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz-build",
|
"chrono-tz-build",
|
||||||
|
@ -48,9 +48,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono-tz-build"
|
name = "chrono-tz-build"
|
||||||
version = "0.0.2"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069"
|
checksum = "d9998fb9f7e9b2111641485bf8beb32f92945f97f92a3d061f744cfef335f751"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parse-zoneinfo",
|
"parse-zoneinfo",
|
||||||
"phf",
|
"phf",
|
||||||
|
@ -71,7 +71,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "emseries"
|
name = "emseries"
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
|
@ -82,7 +82,6 @@ dependencies = [
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"uuid",
|
"uuid",
|
||||||
"yaml-rust",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -135,12 +134,6 @@ version = "0.2.124"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
|
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linked-hash-map"
|
|
||||||
version = "0.5.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-integer"
|
name = "num-integer"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
|
@ -171,18 +164,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf"
|
name = "phf"
|
||||||
version = "0.10.1"
|
version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
|
checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_shared",
|
"phf_shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf_codegen"
|
name = "phf_codegen"
|
||||||
version = "0.10.0"
|
version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd"
|
checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_generator",
|
"phf_generator",
|
||||||
"phf_shared",
|
"phf_shared",
|
||||||
|
@ -190,9 +183,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf_generator"
|
name = "phf_generator"
|
||||||
version = "0.10.0"
|
version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_shared",
|
"phf_shared",
|
||||||
"rand",
|
"rand",
|
||||||
|
@ -200,20 +193,13 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf_shared"
|
name = "phf_shared"
|
||||||
version = "0.10.0"
|
version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
|
checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"siphasher",
|
"siphasher",
|
||||||
"uncased",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ppv-lite86"
|
|
||||||
version = "0.2.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.37"
|
version = "1.0.37"
|
||||||
|
@ -238,18 +224,6 @@ version = "0.8.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
|
||||||
"rand_chacha",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_chacha"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
|
||||||
dependencies = [
|
|
||||||
"ppv-lite86",
|
|
||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -258,9 +232,6 @@ name = "rand_core"
|
||||||
version = "0.6.3"
|
version = "0.6.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
|
@ -392,18 +363,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.15.0"
|
version = "1.16.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "uncased"
|
|
||||||
version = "0.9.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0"
|
|
||||||
dependencies = [
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
|
@ -421,12 +383,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version_check"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.10.2+wasi-snapshot-preview1"
|
version = "0.10.2+wasi-snapshot-preview1"
|
||||||
|
@ -454,12 +410,3 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "yaml-rust"
|
|
||||||
version = "0.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
|
||||||
dependencies = [
|
|
||||||
"linked-hash-map",
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "emseries"
|
name = "emseries"
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
||||||
description = "an Embedded Time Series database"
|
description = "an Embedded Time Series database"
|
||||||
license = "BSD-3-Clause"
|
license = "GPL-3.0-only"
|
||||||
|
# license-file = "../COPYING"
|
||||||
documentation = "https://docs.rs/emseries"
|
documentation = "https://docs.rs/emseries"
|
||||||
homepage = "https://github.com/luminescent-dreams/emseries"
|
homepage = "https://github.com/luminescent-dreams/emseries"
|
||||||
repository = "https://github.com/luminescent-dreams/emseries"
|
repository = "https://github.com/luminescent-dreams/emseries"
|
||||||
|
@ -17,14 +18,13 @@ include = [
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
chrono-tz = { version = "0.6", features = ["serde"] }
|
chrono-tz = { version = "0.8", features = ["serde"] }
|
||||||
dimensioned = { version = "0.7", features = ["serde"] }
|
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_derive = "1"
|
serde_derive = "1"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||||
yaml-rust = "0.4"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.1"
|
tempfile = "3.1"
|
||||||
|
dimensioned = { version = "0.7", features = ["serde"] }
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
{"data":{"weight":77.79109,"date":"2003-11-10T06:00:00.000000000000Z"},"id":"3330c5b0-783f-4919-b2c4-8169c38f65ff"}
|
|
||||||
{"data":{"weight":77.56429,"date":"2003-11-11T06:00:00.000000000000Z"},"id":"54c10502-030e-43d2-9ca6-df2f9a5a5ddf"}
|
|
|
@ -1,5 +1,17 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
use date_time_tz::DateTimeTz;
|
use date_time_tz::DateTimeTz;
|
||||||
use types::Recordable;
|
use types::{Recordable, Timestamp};
|
||||||
|
|
||||||
/// This trait is used for constructing queries for searching the database.
|
/// This trait is used for constructing queries for searching the database.
|
||||||
pub trait Criteria {
|
pub trait Criteria {
|
||||||
|
@ -8,14 +20,12 @@ pub trait Criteria {
|
||||||
fn apply<T: Recordable>(&self, record: &T) -> bool;
|
fn apply<T: Recordable>(&self, record: &T) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify two criteria that must both be matched.
|
/// Specify two criteria that must both be matched.
|
||||||
pub struct And<A: Criteria, B: Criteria> {
|
pub struct And<A: Criteria, B: Criteria> {
|
||||||
pub lside: A,
|
pub lside: A,
|
||||||
pub rside: B,
|
pub rside: B,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<A, B> Criteria for And<A, B>
|
impl<A, B> Criteria for And<A, B>
|
||||||
where
|
where
|
||||||
A: Criteria,
|
A: Criteria,
|
||||||
|
@ -26,22 +36,19 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify two criteria, either of which may be matched.
|
/// Specify two criteria, either of which may be matched.
|
||||||
pub struct Or<A: Criteria, B: Criteria> {
|
pub struct Or<A: Criteria, B: Criteria> {
|
||||||
pub lside: A,
|
pub lside: A,
|
||||||
pub rside: B,
|
pub rside: B,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify the starting time for a search. This consists of a UTC timestamp and a specifier as to
|
/// Specify the starting time for a search. This consists of a UTC timestamp and a specifier as to
|
||||||
/// whether the exact time is included in the search criteria.
|
/// whether the exact time is included in the search criteria.
|
||||||
pub struct StartTime {
|
pub struct StartTime {
|
||||||
pub time: DateTimeTz,
|
pub time: Timestamp,
|
||||||
pub incl: bool,
|
pub incl: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Criteria for StartTime {
|
impl Criteria for StartTime {
|
||||||
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
||||||
if self.incl {
|
if self.incl {
|
||||||
|
@ -52,15 +59,13 @@ impl Criteria for StartTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify the ending time for a search. This consists of a UTC timestamp and a specifier as to
|
/// Specify the ending time for a search. This consists of a UTC timestamp and a specifier as to
|
||||||
/// whether the exact time is included in the search criteria.
|
/// whether the exact time is included in the search criteria.
|
||||||
pub struct EndTime {
|
pub struct EndTime {
|
||||||
pub time: DateTimeTz,
|
pub time: Timestamp,
|
||||||
pub incl: bool,
|
pub incl: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Criteria for EndTime {
|
impl Criteria for EndTime {
|
||||||
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
||||||
if self.incl {
|
if self.incl {
|
||||||
|
@ -71,7 +76,6 @@ impl Criteria for EndTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify a list of tags that must exist on the record.
|
/// Specify a list of tags that must exist on the record.
|
||||||
pub struct Tags {
|
pub struct Tags {
|
||||||
pub tags: Vec<String>,
|
pub tags: Vec<String>,
|
||||||
|
@ -80,15 +84,12 @@ pub struct Tags {
|
||||||
impl Criteria for Tags {
|
impl Criteria for Tags {
|
||||||
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
||||||
let record_tags = record.tags();
|
let record_tags = record.tags();
|
||||||
self.tags
|
self.tags.iter().all(|v| record_tags.contains(v))
|
||||||
.iter()
|
|
||||||
.all(|v| record_tags.contains(v))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify a criteria that searches for records matching an exact time.
|
/// Specify a criteria that searches for records matching an exact time.
|
||||||
pub fn exact_time(time: DateTimeTz) -> And<StartTime, EndTime> {
|
pub fn exact_time(time: Timestamp) -> And<StartTime, EndTime> {
|
||||||
And {
|
And {
|
||||||
lside: StartTime {
|
lside: StartTime {
|
||||||
time: time.clone(),
|
time: time.clone(),
|
||||||
|
@ -98,12 +99,11 @@ pub fn exact_time(time: DateTimeTz) -> And<StartTime, EndTime> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Specify a criteria that searches for all records within a time range.
|
/// Specify a criteria that searches for all records within a time range.
|
||||||
pub fn time_range(
|
pub fn time_range(
|
||||||
start: DateTimeTz,
|
start: Timestamp,
|
||||||
start_incl: bool,
|
start_incl: bool,
|
||||||
end: DateTimeTz,
|
end: Timestamp,
|
||||||
end_incl: bool,
|
end_incl: bool,
|
||||||
) -> And<StartTime, EndTime> {
|
) -> And<StartTime, EndTime> {
|
||||||
And {
|
And {
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate chrono_tz;
|
extern crate chrono_tz;
|
||||||
|
|
||||||
|
@ -5,7 +17,7 @@ use chrono::SecondsFormat;
|
||||||
use chrono_tz::Etc::UTC;
|
use chrono_tz::Etc::UTC;
|
||||||
use serde::de::{self, Deserialize, Deserializer, Visitor};
|
use serde::de::{self, Deserialize, Deserializer, Visitor};
|
||||||
use serde::ser::{Serialize, Serializer};
|
use serde::ser::{Serialize, Serializer};
|
||||||
use std::fmt;
|
use std::{fmt, str::FromStr};
|
||||||
|
|
||||||
/// This is a wrapper around date time objects, using timezones from the chroon-tz database and
|
/// This is a wrapper around date time objects, using timezones from the chroon-tz database and
|
||||||
/// providing string representation and parsing of the form "<RFC3339> <Timezone Name>", i.e.,
|
/// providing string representation and parsing of the form "<RFC3339> <Timezone Name>", i.e.,
|
||||||
|
@ -42,8 +54,12 @@ impl DateTimeTz {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_str(s: &str) -> Result<DateTimeTz, chrono::ParseError> {
|
impl std::str::FromStr for DateTimeTz {
|
||||||
|
type Err = chrono::ParseError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let v: Vec<&str> = s.split_terminator(" ").collect();
|
let v: Vec<&str> = s.split_terminator(" ").collect();
|
||||||
if v.len() == 2 {
|
if v.len() == 2 {
|
||||||
let tz = v[1].parse::<chrono_tz::Tz>().unwrap();
|
let tz = v[1].parse::<chrono_tz::Tz>().unwrap();
|
||||||
|
@ -54,6 +70,12 @@ impl DateTimeTz {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<chrono::DateTime<chrono_tz::Tz>> for DateTimeTz {
|
||||||
|
fn from(dt: chrono::DateTime<chrono_tz::Tz>) -> DateTimeTz {
|
||||||
|
DateTimeTz(dt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct DateTimeTzVisitor;
|
struct DateTimeTzVisitor;
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for DateTimeTzVisitor {
|
impl<'de> Visitor<'de> for DateTimeTzVisitor {
|
||||||
|
@ -86,11 +108,12 @@ impl<'de> Deserialize<'de> for DateTimeTz {
|
||||||
mod test {
|
mod test {
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
use chrono_tz::America::Phoenix;
|
use chrono_tz::America::Phoenix;
|
||||||
use chrono_tz::Etc::UTC;
|
use chrono_tz::Etc::UTC;
|
||||||
use chrono_tz::US::{Arizona, Central};
|
use chrono_tz::US::{Arizona, Central};
|
||||||
use date_time_tz::DateTimeTz;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_creates_timestamp_with_z() {
|
fn it_creates_timestamp_with_z() {
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
// NOTE: this module is a candidate for extraction into its own crate, or should be replaced with
|
// NOTE: this module is a candidate for extraction into its own crate, or should be replaced with
|
||||||
// an existing crate.
|
// an existing crate.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
/*! An Embedded Time Series Database
|
/*! An Embedded Time Series Database
|
||||||
|
|
||||||
This library provides a low-intensity time series database meant to be embedded inside of an
|
This library provides a low-intensity time series database meant to be embedded inside of an
|
||||||
|
@ -66,4 +78,4 @@ mod types;
|
||||||
pub use criteria::*;
|
pub use criteria::*;
|
||||||
pub use date_time_tz::DateTimeTz;
|
pub use date_time_tz::DateTimeTz;
|
||||||
pub use series::Series;
|
pub use series::Series;
|
||||||
pub use types::{EmseriesReadError, EmseriesWriteError, Recordable, UniqueId};
|
pub use types::{EmseriesReadError, EmseriesWriteError, Recordable, Timestamp, UniqueId};
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
use date_time_tz::DateTimeTz;
|
use date_time_tz::DateTimeTz;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::ser::Serialize;
|
use serde::ser::Serialize;
|
||||||
use std::{fmt, io, str};
|
use std::{cmp::Ordering, fmt, io, str};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -31,11 +44,56 @@ pub enum EmseriesWriteError {
|
||||||
JSONWriteError(serde_json::error::Error),
|
JSONWriteError(serde_json::error::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum Timestamp {
|
||||||
|
DateTime(DateTimeTz),
|
||||||
|
Date(NaiveDate),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl str::FromStr for Timestamp {
|
||||||
|
type Err = chrono::ParseError;
|
||||||
|
fn from_str(line: &str) -> Result<Self, Self::Err> {
|
||||||
|
DateTimeTz::from_str(line)
|
||||||
|
.map(|dtz| Timestamp::DateTime(dtz))
|
||||||
|
.or(NaiveDate::from_str(line).map(|d| Timestamp::Date(d)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Timestamp {
|
||||||
|
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Timestamp {
|
||||||
|
fn cmp(&self, other: &Timestamp) -> Ordering {
|
||||||
|
match (self, other) {
|
||||||
|
(Timestamp::DateTime(dt1), Timestamp::DateTime(dt2)) => dt1.cmp(dt2),
|
||||||
|
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.0.date().naive_utc().cmp(&dt2),
|
||||||
|
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => dt1.cmp(&dt2.0.date().naive_utc()),
|
||||||
|
(Timestamp::Date(dt1), Timestamp::Date(dt2)) => dt1.cmp(dt2),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DateTimeTz> for Timestamp {
|
||||||
|
fn from(d: DateTimeTz) -> Self {
|
||||||
|
Self::DateTime(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<NaiveDate> for Timestamp {
|
||||||
|
fn from(d: NaiveDate) -> Self {
|
||||||
|
Self::Date(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Any element to be put into the database needs to be Recordable. This is the common API that
|
/// Any element to be put into the database needs to be Recordable. This is the common API that
|
||||||
/// will aid in searching and later in indexing records.
|
/// will aid in searching and later in indexing records.
|
||||||
pub trait Recordable {
|
pub trait Recordable {
|
||||||
/// The timestamp for the record.
|
/// The timestamp for the record.
|
||||||
fn timestamp(&self) -> DateTimeTz;
|
fn timestamp(&self) -> Timestamp;
|
||||||
|
|
||||||
/// A list of string tags that can be used for indexing. This list defined per-type.
|
/// A list of string tags that can be used for indexing. This list defined per-type.
|
||||||
fn tags(&self) -> Vec<String>;
|
fn tags(&self) -> Vec<String>;
|
||||||
|
@ -98,10 +156,9 @@ mod test {
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use self::dimensioned::si::{Kilogram, KG};
|
use self::dimensioned::si::{Kilogram, KG};
|
||||||
use super::{Record, Recordable};
|
use super::*;
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
use chrono_tz::Etc::UTC;
|
use chrono_tz::{Etc::UTC, US::Central};
|
||||||
use chrono_tz::US::Central;
|
|
||||||
use date_time_tz::DateTimeTz;
|
use date_time_tz::DateTimeTz;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
|
@ -109,12 +166,12 @@ mod test {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct WeightRecord {
|
pub struct WeightRecord {
|
||||||
pub date: DateTimeTz,
|
pub date: Timestamp,
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Recordable for WeightRecord {
|
impl Recordable for WeightRecord {
|
||||||
fn timestamp(&self) -> DateTimeTz {
|
fn timestamp(&self) -> Timestamp {
|
||||||
self.date.clone()
|
self.date.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,10 +180,26 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const WEIGHT_ENTRY: &str = "{\"data\":{\"weight\":77.79109,\"date\":\"2003-11-10T06:00:00.000000000000Z\"},\"id\":\"3330c5b0-783f-4919-b2c4-8169c38f65ff\"}";
|
#[test]
|
||||||
|
fn timestamp_parses_datetimetz_without_timezone() {
|
||||||
|
assert_eq!(
|
||||||
|
"2003-11-10T06:00:00Z".parse::<Timestamp>().unwrap(),
|
||||||
|
Timestamp::DateTime(DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn legacy_deserialization() {
|
fn timestamp_parses_date() {
|
||||||
|
assert_eq!(
|
||||||
|
"2023-11-10".parse::<Timestamp>().unwrap(),
|
||||||
|
Timestamp::Date(NaiveDate::from_ymd_opt(2023, 11, 10).unwrap())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn v_alpha_serialization() {
|
||||||
|
const WEIGHT_ENTRY: &str = "{\"data\":{\"weight\":77.79109,\"date\":\"2003-11-10T06:00:00.000000000000Z\"},\"id\":\"3330c5b0-783f-4919-b2c4-8169c38f65ff\"}";
|
||||||
|
|
||||||
let rec: Record<WeightRecord> = WEIGHT_ENTRY
|
let rec: Record<WeightRecord> = WEIGHT_ENTRY
|
||||||
.parse()
|
.parse()
|
||||||
.expect("should successfully parse the record");
|
.expect("should successfully parse the record");
|
||||||
|
@ -137,16 +210,16 @@ mod test {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
rec.data,
|
rec.data,
|
||||||
Some(WeightRecord {
|
Some(WeightRecord {
|
||||||
date: DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0)),
|
date: Timestamp::DateTime(DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0))),
|
||||||
weight: Weight(77.79109 * KG),
|
weight: Weight(77.79109 * KG),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn serialization_output() {
|
fn serialization_output() {
|
||||||
let rec = WeightRecord {
|
let rec = WeightRecord {
|
||||||
date: DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0)),
|
date: Timestamp::DateTime(DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0))),
|
||||||
weight: Weight(77.0 * KG),
|
weight: Weight(77.0 * KG),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -155,7 +228,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
let rec2 = WeightRecord {
|
let rec2 = WeightRecord {
|
||||||
date: DateTimeTz(Central.ymd(2003, 11, 10).and_hms(0, 0, 0)),
|
date: Timestamp::DateTime(Central.ymd(2003, 11, 10).and_hms(0, 0, 0).into()),
|
||||||
weight: Weight(77.0 * KG),
|
weight: Weight(77.0 * KG),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -163,4 +236,25 @@ mod test {
|
||||||
"{\"date\":\"2003-11-10T06:00:00Z US/Central\",\"weight\":77.0}"
|
"{\"date\":\"2003-11-10T06:00:00Z US/Central\",\"weight\":77.0}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_datetimes_can_be_compared() {
|
||||||
|
let time1 = Timestamp::DateTime(DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0)));
|
||||||
|
let time2 = Timestamp::DateTime(DateTimeTz(UTC.ymd(2003, 11, 11).and_hms(6, 0, 0)));
|
||||||
|
assert!(time1 < time2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_dates_can_be_compared() {
|
||||||
|
let time1 = Timestamp::Date(NaiveDate::from_ymd(2003, 11, 10));
|
||||||
|
let time2 = Timestamp::Date(NaiveDate::from_ymd(2003, 11, 11));
|
||||||
|
assert!(time1 < time2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn datetime_and_date_can_be_compared() {
|
||||||
|
let time1 = Timestamp::DateTime(DateTimeTz(UTC.ymd(2003, 11, 10).and_hms(6, 0, 0)));
|
||||||
|
let time2 = Timestamp::Date(NaiveDate::from_ymd(2003, 11, 11));
|
||||||
|
assert!(time1 < time2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
@ -29,8 +41,8 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Recordable for BikeTrip {
|
impl Recordable for BikeTrip {
|
||||||
fn timestamp(&self) -> DateTimeTz {
|
fn timestamp(&self) -> Timestamp {
|
||||||
self.datetime.clone()
|
self.datetime.clone().into()
|
||||||
}
|
}
|
||||||
fn tags(&self) -> Vec<String> {
|
fn tags(&self) -> Vec<String> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
|
@ -110,7 +122,7 @@ mod test {
|
||||||
Some(tr) => {
|
Some(tr) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tr.timestamp(),
|
tr.timestamp(),
|
||||||
DateTimeTz(UTC.ymd(2011, 10, 29).and_hms(0, 0, 0))
|
DateTimeTz(UTC.ymd(2011, 10, 29).and_hms(0, 0, 0)).into()
|
||||||
);
|
);
|
||||||
assert_eq!(tr.duration, Duration(11040.0 * S));
|
assert_eq!(tr.duration, Duration(11040.0 * S));
|
||||||
assert_eq!(tr.comments, String::from("long time ago"));
|
assert_eq!(tr.comments, String::from("long time ago"));
|
||||||
|
@ -132,9 +144,9 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
let v: Vec<(&UniqueId, &BikeTrip)> = ts
|
let v: Vec<(&UniqueId, &BikeTrip)> = ts
|
||||||
.search(exact_time(DateTimeTz(
|
.search(exact_time(
|
||||||
UTC.ymd(2011, 10, 31).and_hms(0, 0, 0),
|
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)).into(),
|
||||||
)))
|
))
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(v.len(), 1);
|
assert_eq!(v.len(), 1);
|
||||||
assert_eq!(*v[0].1, trips[1]);
|
assert_eq!(*v[0].1, trips[1]);
|
||||||
|
@ -154,9 +166,9 @@ mod test {
|
||||||
|
|
||||||
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
||||||
time_range(
|
time_range(
|
||||||
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
DateTimeTz(UTC.ymd(2011, 11, 04).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 11, 04).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
||||||
|
@ -187,9 +199,9 @@ mod test {
|
||||||
.expect("expect the time series to open correctly");
|
.expect("expect the time series to open correctly");
|
||||||
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
||||||
time_range(
|
time_range(
|
||||||
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
DateTimeTz(UTC.ymd(2011, 11, 04).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 11, 04).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
||||||
|
@ -221,9 +233,9 @@ mod test {
|
||||||
.expect("expect the time series to open correctly");
|
.expect("expect the time series to open correctly");
|
||||||
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
||||||
time_range(
|
time_range(
|
||||||
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
DateTimeTz(UTC.ymd(2011, 11, 04).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 11, 04).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
||||||
|
@ -240,9 +252,9 @@ mod test {
|
||||||
.expect("expect the time series to open correctly");
|
.expect("expect the time series to open correctly");
|
||||||
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
|
||||||
time_range(
|
time_range(
|
||||||
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 10, 31).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
DateTimeTz(UTC.ymd(2011, 11, 05).and_hms(0, 0, 0)),
|
DateTimeTz(UTC.ymd(2011, 11, 05).and_hms(0, 0, 0)).into(),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
|
||||||
|
@ -322,9 +334,9 @@ mod test {
|
||||||
assert_eq!(trips.len(), 3);
|
assert_eq!(trips.len(), 3);
|
||||||
|
|
||||||
let trips: Vec<(&UniqueId, &BikeTrip)> = ts
|
let trips: Vec<(&UniqueId, &BikeTrip)> = ts
|
||||||
.search(exact_time(DateTimeTz(
|
.search(exact_time(
|
||||||
UTC.ymd(2011, 11, 02).and_hms(0, 0, 0),
|
DateTimeTz(UTC.ymd(2011, 11, 02).and_hms(0, 0, 0)).into(),
|
||||||
)))
|
))
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(trips.len(), 1);
|
assert_eq!(trips.len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -370,13 +382,13 @@ mod test {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct WeightRecord {
|
pub struct WeightRecord {
|
||||||
pub date: DateTimeTz,
|
pub date: chrono::NaiveDate,
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Recordable for WeightRecord {
|
impl Recordable for WeightRecord {
|
||||||
fn timestamp(&self) -> DateTimeTz {
|
fn timestamp(&self) -> Timestamp {
|
||||||
self.date.clone()
|
self.date.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tags(&self) -> Vec<String> {
|
fn tags(&self) -> Vec<String> {
|
||||||
|
@ -384,6 +396,7 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#[test]
|
#[test]
|
||||||
pub fn legacy_file_load() {
|
pub fn legacy_file_load() {
|
||||||
let ts: Series<WeightRecord> =
|
let ts: Series<WeightRecord> =
|
||||||
|
@ -398,4 +411,5 @@ mod test {
|
||||||
Some(rec) => assert_eq!(rec.weight, Weight(77.79109 * KG)),
|
Some(rec) => assert_eq!(rec.weight, Weight(77.79109 * KG)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
155
flake.lock
155
flake.lock
|
@ -1,6 +1,37 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"flake-compat": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1650374568,
|
||||||
|
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653893745,
|
||||||
|
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils_2": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
|
@ -20,54 +51,102 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1685573264,
|
"lastModified": 1688392541,
|
||||||
"narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=",
|
"narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "380be19fbd2d9079f677978361792cb25e8a3635",
|
"rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-22.05",
|
"ref": "nixos-22.11",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681358109,
|
"lastModified": 1654275867,
|
||||||
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
|
"narHash": "sha256-pt14ZE4jVPGvfB2NynGsl34pgXfOqum5YJNpDK4+b9E=",
|
||||||
"owner": "NixOS",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
|
"rev": "7a20c208aacf4964c19186dcad51f89165dc7ed0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "nixos",
|
||||||
"ref": "nixpkgs-unstable",
|
"ref": "release-22.05",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"oxalica": {
|
"nixpkgs_3": {
|
||||||
"inputs": {
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": "nixpkgs_2"
|
|
||||||
},
|
|
||||||
"locked": {
|
"locked": {
|
||||||
"narHash": "sha256-SWqxUiEP9O2gvlWtR4Ku6rIMGM7PuNZreAPrU2yAjsk=",
|
"lastModified": 1681303793,
|
||||||
"type": "tarball",
|
"narHash": "sha256-JEdQHsYuCfRL2PICHlOiH/2ue3DwoxUX7DJ6zZxZXFk=",
|
||||||
"url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "fe2ecaf706a5907b5e54d979fbde4924d84b65fc",
|
||||||
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"type": "tarball",
|
"id": "nixpkgs",
|
||||||
"url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"
|
"ref": "nixos-unstable",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pkgs-cargo2nix": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs_2",
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1682891040,
|
||||||
|
"narHash": "sha256-hjajsi7lq24uYitUh4o04UJi1g0Qe6ruPL0s5DgPQMY=",
|
||||||
|
"owner": "cargo2nix",
|
||||||
|
"repo": "cargo2nix",
|
||||||
|
"rev": "0167b39f198d72acdf009265634504fd6f5ace15",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "cargo2nix",
|
||||||
|
"repo": "cargo2nix",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"oxalica": "oxalica"
|
"pkgs-cargo2nix": "pkgs-cargo2nix",
|
||||||
|
"typeshare": "typeshare",
|
||||||
|
"unstable": "unstable"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": [
|
||||||
|
"pkgs-cargo2nix",
|
||||||
|
"flake-utils"
|
||||||
|
],
|
||||||
|
"nixpkgs": [
|
||||||
|
"pkgs-cargo2nix",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653878966,
|
||||||
|
"narHash": "sha256-T51Gck/vrJZi1m+uTbhEFTRgZmE59sydVONadADv358=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "8526d618af012a923ca116be9603e818b502a8db",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
|
@ -84,6 +163,40 @@
|
||||||
"repo": "default",
|
"repo": "default",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"typeshare": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils_2",
|
||||||
|
"nixpkgs": "nixpkgs_3"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1690502632,
|
||||||
|
"narHash": "sha256-+k81RrxfphDUD5kekWbQ4xuZIHBEAQf67uivaQ34Afs=",
|
||||||
|
"owner": "1Password",
|
||||||
|
"repo": "typeshare",
|
||||||
|
"rev": "9f74772af53759aee2f53e64478523e53083719e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "1Password",
|
||||||
|
"repo": "typeshare",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"unstable": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1690367991,
|
||||||
|
"narHash": "sha256-2VwOn1l8y6+cu7zjNE8MgeGJNNz1eat1HwHrINeogFA=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "c9cf0708f00fbe553319258e48ca89ff9a413703",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
84
flake.nix
84
flake.nix
|
@ -2,11 +2,13 @@
|
||||||
description = "Lumenescent Dreams Tools";
|
description = "Lumenescent Dreams Tools";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "nixpkgs/nixos-22.05";
|
nixpkgs.url = "nixpkgs/nixos-22.11";
|
||||||
oxalica.url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
|
unstable.url = "nixpkgs/nixos-unstable";
|
||||||
|
pkgs-cargo2nix.url = "github:cargo2nix/cargo2nix";
|
||||||
|
typeshare.url = "github:1Password/typeshare";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, oxalica }:
|
outputs = { self, nixpkgs, unstable, pkgs-cargo2nix, typeshare, ... }:
|
||||||
let
|
let
|
||||||
version = builtins.string 0 8 self.lastModifiedDate;
|
version = builtins.string 0 8 self.lastModifiedDate;
|
||||||
supportedSystems = [ "x86_64-linux" ];
|
supportedSystems = [ "x86_64-linux" ];
|
||||||
|
@ -14,19 +16,81 @@
|
||||||
{
|
{
|
||||||
devShell."x86_64-linux" =
|
devShell."x86_64-linux" =
|
||||||
let
|
let
|
||||||
rust_overlay = import oxalica;
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ rust_overlay ]; };
|
pkgs-unstable = import unstable { system = "x86_64-linux"; };
|
||||||
rust = pkgs.rust-bin.stable."1.65.0".default.override {
|
cargo2nix = pkgs-cargo2nix.packages."x86_64-linux";
|
||||||
extensions = [ "rust-src" ];
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
name = "ld-tools-devshell";
|
name = "ld-tools-devshell";
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
pkgs.pkg-config
|
pkgs.clang
|
||||||
|
pkgs.entr
|
||||||
|
pkgs.glade
|
||||||
|
pkgs.glib
|
||||||
|
pkgs.gst_all_1.gst-plugins-bad
|
||||||
|
pkgs.gst_all_1.gst-plugins-base
|
||||||
|
pkgs.gst_all_1.gst-plugins-good
|
||||||
|
pkgs.gst_all_1.gst-plugins-ugly
|
||||||
|
pkgs.gst_all_1.gstreamer
|
||||||
|
pkgs.gtk4
|
||||||
|
pkgs.nodejs
|
||||||
pkgs.openssl
|
pkgs.openssl
|
||||||
rust
|
pkgs.pipewire
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.sqlite
|
||||||
|
pkgs.rustup
|
||||||
|
pkgs.cargo-nextest
|
||||||
|
pkgs.crate2nix
|
||||||
|
pkgs.wasm-pack
|
||||||
|
typeshare.packages."x86_64-linux".default
|
||||||
|
];
|
||||||
|
LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
|
||||||
|
};
|
||||||
|
packages."x86_64-linux" =
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
|
standardOverride = attrs: {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.gtk4
|
||||||
|
];
|
||||||
|
verbose = true;
|
||||||
|
};
|
||||||
|
customBuildInfo = pkgs: pkgs.buildRustCrate.override {
|
||||||
|
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
|
||||||
|
cairo-sys-rs = standardOverride;
|
||||||
|
graphene-sys = standardOverride;
|
||||||
|
gobject-sys = standardOverride;
|
||||||
|
pango-sys = standardOverride;
|
||||||
|
gio-sys = standardOverride;
|
||||||
|
gdk-pixbuf-sys = standardOverride;
|
||||||
|
gdk4-sys = standardOverride;
|
||||||
|
gsk4-sys = standardOverride;
|
||||||
|
gtk4-sys = standardOverride;
|
||||||
|
kifu-gtk = attrs: {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.glib
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
# gobject-sys = pkgs.buildRustCrate cargo.internal.crates.gobject-sys;
|
||||||
|
# kifu-gtk = (import ./kifu/kifu-gtk/Cargo.nix {
|
||||||
|
# inherit pkgs;
|
||||||
|
# buildRustCrateForPkgs = customBuildInfo;
|
||||||
|
# rootFeatures = [ "screenplay" ];
|
||||||
|
# release = true;
|
||||||
|
# }).rootCrate.build;
|
||||||
|
cyberpunk-splash = (import ./cyberpunk-splash/Cargo.nix {
|
||||||
|
inherit pkgs;
|
||||||
|
buildRustCrateForPkgs = customBuildInfo;
|
||||||
|
release = true;
|
||||||
|
}).rootCrate.build;
|
||||||
|
};
|
||||||
|
|
||||||
|
hydraJobs = {
|
||||||
|
inherit (self) packages;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flow"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.51"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.107"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "flow"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
license-file = "../COPYING"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
thiserror = "1"
|
|
@ -0,0 +1,5 @@
|
||||||
|
dev:
|
||||||
|
cargo watch -x build
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo watch -x test
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Flow
|
||||||
|
|
||||||
|
This is a library to help with application control flow, separating fatal errors from normal recoverable errors. This is almost entirely inspired by [Error Handling in a Correctness-Critical Rust Project](https://sled.rs/errors.html) in the sled.rs library.
|
|
@ -0,0 +1,282 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! Control Flow for Correctness-Critical applications
|
||||||
|
//!
|
||||||
|
//! https://sled.rs/errors.html
|
||||||
|
//!
|
||||||
|
//! Where the sled.rs library uses `Result<Result<A, Error>, FatalError>`, these are a little hard to
|
||||||
|
//! work with. This library works out a set of utility functions that allow us to work with the
|
||||||
|
//! nested errors in the same way as a regular Result.
|
||||||
|
use std::{error::Error, fmt};
|
||||||
|
|
||||||
|
/// Implement this trait for the application's fatal errors.
|
||||||
|
///
|
||||||
|
/// Fatal errors should be things that should trigger an application shutdown. Applications should
|
||||||
|
/// not try to recover from fatal errors, but simply bring the app to the safest shutdown point and
|
||||||
|
/// report the best possible information to the user.
|
||||||
|
///
|
||||||
|
/// Examples: database corruption, or the database is unavailable in an application that cannot
|
||||||
|
/// function without it. Graphics environment cannot be initialized in a GUI app.
|
||||||
|
///
|
||||||
|
/// Applications should generally have only one FatalError type. There are no handling utilities
|
||||||
|
/// for Fatal conditions, so Fatal conditions must be handled through an ordinary `match`
|
||||||
|
/// statement.
|
||||||
|
pub trait FatalError: Error {}
|
||||||
|
|
||||||
|
/// Flow<A, FE, E> represents a return value that might be a success, might be a fatal error, or
|
||||||
|
/// might be a normal handleable error.
|
||||||
|
pub enum Flow<A, FE, E> {
|
||||||
|
/// The operation was successful
|
||||||
|
Ok(A),
|
||||||
|
/// The operation encountered a fatal error. These should be bubbled up to a level that can
|
||||||
|
/// safely shut the application down.
|
||||||
|
Fatal(FE),
|
||||||
|
/// Ordinary errors. These should be handled and the application should recover gracefully.
|
||||||
|
Err(E),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A, FE, E> Flow<A, FE, E> {
|
||||||
|
/// Apply an infallible function to a successful value.
|
||||||
|
pub fn map<B, O>(self, mapper: O) -> Flow<B, FE, E>
|
||||||
|
where
|
||||||
|
O: FnOnce(A) -> B,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Flow::Ok(val) => Flow::Ok(mapper(val)),
|
||||||
|
Flow::Fatal(err) => Flow::Fatal(err),
|
||||||
|
Flow::Err(err) => Flow::Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply a potentially fallible function to a successful value.
|
||||||
|
///
|
||||||
|
/// Like `Result.and_then`, the mapping function can itself fail.
|
||||||
|
pub fn and_then<B, O>(self, handler: O) -> Flow<B, FE, E>
|
||||||
|
where
|
||||||
|
O: FnOnce(A) -> Flow<B, FE, E>,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Flow::Ok(val) => handler(val),
|
||||||
|
Flow::Fatal(err) => Flow::Fatal(err),
|
||||||
|
Flow::Err(err) => Flow::Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Map a normal error from one type to another. This is useful for converting an error from
|
||||||
|
/// one type to another, especially in re-throwing an underlying error. `?` syntax does not
|
||||||
|
/// work with `Flow`, so you will likely need to use this a lot.
|
||||||
|
pub fn map_err<F, O>(self, mapper: O) -> Flow<A, FE, F>
|
||||||
|
where
|
||||||
|
O: FnOnce(E) -> F,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Flow::Ok(val) => Flow::Ok(val),
|
||||||
|
Flow::Fatal(err) => Flow::Fatal(err),
|
||||||
|
Flow::Err(err) => Flow::Err(mapper(err)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provide a function to use to recover from (or simply re-throw) an error.
|
||||||
|
pub fn or_else<O, F>(self, handler: O) -> Flow<A, FE, F>
|
||||||
|
where
|
||||||
|
O: FnOnce(E) -> Flow<A, FE, F>,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Flow::Ok(val) => Flow::Ok(val),
|
||||||
|
Flow::Fatal(err) => Flow::Fatal(err),
|
||||||
|
Flow::Err(err) => handler(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert from a normal `Result` type to a `Flow` type. The error condition for a `Result` will
|
||||||
|
/// be treated as `Flow::Err`, never `Flow::Fatal`.
|
||||||
|
impl<A, FE, E> From<Result<A, E>> for Flow<A, FE, E> {
|
||||||
|
fn from(r: Result<A, E>) -> Self {
|
||||||
|
match r {
|
||||||
|
Ok(val) => Flow::Ok(val),
|
||||||
|
Err(err) => Flow::Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A, FE, E> fmt::Debug for Flow<A, FE, E>
|
||||||
|
where
|
||||||
|
A: fmt::Debug,
|
||||||
|
FE: fmt::Debug,
|
||||||
|
E: fmt::Debug,
|
||||||
|
{
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Flow::Ok(val) => f.write_fmt(format_args!("Flow::Ok {:?}", val)),
|
||||||
|
Flow::Err(err) => f.write_fmt(format_args!("Flow::Err {:?}", err)),
|
||||||
|
Flow::Fatal(err) => f.write_fmt(format_args!("Flow::Fatal {:?}", err)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A, FE, E> PartialEq for Flow<A, FE, E>
|
||||||
|
where
|
||||||
|
A: PartialEq,
|
||||||
|
FE: PartialEq,
|
||||||
|
E: PartialEq,
|
||||||
|
{
|
||||||
|
fn eq(&self, rhs: &Self) -> bool {
|
||||||
|
match (self, rhs) {
|
||||||
|
(Flow::Ok(val), Flow::Ok(rhs)) => val == rhs,
|
||||||
|
(Flow::Err(_), Flow::Err(_)) => true,
|
||||||
|
(Flow::Fatal(_), Flow::Fatal(_)) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience function to create an ok value.
|
||||||
|
pub fn ok<A, FE: FatalError, E: Error>(val: A) -> Flow<A, FE, E> {
|
||||||
|
Flow::Ok(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience function to create an error value.
|
||||||
|
pub fn error<A, FE: FatalError, E: Error>(err: E) -> Flow<A, FE, E> {
|
||||||
|
Flow::Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience function to create a fatal value.
|
||||||
|
pub fn fatal<A, FE: FatalError, E: Error>(err: FE) -> Flow<A, FE, E> {
|
||||||
|
Flow::Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return early from the current function if the value is a fatal error.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! return_fatal {
|
||||||
|
($x:expr) => {
|
||||||
|
match $x {
|
||||||
|
Flow::Fatal(err) => return Flow::Fatal(err),
|
||||||
|
Flow::Err(err) => Err(err),
|
||||||
|
Flow::Ok(val) => Ok(val),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
/// Return early from the current function is the value is an error.
|
||||||
|
macro_rules! return_error {
|
||||||
|
($x:expr) => {
|
||||||
|
match $x {
|
||||||
|
Flow::Ok(val) => val,
|
||||||
|
Flow::Err(err) => return Flow::Err(err),
|
||||||
|
Flow::Fatal(err) => return Flow::Fatal(err),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
enum FatalError {
|
||||||
|
#[error("A fatal error occurred")]
|
||||||
|
FatalError,
|
||||||
|
}
|
||||||
|
impl super::FatalError for FatalError {}
|
||||||
|
impl PartialEq for FatalError {
|
||||||
|
fn eq(&self, _rhs: &Self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
enum Error {
|
||||||
|
#[error("an error occurred")]
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
impl PartialEq for Error {
|
||||||
|
fn eq(&self, _rhs: &Self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_map_things() {
|
||||||
|
let success: Flow<i32, FatalError, Error> = ok(15);
|
||||||
|
assert_eq!(ok(16), success.map(|v| v + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_chain_success() {
|
||||||
|
let success: Flow<i32, FatalError, Error> = ok(15);
|
||||||
|
assert_eq!(ok(16), success.and_then(|v| ok(v + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_handle_an_error() {
|
||||||
|
let failure: Flow<i32, FatalError, Error> = error(Error::Error);
|
||||||
|
assert_eq!(
|
||||||
|
ok::<i32, FatalError, Error>(16),
|
||||||
|
failure.or_else(|_| ok(16))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn early_exit_on_fatal() {
|
||||||
|
fn ok_func() -> Flow<i32, FatalError, Error> {
|
||||||
|
let value = return_fatal!(ok::<i32, FatalError, Error>(15));
|
||||||
|
match value {
|
||||||
|
Ok(_) => ok(14),
|
||||||
|
Err(err) => error(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn err_func() -> Flow<i32, FatalError, Error> {
|
||||||
|
let value = return_fatal!(error::<i32, FatalError, Error>(Error::Error));
|
||||||
|
match value {
|
||||||
|
Ok(_) => panic!("shouldn't have gotten here"),
|
||||||
|
Err(_) => ok(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fatal_func() -> Flow<i32, FatalError, Error> {
|
||||||
|
return_fatal!(fatal::<i32, FatalError, Error>(FatalError::FatalError));
|
||||||
|
panic!("failed to bail");
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal_func();
|
||||||
|
assert_eq!(ok_func(), ok(14));
|
||||||
|
assert_eq!(err_func(), ok(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_early_exit_on_all_errors() {
|
||||||
|
fn ok_func() -> Flow<i32, FatalError, Error> {
|
||||||
|
let value = return_error!(ok::<i32, FatalError, Error>(15));
|
||||||
|
assert_eq!(value, 15);
|
||||||
|
ok(14)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn err_func() -> Flow<i32, FatalError, Error> {
|
||||||
|
return_error!(error::<i32, FatalError, Error>(Error::Error));
|
||||||
|
panic!("failed to bail");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fatal_func() -> Flow<i32, FatalError, Error> {
|
||||||
|
return_error!(fatal::<i32, FatalError, Error>(FatalError::FatalError));
|
||||||
|
panic!("failed to bail");
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal_func();
|
||||||
|
assert_eq!(ok_func(), ok(14));
|
||||||
|
err_func();
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,8 @@ authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
description = "An ergonomics wrapper around Fluent-RS"
|
description = "An ergonomics wrapper around Fluent-RS"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "GPL-3.0-only"
|
||||||
|
license-file = "../COPYING"
|
||||||
homepage = "https://github.com/luminescent-dreams/fluent-ergonomics"
|
homepage = "https://github.com/luminescent-dreams/fluent-ergonomics"
|
||||||
repository = "https://github.com/luminescent-dreams/fluent-ergonomics"
|
repository = "https://github.com/luminescent-dreams/fluent-ergonomics"
|
||||||
categories = ["internationalization"]
|
categories = ["internationalization"]
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
//! Provide a more ergonomic interface to the base Fluent library
|
//! Provide a more ergonomic interface to the base Fluent library
|
||||||
//!
|
//!
|
||||||
//! The Fluent class makes it easier to load translation bundles with language fallbacks and to go
|
//! The Fluent class makes it easier to load translation bundles with language fallbacks and to go
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "hex-grid"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
license-file = "../COPYING"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cairo-rs = "0.16"
|
||||||
|
gio = "0.16"
|
||||||
|
glib = "0.16"
|
||||||
|
gtk = { version = "0.5", package = "gtk4" }
|
||||||
|
coordinates = { path = "../coordinates" }
|
||||||
|
image = { version = "0.24" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
glib-build-tools = "0.16"
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() {
|
||||||
|
glib_build_tools::compile_resources(
|
||||||
|
"resources",
|
||||||
|
"resources/resources.gresources.xml",
|
||||||
|
"com.luminescent-dreams.hex-grid.gresource",
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
[0, 0] m
|
||||||
|
[-3, 2] sw
|
||||||
|
[1, -2] g
|
||||||
|
[0, 3] g
|
||||||
|
[2, 1] g
|
||||||
|
[0, -2] g
|
||||||
|
[-1, 0] g
|
||||||
|
[-2, 2] g
|
||||||
|
[3, -3] sw
|
||||||
|
[1, 2] g
|
||||||
|
[1, 1] d
|
||||||
|
[2, -2] b
|
||||||
|
[-3, 0] sw
|
||||||
|
[-2, 0] g
|
||||||
|
[2, -3] sw
|
||||||
|
[-1, -1] g
|
||||||
|
[-2, 3] sw
|
||||||
|
[1, -3] sw
|
||||||
|
[-3, 3] sw
|
||||||
|
[-1, 1] g
|
||||||
|
[1, 0] g
|
||||||
|
[0, 1] g
|
||||||
|
[-1, 2] s
|
||||||
|
[1, -1] g
|
||||||
|
[2, -1] g
|
||||||
|
[0, -3] sw
|
||||||
|
[0, 2] g
|
||||||
|
[3, 0] sw
|
||||||
|
[-1, 3] sw
|
||||||
|
[0, -1] g
|
||||||
|
[3, -1] sw
|
||||||
|
[-3, 1] sw
|
||||||
|
[2, 0] g
|
||||||
|
[-2, 1] g
|
||||||
|
[3, -2] sw
|
||||||
|
[-1, -2] sw
|
||||||
|
[-2, -1] dw
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/com/luminescent-dreams/hex-grid/">
|
||||||
|
<file>terrain.ppm</file>
|
||||||
|
<file>map.txt</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
gtk::init();
|
||||||
|
for name in gtk::IconTheme::new().icon_names() {
|
||||||
|
println!("{}", name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
use glib::Object;
|
||||||
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct LabeledFieldPrivate {
|
||||||
|
value: gtk::Label,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for LabeledFieldPrivate {
|
||||||
|
const NAME: &'static str = "LabeledField";
|
||||||
|
type Type = LabeledField;
|
||||||
|
type ParentType = gtk::Box;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for LabeledFieldPrivate {}
|
||||||
|
impl WidgetImpl for LabeledFieldPrivate {}
|
||||||
|
impl BoxImpl for LabeledFieldPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct LabeledField(ObjectSubclass<LabeledFieldPrivate>) @extends gtk::Box, gtk::Widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LabeledField {
|
||||||
|
pub fn new(label: &str, default_value: &str) -> Self {
|
||||||
|
let field: Self = Object::builder().build();
|
||||||
|
field.set_hexpand(true);
|
||||||
|
field.set_spacing(8);
|
||||||
|
field.set_homogeneous(true);
|
||||||
|
field.append(>k::Label::new(Some(label)));
|
||||||
|
field.append(&field.imp().value);
|
||||||
|
field.imp().value.set_label(default_value);
|
||||||
|
field
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_value(&self, value: &str) {
|
||||||
|
self.imp().value.set_label(value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,282 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use cairo::Context;
|
||||||
|
use coordinates::{hex_map::parse_data, AxialAddr};
|
||||||
|
use gio::resources_lookup_data;
|
||||||
|
use glib::{subclass::InitializingObject, Object};
|
||||||
|
use gtk::{gio, prelude::*, subclass::prelude::*, Application, DrawingArea};
|
||||||
|
use image::io::Reader as ImageReader;
|
||||||
|
use std::{cell::RefCell, io::Cursor, rc::Rc};
|
||||||
|
|
||||||
|
mod labeled_field;
|
||||||
|
mod palette_entry;
|
||||||
|
mod tile;
|
||||||
|
mod utilities;
|
||||||
|
|
||||||
|
const APP_ID: &'static str = "com.luminescent-dreams.hex-grid";
|
||||||
|
const HEX_RADIUS: f64 = 50.;
|
||||||
|
const MAP_RADIUS: usize = 3;
|
||||||
|
const DRAWING_ORIGIN: (f64, f64) = (1024. / 2., 768. / 2.);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
gio::resources_register_include!("com.luminescent-dreams.hex-grid.gresource")
|
||||||
|
.expect("Failed to register resources");
|
||||||
|
|
||||||
|
let app = Application::builder().application_id(APP_ID).build();
|
||||||
|
|
||||||
|
app.connect_activate(|app| {
|
||||||
|
let window = HexGridWindow::new(app);
|
||||||
|
window.present();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HexGridWindowPrivate {
|
||||||
|
layout: gtk::Box,
|
||||||
|
palette: gtk::Box,
|
||||||
|
|
||||||
|
drawing_area: DrawingArea,
|
||||||
|
hex_address: labeled_field::LabeledField,
|
||||||
|
canvas_address: labeled_field::LabeledField,
|
||||||
|
|
||||||
|
current_coordinate: Rc<RefCell<Option<AxialAddr>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for HexGridWindowPrivate {
|
||||||
|
const NAME: &'static str = "HexGridWindow";
|
||||||
|
type Type = HexGridWindow;
|
||||||
|
type ParentType = gtk::ApplicationWindow;
|
||||||
|
|
||||||
|
fn new() -> Self {
|
||||||
|
println!("hexGridWindowPrivate::new()");
|
||||||
|
let current_coordinate = Rc::new(RefCell::new(None));
|
||||||
|
|
||||||
|
let drawing_area = DrawingArea::builder()
|
||||||
|
.width_request(1024)
|
||||||
|
.height_request(768)
|
||||||
|
.margin_start(8)
|
||||||
|
.margin_end(8)
|
||||||
|
.margin_top(8)
|
||||||
|
.margin_bottom(8)
|
||||||
|
.hexpand(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let layout = gtk::Box::builder()
|
||||||
|
.homogeneous(false)
|
||||||
|
.spacing(8)
|
||||||
|
.can_focus(false)
|
||||||
|
.visible(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let sidebar = gtk::Box::builder()
|
||||||
|
.orientation(gtk::Orientation::Vertical)
|
||||||
|
.width_request(100)
|
||||||
|
.visible(true)
|
||||||
|
.can_focus(false)
|
||||||
|
.margin_start(4)
|
||||||
|
.margin_end(4)
|
||||||
|
.margin_top(4)
|
||||||
|
.margin_bottom(4)
|
||||||
|
.spacing(8)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let canvas_address = labeled_field::LabeledField::new("Canvas Address", "-----");
|
||||||
|
let hex_address = labeled_field::LabeledField::new("Hex Address", "-----");
|
||||||
|
|
||||||
|
let palette = gtk::Box::builder()
|
||||||
|
.spacing(8)
|
||||||
|
.orientation(gtk::Orientation::Vertical)
|
||||||
|
.hexpand(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
sidebar.append(&canvas_address);
|
||||||
|
sidebar.append(&hex_address);
|
||||||
|
sidebar.append(&palette);
|
||||||
|
|
||||||
|
layout.append(&drawing_area);
|
||||||
|
layout.append(&sidebar);
|
||||||
|
|
||||||
|
layout.show();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
drawing_area,
|
||||||
|
hex_address,
|
||||||
|
canvas_address,
|
||||||
|
current_coordinate,
|
||||||
|
layout,
|
||||||
|
palette,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for HexGridWindowPrivate {
|
||||||
|
fn constructed(&self) {
|
||||||
|
println!("HexGridWindowPrivate::constructed()");
|
||||||
|
self.parent_constructed();
|
||||||
|
|
||||||
|
let map_text_resource = resources_lookup_data(
|
||||||
|
"/com/luminescent-dreams/hex-grid/map.txt",
|
||||||
|
gio::ResourceLookupFlags::NONE,
|
||||||
|
)
|
||||||
|
.expect("map should be in the bundle")
|
||||||
|
.to_vec();
|
||||||
|
|
||||||
|
let hex_map =
|
||||||
|
parse_data::<tile::Terrain>(String::from_utf8(map_text_resource).unwrap().lines());
|
||||||
|
|
||||||
|
let terrain_data = resources_lookup_data(
|
||||||
|
"/com/luminescent-dreams/hex-grid/terrain.ppm",
|
||||||
|
gio::ResourceLookupFlags::NONE,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let reader = ImageReader::new(Cursor::new(terrain_data))
|
||||||
|
.with_guessed_format()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let image = reader.decode().unwrap();
|
||||||
|
let badlands = tile::Tile::new(&image, tile::Terrain::Badlands);
|
||||||
|
let deep_water = tile::Tile::new(&image, tile::Terrain::DeepWater);
|
||||||
|
let desert = tile::Tile::new(&image, tile::Terrain::Desert);
|
||||||
|
let grasslands = tile::Tile::new(&image, tile::Terrain::Grasslands);
|
||||||
|
let mountain = tile::Tile::new(&image, tile::Terrain::Mountain);
|
||||||
|
let shallow_water = tile::Tile::new(&image, tile::Terrain::ShallowWater);
|
||||||
|
let swamp = tile::Tile::new(&image, tile::Terrain::Swamp);
|
||||||
|
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&badlands));
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&deep_water));
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&desert));
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&grasslands));
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&mountain));
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&shallow_water));
|
||||||
|
self.palette
|
||||||
|
.append(&palette_entry::PaletteEntry::new(&swamp));
|
||||||
|
|
||||||
|
let motion_controller = gtk::EventControllerMotion::new();
|
||||||
|
{
|
||||||
|
let canvas_address = self.canvas_address.clone();
|
||||||
|
let hex_address = self.hex_address.clone();
|
||||||
|
let c = self.current_coordinate.clone();
|
||||||
|
motion_controller.connect_motion(move |_, x, y| {
|
||||||
|
let norm_x = x - DRAWING_ORIGIN.0;
|
||||||
|
let norm_y = y - DRAWING_ORIGIN.1;
|
||||||
|
let q = (2. / 3. * norm_x) / HEX_RADIUS;
|
||||||
|
let r = (-1. / 3. * norm_x + (3. as f64).sqrt() / 3. * norm_y) / HEX_RADIUS;
|
||||||
|
|
||||||
|
let (q, r) = axial_round(q, r);
|
||||||
|
let coordinate = AxialAddr::new(q, r);
|
||||||
|
canvas_address.set_value(&format!("{:.0} {:.0}", x, y));
|
||||||
|
|
||||||
|
if coordinate.distance(&AxialAddr::origin()) > MAP_RADIUS {
|
||||||
|
hex_address.set_value(&format!("-----"));
|
||||||
|
*c.borrow_mut() = None;
|
||||||
|
} else {
|
||||||
|
hex_address.set_value(&format!("{:.0} {:.0}", coordinate.q(), coordinate.r()));
|
||||||
|
*c.borrow_mut() = Some(coordinate);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
self.drawing_area.set_draw_func(move |_, context, _, _| {
|
||||||
|
context.set_source_rgb(0., 0., 0.);
|
||||||
|
let _ = context.paint();
|
||||||
|
|
||||||
|
context.set_line_width(2.);
|
||||||
|
|
||||||
|
for coordinate in vec![AxialAddr::origin()]
|
||||||
|
.into_iter()
|
||||||
|
.chain(AxialAddr::origin().addresses(MAP_RADIUS))
|
||||||
|
{
|
||||||
|
let center_x =
|
||||||
|
DRAWING_ORIGIN.0 + HEX_RADIUS * (3. / 2. * (coordinate.q() as f64));
|
||||||
|
let center_y = DRAWING_ORIGIN.1
|
||||||
|
+ HEX_RADIUS
|
||||||
|
* ((3. as f64).sqrt() / 2. * (coordinate.q() as f64)
|
||||||
|
+ (3. as f64).sqrt() * (coordinate.r() as f64));
|
||||||
|
let translate_x = center_x - HEX_RADIUS;
|
||||||
|
let translate_y = center_y - (3. as f64).sqrt() * HEX_RADIUS / 2.;
|
||||||
|
|
||||||
|
let tile = match hex_map.get(&coordinate).unwrap() {
|
||||||
|
tile::Terrain::Mountain => &mountain,
|
||||||
|
tile::Terrain::Grasslands => &grasslands,
|
||||||
|
tile::Terrain::ShallowWater => &shallow_water,
|
||||||
|
tile::Terrain::DeepWater => &deep_water,
|
||||||
|
tile::Terrain::Badlands => &badlands,
|
||||||
|
tile::Terrain::Desert => &desert,
|
||||||
|
tile::Terrain::Swamp => &swamp,
|
||||||
|
_ => panic!("unhandled terrain type"),
|
||||||
|
};
|
||||||
|
tile.render_on_context(context, translate_x, translate_y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
self.drawing_area.add_controller(&motion_controller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WidgetImpl for HexGridWindowPrivate {}
|
||||||
|
impl WindowImpl for HexGridWindowPrivate {}
|
||||||
|
impl ApplicationWindowImpl for HexGridWindowPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct HexGridWindow(ObjectSubclass<HexGridWindowPrivate>) @extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||||
|
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HexGridWindow {
|
||||||
|
pub fn new(app: &Application) -> Self {
|
||||||
|
let window: Self = Object::builder().property("application", app).build();
|
||||||
|
window.set_child(Some(&window.imp().layout));
|
||||||
|
window
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_hexagon(context: &Context, center_x: f64, center_y: f64, radius: f64) {
|
||||||
|
let ul_x = center_x - radius;
|
||||||
|
let ul_y = center_y - (3. as f64).sqrt() * radius / 2.;
|
||||||
|
let points: Vec<(f64, f64)> = utilities::hexagon(radius * 2., (3. as f64).sqrt() * radius);
|
||||||
|
context.new_path();
|
||||||
|
context.move_to(ul_x + points[0].0, ul_y + points[0].1);
|
||||||
|
context.line_to(ul_x + points[1].0, ul_y + points[1].1);
|
||||||
|
context.line_to(ul_x + points[2].0, ul_y + points[2].1);
|
||||||
|
context.line_to(ul_x + points[3].0, ul_y + points[3].1);
|
||||||
|
context.line_to(ul_x + points[4].0, ul_y + points[4].1);
|
||||||
|
context.line_to(ul_x + points[5].0, ul_y + points[5].1);
|
||||||
|
context.close_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn axial_round(q_f64: f64, r_f64: f64) -> (i32, i32) {
|
||||||
|
let s_f64 = -q_f64 - r_f64;
|
||||||
|
let mut q = q_f64.round();
|
||||||
|
let mut r = r_f64.round();
|
||||||
|
let s = s_f64.round();
|
||||||
|
|
||||||
|
let q_diff = (q - q_f64).abs();
|
||||||
|
let r_diff = (r - r_f64).abs();
|
||||||
|
let s_diff = (s - s_f64).abs();
|
||||||
|
|
||||||
|
if q_diff > r_diff && q_diff > s_diff {
|
||||||
|
q = -r - s;
|
||||||
|
} else if r_diff > s_diff {
|
||||||
|
r = -q - s;
|
||||||
|
}
|
||||||
|
unsafe { (q.to_int_unchecked::<i32>(), r.to_int_unchecked::<i32>()) }
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
use crate::tile;
|
||||||
|
use glib::Object;
|
||||||
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
|
pub struct PaletteEntryPrivate {
|
||||||
|
terrain: Rc<RefCell<tile::Terrain>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for PaletteEntryPrivate {
|
||||||
|
const NAME: &'static str = "PaletteEntry";
|
||||||
|
type Type = PaletteEntry;
|
||||||
|
type ParentType = gtk::ListBoxRow;
|
||||||
|
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
terrain: Rc::new(RefCell::new(tile::Terrain::Empty)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for PaletteEntryPrivate {}
|
||||||
|
impl WidgetImpl for PaletteEntryPrivate {}
|
||||||
|
impl ListBoxRowImpl for PaletteEntryPrivate {
|
||||||
|
fn activate(&self) {
|
||||||
|
println!("row activated: {:?}", self.terrain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct PaletteEntry(ObjectSubclass<PaletteEntryPrivate>) @extends gtk::ListBoxRow, gtk::Widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PaletteEntry {
|
||||||
|
pub fn new(tile: &tile::Tile) -> Self {
|
||||||
|
let row: Self = Object::builder().build();
|
||||||
|
*row.imp().terrain.borrow_mut() = tile.terrain.clone();
|
||||||
|
let layout = gtk::Box::builder().spacing(8).build();
|
||||||
|
|
||||||
|
let image = gtk::Image::from_pixbuf(Some(&tile.image));
|
||||||
|
image.set_width_request(100);
|
||||||
|
image.set_height_request(88);
|
||||||
|
|
||||||
|
layout.append(&image);
|
||||||
|
layout.append(>k::Label::new(Some(&String::from(&tile.terrain))));
|
||||||
|
|
||||||
|
row.set_child(Some(&layout));
|
||||||
|
|
||||||
|
row
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
use crate::utilities;
|
||||||
|
use cairo::Context;
|
||||||
|
use gtk::{gdk_pixbuf::Pixbuf, prelude::*};
|
||||||
|
use image::DynamicImage;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum Terrain {
|
||||||
|
Badlands,
|
||||||
|
DeepWater,
|
||||||
|
Desert,
|
||||||
|
Empty,
|
||||||
|
Grasslands,
|
||||||
|
Mountain,
|
||||||
|
ShallowWater,
|
||||||
|
Swamp,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Terrain {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for Terrain {
|
||||||
|
fn from(s: &str) -> Self {
|
||||||
|
match s {
|
||||||
|
"m" => Self::Mountain,
|
||||||
|
"g" => Self::Grasslands,
|
||||||
|
"sw" => Self::ShallowWater,
|
||||||
|
"dw" => Self::DeepWater,
|
||||||
|
"b" => Self::Badlands,
|
||||||
|
"d" => Self::Desert,
|
||||||
|
"s" => Self::Swamp,
|
||||||
|
_ => Self::Empty,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<String> for Terrain {
|
||||||
|
fn from(s: String) -> Self {
|
||||||
|
Self::from(s.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Terrain> for String {
|
||||||
|
fn from(t: &Terrain) -> Self {
|
||||||
|
match t {
|
||||||
|
Terrain::Badlands => "Badlands",
|
||||||
|
Terrain::DeepWater => "Deep Water",
|
||||||
|
Terrain::Desert => "Desert",
|
||||||
|
Terrain::Empty => "Empty",
|
||||||
|
Terrain::Grasslands => "Grasslands",
|
||||||
|
Terrain::Mountain => "Mountain",
|
||||||
|
Terrain::ShallowWater => "Shallow Water",
|
||||||
|
Terrain::Swamp => "Swamp",
|
||||||
|
}
|
||||||
|
.to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Tile {
|
||||||
|
pub terrain: Terrain,
|
||||||
|
pub image: Pixbuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tile {
|
||||||
|
pub fn new(source: &DynamicImage, terrain: Terrain) -> Tile {
|
||||||
|
let image = match terrain {
|
||||||
|
Terrain::DeepWater => pixbuf_from_image_tile(source.clone().crop(0, 0, 100, 88)),
|
||||||
|
Terrain::ShallowWater => pixbuf_from_image_tile(source.clone().crop(100, 0, 100, 88)),
|
||||||
|
Terrain::Grasslands => pixbuf_from_image_tile(source.clone().crop(200, 0, 100, 88)),
|
||||||
|
Terrain::Desert => pixbuf_from_image_tile(source.clone().crop(300, 0, 100, 88)),
|
||||||
|
Terrain::Mountain => pixbuf_from_image_tile(source.clone().crop(0, 88, 100, 88)),
|
||||||
|
Terrain::Badlands => pixbuf_from_image_tile(source.clone().crop(100, 88, 100, 88)),
|
||||||
|
Terrain::Swamp => pixbuf_from_image_tile(source.clone().crop(0, 176, 100, 88)),
|
||||||
|
Terrain::Empty => pixbuf_from_image_tile(source.clone().crop(300, 176, 100, 88)),
|
||||||
|
};
|
||||||
|
|
||||||
|
Tile { terrain, image }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render_on_context(&self, context: &Context, translate_x: f64, translate_y: f64) {
|
||||||
|
context.save().unwrap();
|
||||||
|
context.append_path(&utilities::hexagon_path(
|
||||||
|
context,
|
||||||
|
translate_x,
|
||||||
|
translate_y,
|
||||||
|
100.,
|
||||||
|
88.,
|
||||||
|
));
|
||||||
|
context.clip();
|
||||||
|
context.set_source_pixbuf(&self.image, translate_x, translate_y);
|
||||||
|
context.paint().expect("paint should succeed");
|
||||||
|
context.restore().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pixbuf_from_image_tile(image: image::DynamicImage) -> Pixbuf {
|
||||||
|
Pixbuf::from_bytes(
|
||||||
|
&glib::Bytes::from(image.as_bytes()),
|
||||||
|
gtk::gdk_pixbuf::Colorspace::Rgb,
|
||||||
|
false,
|
||||||
|
8,
|
||||||
|
image.width() as i32,
|
||||||
|
image.height() as i32,
|
||||||
|
image.to_rgb8().sample_layout().height_stride as i32,
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
use cairo::{Context, Path};
|
||||||
|
|
||||||
|
pub fn hexagon_path(
|
||||||
|
context: &Context,
|
||||||
|
translate_x: f64,
|
||||||
|
translate_y: f64,
|
||||||
|
width: f64,
|
||||||
|
height: f64,
|
||||||
|
) -> Path {
|
||||||
|
context.new_path();
|
||||||
|
let points = hexagon(width, height);
|
||||||
|
context.move_to(translate_x + points[0].0, translate_y + points[0].1);
|
||||||
|
context.line_to(translate_x + points[1].0, translate_y + points[1].1);
|
||||||
|
context.line_to(translate_x + points[2].0, translate_y + points[2].1);
|
||||||
|
context.line_to(translate_x + points[3].0, translate_y + points[3].1);
|
||||||
|
context.line_to(translate_x + points[4].0, translate_y + points[4].1);
|
||||||
|
context.line_to(translate_x + points[5].0, translate_y + points[5].1);
|
||||||
|
context.copy_path().expect("to successfully copy a path")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hexagon(width: f64, height: f64) -> Vec<(f64, f64)> {
|
||||||
|
let center_x = width / 2.;
|
||||||
|
let center_y = height / 2.;
|
||||||
|
let radius = width / 2.;
|
||||||
|
|
||||||
|
vec![
|
||||||
|
(center_x + radius, center_y),
|
||||||
|
(
|
||||||
|
center_x + radius / 2.,
|
||||||
|
center_y + (3. as f64).sqrt() * radius / 2.,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
center_x - radius / 2.,
|
||||||
|
center_y + (3. as f64).sqrt() * radius / 2.,
|
||||||
|
),
|
||||||
|
(center_x - radius, center_y),
|
||||||
|
(
|
||||||
|
center_x - radius / 2.,
|
||||||
|
center_y - (3. as f64).sqrt() * radius / 2.,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
center_x + radius / 2.,
|
||||||
|
center_y - (3. as f64).sqrt() * radius / 2.,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
keywords = ["date", "time", "calendar"]
|
keywords = ["date", "time", "calendar"]
|
||||||
categories = ["date-and-time"]
|
categories = ["date-and-time"]
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
license-file = "../COPYING"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4" }
|
chrono = { version = "0.4" }
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
use chrono::{Datelike, NaiveDate};
|
use chrono::{Datelike, NaiveDate};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate chrono_tz;
|
extern crate chrono_tz;
|
||||||
extern crate international_fixed_calendar as IFC;
|
extern crate international_fixed_calendar as IFC;
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of the Luminescent Dreams Tools.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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.
|
||||||
|
|
||||||
|
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
use chrono::{Datelike, Utc};
|
use chrono::{Datelike, Utc};
|
||||||
use international_fixed_calendar as IFC;
|
use international_fixed_calendar as IFC;
|
||||||
use iron::headers;
|
use iron::headers;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
SOURCES = $(shell find ../core -name "*.rs")
|
||||||
|
dist/index.ts: $(SOURCES)
|
||||||
|
mkdir -p dist
|
||||||
|
typeshare ../core --lang=typescript --output-file=dist/index.ts
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"name": "core-types",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"types": "dist/index.ts",
|
||||||
|
"main": "dist/index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"build": "make",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "Savanni D'Gerinel <savanni@luminescent-dreams.com>",
|
||||||
|
"license": "GPL-3.0-or-later"
|
||||||
|
}
|
|
@ -0,0 +1,591 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_system_properties"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bumpalo"
|
||||||
|
version = "3.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.79"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
|
||||||
|
dependencies = [
|
||||||
|
"iana-time-zone",
|
||||||
|
"js-sys",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"serde",
|
||||||
|
"time",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "codespan-reporting"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
|
||||||
|
dependencies = [
|
||||||
|
"termcolor",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cool_asserts"
|
||||||
|
version = "2.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee9f254e53f61e2688d3677fa2cbe4e9b950afd56f48819c98817417cf6b28ec"
|
||||||
|
dependencies = [
|
||||||
|
"indent_write",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxx"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"cxxbridge-flags",
|
||||||
|
"cxxbridge-macro",
|
||||||
|
"link-cplusplus",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxx-build"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"codespan-reporting",
|
||||||
|
"once_cell",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"scratch",
|
||||||
|
"syn 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxxbridge-flags"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxxbridge-macro"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "grid"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0634107a3a005070dd73e27e74ecb691a94e9e5ba7829f434db7fbf73a6b5c47"
|
||||||
|
dependencies = [
|
||||||
|
"no-std-compat",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone"
|
||||||
|
version = "0.1.56"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
|
||||||
|
dependencies = [
|
||||||
|
"android_system_properties",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"iana-time-zone-haiku",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone-haiku"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
|
||||||
|
dependencies = [
|
||||||
|
"cxx",
|
||||||
|
"cxx-build",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indent_write"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0cfe9645a18782869361d9c8732246be7b410ad4e919d3609ebabdac00ba12c3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "js-sys"
|
||||||
|
version = "0.3.61"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
|
||||||
|
dependencies = [
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kifu-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"cool_asserts",
|
||||||
|
"grid",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sgf",
|
||||||
|
"thiserror",
|
||||||
|
"typeshare",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.140"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "link-cplusplus"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "no-std-compat"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.17.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.52"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scratch"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.162"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.162"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.96"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sgf"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"nom",
|
||||||
|
"serde",
|
||||||
|
"thiserror",
|
||||||
|
"typeshare",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typeshare"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f44d1a2f454cb35fbe05b218c410792697e76bd868f48d3a418f2cd1a7d527d6"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"typeshare-annotation",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typeshare-annotation"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc670d0e358428857cc3b4bf504c691e572fccaec9542ff09212d3f13d74b7a9"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.10.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"wasm-bindgen-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-backend"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro-support"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-shared"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
|
@ -0,0 +1,18 @@
|
||||||
|
[package]
|
||||||
|
name = "kifu-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = { version = "0.4" }
|
||||||
|
sgf = { path = "../../sgf" }
|
||||||
|
grid = { version = "0.9" }
|
||||||
|
serde_json = { version = "1" }
|
||||||
|
serde = { version = "1", features = [ "derive" ] }
|
||||||
|
thiserror = { version = "1" }
|
||||||
|
typeshare = { version = "1" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
cool_asserts = { version = "2" }
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo watch -x 'nextest run'
|
||||||
|
|
||||||
|
test-oneshot:
|
||||||
|
cargo nextest run
|
|
@ -0,0 +1,432 @@
|
||||||
|
(;FF[4]
|
||||||
|
CA[UTF-8]
|
||||||
|
GM[1]
|
||||||
|
GN[2019 Masters R7 B1]
|
||||||
|
PC[https://online-go.com/review/404377]
|
||||||
|
PB[Zhongfan Jian]
|
||||||
|
PW[Mark Lee]
|
||||||
|
BR[7d]
|
||||||
|
WR[7d]
|
||||||
|
TM[0]OT[0 none]
|
||||||
|
RE[B+R]
|
||||||
|
SZ[19]
|
||||||
|
KM[7.5]
|
||||||
|
RU[AGA]
|
||||||
|
C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
krnzmb: hi
|
||||||
|
FrostedNuke: hi
|
||||||
|
USGO1: Hello! As most of you know, this is the final round of the US Open Master's division at the US Go Congress between Mark Lee 7d (w) and Zhongfan Jian 7d (b)
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[dp]
|
||||||
|
;W[pp]
|
||||||
|
;B[dd]
|
||||||
|
;W[pd]
|
||||||
|
;B[nc]
|
||||||
|
;W[fc]
|
||||||
|
;B[hc]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
snakesss: h16
|
||||||
|
BHydden: close
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[cc]
|
||||||
|
;B[dc]
|
||||||
|
;W[cd]
|
||||||
|
;B[de]
|
||||||
|
;W[db]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hardstone: Mark Lee is B?
|
||||||
|
hardstone: ok, W
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[eb]
|
||||||
|
;W[cb]
|
||||||
|
;B[fb]
|
||||||
|
;W[cf]
|
||||||
|
;B[qf]
|
||||||
|
;W[pf]
|
||||||
|
;B[pg]
|
||||||
|
;W[of]
|
||||||
|
;B[qd]
|
||||||
|
;W[qc]
|
||||||
|
;B[qe]
|
||||||
|
;W[pb]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
MeiGuoTang: crosstabs
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[og]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
MeiGuoTang: please
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[md]
|
||||||
|
;B[qn]
|
||||||
|
;W[jc]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
shipshape: https://www.usgo.org/tournaments/crosstab/band-matrix/187
|
||||||
|
snakesss: lol he played the only move i just checked on my bot and saw was a bad one
|
||||||
|
snakesss: feels good to have the same bad instinct as a pro
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[nq]
|
||||||
|
;W[pn]
|
||||||
|
;B[pm]
|
||||||
|
;W[on]
|
||||||
|
;B[qp]
|
||||||
|
;W[gc]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: tenuki from the lower right is very interesting
|
||||||
|
snakesss: "interesting" like "haylee
|
||||||
|
snakesss: 's interestings"?
|
||||||
|
redreoicy: First guess is to make a ladder breaker to play r7
|
||||||
|
Cyanriddle: h16 would be simple
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gd]
|
||||||
|
;W[fd]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: so black resists the ladder
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gb]
|
||||||
|
;W[hd]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
redreoicy: but, i thought white's intention was to follow up a few more moves than just g17 before playing r7
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[id]
|
||||||
|
;W[ge]
|
||||||
|
;B[ic]
|
||||||
|
;W[qm]
|
||||||
|
;B[qo]
|
||||||
|
;W[pl]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
redreoicy: ok g15 makes a lot more sense
|
||||||
|
USGO1: Sorry about that, table shook a bit as I placed G15
|
||||||
|
BHydden: if you're the pedantic type, you can click onto the wrong move 40 and then click the trashcan :)
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[hf]
|
||||||
|
;W[om]
|
||||||
|
;B[df]
|
||||||
|
;W[cg]
|
||||||
|
;B[fg]
|
||||||
|
;W[oq]
|
||||||
|
;B[qr]
|
||||||
|
;W[pr]
|
||||||
|
;B[fq]
|
||||||
|
;W[pe]
|
||||||
|
;B[qi]
|
||||||
|
;W[ie]
|
||||||
|
;B[jd]
|
||||||
|
;W[he]
|
||||||
|
;B[mc]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO1: Zhongfan put that one down with no small amount of vigor
|
||||||
|
BHydden: this area is mine, don't at me
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[hg]
|
||||||
|
;B[oc]
|
||||||
|
;W[pc]
|
||||||
|
;B[ld]
|
||||||
|
;W[if]
|
||||||
|
;B[jp]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: white upper right right not having local live has got to feel annoying for white
|
||||||
|
BHydden: eh, he tenukid from an approach... it's to be expected, right?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[bp]
|
||||||
|
;B[cp]
|
||||||
|
;W[bo]
|
||||||
|
;B[bq]
|
||||||
|
;W[br]
|
||||||
|
;B[cq]
|
||||||
|
;W[cl]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: it used to be okay,but black got to dig out the top area while white had to defend the center group
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[dk]
|
||||||
|
;W[ck]
|
||||||
|
;B[dj]
|
||||||
|
;W[dn]
|
||||||
|
;B[cn]
|
||||||
|
;W[bn]
|
||||||
|
;B[dg]
|
||||||
|
;W[ho]
|
||||||
|
;B[iq]
|
||||||
|
;W[dh]
|
||||||
|
;B[ch]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
BHydden: quiet in here
|
||||||
|
hexahedron: friday night, not surprising :)
|
||||||
|
BHydden: final round of USGC, who could have more important plans than this? :D
|
||||||
|
USGO1: I agree with BHydden:)
|
||||||
|
BHydden: ;)
|
||||||
|
USGO1: Mark has used more than half his time, now being at 42 minutes
|
||||||
|
xed_over: on this one move? :)
|
||||||
|
hexahedron: maybe white didn't expect this move by black
|
||||||
|
USGO1: I'm not sure about Zhongfan's time left, but he IS 2/3 of the way through a starbucks
|
||||||
|
USGO1: I'm now told by our fearless recording leader that Black has an hour and ten minutes left
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ei]
|
||||||
|
;B[bh]
|
||||||
|
;W[ce]
|
||||||
|
;B[fj]
|
||||||
|
;W[ej]
|
||||||
|
;B[ek]
|
||||||
|
;W[fi]
|
||||||
|
;B[di]
|
||||||
|
;W[eh]
|
||||||
|
;B[gi]
|
||||||
|
;W[gj]
|
||||||
|
;B[fk]
|
||||||
|
;W[gh]
|
||||||
|
;B[hi]
|
||||||
|
;W[fh]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
樱桃花: what's popping
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[bj]
|
||||||
|
;W[co]
|
||||||
|
;B[ec]
|
||||||
|
;W[hj]
|
||||||
|
;B[fn]
|
||||||
|
;W[aq]
|
||||||
|
;B[cr]
|
||||||
|
;W[bk]
|
||||||
|
;B[ii]
|
||||||
|
;W[ij]
|
||||||
|
;B[ji]
|
||||||
|
;W[jj]
|
||||||
|
;B[ki]
|
||||||
|
;W[eg]
|
||||||
|
;B[kj]
|
||||||
|
;W[hl]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: what did it say the % was at move 114?
|
||||||
|
hexahedron: around 95% for black
|
||||||
|
Falchion: wow, already that bad
|
||||||
|
hexahedron: keep in mind not to trust all these percents too much, we've seen in plenty of games at this tournament that it can swing quite a bit
|
||||||
|
hexahedron: bot is assuming superhuman-level tactics, in a sharp position it's very possible for one mistake to swing it all the way back to even
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[dm]
|
||||||
|
;W[cm]
|
||||||
|
;B[jl]
|
||||||
|
;W[jm]
|
||||||
|
;B[km]
|
||||||
|
;W[jn]
|
||||||
|
;B[kn]
|
||||||
|
;W[il]
|
||||||
|
;B[jk]
|
||||||
|
;W[kl]
|
||||||
|
;B[kk]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: last few moves feel good for B
|
||||||
|
hexahedron: KG says 97% for B (white lives in the middle, but black got a lot of profit
|
||||||
|
hexahedron: )
|
||||||
|
hexahedron: and connects his own group on the left in the process
|
||||||
|
hexahedron: we'll see what happens though, the tactics are so complicated
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[gn]
|
||||||
|
;B[en]
|
||||||
|
;W[dl]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: B would have to mess up pretty badly to throw such an advantage away though
|
||||||
|
hexahedron: after the last 3 moves KG is thinking the white group in the middle dies now
|
||||||
|
Falchion: ouch, that's even worse
|
||||||
|
hexahedron: it's not entirely confident though, territory map shows it as all blackish, but not completely
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[fm]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Zhadow: what is KG?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[jo]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: bot that is around LZ-ELFv2 strength, but with score estimation and territory prediction
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[ko]
|
||||||
|
;W[hq]
|
||||||
|
;B[in]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: oooh black's going for the kill!
|
||||||
|
Falchion: J5 here?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[io]
|
||||||
|
;B[gq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: G3 nice
|
||||||
|
Falchion: J4 now maybe?
|
||||||
|
hexahedron: no, J4 makes no eyeshape
|
||||||
|
hexahedron: all it would do is strengthen black and immediately kill any hope of black messing up
|
||||||
|
hexahedron: (the only point that J4 could help turn into an eye is H4, but notice how G3 and J3 already make H4 false)
|
||||||
|
hexahedron: do you see?
|
||||||
|
hexahedron: right, and that would help black
|
||||||
|
hexahedron: there's no ko
|
||||||
|
hexahedron: the only bit that remains not entirely clear to my lowly amateur reading is the L4 cut aji
|
||||||
|
hexahedron: but maybe I"m also missing some other variations
|
||||||
|
USGO1: The clock now tells us that Mark has only 10 minutes of main time remaining
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
(;W[fo]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: G5 then?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
)(;W[ip]
|
||||||
|
;B[jq]
|
||||||
|
;W[gr]
|
||||||
|
;B[hr]
|
||||||
|
;W[ir]
|
||||||
|
;B[hp]
|
||||||
|
;W[hs]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: J4 would make B play at K3 probably?
|
||||||
|
Falchion: maybe it sets up a ko
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
)(;W[gp]
|
||||||
|
;B[fp]
|
||||||
|
;W[kp]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: hey, he played your L4 cut
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[lp]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: ooh maybe white does have something
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[kq]
|
||||||
|
;B[lq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: hm, not sure it works tho
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[kr]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO1: Mark kept his finger on that stone for a long while before releaing and pressing the clock
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[hr]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO1: Zhongfan is now down to an eighth of his coffee
|
||||||
|
dy_baduk: hmmr
|
||||||
|
dy_baduk: j2 might actually be reasonable
|
||||||
|
hexahedron: ko?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ir]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: nice dy
|
||||||
|
hexahedron: I guess there might be a ko after all :)
|
||||||
|
Falchion: I think you found it
|
||||||
|
dy_baduk: lol
|
||||||
|
dy_baduk: it's cause I do a shit ton of tsumego
|
||||||
|
Falchion: wait, what about K2 next, does W still die?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
(;B[jq]
|
||||||
|
;W[ip]
|
||||||
|
;B[hp]
|
||||||
|
;W[fl]
|
||||||
|
;B[go]C[B+r
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: board is different tho
|
||||||
|
USGO1: W resigns
|
||||||
|
Falchion: ouch
|
||||||
|
hexahedron: congrats to black (zhongfan)
|
||||||
|
hexahedron: really nice play at the end
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
)(;B[jr]
|
||||||
|
;W[ip]
|
||||||
|
;B[is]
|
||||||
|
;W[jq]
|
||||||
|
;B[ir]
|
||||||
|
;W[lr]
|
||||||
|
;B[mr]
|
||||||
|
;W[lo]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
hexahedron: @Falchion - something like this. From move 0: D4 Q4 D16 Q16 O17 F17 H17 C17 D17 C16 D15 D18 E18 C18 F18 C14 R14 Q14 Q13 P14 R16 R17 R15 Q18 P13 N16 R6 K17 O3 Q6 Q7 P6 R4 G17 G16 F16 G18 H16 J16 G15 J17 R7 R5 Q8 H14 P7 D14 C13 F13 P3 R2 Q2 F3 Q15 R11 J15 K16 H15 N17 H13 P17 Q17 M16 J14 K4 B4 C4 B5 B3 B2 C3 C8 D9 C9 D10 D6 C6 B6 D13 H5 J3 D12 C12 E11 B12 C15 F10 E10 E9 F11 D11 E12 G11 G10 F9 G12 H11 F12 B10 C5 E17 H10 F6 A3 C2 B9 J11 J10 K11 K10 L11 E13 L10 H8 D7 C7 K8 K7 L7 K6 L6 J8 K9 L8 L9 G6 E6 D8 F7 K5 L5 H3 J6 J5 G3 G4 F4 L4 M4 L3 M3 L2 H2 J2 K2 J4 J1 K3 J2 M2 N2 M5
|
||||||
|
Falchion: yeah
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
)))
|
|
@ -0,0 +1,499 @@
|
||||||
|
(;FF[4]
|
||||||
|
CA[UTF-8]
|
||||||
|
GM[1]
|
||||||
|
GN[2019 Masters R7 B2]
|
||||||
|
PC[https://online-go.com/review/404376]
|
||||||
|
PB[Eric Lui]
|
||||||
|
PW[Nyu Eiko]
|
||||||
|
BR[1p]
|
||||||
|
WR[2p]
|
||||||
|
TM[0]OT[0 none]
|
||||||
|
RE[W+r]
|
||||||
|
SZ[19]
|
||||||
|
KM[7.5]
|
||||||
|
RU[AGA]
|
||||||
|
C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
dogbert: when will the game start?
|
||||||
|
USGO2: in approximately 15 minutes
|
||||||
|
USGO2: After the ceremonies the game should begin any minute now
|
||||||
|
USGO2: Putting phones into the designated bins
|
||||||
|
USGO2: TD Josh Lee yells out "2 minutes"
|
||||||
|
USGO2: Both players have sat, game should begin soon
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[pd]
|
||||||
|
;W[dd]
|
||||||
|
;B[pq]
|
||||||
|
;W[dp]
|
||||||
|
;B[qk]
|
||||||
|
;W[nc]
|
||||||
|
;B[pf]
|
||||||
|
;W[qc]
|
||||||
|
;B[pc]
|
||||||
|
;W[pb]
|
||||||
|
;B[qd]
|
||||||
|
;W[rb]
|
||||||
|
;B[rc]
|
||||||
|
;W[qb]
|
||||||
|
;B[fq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
BHydden: wow lightning opening
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[cn]
|
||||||
|
;B[lp]
|
||||||
|
;W[hq]
|
||||||
|
;B[fo]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
mark5000: This is a traditional and well-studied opening pattern, if you excuse the 2016-era joseki in the upper left.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[jp]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
BHydden: looks at upper left... sees lonely isolated 4-4 stone... yes, such joseki o.o
|
||||||
|
mark5000: Ha, which one is left again? ;)
|
||||||
|
mark5000: It's been a long day.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[dm]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
BHydden: if you hold up both your hands, the left one can make an L between index and thumb with palm facing away from you ;)
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[dn]
|
||||||
|
;B[em]
|
||||||
|
;W[en]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
pyv: I thought you were referring to the fact that noone went 3-3 yet
|
||||||
|
pyv: as an old joseki
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[fn]
|
||||||
|
;W[fm]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
BHydden: i accept that it was a standard and well known pattern... but I'm still not used to pros putting stones on the board that quickly :P
|
||||||
|
BHydden: we had a move 8 3-3 so they can hold off a bit on the other one ;)
|
||||||
|
USGO2: Nyu dug into her purse and got out what appeared to be a piece of gum or a breathmint
|
||||||
|
BHydden: for herself or as a subtle insult to her opponent to throw Eric off his game?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gm]
|
||||||
|
;W[fl]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: For herself as far as i can tell
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[kn]
|
||||||
|
;W[hn]
|
||||||
|
;B[gn]
|
||||||
|
;W[jn]
|
||||||
|
;B[km]
|
||||||
|
;W[il]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: Hmm, I wonder if saving f5 worth W extending f8.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[dr]
|
||||||
|
;W[cq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: Or can B live in the lower left somehow?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[im]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Eric has almost played a move a few times now but always puts the stone back in the bowl. but finally committed to this one
|
||||||
|
USGO2: then steps out of the room
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[hm]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
BHydden: ominous
|
||||||
|
USGO2: Nyu's focus has completely unwavered meanwhile
|
||||||
|
USGO2: Eric has returned
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gl]
|
||||||
|
;W[fk]
|
||||||
|
;B[jm]
|
||||||
|
;W[hl]
|
||||||
|
;B[gk]
|
||||||
|
;W[fj]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: white must feel pretty confident about living along the bottom
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gj]
|
||||||
|
;W[fi]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: B f5 is not out of the woods yet tho...
|
||||||
|
unholysix1: pretty close to being out of them
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[in]
|
||||||
|
;W[ho]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: ohh neat
|
||||||
|
Аlрhа - 1 5 2: W can still harras that group to help save h5 if h5 can't live at the bottom.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[kq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: hmm... I thought b had to deend the f4 cut after white's move. guess not
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ij]
|
||||||
|
;B[jk]
|
||||||
|
;W[hj]
|
||||||
|
;B[gi]
|
||||||
|
(;W[fh]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: I think f4 cut douesn't work because of W's h4 aji.
|
||||||
|
unholysix1: no i just misread it. b has a sequence to make it fail
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gh]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: that one seems to work
|
||||||
|
unholysix1: white just relentlessly takes that 6 line territory. fun stuff
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ih]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Eric has used 40 minutes so far. Deducting from the start of the game, that means Nyu has used maybe 10 or so minutes
|
||||||
|
USGO2: Can't see Nyu's time unless Eric checks it
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[hg]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: Looks like B is determined to kill h5 no matter the cost.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ki]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: whites like sorry, noly need one eye and now i've got stones to connect to
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[cf]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: Hmm.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ce]
|
||||||
|
;B[df]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: so cool. :-D
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[gg]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: B doesn't need to connect at h12 I think. He can kill f12 if he cuts.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
(;B[hh]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: c8 net. 6 libs w to 3 for b
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ee]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: ok b cuts w extend im guessing you want b to e13? i play c8 net
|
||||||
|
unholysix1: doe
|
||||||
|
unholysix1: er done
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[cj]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: now hes using your plan haha
|
||||||
|
unholysix1: only net still works
|
||||||
|
Аlрhа - 1 5 2: He's not going for the kill tho.
|
||||||
|
unholysix1: hes trying to live
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[bk]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: thats most of whites points so far. its huge if he pulls it off
|
||||||
|
USGO2: Eric slips on his jacket. Despite it being almost 100F today its fairly ccomfortable in the strong players room
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[bj]
|
||||||
|
;W[di]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: d9?
|
||||||
|
unholysix1: And the heat is on black in this game! :-P
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[ch]
|
||||||
|
;W[be]
|
||||||
|
;B[bf]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: she still chewing that gum?
|
||||||
|
USGO2: I never saw a chewing motion so i assume it was a mint instead of gum
|
||||||
|
unholysix1: ooohhhh that explains a lot
|
||||||
|
USGO2: I think this is the longest she has spent on a move so far
|
||||||
|
unholysix1: this is exciting.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[gf]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: wow. make a move and save those if you want. I'll just trap this string
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[dh]
|
||||||
|
;W[jf]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: !
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[jh]
|
||||||
|
;W[ii]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: the B stick is contained and needs to find 2 eyes, right?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[hr]
|
||||||
|
;W[gp]
|
||||||
|
;B[gq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: thats the way it is
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[fp]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: he just traded the tail for the rest
|
||||||
|
aesalon: fat tail
|
||||||
|
unholysix1: for sure
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[kh]
|
||||||
|
;W[lh]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Nyu leaves the room
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[lg]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: and returns
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[kg]
|
||||||
|
;B[he]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Eric dropped the stone onto the board but fortunately it fell into an empty area
|
||||||
|
unholysix1: This looks like making it worse to me.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[jg]
|
||||||
|
;B[hf]
|
||||||
|
;W[id]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
S_Alexander: white feels good?
|
||||||
|
Falchion: ya, think so
|
||||||
|
Falchion: B is going to have to make a huge territory on the right side to even it up
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[hd]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: I mean what black's doing, it would work on me 100%
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ic]
|
||||||
|
;B[fg]
|
||||||
|
;W[ff]
|
||||||
|
;B[eg]
|
||||||
|
;W[dl]
|
||||||
|
;B[ec]
|
||||||
|
;W[dc]
|
||||||
|
;B[db]
|
||||||
|
;W[cb]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Nova Luna: ko. From move 0: Q16 D16 Q3 D4 R9 O17 Q14 R17 Q17 Q18 R16 S18 S17 R18 F3 C6 M4 H3 F5 K4 D7 D6 E7 E6 F6 F7 G7 F8 L6 H6 G6 K6 L7 J8 D2 C3 J7 H7 G8 F9 K7 H8 G9 F10 G10 F11 J6 H5 L3 J10 K9 H10 G11 F12 G12 J12 H13 L11 C14 C15 D14 G13 H12 E15 C10 B9 B10 D11 C12 B15 B14 G14 D12 K14 K12 J11 H2 G4 G3 F4 L12 M12 M13 L13 H15 K13 H14 J16 H16 J17 F13 F14 E13 D8 E17 D17 D18 C18
|
||||||
|
Zhadow: where
|
||||||
|
Zhadow: cant white G17 if black F18
|
||||||
|
Zhadow: ?
|
||||||
|
unholysix1: could he be thinking of e18 and just maing whte play a defensive move in the corner? he has a couple of forcing moves around the cut points?
|
||||||
|
USGO2: Eric has 10 minutes main time left. Nyu has approximately 50
|
||||||
|
mekriff 白金花: Anybody got a win rate?
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[fe]
|
||||||
|
;W[ge]
|
||||||
|
;B[fd]
|
||||||
|
;W[ef]
|
||||||
|
;B[fb]
|
||||||
|
;W[eh]
|
||||||
|
;B[dg]
|
||||||
|
;W[gd]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Given the info that Mark Lee lost on board 1, if Nyu wins this game she will very likely be the Masters winner
|
||||||
|
aesalon: Yeah
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gc]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
aesalon: and it looks near impossible for W to lose
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[bc]
|
||||||
|
;B[hc]
|
||||||
|
;W[bg]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Nyu steps across the room to refill her cup of water. Theres many water coolers in this building which is great given the heat this week
|
||||||
|
unholysix1: so at this point leela says white is winning 90% and the black group is dead
|
||||||
|
Zhadow: which one, left side or the stick
|
||||||
|
unholysix1: left side although there are variations where the stick dies instead
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[ae]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: it also expects fighting to start soon with an invasion around the Q3 stone
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ad]
|
||||||
|
;B[bl]
|
||||||
|
;W[ck]
|
||||||
|
;B[cm]
|
||||||
|
;W[bm]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: Eric has entered byo yomi. 5 periods of 30 seconds
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[bn]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
unholysix1: wow now it wants black to pla d15, w e16 b c16 and white take the f16 stones. b lives on the side the string dies
|
||||||
|
aesalon: It's difficult to parse bot variations when it's so lopsided
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[am]
|
||||||
|
;B[al]
|
||||||
|
;W[cl]
|
||||||
|
;B[an]
|
||||||
|
;W[bm]
|
||||||
|
;B[ak]
|
||||||
|
;W[el]C[W+Resign
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO2: 4 periods left
|
||||||
|
USGO2: 3 periods left
|
||||||
|
USGO2: Eric shuts off the clock. White wins the game. Thanks for watching!
|
||||||
|
savanni.dgerinel: Thank you for transcribing!
|
||||||
|
S_Alexander: gg
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
)(;B[fg]
|
||||||
|
;W[gf]
|
||||||
|
;B[dk]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: ?. From move 0: Q16 D16 Q3 D4 R9 O17 Q14 R17 Q17 Q18 R16 S18 S17 R18 F3 C6 M4 H3 F5 K4 D7 D6 E7 E6 F6 F7 G7 F8 L6 H6 G6 K6 L7 J8 D2 C3 J7 H7 G8 F9 K7 H8 G9 F10 G10 F11 J6 H5 L3 J10 K9 H10 G11 F12 G12 J12 H13 L11 C14 C15 D14 G13 F13 G14 D9
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
))(;W[fp]
|
||||||
|
;B[ep]
|
||||||
|
;W[gp]
|
||||||
|
;B[eo]
|
||||||
|
;W[eq]
|
||||||
|
;B[dq]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Аlрhа - 1 5 2: this one?. From move 0: Q16 D16 Q3 D4 R9 O17 Q14 R17 Q17 Q18 R16 S18 S17 R18 F3 C6 M4 H3 F5 K4 D7 D6 E7 E6 F6 F7 G7 F8 L6 H6 G6 K6 L7 J8 D2 C3 J7 H7 G8 F9 K7 H8 G9 F10 G10 F11 J6 H5 L3 J10 K9 H10 G11 F4 E4 G4 E5 E3 D3
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
))
|
|
@ -0,0 +1,395 @@
|
||||||
|
(;FF[4]
|
||||||
|
CA[UTF-8]
|
||||||
|
GM[1]
|
||||||
|
GN[2019 Masters R7 B3]
|
||||||
|
PC[https://online-go.com/review/404375]
|
||||||
|
PB[Alan Huang]
|
||||||
|
PW[Yongfei Ge]
|
||||||
|
BR[7d]
|
||||||
|
WR[7d]
|
||||||
|
TM[0]OT[0 none]
|
||||||
|
RE[B+7.5]
|
||||||
|
SZ[19]
|
||||||
|
KM[7.5]
|
||||||
|
RU[AGA]
|
||||||
|
C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: Welcome to Round 7 of the US Masters. This is the last round. This is table 3.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[pd]
|
||||||
|
;W[dc]
|
||||||
|
;B[qp]
|
||||||
|
;W[dq]
|
||||||
|
;B[np]
|
||||||
|
;W[nc]
|
||||||
|
;B[qf]
|
||||||
|
;W[pc]
|
||||||
|
;B[qc]
|
||||||
|
;W[qb]
|
||||||
|
;B[oc]
|
||||||
|
;W[pb]
|
||||||
|
;B[od]
|
||||||
|
;W[ob]
|
||||||
|
;B[nd]
|
||||||
|
;W[mc]
|
||||||
|
;B[ce]
|
||||||
|
;W[dh]
|
||||||
|
;B[co]
|
||||||
|
;W[cl]
|
||||||
|
;B[ep]
|
||||||
|
;W[dp]
|
||||||
|
;B[do]
|
||||||
|
;W[eo]
|
||||||
|
;B[eq]
|
||||||
|
;W[er]
|
||||||
|
;B[fr]
|
||||||
|
;W[dr]
|
||||||
|
;B[en]
|
||||||
|
;W[fo]
|
||||||
|
;B[gp]
|
||||||
|
;W[dn]
|
||||||
|
;B[cn]
|
||||||
|
;W[dm]
|
||||||
|
;B[gn]
|
||||||
|
;W[fn]
|
||||||
|
;B[fm]
|
||||||
|
;W[em]
|
||||||
|
;B[go]
|
||||||
|
;W[fl]
|
||||||
|
;B[gm]
|
||||||
|
;W[bp]
|
||||||
|
;B[pk]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
redreoicy: Go Alan! I'm sure AI prefers black here :)
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[lq]
|
||||||
|
;B[lp]
|
||||||
|
;W[kp]
|
||||||
|
;B[lo]
|
||||||
|
;W[nq]
|
||||||
|
;B[oq]
|
||||||
|
;W[mr]
|
||||||
|
;B[or]
|
||||||
|
;W[ko]
|
||||||
|
;B[ln]
|
||||||
|
;W[iq]
|
||||||
|
;B[kn]
|
||||||
|
;W[hr]
|
||||||
|
;B[dd]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: The game has been underway for about 30 minutes...B has used about 19 minutes.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ec]
|
||||||
|
;B[cc]
|
||||||
|
;W[cb]
|
||||||
|
;B[bb]
|
||||||
|
;W[bc]
|
||||||
|
;B[bd]
|
||||||
|
;W[cd]
|
||||||
|
;B[kr]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
redreoicy: Good part about that joseki in lower left is that it leaves so many easy threats
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[kq]
|
||||||
|
;B[cc]
|
||||||
|
;W[qi]
|
||||||
|
;B[qj]
|
||||||
|
;W[oi]
|
||||||
|
;B[mi]
|
||||||
|
;W[qg]
|
||||||
|
;B[pf]
|
||||||
|
;W[rj]
|
||||||
|
;B[rk]
|
||||||
|
;W[rf]
|
||||||
|
;B[rh]
|
||||||
|
;W[pj]
|
||||||
|
;B[qk]
|
||||||
|
;W[rg]
|
||||||
|
;B[rd]
|
||||||
|
;W[ri]
|
||||||
|
;B[ph]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: About 1 hour into the game...B has used 39 minutes of time
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[pg]
|
||||||
|
;B[oh]
|
||||||
|
;W[og]
|
||||||
|
;B[nh]
|
||||||
|
;W[qh]
|
||||||
|
;B[md]
|
||||||
|
;W[re]
|
||||||
|
;B[lc]
|
||||||
|
;W[rc]
|
||||||
|
;B[qd]
|
||||||
|
;W[sd]
|
||||||
|
;B[ac]
|
||||||
|
;W[hc]
|
||||||
|
;B[lb]
|
||||||
|
;W[mb]
|
||||||
|
;B[ma]
|
||||||
|
;W[nb]
|
||||||
|
;B[ke]
|
||||||
|
;W[pi]
|
||||||
|
;B[nk]
|
||||||
|
;W[nj]
|
||||||
|
;B[mj]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: B needs to play F4 at some point, no? It's forcing too
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[gk]
|
||||||
|
;B[cj]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: 90 minutes in...B has used 52 minutes
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[ci]
|
||||||
|
;B[dj]
|
||||||
|
;W[fi]
|
||||||
|
;B[bj]
|
||||||
|
;W[bk]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: is that B group just going to die? jumping in like that was pretty risky
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[bh]
|
||||||
|
;W[gh]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Falchion: guess it lives, but low, and W wasn't reduced very much
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[ek]
|
||||||
|
;W[el]
|
||||||
|
;B[hi]
|
||||||
|
;W[gj]
|
||||||
|
;B[ik]
|
||||||
|
;W[hh]
|
||||||
|
;B[ii]
|
||||||
|
;W[ih]
|
||||||
|
;B[ed]
|
||||||
|
;W[fd]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
Zhadow: how much time does each player have left?
|
||||||
|
USGO3: B has 21 min
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[ni]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: They have been playing 117 minutes
|
||||||
|
USGO3: I will let you do the math for W
|
||||||
|
Zhadow: thanks
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;W[kg]
|
||||||
|
;B[ic]
|
||||||
|
;W[id]
|
||||||
|
;B[jc]
|
||||||
|
;W[hb]
|
||||||
|
;B[jr]
|
||||||
|
;W[gr]
|
||||||
|
;B[fs]
|
||||||
|
;W[io]
|
||||||
|
;B[jn]
|
||||||
|
;W[gq]
|
||||||
|
;B[fq]
|
||||||
|
;W[hp]
|
||||||
|
;B[fp]
|
||||||
|
;W[en]
|
||||||
|
;B[jo]
|
||||||
|
;W[jp]
|
||||||
|
;B[ir]
|
||||||
|
;W[gs]
|
||||||
|
;B[ho]
|
||||||
|
;W[in]
|
||||||
|
;B[im]
|
||||||
|
;W[is]
|
||||||
|
;B[fe]
|
||||||
|
;W[gd]
|
||||||
|
;B[db]
|
||||||
|
;W[eb]
|
||||||
|
;B[ca]
|
||||||
|
;W[jd]
|
||||||
|
;B[kd]
|
||||||
|
;W[jb]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: B has 10 minutes basic time left
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[mf]
|
||||||
|
;W[sk]
|
||||||
|
;B[sl]
|
||||||
|
;W[sj]
|
||||||
|
;B[ql]
|
||||||
|
;W[bi]
|
||||||
|
;B[ai]
|
||||||
|
;W[ch]
|
||||||
|
;B[bg]
|
||||||
|
;W[ib]
|
||||||
|
;B[jh]
|
||||||
|
;W[jg]
|
||||||
|
;B[kh]
|
||||||
|
;W[ok]
|
||||||
|
;B[ol]
|
||||||
|
;W[oj]
|
||||||
|
;B[mk]
|
||||||
|
;W[nr]
|
||||||
|
;B[os]
|
||||||
|
;W[lg]
|
||||||
|
;B[ng]
|
||||||
|
;W[lh]
|
||||||
|
;B[li]
|
||||||
|
;W[ge]
|
||||||
|
;B[ff]
|
||||||
|
;W[df]
|
||||||
|
;B[cf]
|
||||||
|
;W[dg]
|
||||||
|
;B[fg]
|
||||||
|
;W[fh]
|
||||||
|
;B[de]
|
||||||
|
;W[je]
|
||||||
|
;B[ei]
|
||||||
|
;W[eh]
|
||||||
|
;B[rb]
|
||||||
|
;W[sc]
|
||||||
|
;B[se]
|
||||||
|
;W[sf]
|
||||||
|
;B[ra]
|
||||||
|
;W[sb]
|
||||||
|
;B[na]
|
||||||
|
;W[qa]
|
||||||
|
;B[ea]
|
||||||
|
;W[fb]
|
||||||
|
;B[kf]
|
||||||
|
;W[jf]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: B in byomi
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[gf]
|
||||||
|
;W[hf]
|
||||||
|
;B[of]
|
||||||
|
;W[kc]
|
||||||
|
;B[hn]
|
||||||
|
;W[ns]
|
||||||
|
;B[mp]
|
||||||
|
;W[ls]
|
||||||
|
;B[ip]
|
||||||
|
;W[io]
|
||||||
|
;B[lr]
|
||||||
|
;W[mq]
|
||||||
|
;B[js]
|
||||||
|
;W[jq]
|
||||||
|
;B[hs]
|
||||||
|
;W[hq]
|
||||||
|
;B[cp]
|
||||||
|
;W[cq]
|
||||||
|
;B[ds]
|
||||||
|
;W[br]
|
||||||
|
;B[es]
|
||||||
|
;W[cs]
|
||||||
|
;B[kb]
|
||||||
|
;W[jc]
|
||||||
|
;B[hk]
|
||||||
|
;W[hj]
|
||||||
|
;B[ij]
|
||||||
|
;W[gl]
|
||||||
|
;B[hl]
|
||||||
|
;W[ak]
|
||||||
|
;B[aj]
|
||||||
|
;W[qe]
|
||||||
|
;B[ck]
|
||||||
|
;W[bl]
|
||||||
|
;B[gg]
|
||||||
|
;W[pe]
|
||||||
|
;B[oe]
|
||||||
|
;W[lf]
|
||||||
|
;B[le]
|
||||||
|
;W[fa]
|
||||||
|
;B[da]
|
||||||
|
;W[hg]
|
||||||
|
;B[oa]
|
||||||
|
;W[sa]
|
||||||
|
;B[cg]
|
||||||
|
;W[ja]
|
||||||
|
;B[la]
|
||||||
|
;W[is]
|
||||||
|
;B[in]
|
||||||
|
;W[ks]
|
||||||
|
;B[ip]
|
||||||
|
;W[rm]
|
||||||
|
;B[rl]
|
||||||
|
;W[io]
|
||||||
|
;B[bs]
|
||||||
|
;W[as]
|
||||||
|
;B[ip]
|
||||||
|
;W[pm]
|
||||||
|
;B[pl]
|
||||||
|
;W[io]
|
||||||
|
;B[ej]
|
||||||
|
;W[dl]
|
||||||
|
;B[ip]
|
||||||
|
;W[op]
|
||||||
|
;B[pq]
|
||||||
|
;W[io]
|
||||||
|
;B[ee]
|
||||||
|
;W[ip]
|
||||||
|
;B[ah]
|
||||||
|
;W[fj]
|
||||||
|
;B[mg]
|
||||||
|
;W[mh]
|
||||||
|
;B[ld]
|
||||||
|
;W[ka]
|
||||||
|
;B[dk]
|
||||||
|
;W[di]
|
||||||
|
;B[pa]
|
||||||
|
;W[eg]
|
||||||
|
;B[ef]
|
||||||
|
;W[fk]
|
||||||
|
;B[gi]
|
||||||
|
;W[]C[
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: Counting
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
;B[]
|
||||||
|
;W[]C[B+7.5
|
||||||
|
|
||||||
|
-- chat --
|
||||||
|
USGO3: B wins
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
)
|
|
@ -0,0 +1,224 @@
|
||||||
|
(;FF[4]GM[1]AP[gobandroid:0]SZ[19]GN[Kat vs. Savanni]DT[2022-10-05]PB[Kat]PW[Savanni]BR[10k]WR[10k]KM[6.5]RE[W+15.5]
|
||||||
|
;B[dp]
|
||||||
|
;W[pd]
|
||||||
|
;B[qp]
|
||||||
|
;W[cd]
|
||||||
|
;B[oq]
|
||||||
|
;W[fd]
|
||||||
|
;B[qf]
|
||||||
|
;W[qh]
|
||||||
|
(;B[pf]
|
||||||
|
)(;B[of]
|
||||||
|
;W[nd]
|
||||||
|
;B[mf]
|
||||||
|
;W[pk]
|
||||||
|
;B[ql]
|
||||||
|
;W[qk]
|
||||||
|
;B[cj]
|
||||||
|
;W[jp]
|
||||||
|
;B[hq]
|
||||||
|
;W[le]
|
||||||
|
;B[jc]
|
||||||
|
;W[lc]
|
||||||
|
;B[gc]
|
||||||
|
;W[fc]
|
||||||
|
;B[qd]
|
||||||
|
;W[qc]
|
||||||
|
;B[rd]
|
||||||
|
;W[rc]
|
||||||
|
;B[pe]
|
||||||
|
;W[od]
|
||||||
|
;B[ri]
|
||||||
|
;W[qi]
|
||||||
|
;B[rh]
|
||||||
|
;W[di]
|
||||||
|
;B[dl]
|
||||||
|
;W[ci]
|
||||||
|
;B[lp]
|
||||||
|
;W[jn]
|
||||||
|
;B[hn]
|
||||||
|
;W[cq]
|
||||||
|
;B[dq]
|
||||||
|
;W[cp]
|
||||||
|
;B[co]
|
||||||
|
;W[bo]
|
||||||
|
;B[cn]
|
||||||
|
;W[bn]
|
||||||
|
;B[cm]
|
||||||
|
;W[dr]
|
||||||
|
;B[er]
|
||||||
|
;W[cr]
|
||||||
|
;B[fq]
|
||||||
|
;W[ln]
|
||||||
|
;B[nm]
|
||||||
|
;W[nk]
|
||||||
|
;B[ol]
|
||||||
|
;W[ok]
|
||||||
|
;B[lk]
|
||||||
|
;W[ng]
|
||||||
|
;B[nf]
|
||||||
|
;W[mj]
|
||||||
|
;B[ml]
|
||||||
|
;W[pl]
|
||||||
|
;B[qm]
|
||||||
|
;W[om]
|
||||||
|
;B[nn]
|
||||||
|
;W[nl]
|
||||||
|
;B[mm]
|
||||||
|
;W[kl]
|
||||||
|
;B[hk]
|
||||||
|
;W[ho]
|
||||||
|
;B[io]
|
||||||
|
;W[in]
|
||||||
|
;B[ip]
|
||||||
|
;W[hm]
|
||||||
|
;B[gn]
|
||||||
|
;W[jo]
|
||||||
|
;B[jq]
|
||||||
|
;W[mp]
|
||||||
|
;B[np]
|
||||||
|
;W[mo]
|
||||||
|
;B[no]
|
||||||
|
;W[kq]
|
||||||
|
;B[jr]
|
||||||
|
;W[mq]
|
||||||
|
;B[hf]
|
||||||
|
;W[ff]
|
||||||
|
;B[lf]
|
||||||
|
;W[jd]
|
||||||
|
;B[ic]
|
||||||
|
;W[jf]
|
||||||
|
;B[jk]
|
||||||
|
;W[kk]
|
||||||
|
;B[fk]
|
||||||
|
;W[kr]
|
||||||
|
;B[nr]
|
||||||
|
;W[mr]
|
||||||
|
;B[lj]
|
||||||
|
;W[mi]
|
||||||
|
;B[li]
|
||||||
|
;W[jh]
|
||||||
|
;B[ji]
|
||||||
|
;W[lg]
|
||||||
|
;B[hl]
|
||||||
|
;W[dj]
|
||||||
|
;B[ck]
|
||||||
|
;W[fj]
|
||||||
|
;B[jl]
|
||||||
|
;W[ll]
|
||||||
|
;B[mk]
|
||||||
|
;W[jm]
|
||||||
|
;B[gm]
|
||||||
|
;W[gh]
|
||||||
|
;B[hi]
|
||||||
|
;W[hd]
|
||||||
|
;B[hc]
|
||||||
|
;W[hh]
|
||||||
|
;B[fi]
|
||||||
|
;W[fh]
|
||||||
|
;B[ei]
|
||||||
|
;W[eh]
|
||||||
|
;B[ej]
|
||||||
|
;W[ek]
|
||||||
|
;B[gj]
|
||||||
|
;W[gi]
|
||||||
|
;B[fj]
|
||||||
|
;W[dk]
|
||||||
|
;B[el]
|
||||||
|
;W[pg]
|
||||||
|
;B[dh]
|
||||||
|
;W[ch]
|
||||||
|
;B[dg]
|
||||||
|
;W[cf]
|
||||||
|
;B[mg]
|
||||||
|
;W[og]
|
||||||
|
;B[kb]
|
||||||
|
;W[lb]
|
||||||
|
;B[fb]
|
||||||
|
;W[eb]
|
||||||
|
;B[gb]
|
||||||
|
;W[ec]
|
||||||
|
;B[ig]
|
||||||
|
;W[ih]
|
||||||
|
;B[kf]
|
||||||
|
;W[kg]
|
||||||
|
;B[je]
|
||||||
|
;W[ie]
|
||||||
|
;B[ke]
|
||||||
|
;W[if]
|
||||||
|
;B[id]
|
||||||
|
;W[gd]
|
||||||
|
;B[ld]
|
||||||
|
;W[md]
|
||||||
|
;B[me]
|
||||||
|
;W[pm]
|
||||||
|
;B[qn]
|
||||||
|
;W[rj]
|
||||||
|
;B[rg]
|
||||||
|
;W[rl]
|
||||||
|
;B[rm]
|
||||||
|
;W[bj]
|
||||||
|
;B[bk]
|
||||||
|
;W[cg]
|
||||||
|
;B[bi]
|
||||||
|
;W[bh]
|
||||||
|
;B[aj]
|
||||||
|
;W[mh]
|
||||||
|
;B[kc]
|
||||||
|
;W[kj]
|
||||||
|
;B[pn]
|
||||||
|
;W[on]
|
||||||
|
;B[oo]
|
||||||
|
;W[jj]
|
||||||
|
;B[ij]
|
||||||
|
;W[ki]
|
||||||
|
;B[lh]
|
||||||
|
;W[ii]
|
||||||
|
;B[hj]
|
||||||
|
;W[lm]
|
||||||
|
;B[im]
|
||||||
|
;W[ns]
|
||||||
|
;B[os]
|
||||||
|
;W[ms]
|
||||||
|
;B[bm]
|
||||||
|
;W[bp]
|
||||||
|
;B[la]
|
||||||
|
;W[ma]
|
||||||
|
;B[ka]
|
||||||
|
;W[mb]
|
||||||
|
;B[sk]
|
||||||
|
;W[sl]
|
||||||
|
;B[sj]
|
||||||
|
;W[rk]
|
||||||
|
;B[si]
|
||||||
|
;W[sm]
|
||||||
|
;B[sn]
|
||||||
|
;W[js]
|
||||||
|
;B[ir]
|
||||||
|
;W[is]
|
||||||
|
;B[hs]
|
||||||
|
;W[ks]
|
||||||
|
;B[ea]
|
||||||
|
;W[da]
|
||||||
|
;B[fa]
|
||||||
|
;W[db]
|
||||||
|
;B[sc]
|
||||||
|
;W[sb]
|
||||||
|
;B[sd]
|
||||||
|
;W[rb]
|
||||||
|
;B[ds]
|
||||||
|
;W[cs]
|
||||||
|
;B[es]
|
||||||
|
;W[nq]
|
||||||
|
;B[or]
|
||||||
|
;W[am]
|
||||||
|
;B[al]
|
||||||
|
;W[an]
|
||||||
|
;B[kh]
|
||||||
|
;W[jg]
|
||||||
|
;B[ah]
|
||||||
|
;W[ag]
|
||||||
|
;B[ai]
|
||||||
|
;W[qg]
|
||||||
|
;B[pf]
|
||||||
|
))
|
|
@ -0,0 +1,179 @@
|
||||||
|
(;FF[4]GM[1]AP[gobandroid:0]SZ[19]DT[2023-04-19]PB[Steve]PW[Savanni]KM[6.5]
|
||||||
|
;B[dd]
|
||||||
|
;W[pp]
|
||||||
|
;B[pd]
|
||||||
|
;W[dp]
|
||||||
|
;B[qn]
|
||||||
|
;W[qo]
|
||||||
|
;B[pn]
|
||||||
|
;W[np]
|
||||||
|
;B[qj]
|
||||||
|
;W[cf]
|
||||||
|
;B[fc]
|
||||||
|
;W[cd]
|
||||||
|
;B[cc]
|
||||||
|
;W[bc]
|
||||||
|
;B[cb]
|
||||||
|
;W[bb]
|
||||||
|
;B[ce]
|
||||||
|
;W[bd]
|
||||||
|
;B[de]
|
||||||
|
;W[be]
|
||||||
|
;B[df]
|
||||||
|
;W[cg]
|
||||||
|
;B[ck]
|
||||||
|
;W[dg]
|
||||||
|
;B[cn]
|
||||||
|
;W[co]
|
||||||
|
;B[bn]
|
||||||
|
;W[en]
|
||||||
|
;B[ek]
|
||||||
|
;W[ef]
|
||||||
|
;B[ee]
|
||||||
|
;W[db]
|
||||||
|
;B[dc]
|
||||||
|
;W[ca]
|
||||||
|
;B[eb]
|
||||||
|
;W[da]
|
||||||
|
;B[ge]
|
||||||
|
;W[ff]
|
||||||
|
;B[fe]
|
||||||
|
;W[dj]
|
||||||
|
;B[bo]
|
||||||
|
;W[bp]
|
||||||
|
;B[di]
|
||||||
|
;W[dk]
|
||||||
|
;B[cj]
|
||||||
|
;W[dl]
|
||||||
|
;B[cl]
|
||||||
|
;W[ei]
|
||||||
|
;B[ci]
|
||||||
|
;W[eh]
|
||||||
|
;B[ej]
|
||||||
|
;W[el]
|
||||||
|
;B[fm]
|
||||||
|
;W[gn]
|
||||||
|
;B[do]
|
||||||
|
;W[cp]
|
||||||
|
;B[dn]
|
||||||
|
;W[eo]
|
||||||
|
;B[em]
|
||||||
|
;W[fl]
|
||||||
|
;B[gk]
|
||||||
|
;W[gl]
|
||||||
|
;B[gm]
|
||||||
|
;W[hm]
|
||||||
|
;B[fn]
|
||||||
|
;W[fo]
|
||||||
|
;B[dm]
|
||||||
|
;W[hl]
|
||||||
|
;B[go]
|
||||||
|
;W[hn]
|
||||||
|
;B[gp]
|
||||||
|
;W[ep]
|
||||||
|
;B[gq]
|
||||||
|
;W[ip]
|
||||||
|
;B[er]
|
||||||
|
;W[dr]
|
||||||
|
;B[iq]
|
||||||
|
;W[jq]
|
||||||
|
;B[ir]
|
||||||
|
;W[jr]
|
||||||
|
;B[hp]
|
||||||
|
;W[jp]
|
||||||
|
;B[eq]
|
||||||
|
;W[dq]
|
||||||
|
;B[fp]
|
||||||
|
;W[br]
|
||||||
|
;B[ds]
|
||||||
|
;W[cs]
|
||||||
|
;B[es]
|
||||||
|
;W[nn]
|
||||||
|
;B[nj]
|
||||||
|
;W[nc]
|
||||||
|
;B[lc]
|
||||||
|
;W[qc]
|
||||||
|
;B[pc]
|
||||||
|
;W[qd]
|
||||||
|
;B[qe]
|
||||||
|
;W[pb]
|
||||||
|
;B[ob]
|
||||||
|
;W[qb]
|
||||||
|
;B[oc]
|
||||||
|
;W[nb]
|
||||||
|
;B[oa]
|
||||||
|
;W[pe]
|
||||||
|
;B[oe]
|
||||||
|
;W[pf]
|
||||||
|
;B[of]
|
||||||
|
;W[pg]
|
||||||
|
;B[re]
|
||||||
|
;W[sc]
|
||||||
|
;B[nd]
|
||||||
|
;W[kd]
|
||||||
|
;B[kc]
|
||||||
|
;W[jd]
|
||||||
|
;B[ic]
|
||||||
|
;W[md]
|
||||||
|
;B[mc]
|
||||||
|
;W[ne]
|
||||||
|
;B[od]
|
||||||
|
;W[me]
|
||||||
|
;B[og]
|
||||||
|
;W[oh]
|
||||||
|
;B[ph]
|
||||||
|
;W[qh]
|
||||||
|
;B[pi]
|
||||||
|
;W[rf]
|
||||||
|
;B[qg]
|
||||||
|
;W[qf]
|
||||||
|
;B[rg]
|
||||||
|
;W[rd]
|
||||||
|
;B[sf]
|
||||||
|
;W[mg]
|
||||||
|
;B[nh]
|
||||||
|
;W[om]
|
||||||
|
;B[ql]
|
||||||
|
;W[mh]
|
||||||
|
;B[mi]
|
||||||
|
;W[li]
|
||||||
|
;B[lj]
|
||||||
|
;W[kj]
|
||||||
|
;B[lh]
|
||||||
|
;W[ki]
|
||||||
|
;B[lg]
|
||||||
|
;W[ng]
|
||||||
|
;B[oi]
|
||||||
|
;W[lk]
|
||||||
|
;B[mf]
|
||||||
|
;W[nf]
|
||||||
|
;B[lf]
|
||||||
|
;W[ld]
|
||||||
|
;B[jg]
|
||||||
|
;W[hf]
|
||||||
|
;B[ie]
|
||||||
|
;W[id]
|
||||||
|
;B[hd]
|
||||||
|
;W[jc]
|
||||||
|
;B[jb]
|
||||||
|
;W[ib]
|
||||||
|
;B[hb]
|
||||||
|
;W[kb]
|
||||||
|
;B[lb]
|
||||||
|
;W[ja]
|
||||||
|
;B[na]
|
||||||
|
;W[hc]
|
||||||
|
;B[gc]
|
||||||
|
;W[he]
|
||||||
|
;B[gd]
|
||||||
|
;W[ic]
|
||||||
|
;B[ha]
|
||||||
|
;W[if]
|
||||||
|
;B[je]
|
||||||
|
;W[ih]
|
||||||
|
;B[ke]
|
||||||
|
;W[kh]
|
||||||
|
;B[le]
|
||||||
|
;W[kg]
|
||||||
|
;B[ia]
|
||||||
|
)
|
|
@ -0,0 +1,143 @@
|
||||||
|
use crate::{
|
||||||
|
types::{AppState, GameState, Player, Rank},
|
||||||
|
ui::{home, playing_field, HomeView, PlayingFieldView},
|
||||||
|
Config, DatabasePath,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
#[serde(tag = "type", content = "content")]
|
||||||
|
pub enum CoreRequest {
|
||||||
|
CreateGame(CreateGameRequest),
|
||||||
|
Home,
|
||||||
|
PlayingField,
|
||||||
|
PlayStone(PlayStoneRequest),
|
||||||
|
StartGame,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct PlayStoneRequest {
|
||||||
|
pub column: u8,
|
||||||
|
pub row: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct CreateGameRequest {
|
||||||
|
pub black_player: PlayerInfoRequest,
|
||||||
|
pub white_player: PlayerInfoRequest,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub enum PlayerInfoRequest {
|
||||||
|
Hotseat(HotseatPlayerRequest),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct HotseatPlayerRequest {
|
||||||
|
pub name: String,
|
||||||
|
pub rank: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HotseatPlayerRequest> for Player {
|
||||||
|
fn from(p: HotseatPlayerRequest) -> Self {
|
||||||
|
Self {
|
||||||
|
name: p.name,
|
||||||
|
rank: p.rank.and_then(|r| Rank::try_from(r.as_ref()).ok()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
#[serde(tag = "type", content = "content")]
|
||||||
|
pub enum CoreResponse {
|
||||||
|
HomeView(HomeView),
|
||||||
|
PlayingFieldView(PlayingFieldView),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct CoreApp {
|
||||||
|
config: Config,
|
||||||
|
state: Arc<RwLock<AppState>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CoreApp {
|
||||||
|
pub fn new(config_path: std::path::PathBuf) -> Self {
|
||||||
|
println!("config_path: {:?}", config_path);
|
||||||
|
let config = Config::from_path(config_path).expect("configuration to open");
|
||||||
|
|
||||||
|
let db_path: DatabasePath = config.get();
|
||||||
|
let state = Arc::new(RwLock::new(AppState::new(db_path)));
|
||||||
|
|
||||||
|
println!("config: {:?}", config);
|
||||||
|
println!("games database: {:?}", state.read().unwrap().database.len());
|
||||||
|
|
||||||
|
Self { config, state }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn dispatch(&self, request: CoreRequest) -> CoreResponse {
|
||||||
|
match request {
|
||||||
|
/*
|
||||||
|
CoreRequest::LaunchScreen => {
|
||||||
|
let app_state = self.state.read().unwrap();
|
||||||
|
|
||||||
|
At launch, I want to either show a list of games in progress, the current game, or the game creation screen.
|
||||||
|
- if a live game is in progress, immmediately go to that game. Such a game will be classified at game creation, so it should be persisted to the state.
|
||||||
|
- if no live games are in progress, but there are slow games in progress, show a list of the slow games and let the player choose which one to jump into.
|
||||||
|
- if no games are in progress, show only the game creation screen
|
||||||
|
- game creation menu should be present both when there are only slow games and when there are no games
|
||||||
|
- the UI returned here will always be available in other places, such as when the user is viewing a game and wants to return to this page
|
||||||
|
|
||||||
|
For the initial version, I want only to show the game creation screen. Then I will backtrack record application state so that the only decisions can be made.
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
CoreRequest::CreateGame(create_request) => {
|
||||||
|
let mut app_state = self.state.write().unwrap();
|
||||||
|
let white_player = {
|
||||||
|
match create_request.white_player {
|
||||||
|
PlayerInfoRequest::Hotseat(request) => Player::from(request),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let black_player = {
|
||||||
|
match create_request.black_player {
|
||||||
|
PlayerInfoRequest::Hotseat(request) => Player::from(request),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
app_state.game = Some(GameState {
|
||||||
|
white_player,
|
||||||
|
black_player,
|
||||||
|
..GameState::new()
|
||||||
|
});
|
||||||
|
let game_state = app_state.game.as_ref().unwrap();
|
||||||
|
CoreResponse::PlayingFieldView(playing_field(game_state))
|
||||||
|
}
|
||||||
|
CoreRequest::Home => {
|
||||||
|
CoreResponse::HomeView(home(self.state.read().unwrap().database.all_games()))
|
||||||
|
}
|
||||||
|
CoreRequest::PlayingField => {
|
||||||
|
let app_state = self.state.read().unwrap();
|
||||||
|
let game = app_state.game.as_ref().unwrap();
|
||||||
|
CoreResponse::PlayingFieldView(playing_field(game))
|
||||||
|
}
|
||||||
|
CoreRequest::PlayStone(request) => {
|
||||||
|
let mut app_state = self.state.write().unwrap();
|
||||||
|
app_state.place_stone(request);
|
||||||
|
|
||||||
|
let game = app_state.game.as_ref().unwrap();
|
||||||
|
CoreResponse::PlayingFieldView(playing_field(game))
|
||||||
|
}
|
||||||
|
CoreRequest::StartGame => {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run(&self) {}
|
||||||
|
}
|
|
@ -0,0 +1,633 @@
|
||||||
|
use crate::{BoardError, Color, Size};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Board {
|
||||||
|
pub size: Size,
|
||||||
|
pub groups: Vec<Group>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Board {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
|
write!(f, " ")?;
|
||||||
|
// for c in 'A'..'U' {
|
||||||
|
for c in 0..19 {
|
||||||
|
write!(f, "{:2}", c)?;
|
||||||
|
}
|
||||||
|
writeln!(f, "")?;
|
||||||
|
|
||||||
|
for row in 0..self.size.height {
|
||||||
|
write!(f, " {:2}", row)?;
|
||||||
|
for column in 0..self.size.width {
|
||||||
|
match self.stone(&Coordinate { column, row }) {
|
||||||
|
None => write!(f, " .")?,
|
||||||
|
Some(Color::Black) => write!(f, " X")?,
|
||||||
|
Some(Color::White) => write!(f, " O")?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln!(f, "")?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Board {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
if self.size != other.size {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for group in self.groups.iter() {
|
||||||
|
if !other.groups.contains(&group) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for group in other.groups.iter() {
|
||||||
|
if !self.groups.contains(&group) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Board {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
size: Size {
|
||||||
|
width: 19,
|
||||||
|
height: 19,
|
||||||
|
},
|
||||||
|
groups: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_coordinates(
|
||||||
|
mut coordinates: impl Iterator<Item = (Coordinate, Color)>,
|
||||||
|
) -> Result<Self, BoardError> {
|
||||||
|
coordinates.try_fold(Self::new(), |board, (coordinate, color)| {
|
||||||
|
board.place_stone(coordinate, color)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, Eq)]
|
||||||
|
pub struct Coordinate {
|
||||||
|
pub column: u8,
|
||||||
|
pub row: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Board {
|
||||||
|
pub fn place_stone(mut self, coordinate: Coordinate, color: Color) -> Result<Self, BoardError> {
|
||||||
|
if let Some(_) = self.stone(&coordinate) {
|
||||||
|
return Err(BoardError::InvalidPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut friendly_group = self
|
||||||
|
.adjacencies(&coordinate)
|
||||||
|
.into_iter()
|
||||||
|
.filter(|c| self.stone(c) == Some(color))
|
||||||
|
.filter_map(|c| self.group(&c).map(|g| g.coordinates.clone()))
|
||||||
|
.fold(HashSet::new(), |acc, set| {
|
||||||
|
acc.union(&set).cloned().collect()
|
||||||
|
});
|
||||||
|
|
||||||
|
friendly_group.insert(coordinate.clone());
|
||||||
|
|
||||||
|
self.groups
|
||||||
|
.retain(|g| g.coordinates.is_disjoint(&friendly_group));
|
||||||
|
let friendly_group = Group {
|
||||||
|
color,
|
||||||
|
coordinates: friendly_group,
|
||||||
|
};
|
||||||
|
self.groups.push(friendly_group.clone());
|
||||||
|
|
||||||
|
let adjacent_groups = self.adjacent_groups(&friendly_group);
|
||||||
|
for group in adjacent_groups {
|
||||||
|
if self.liberties(&group) == 0 {
|
||||||
|
self.remove_group(&group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.liberties(&friendly_group) == 0 {
|
||||||
|
return Err(BoardError::SelfCapture);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stone(&self, coordinate: &Coordinate) -> Option<Color> {
|
||||||
|
self.groups
|
||||||
|
.iter()
|
||||||
|
.find(|g| g.contains(coordinate))
|
||||||
|
.map(|g| g.color)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn group(&self, coordinate: &Coordinate) -> Option<&Group> {
|
||||||
|
self.groups
|
||||||
|
.iter()
|
||||||
|
.find(|g| g.coordinates.contains(coordinate))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_group(&mut self, group: &Group) {
|
||||||
|
self.groups.retain(|g| g != group);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn adjacent_groups(&self, group: &Group) -> Vec<Group> {
|
||||||
|
let adjacent_spaces = self.group_halo(group).into_iter();
|
||||||
|
let mut grps: Vec<Group> = Vec::new();
|
||||||
|
|
||||||
|
adjacent_spaces.for_each(|coord| match self.group(&coord) {
|
||||||
|
None => return,
|
||||||
|
Some(adj) => {
|
||||||
|
if group.color == adj.color {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if grps.iter().any(|g| g.coordinates.contains(&coord)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
grps.push(adj.clone());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
grps
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn group_halo(&self, group: &Group) -> HashSet<Coordinate> {
|
||||||
|
group
|
||||||
|
.coordinates
|
||||||
|
.iter()
|
||||||
|
.map(|c| self.adjacencies(c))
|
||||||
|
.flatten()
|
||||||
|
.collect::<HashSet<Coordinate>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn liberties(&self, group: &Group) -> usize {
|
||||||
|
self.group_halo(group)
|
||||||
|
.into_iter()
|
||||||
|
.filter(|c| self.stone(&c) == None)
|
||||||
|
.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn adjacencies(&self, coordinate: &Coordinate) -> Vec<Coordinate> {
|
||||||
|
let mut v = Vec::new();
|
||||||
|
if coordinate.column > 0 {
|
||||||
|
v.push(Coordinate {
|
||||||
|
column: coordinate.column - 1,
|
||||||
|
row: coordinate.row,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if coordinate.row > 0 {
|
||||||
|
v.push(Coordinate {
|
||||||
|
column: coordinate.column,
|
||||||
|
row: coordinate.row - 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
v.push(Coordinate {
|
||||||
|
column: coordinate.column + 1,
|
||||||
|
row: coordinate.row,
|
||||||
|
});
|
||||||
|
v.push(Coordinate {
|
||||||
|
column: coordinate.column,
|
||||||
|
row: coordinate.row + 1,
|
||||||
|
});
|
||||||
|
v.into_iter().filter(|c| self.within_board(c)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn within_board(&self, coordinate: &Coordinate) -> bool {
|
||||||
|
coordinate.column < self.size.width && coordinate.row < self.size.height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct Group {
|
||||||
|
color: Color,
|
||||||
|
coordinates: HashSet<Coordinate>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Group {
|
||||||
|
fn contains(&self, coordinate: &Coordinate) -> bool {
|
||||||
|
self.coordinates.contains(coordinate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/* Two players (Black and White) take turns and Black plays first
|
||||||
|
* Stones are placed on the line intersections and not moved.
|
||||||
|
* A stone with no liberties is removed from the board.
|
||||||
|
* A group of stones of the same color share liberties.
|
||||||
|
* A stone at the edge of the board has only three liberties.
|
||||||
|
* A stone at the corner of the board has only two liberties.
|
||||||
|
* A stone may not be placed in a suicidal position.
|
||||||
|
* A stone placed in a suicidal position is legal if it captures other stones first.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn with_example_board(test: impl FnOnce(Board)) {
|
||||||
|
let board = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 3, row: 3 }, Color::White),
|
||||||
|
(Coordinate { column: 3, row: 4 }, Color::White),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 8, row: 3 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 3 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 4 }, Color::Black),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 15, row: 3 }, Color::White),
|
||||||
|
(Coordinate { column: 15, row: 4 }, Color::White),
|
||||||
|
(Coordinate { column: 15, row: 5 }, Color::White),
|
||||||
|
(Coordinate { column: 14, row: 4 }, Color::White),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 3, row: 8 }, Color::White),
|
||||||
|
(Coordinate { column: 3, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 4, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 3, row: 10 }, Color::Black),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 0, row: 0 }, Color::White),
|
||||||
|
(Coordinate { column: 1, row: 0 }, Color::White),
|
||||||
|
(Coordinate { column: 0, row: 1 }, Color::White),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 9, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 8, row: 9 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 8 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 10 }, Color::Black),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 0, row: 17 }, Color::White),
|
||||||
|
(Coordinate { column: 1, row: 18 }, Color::White),
|
||||||
|
(Coordinate { column: 0, row: 18 }, Color::White),
|
||||||
|
(Coordinate { column: 0, row: 16 }, Color::Black),
|
||||||
|
(Coordinate { column: 1, row: 17 }, Color::Black),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 4, row: 17 }, Color::Black),
|
||||||
|
(Coordinate { column: 5, row: 17 }, Color::Black),
|
||||||
|
(Coordinate { column: 6, row: 17 }, Color::Black),
|
||||||
|
(Coordinate { column: 4, row: 18 }, Color::Black),
|
||||||
|
(Coordinate { column: 6, row: 18 }, Color::Black),
|
||||||
|
(Coordinate { column: 3, row: 17 }, Color::White),
|
||||||
|
(Coordinate { column: 3, row: 18 }, Color::White),
|
||||||
|
(Coordinate { column: 4, row: 16 }, Color::White),
|
||||||
|
(Coordinate { column: 5, row: 16 }, Color::White),
|
||||||
|
(Coordinate { column: 6, row: 16 }, Color::White),
|
||||||
|
(Coordinate { column: 7, row: 17 }, Color::White),
|
||||||
|
(Coordinate { column: 7, row: 18 }, Color::White),
|
||||||
|
/* */
|
||||||
|
(Coordinate { column: 17, row: 0 }, Color::White),
|
||||||
|
(Coordinate { column: 17, row: 1 }, Color::White),
|
||||||
|
(Coordinate { column: 18, row: 1 }, Color::White),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
test(board);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_gets_adjacencies_for_coordinate() {
|
||||||
|
let board = Board::new();
|
||||||
|
for column in 0..19 {
|
||||||
|
for row in 0..19 {
|
||||||
|
for coordinate in board.adjacencies(&Coordinate { column, row }) {
|
||||||
|
assert!(
|
||||||
|
board.within_board(&coordinate),
|
||||||
|
"{} {}: {:?}",
|
||||||
|
column,
|
||||||
|
row,
|
||||||
|
coordinate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_counts_individual_liberties() {
|
||||||
|
let board = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 3, row: 3 }, Color::White),
|
||||||
|
(Coordinate { column: 0, row: 3 }, Color::White),
|
||||||
|
(Coordinate { column: 0, row: 0 }, Color::White),
|
||||||
|
(Coordinate { column: 18, row: 9 }, Color::Black),
|
||||||
|
(
|
||||||
|
Coordinate {
|
||||||
|
column: 18,
|
||||||
|
row: 18,
|
||||||
|
},
|
||||||
|
Color::Black,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert!(board.group(&Coordinate { column: 18, row: 3 }).is_none());
|
||||||
|
assert_eq!(
|
||||||
|
board
|
||||||
|
.group(&Coordinate { column: 3, row: 3 })
|
||||||
|
.map(|g| board.liberties(&g)),
|
||||||
|
Some(4)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
board
|
||||||
|
.group(&Coordinate { column: 0, row: 3 })
|
||||||
|
.map(|g| board.liberties(&g)),
|
||||||
|
Some(3)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
board
|
||||||
|
.group(&Coordinate { column: 0, row: 0 })
|
||||||
|
.map(|g| board.liberties(&g)),
|
||||||
|
Some(2)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
board
|
||||||
|
.group(&Coordinate { column: 18, row: 9 })
|
||||||
|
.map(|g| board.liberties(&g)),
|
||||||
|
Some(3)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
board
|
||||||
|
.group(&Coordinate {
|
||||||
|
column: 18,
|
||||||
|
row: 18
|
||||||
|
})
|
||||||
|
.map(|g| board.liberties(&g)),
|
||||||
|
Some(2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stones_share_liberties() {
|
||||||
|
with_example_board(|board: Board| {
|
||||||
|
let test_cases = vec![
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 0, row: 0 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 0, row: 0 },
|
||||||
|
Coordinate { column: 1, row: 0 },
|
||||||
|
Coordinate { column: 0, row: 1 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(3),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 1, row: 0 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 0, row: 0 },
|
||||||
|
Coordinate { column: 1, row: 0 },
|
||||||
|
Coordinate { column: 0, row: 1 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(3),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 9, row: 9 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![Coordinate { column: 9, row: 9 }].into_iter().collect(),
|
||||||
|
}),
|
||||||
|
Some(1),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 3, row: 4 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 3, row: 3 },
|
||||||
|
Coordinate { column: 3, row: 4 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(6),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 9, row: 3 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::Black,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 8, row: 3 },
|
||||||
|
Coordinate { column: 9, row: 3 },
|
||||||
|
Coordinate { column: 9, row: 4 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(7),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 15, row: 4 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 15, row: 3 },
|
||||||
|
Coordinate { column: 15, row: 4 },
|
||||||
|
Coordinate { column: 15, row: 5 },
|
||||||
|
Coordinate { column: 14, row: 4 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(8),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 3, row: 9 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 3, row: 8 },
|
||||||
|
Coordinate { column: 3, row: 9 },
|
||||||
|
Coordinate { column: 4, row: 9 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(6),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 0, row: 18 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 0, row: 17 },
|
||||||
|
Coordinate { column: 0, row: 18 },
|
||||||
|
Coordinate { column: 1, row: 18 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(1),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
board.clone(),
|
||||||
|
Coordinate { column: 0, row: 17 },
|
||||||
|
Some(Group {
|
||||||
|
color: Color::White,
|
||||||
|
coordinates: vec![
|
||||||
|
Coordinate { column: 0, row: 17 },
|
||||||
|
Coordinate { column: 0, row: 18 },
|
||||||
|
Coordinate { column: 1, row: 18 },
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
Some(1),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
println!("{}", board);
|
||||||
|
for (board, coordinate, group, liberties) in test_cases {
|
||||||
|
assert_eq!(board.group(&coordinate), group.as_ref());
|
||||||
|
assert_eq!(
|
||||||
|
board.group(&coordinate).map(|g| board.liberties(&g)),
|
||||||
|
liberties,
|
||||||
|
"{:?}",
|
||||||
|
coordinate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_finds_adjacent_groups() {
|
||||||
|
with_example_board(|board| {
|
||||||
|
let group = board
|
||||||
|
.group(&Coordinate { column: 0, row: 0 })
|
||||||
|
.cloned()
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(board.adjacent_groups(&group), Vec::new());
|
||||||
|
|
||||||
|
let group = board
|
||||||
|
.group(&Coordinate { column: 3, row: 10 })
|
||||||
|
.cloned()
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(board.adjacent_groups(&group).len(), 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn surrounding_a_group_removes_it() {
|
||||||
|
with_example_board(|board| {
|
||||||
|
let board = board
|
||||||
|
.place_stone(Coordinate { column: 10, row: 9 }, Color::Black)
|
||||||
|
.unwrap();
|
||||||
|
assert!(board.stone(&Coordinate { column: 9, row: 9 }).is_none());
|
||||||
|
|
||||||
|
let board = board
|
||||||
|
.place_stone(Coordinate { column: 2, row: 18 }, Color::Black)
|
||||||
|
.unwrap();
|
||||||
|
assert!(board.stone(&Coordinate { column: 0, row: 18 }).is_none());
|
||||||
|
assert!(board.stone(&Coordinate { column: 1, row: 18 }).is_none());
|
||||||
|
assert!(board.stone(&Coordinate { column: 0, row: 17 }).is_none());
|
||||||
|
assert!(board.group(&Coordinate { column: 0, row: 18 }).is_none());
|
||||||
|
|
||||||
|
let board = board
|
||||||
|
.place_stone(Coordinate { column: 5, row: 18 }, Color::White)
|
||||||
|
.unwrap();
|
||||||
|
assert!(board.stone(&Coordinate { column: 4, row: 17 }).is_none());
|
||||||
|
assert!(board.stone(&Coordinate { column: 5, row: 17 }).is_none());
|
||||||
|
assert!(board.stone(&Coordinate { column: 6, row: 17 }).is_none());
|
||||||
|
assert!(board.stone(&Coordinate { column: 4, row: 18 }).is_none());
|
||||||
|
assert!(board.stone(&Coordinate { column: 6, row: 18 }).is_none());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn self_capture_is_forbidden() {
|
||||||
|
with_example_board(|board| {
|
||||||
|
{
|
||||||
|
let board = board.clone();
|
||||||
|
let res = board.place_stone(Coordinate { column: 18, row: 0 }, Color::Black);
|
||||||
|
assert_eq!(res, Err(BoardError::SelfCapture));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let board = board.clone();
|
||||||
|
let res = board.place_stone(Coordinate { column: 5, row: 18 }, Color::Black);
|
||||||
|
assert_eq!(res, Err(BoardError::SelfCapture));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn validate_group_comparisons() {
|
||||||
|
{
|
||||||
|
let b1 = Board::from_coordinates(
|
||||||
|
vec![(Coordinate { column: 7, row: 9 }, Color::White)].into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let b2 = Board::from_coordinates(
|
||||||
|
vec![(Coordinate { column: 7, row: 9 }, Color::White)].into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(b1, b2);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let b1 = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 7, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 8, row: 10 }, Color::White),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let b2 = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 8, row: 10 }, Color::White),
|
||||||
|
(Coordinate { column: 7, row: 9 }, Color::White),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(b1, b2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_boards_can_be_compared() {
|
||||||
|
let board = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 7, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 8, row: 8 }, Color::White),
|
||||||
|
(Coordinate { column: 8, row: 10 }, Color::White),
|
||||||
|
(Coordinate { column: 9, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 10, row: 9 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 8 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 10 }, Color::Black),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let b1 = board
|
||||||
|
.clone()
|
||||||
|
.place_stone(Coordinate { column: 8, row: 9 }, Color::Black)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let b2 = b1
|
||||||
|
.clone()
|
||||||
|
.place_stone(Coordinate { column: 9, row: 9 }, Color::White)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(board, b2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,198 @@
|
||||||
|
use crate::types::Player;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
fs::File,
|
||||||
|
io::{ErrorKind, Read},
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub trait ConfigOption {
|
||||||
|
type Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DatabasePath(PathBuf);
|
||||||
|
|
||||||
|
impl ConfigOption for DatabasePath {
|
||||||
|
type Value = PathBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConfigOption for Player {
|
||||||
|
type Value = Player;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Config {
|
||||||
|
// fn set_option(option: ConfigOption);
|
||||||
|
fn get_option<N, C: ConfigOption>(name: Name) -> C<Name = Name>
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
enum OptionNames {
|
||||||
|
DatabasePath,
|
||||||
|
Me,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum ConfigOption {
|
||||||
|
DatabasePath(DatabasePath),
|
||||||
|
Me(Me),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum ConfigReadError {
|
||||||
|
#[error("Cannot read the configuration file: {0}")]
|
||||||
|
CannotRead(std::io::Error),
|
||||||
|
#[error("Cannot open the configuration file for reading: {0}")]
|
||||||
|
CannotOpen(std::io::Error),
|
||||||
|
#[error("Invalid json data found in the configurationfile: {0}")]
|
||||||
|
InvalidJSON(serde_json::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Config {
|
||||||
|
config_path: PathBuf,
|
||||||
|
values: HashMap<OptionNames, ConfigOption>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn new(config_path: PathBuf) -> Self {
|
||||||
|
Self {
|
||||||
|
config_path,
|
||||||
|
values: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_path(config_path: PathBuf) -> Result<Self, ConfigReadError> {
|
||||||
|
let mut settings = config_path.clone();
|
||||||
|
settings.push("config");
|
||||||
|
|
||||||
|
match File::open(settings) {
|
||||||
|
Ok(mut file) => {
|
||||||
|
let mut buf = String::new();
|
||||||
|
file.read_to_string(&mut buf)
|
||||||
|
.map_err(|err| ConfigReadError::CannotRead(err))?;
|
||||||
|
let values = serde_json::from_str(buf.as_ref())
|
||||||
|
.map_err(|err| ConfigReadError::InvalidJSON(err))?;
|
||||||
|
Ok(Self {
|
||||||
|
config_path,
|
||||||
|
values,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(io_err) => {
|
||||||
|
match io_err.kind() {
|
||||||
|
ErrorKind::NotFound => {
|
||||||
|
/* create the path and an empty file */
|
||||||
|
Ok(Self {
|
||||||
|
config_path,
|
||||||
|
values: HashMap::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_ => Err(ConfigReadError::CannotOpen(io_err)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set(&mut self, val: ConfigOption) {
|
||||||
|
let _ = match val {
|
||||||
|
ConfigOption::DatabasePath(_) => self.values.insert(OptionNames::DatabasePath, val),
|
||||||
|
ConfigOption::Me(_) => self.values.insert(OptionNames::Me, val),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get<'a, T>(&'a self) -> T
|
||||||
|
where
|
||||||
|
T: From<&'a Self>,
|
||||||
|
{
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct DatabasePath(PathBuf);
|
||||||
|
|
||||||
|
impl std::ops::Deref for DatabasePath {
|
||||||
|
type Target = PathBuf;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Config> for DatabasePath {
|
||||||
|
fn from(config: &Config) -> Self {
|
||||||
|
match config.values.get(&OptionNames::DatabasePath) {
|
||||||
|
Some(ConfigOption::DatabasePath(path)) => path.clone(),
|
||||||
|
_ => DatabasePath(config.config_path.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct Me(Player);
|
||||||
|
|
||||||
|
impl From<&Config> for Option<Me> {
|
||||||
|
fn from(config: &Config) -> Self {
|
||||||
|
config
|
||||||
|
.values
|
||||||
|
.get(&OptionNames::Me)
|
||||||
|
.and_then(|val| match val {
|
||||||
|
ConfigOption::Me(me) => Some(me.clone()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for Me {
|
||||||
|
type Target = Player;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::types::Rank;
|
||||||
|
use cool_asserts::assert_matches;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_set_and_get_options() {
|
||||||
|
let mut config = Config::new(PathBuf::from("."));
|
||||||
|
config.set(ConfigOption::DatabasePath(DatabasePath(PathBuf::from(
|
||||||
|
"fixtures/five_games",
|
||||||
|
))));
|
||||||
|
config.set(ConfigOption::Me(Me(Player {
|
||||||
|
name: "Savanni".to_owned(),
|
||||||
|
rank: Some(Rank::Kyu(10)),
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_can_serialize_and_deserialize() {
|
||||||
|
let mut config = Config::new(PathBuf::from("."));
|
||||||
|
config.set(ConfigOption::DatabasePath(DatabasePath(PathBuf::from(
|
||||||
|
"fixtures/five_games",
|
||||||
|
))));
|
||||||
|
config.set(ConfigOption::Me(Me(Player {
|
||||||
|
name: "Savanni".to_owned(),
|
||||||
|
rank: Some(Rank::Kyu(10)),
|
||||||
|
})));
|
||||||
|
let s = serde_json::to_string(&config.values).unwrap();
|
||||||
|
println!("{}", s);
|
||||||
|
let values: HashMap<OptionNames, ConfigOption> = serde_json::from_str(s.as_ref()).unwrap();
|
||||||
|
println!("options: {:?}", values);
|
||||||
|
|
||||||
|
assert_matches!(values.get(&OptionNames::DatabasePath),
|
||||||
|
Some(ConfigOption::DatabasePath(db_path)) =>
|
||||||
|
assert_eq!(*db_path, config.get())
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_matches!(values.get(&OptionNames::Me), Some(ConfigOption::Me(val)) =>
|
||||||
|
assert_eq!(Some(val.clone()), config.get())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
use std::{ffi::OsStr, io::Read, os::unix::ffi::OsStrExt, path::PathBuf};
|
||||||
|
|
||||||
|
use sgf::{go, parse_sgf, Game};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("Database permission denied")]
|
||||||
|
PermissionDenied,
|
||||||
|
#[error("An IO error occurred: {0}")]
|
||||||
|
IOError(std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for Error {
|
||||||
|
fn from(err: std::io::Error) -> Self {
|
||||||
|
Error::IOError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Database {
|
||||||
|
path: PathBuf,
|
||||||
|
games: Vec<go::Game>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub fn open_path(path: PathBuf) -> Result<Database, Error> {
|
||||||
|
let mut games: Vec<go::Game> = Vec::new();
|
||||||
|
|
||||||
|
let extension = PathBuf::from("sgf").into_os_string();
|
||||||
|
|
||||||
|
let path_iter = std::fs::read_dir(path.clone())?;
|
||||||
|
for entry in path_iter {
|
||||||
|
match entry {
|
||||||
|
Ok(entry) => {
|
||||||
|
if entry.path().extension() == Some(&extension) {
|
||||||
|
let mut buffer = String::new();
|
||||||
|
std::fs::File::open(entry.path())
|
||||||
|
.unwrap()
|
||||||
|
.read_to_string(&mut buffer)
|
||||||
|
.unwrap();
|
||||||
|
for sgf in parse_sgf(&buffer).unwrap() {
|
||||||
|
match sgf {
|
||||||
|
Game::Go(game) => games.push(game),
|
||||||
|
Game::Unsupported(_) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => println!("failed entry: {:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Database { path, games })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.games.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn all_games(&self) -> impl Iterator<Item = &go::Game> {
|
||||||
|
self.games.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use cool_asserts::assert_matches;
|
||||||
|
use sgf::Date;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_reads_empty_database() {
|
||||||
|
let db = Database::open_path(PathBuf::from("fixtures/empty_database/"))
|
||||||
|
.expect("database to open");
|
||||||
|
assert_eq!(db.all_games().count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_reads_five_games_from_database() {
|
||||||
|
let db =
|
||||||
|
Database::open_path(PathBuf::from("fixtures/five_games/")).expect("database to open");
|
||||||
|
assert_eq!(db.all_games().count(), 5);
|
||||||
|
for game in db.all_games() {}
|
||||||
|
|
||||||
|
assert_matches!(db.all_games().find(|g| g.info.black_player == Some("Steve".to_owned())),
|
||||||
|
Some(game) => {
|
||||||
|
assert_eq!(game.info.black_player, Some("Steve".to_owned()));
|
||||||
|
assert_eq!(game.info.white_player, Some("Savanni".to_owned()));
|
||||||
|
assert_eq!(game.info.date, vec![Date::Date(chrono::NaiveDate::from_ymd_opt(2023, 4, 19).unwrap())]);
|
||||||
|
assert_eq!(game.info.komi, Some(6.5));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
mod api;
|
||||||
|
pub use api::{
|
||||||
|
CoreApp, CoreRequest, CoreResponse, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
mod board;
|
||||||
|
pub use board::*;
|
||||||
|
|
||||||
|
mod config;
|
||||||
|
pub use config::*;
|
||||||
|
|
||||||
|
mod database;
|
||||||
|
|
||||||
|
mod types;
|
||||||
|
pub use types::{BoardError, Color, Rank, Size};
|
||||||
|
|
||||||
|
pub mod ui;
|
|
@ -0,0 +1,213 @@
|
||||||
|
use crate::{
|
||||||
|
api::PlayStoneRequest,
|
||||||
|
board::{Board, Coordinate},
|
||||||
|
config::DatabasePath,
|
||||||
|
database::Database,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{path::PathBuf, time::Duration};
|
||||||
|
use thiserror::Error;
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Error)]
|
||||||
|
pub enum BoardError {
|
||||||
|
#[error("Position is invalid")]
|
||||||
|
InvalidPosition,
|
||||||
|
#[error("Self-capture is forbidden")]
|
||||||
|
SelfCapture,
|
||||||
|
#[error("Ko")]
|
||||||
|
Ko,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub enum Color {
|
||||||
|
Black,
|
||||||
|
White,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct Size {
|
||||||
|
pub width: u8,
|
||||||
|
pub height: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Size {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
width: 19,
|
||||||
|
height: 19,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AppState {
|
||||||
|
pub game: Option<GameState>,
|
||||||
|
pub database: Database,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
pub fn new(database_path: DatabasePath) -> Self {
|
||||||
|
Self {
|
||||||
|
game: Some(GameState::new()),
|
||||||
|
database: Database::open_path(database_path.to_path_buf()).unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn place_stone(&mut self, req: PlayStoneRequest) {
|
||||||
|
match self.game {
|
||||||
|
Some(ref mut game) => {
|
||||||
|
let _ = game.place_stone(Coordinate {
|
||||||
|
column: req.column,
|
||||||
|
row: req.row,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub enum Rank {
|
||||||
|
Kyu(u8),
|
||||||
|
Dan(u8),
|
||||||
|
Pro(u8),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for Rank {
|
||||||
|
type Error = String;
|
||||||
|
|
||||||
|
fn try_from(_: &str) -> Result<Rank, Self::Error> {
|
||||||
|
Ok(Rank::Kyu(15))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Rank> for String {
|
||||||
|
fn from(r: Rank) -> String {
|
||||||
|
match r {
|
||||||
|
Rank::Kyu(v) => format!("{} kyu", v),
|
||||||
|
Rank::Dan(v) => format!("{} dan", v),
|
||||||
|
Rank::Pro(v) => format!("{} pro", v),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct Player {
|
||||||
|
pub name: String,
|
||||||
|
pub rank: Option<Rank>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct GameState {
|
||||||
|
pub board: Board,
|
||||||
|
pub past_positions: Vec<Board>,
|
||||||
|
|
||||||
|
pub conversation: Vec<String>,
|
||||||
|
pub current_player: Color,
|
||||||
|
|
||||||
|
pub white_player: Player,
|
||||||
|
pub black_player: Player,
|
||||||
|
|
||||||
|
pub white_clock: Duration,
|
||||||
|
pub black_clock: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GameState {
|
||||||
|
pub fn new() -> GameState {
|
||||||
|
GameState {
|
||||||
|
board: Board::new(),
|
||||||
|
past_positions: vec![],
|
||||||
|
conversation: vec![],
|
||||||
|
current_player: Color::Black,
|
||||||
|
white_player: Player {
|
||||||
|
name: "".to_owned(),
|
||||||
|
rank: None,
|
||||||
|
},
|
||||||
|
black_player: Player {
|
||||||
|
name: "".to_owned(),
|
||||||
|
rank: None,
|
||||||
|
},
|
||||||
|
white_clock: Duration::from_secs(600),
|
||||||
|
black_clock: Duration::from_secs(600),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn place_stone(&mut self, coordinate: Coordinate) -> Result<(), BoardError> {
|
||||||
|
let board = self.board.clone();
|
||||||
|
let new_board = board.place_stone(coordinate, self.current_player)?;
|
||||||
|
|
||||||
|
if self.past_positions.contains(&new_board) {
|
||||||
|
return Err(BoardError::Ko);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.past_positions.push(self.board.clone());
|
||||||
|
self.board = new_board;
|
||||||
|
match self.current_player {
|
||||||
|
Color::White => self.current_player = Color::Black,
|
||||||
|
Color::Black => self.current_player = Color::White,
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn current_player_changes_after_move() {
|
||||||
|
let mut state = GameState::new();
|
||||||
|
assert_eq!(state.current_player, Color::Black);
|
||||||
|
state.place_stone(Coordinate { column: 9, row: 9 }).unwrap();
|
||||||
|
assert_eq!(state.current_player, Color::White);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn current_player_remains_the_same_after_self_capture() {
|
||||||
|
let mut state = GameState::new();
|
||||||
|
state.board = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 17, row: 0 }, Color::White),
|
||||||
|
(Coordinate { column: 17, row: 1 }, Color::White),
|
||||||
|
(Coordinate { column: 18, row: 1 }, Color::White),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
state.current_player = Color::Black;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
state.place_stone(Coordinate { column: 18, row: 0 }),
|
||||||
|
Err(BoardError::SelfCapture)
|
||||||
|
);
|
||||||
|
assert_eq!(state.current_player, Color::Black);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ko_rules_are_enforced() {
|
||||||
|
let mut state = GameState::new();
|
||||||
|
state.board = Board::from_coordinates(
|
||||||
|
vec![
|
||||||
|
(Coordinate { column: 7, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 8, row: 8 }, Color::White),
|
||||||
|
(Coordinate { column: 8, row: 10 }, Color::White),
|
||||||
|
(Coordinate { column: 9, row: 9 }, Color::White),
|
||||||
|
(Coordinate { column: 10, row: 9 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 8 }, Color::Black),
|
||||||
|
(Coordinate { column: 9, row: 10 }, Color::Black),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
state.place_stone(Coordinate { column: 8, row: 9 }).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
state.place_stone(Coordinate { column: 9, row: 9 }),
|
||||||
|
Err(BoardError::Ko)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct Action<A> {
|
||||||
|
pub id: String,
|
||||||
|
pub label: String,
|
||||||
|
pub action: A,
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sgf::{
|
||||||
|
go::{Game, Rank},
|
||||||
|
Date,
|
||||||
|
};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct GamePreviewElement {
|
||||||
|
pub date: Vec<Date>,
|
||||||
|
pub black_player: String,
|
||||||
|
pub black_rank: Option<Rank>,
|
||||||
|
pub white_player: String,
|
||||||
|
pub white_rank: Option<Rank>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GamePreviewElement {
|
||||||
|
pub fn new(game: &Game) -> GamePreviewElement {
|
||||||
|
GamePreviewElement {
|
||||||
|
date: game.info.date.clone(),
|
||||||
|
black_player: game
|
||||||
|
.info
|
||||||
|
.black_player
|
||||||
|
.clone()
|
||||||
|
.unwrap_or("black_player".to_owned()),
|
||||||
|
black_rank: game.info.black_rank.clone(),
|
||||||
|
white_player: game
|
||||||
|
.info
|
||||||
|
.white_player
|
||||||
|
.clone()
|
||||||
|
.unwrap_or("white_player".to_owned()),
|
||||||
|
white_rank: game.info.white_rank.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct Menu<T: PartialEq + Eq> {
|
||||||
|
current: Option<T>,
|
||||||
|
options: Vec<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: PartialEq + Eq> Menu<T> {
|
||||||
|
pub fn new(options: Vec<T>, current: Option<T>) -> Menu<T> {
|
||||||
|
if let Some(ref current) = current {
|
||||||
|
assert!(options.contains(current));
|
||||||
|
}
|
||||||
|
Menu { current, options }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod action;
|
||||||
|
pub mod game_preview;
|
||||||
|
pub mod menu;
|
|
@ -0,0 +1,80 @@
|
||||||
|
use crate::ui::{Action, GamePreviewElement};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sgf::go::Game;
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
fn rank_strings() -> Vec<String> {
|
||||||
|
vec![
|
||||||
|
"", "30 kyu", "29 kyu", "28 kyu", "27 kyu", "26 kyu", "25 kyu", "24 kyu", "23 kyu",
|
||||||
|
"22 kyu", "21 kyu", "20 kyu", "19 kyu", "18 kyu", "17 kyu", "16 kyu", "15 kyu", "14 kyu",
|
||||||
|
"13 kyu", "12 kyu", "11 kyu", "10 kyu", "9 kyu", "8 kyu", "7 kyu", "6 kyu", "5 kyu",
|
||||||
|
"4 kyu", "3 kyu", "2 kyu", "1 kyu", "1 dan", "2 dan", "3 dan", "4 dan", "5 dan", "6 dan",
|
||||||
|
"7 dan", "8 dan", "9 dan", "1 pro", "2 pro", "3 pro", "4 pro", "5 pro", "6 pro", "7 pro",
|
||||||
|
"8 pro", "9 pro",
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub enum PlayerElement {
|
||||||
|
Hotseat(HotseatPlayerElement),
|
||||||
|
// Remote(RemotePlayerElement),
|
||||||
|
// Bot(BotPlayerElement),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PlayerElement {
|
||||||
|
fn default() -> PlayerElement {
|
||||||
|
PlayerElement::Hotseat(HotseatPlayerElement::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct HotseatPlayerElement {
|
||||||
|
pub placeholder: Option<String>,
|
||||||
|
pub default_rank: Option<String>,
|
||||||
|
pub ranks: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct RemotePlayerElement {}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct BotPlayerElement {}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct HomeView {
|
||||||
|
pub black_player: PlayerElement,
|
||||||
|
pub white_player: PlayerElement,
|
||||||
|
pub games: Vec<GamePreviewElement>,
|
||||||
|
pub start_game: Action<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn home<'a>(games: impl Iterator<Item = &'a Game>) -> HomeView {
|
||||||
|
let black_player = PlayerElement::Hotseat(HotseatPlayerElement {
|
||||||
|
placeholder: Some("black player".to_owned()),
|
||||||
|
default_rank: None,
|
||||||
|
ranks: rank_strings(),
|
||||||
|
});
|
||||||
|
let white_player = PlayerElement::Hotseat(HotseatPlayerElement {
|
||||||
|
placeholder: Some("white player".to_owned()),
|
||||||
|
default_rank: None,
|
||||||
|
ranks: rank_strings(),
|
||||||
|
});
|
||||||
|
HomeView {
|
||||||
|
black_player,
|
||||||
|
white_player,
|
||||||
|
games: games.map(GamePreviewElement::new).collect(),
|
||||||
|
start_game: Action {
|
||||||
|
id: "start-game-action".to_owned(),
|
||||||
|
label: "New Game".to_owned(),
|
||||||
|
action: (),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
use crate::{
|
||||||
|
ui::types;
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub enum LaunchScreenView {
|
||||||
|
CreateGame(CreateGameView)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will be called when the Kifu application starts.
|
||||||
|
pub fn launch_screen() -> LaunchScreenView {
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
mod elements;
|
||||||
|
pub use elements::{action::Action, game_preview::GamePreviewElement, menu::Menu};
|
||||||
|
|
||||||
|
mod playing_field;
|
||||||
|
pub use playing_field::{playing_field, PlayingFieldView};
|
||||||
|
|
||||||
|
// mod launch_screen;
|
||||||
|
// pub use launch_screen::{launch_screen, LaunchScreenView};
|
||||||
|
|
||||||
|
mod home;
|
||||||
|
pub use home::{home, HomeView, HotseatPlayerElement, PlayerElement};
|
||||||
|
|
||||||
|
mod types;
|
||||||
|
pub use types::{
|
||||||
|
BoardElement, ChatElement, IntersectionElement, PlayerCardElement, StoneElement,
|
||||||
|
TextFieldElement,
|
||||||
|
};
|
|
@ -0,0 +1,60 @@
|
||||||
|
use crate::{
|
||||||
|
types::{Color, GameState},
|
||||||
|
ui::types,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct PlayingFieldView {
|
||||||
|
pub board: types::BoardElement,
|
||||||
|
pub player_card_black: types::PlayerCardElement,
|
||||||
|
pub player_card_white: types::PlayerCardElement,
|
||||||
|
pub chat: types::ChatElement,
|
||||||
|
pub message: types::TextFieldElement,
|
||||||
|
pub current_player: Color,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn playing_field(game: &GameState) -> PlayingFieldView {
|
||||||
|
let board = types::BoardElement::from(&game.board);
|
||||||
|
|
||||||
|
let player_card_black = types::PlayerCardElement {
|
||||||
|
color: Color::Black,
|
||||||
|
name: game.black_player.name.clone(),
|
||||||
|
rank: game
|
||||||
|
.black_player
|
||||||
|
.rank
|
||||||
|
.map(String::from)
|
||||||
|
.unwrap_or("".to_owned()),
|
||||||
|
clock: "".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let player_card_white = types::PlayerCardElement {
|
||||||
|
color: Color::White,
|
||||||
|
name: game.white_player.name.clone(),
|
||||||
|
rank: game
|
||||||
|
.black_player
|
||||||
|
.rank
|
||||||
|
.map(String::from)
|
||||||
|
.unwrap_or("".to_owned()),
|
||||||
|
clock: "".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let chat = types::ChatElement {
|
||||||
|
messages: vec![
|
||||||
|
"[22:05] Savanni: oops".to_owned(),
|
||||||
|
"[22:06] Opal: you know I'll take advantage of that, right?".to_owned(),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
let message = types::TextFieldElement {};
|
||||||
|
|
||||||
|
PlayingFieldView {
|
||||||
|
board,
|
||||||
|
player_card_black,
|
||||||
|
player_card_white,
|
||||||
|
chat,
|
||||||
|
message,
|
||||||
|
current_player: game.current_player,
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
use crate::types::{Color, Size};
|
||||||
|
use crate::{
|
||||||
|
api::{CoreRequest, PlayStoneRequest},
|
||||||
|
Board, Coordinate,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use typeshare::typeshare;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct Jitter {
|
||||||
|
pub x: i8,
|
||||||
|
pub y: i8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct StoneElement {
|
||||||
|
pub color: Color,
|
||||||
|
pub jitter: Jitter,
|
||||||
|
pub liberties: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StoneElement {
|
||||||
|
pub fn new(color: Color, liberties: Option<u8>) -> Self {
|
||||||
|
Self {
|
||||||
|
color,
|
||||||
|
liberties,
|
||||||
|
jitter: Jitter { x: 0, y: 0 },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
#[serde(tag = "type", content = "content")]
|
||||||
|
pub enum IntersectionElement {
|
||||||
|
Unplayable,
|
||||||
|
Empty(CoreRequest),
|
||||||
|
Filled(StoneElement),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct BoardElement {
|
||||||
|
pub size: Size,
|
||||||
|
pub spaces: Vec<IntersectionElement>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BoardElement {
|
||||||
|
pub fn new(size: Size) -> Self {
|
||||||
|
let spaces: Vec<IntersectionElement> = (0..size.height)
|
||||||
|
.map(|row| {
|
||||||
|
(0..size.width)
|
||||||
|
.map(|column| {
|
||||||
|
IntersectionElement::Empty(CoreRequest::PlayStone(PlayStoneRequest {
|
||||||
|
column,
|
||||||
|
row,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
.collect::<Vec<IntersectionElement>>()
|
||||||
|
})
|
||||||
|
.collect::<Vec<Vec<IntersectionElement>>>()
|
||||||
|
.concat();
|
||||||
|
Self { size, spaces }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stone(&self, column: u8, row: u8) -> IntersectionElement {
|
||||||
|
let addr = self.addr(column, row);
|
||||||
|
self.spaces[addr].clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stone_mut(&mut self, column: u8, row: u8) -> &mut IntersectionElement {
|
||||||
|
let addr = self.addr(column, row);
|
||||||
|
&mut self.spaces[addr]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn addr(&self, column: u8, row: u8) -> usize {
|
||||||
|
((row as usize) * (self.size.width as usize) + (column as usize)) as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Board> for BoardElement {
|
||||||
|
fn from(board: &Board) -> Self {
|
||||||
|
let spaces: Vec<IntersectionElement> =
|
||||||
|
(0..board.size.height)
|
||||||
|
.map(|row| {
|
||||||
|
(0..board.size.width)
|
||||||
|
.map(|column| match board.stone(&Coordinate { column, row }) {
|
||||||
|
Some(color) => IntersectionElement::Filled(StoneElement {
|
||||||
|
jitter: Jitter { x: 0, y: 0 },
|
||||||
|
liberties: None,
|
||||||
|
color,
|
||||||
|
}),
|
||||||
|
None => IntersectionElement::Empty(CoreRequest::PlayStone(
|
||||||
|
PlayStoneRequest { column, row },
|
||||||
|
)),
|
||||||
|
})
|
||||||
|
.collect::<Vec<IntersectionElement>>()
|
||||||
|
})
|
||||||
|
.collect::<Vec<Vec<IntersectionElement>>>()
|
||||||
|
.concat();
|
||||||
|
Self {
|
||||||
|
size: board.size,
|
||||||
|
spaces,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BoardElement {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new(Size::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct PlayerCardElement {
|
||||||
|
pub color: Color,
|
||||||
|
pub name: String,
|
||||||
|
pub rank: String,
|
||||||
|
pub clock: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct ChatElement {
|
||||||
|
pub messages: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[typeshare]
|
||||||
|
pub struct TextFieldElement {}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
Generated by typeshare 1.5.1
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface PlayStoneRequest {
|
||||||
|
column: number;
|
||||||
|
row: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Size {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IntersectionElement =
|
||||||
|
| { type: "Unplayable", content?: undefined }
|
||||||
|
| { type: "Empty", content: CoreRequest }
|
||||||
|
| { type: "Filled", content: StoneElement };
|
||||||
|
|
||||||
|
export interface BoardElement {
|
||||||
|
size: Size;
|
||||||
|
spaces: IntersectionElement[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Color {
|
||||||
|
Black = "Black",
|
||||||
|
White = "White",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlayerCardElement {
|
||||||
|
color: Color;
|
||||||
|
name: string;
|
||||||
|
rank: string;
|
||||||
|
clock: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatElement {
|
||||||
|
messages: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TextFieldElement {
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlayingFieldView {
|
||||||
|
board: BoardElement;
|
||||||
|
player_card_black: PlayerCardElement;
|
||||||
|
player_card_white: PlayerCardElement;
|
||||||
|
chat: ChatElement;
|
||||||
|
message: TextFieldElement;
|
||||||
|
current_player: Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Jitter {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StoneElement {
|
||||||
|
color: Color;
|
||||||
|
jitter: Jitter;
|
||||||
|
liberties?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CoreRequest =
|
||||||
|
| { type: "PlayingField", content?: undefined }
|
||||||
|
| { type: "PlayStoneRequest", content: PlayStoneRequest };
|
||||||
|
|
||||||
|
export type CoreResponse =
|
||||||
|
| { type: "PlayingFieldView", content: PlayingFieldView };
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" type="text/css" href="styles.css" />
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="menu">
|
||||||
|
<ul>
|
||||||
|
<li> <a href="index.html">Index</a> </li>
|
||||||
|
<li> <a href="playing.html">Game Board for playing</a> </li>
|
||||||
|
<li> <a href="database.html">Game database</a> </li>
|
||||||
|
<li> <a href="analysis.html">Game board for analysis</a> </li>
|
||||||
|
<li> Connection management </li>
|
||||||
|
<li> Challenge list </li>
|
||||||
|
<li> Friends list </li>
|
||||||
|
<li> Open challenges </li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="widget">
|
||||||
|
<div> US Go Congress 2023, DDK Tournament, Round 1, Board 25 </div>
|
||||||
|
<div class="game-analysis">
|
||||||
|
<div class="game-analysis__board">
|
||||||
|
<img src="game-screen.jpg" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-analysis__tree">
|
||||||
|
<div>
|
||||||
|
<img src="game-tree.jpg" />
|
||||||
|
</div>
|
||||||
|
<p> Shoring up the wall. Any chance to capture that group was lost a couple of moves back and Savanni knows it. </p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-info">
|
||||||
|
<div class="player-info">
|
||||||
|
<div> Savanni (10k) </div>
|
||||||
|
</div>
|
||||||
|
<div class="player-info">
|
||||||
|
<div> Opal (10k) </div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" type="text/css" href="styles.css" />
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="menu">
|
||||||
|
<ul>
|
||||||
|
<li> <a href="index.html">Index</a> </li>
|
||||||
|
<li> <a href="playing.html">Game Board for playing</a> </li>
|
||||||
|
<li> <a href="database.html">Game database</a> </li>
|
||||||
|
<li> Game board for analysis </li>
|
||||||
|
<li> Connection management </li>
|
||||||
|
<li> Challenge list </li>
|
||||||
|
<li> Friends list </li>
|
||||||
|
<li> Open challenges </li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="widget">
|
||||||
|
<div class="game-filter">
|
||||||
|
<input class="game-filter__term" placeholder="date" />
|
||||||
|
<input class="game-filter__term" placeholder="player name" />
|
||||||
|
<input class="game-filter__term" placeholder="minimum strength" />
|
||||||
|
<input class="game-filter__term" placeholder="maximum strength" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-database">
|
||||||
|
<div class="game-entry">
|
||||||
|
<a href="analysis.html"><img class="game-entry__icon" src="game-thumbnail.jpg" /></a>
|
||||||
|
<div class="game-entry__info-card">
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
2016-06-15
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(B) Alpha Go (w)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(W) Lee Sedol
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry">
|
||||||
|
<img class="game-entry__icon" src="game-thumbnail.jpg" />
|
||||||
|
<div class="game-entry__info-card">
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
2016-06-15
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(B) Alpha Go (w)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(W) Lee Sedol
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry">
|
||||||
|
<img class="game-entry__icon" src="game-thumbnail.jpg" />
|
||||||
|
<div class="game-entry__info-card">
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
2016-06-15
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(B) Alpha Go (w)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(W) Lee Sedol
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry">
|
||||||
|
<img class="game-entry__icon" src="game-thumbnail.jpg" />
|
||||||
|
<div class="game-entry__info-card">
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
2016-06-15
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(B) Alpha Go (w)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(W) Lee Sedol
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry">
|
||||||
|
<img class="game-entry__icon" src="game-thumbnail.jpg" />
|
||||||
|
<div class="game-entry__info-card">
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
2016-06-15
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(B) Alpha Go (w)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="game-entry__info-row">
|
||||||
|
(W) Lee Sedol
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 151 KiB |
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
|
@ -0,0 +1,24 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" type="text/css" href="styles.css" />
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="menu">
|
||||||
|
<ul>
|
||||||
|
<li> <a href="playing.html">Game Board for playing</a> </li>
|
||||||
|
<li> <a href="database.html">Game database</a> </li>
|
||||||
|
<li> <a href="analysis.html">Game board for analysis</a> </li>
|
||||||
|
<li> Connection management </li>
|
||||||
|
<li> Challenge list </li>
|
||||||
|
<li> Friends list </li>
|
||||||
|
<li> Open challenges </li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="widget">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -0,0 +1,49 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" type="text/css" href="styles.css" />
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="menu">
|
||||||
|
<ul>
|
||||||
|
<li> <a href="index.html">Index</a> </li>
|
||||||
|
<li> <a href="playing.html">Game Board for playing</a> </li>
|
||||||
|
<li> Game database </li>
|
||||||
|
<li> Game board for analysis </li>
|
||||||
|
<li> Connection management </li>
|
||||||
|
<li> Challenge list </li>
|
||||||
|
<li> Friends list </li>
|
||||||
|
<li> Open challenges </li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="widget">
|
||||||
|
|
||||||
|
<img src="game-screen.jpg" />
|
||||||
|
|
||||||
|
<div class="game-info">
|
||||||
|
<div class="player-info">
|
||||||
|
<div> Savanni (10k) </div> <div> 24:53 </div>
|
||||||
|
</div>
|
||||||
|
<div class="player-info">
|
||||||
|
<div> Opal (10k) </div> <div> 25:00 </div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chat">
|
||||||
|
<div>
|
||||||
|
<textarea cols="80" rows="25">
|
||||||
|
[22:05] Savanni: oops
|
||||||
|
[22:06] Opal: you know I'll take advantage of that, right?
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input size="60"></input>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,270 @@
|
||||||
|
(;FF[4]
|
||||||
|
CA[UTF-8]
|
||||||
|
GM[1]
|
||||||
|
DT[2022-02-17]
|
||||||
|
GN[Amika Matĉo]
|
||||||
|
PC[https://online-go.com/review/823151]
|
||||||
|
PB[mearss25]
|
||||||
|
PW[savanni.dgerinel]
|
||||||
|
BR[16k]
|
||||||
|
WR[10k]
|
||||||
|
TM[1500]OT[15 fischer]
|
||||||
|
RE[W+46.5]
|
||||||
|
SZ[19]
|
||||||
|
KM[7.5]
|
||||||
|
RU[AGA]
|
||||||
|
|
||||||
|
;B[pd]SQ[ph]SQ[oi]LB[pi:B]LB[qi:A]SQ[pj]LB[qj:C]
|
||||||
|
;W[dp]
|
||||||
|
;B[dd]
|
||||||
|
;W[qp]
|
||||||
|
;B[ch]
|
||||||
|
;W[np]
|
||||||
|
;B[cl]
|
||||||
|
;W[qf]
|
||||||
|
;B[qh]
|
||||||
|
(;W[of]
|
||||||
|
(;B[nc]
|
||||||
|
;W[oi]
|
||||||
|
;B[pj]
|
||||||
|
;W[md]
|
||||||
|
;B[nk]
|
||||||
|
;W[jd]
|
||||||
|
;B[gc]
|
||||||
|
(;W[jj]
|
||||||
|
;B[mi]
|
||||||
|
;W[mj]
|
||||||
|
;B[lj]
|
||||||
|
;W[nj]
|
||||||
|
;B[ok]
|
||||||
|
;W[li]
|
||||||
|
;B[ki]
|
||||||
|
;W[lh]
|
||||||
|
;B[kj]
|
||||||
|
;W[kh]
|
||||||
|
;B[mk]
|
||||||
|
(;W[pi]
|
||||||
|
;B[qi]
|
||||||
|
;W[ji]
|
||||||
|
;B[ni]
|
||||||
|
;W[oj]
|
||||||
|
;B[nh]
|
||||||
|
;W[mh]
|
||||||
|
;B[oh]
|
||||||
|
;W[ng]
|
||||||
|
;B[ig]
|
||||||
|
;W[qc]
|
||||||
|
;B[pf]
|
||||||
|
;W[pg]
|
||||||
|
;B[ph]
|
||||||
|
;W[pe]
|
||||||
|
;B[qd]
|
||||||
|
;W[od]
|
||||||
|
;B[oc]
|
||||||
|
;W[pc]
|
||||||
|
;B[nd]
|
||||||
|
;W[oe]
|
||||||
|
;B[og]
|
||||||
|
;W[rd]
|
||||||
|
;B[mc]
|
||||||
|
;W[mf]
|
||||||
|
;B[ld]
|
||||||
|
;W[me]
|
||||||
|
;B[jh]
|
||||||
|
;W[cc]
|
||||||
|
;B[cd]
|
||||||
|
;W[dc]
|
||||||
|
;B[ec]
|
||||||
|
;W[eb]
|
||||||
|
;B[fd]
|
||||||
|
;W[fb]
|
||||||
|
;B[gb]
|
||||||
|
;W[bd]
|
||||||
|
;B[be]
|
||||||
|
;W[bc]
|
||||||
|
;B[ad]
|
||||||
|
;W[ce]
|
||||||
|
;B[de]
|
||||||
|
;W[ac]
|
||||||
|
;B[cf]
|
||||||
|
;W[ae]
|
||||||
|
;B[fa]
|
||||||
|
;W[ea]
|
||||||
|
;B[ga]
|
||||||
|
;W[ca]
|
||||||
|
;B[cq]
|
||||||
|
;W[dq]
|
||||||
|
;B[cp]
|
||||||
|
;W[cn]
|
||||||
|
;B[bn]
|
||||||
|
;W[do]
|
||||||
|
;B[cm]
|
||||||
|
;W[cr]
|
||||||
|
;B[co]
|
||||||
|
;W[dn]
|
||||||
|
;B[dm]
|
||||||
|
;W[fn]
|
||||||
|
;B[fm]
|
||||||
|
;W[hn]
|
||||||
|
;B[il]
|
||||||
|
;W[jp]
|
||||||
|
;B[hq]
|
||||||
|
;W[jq]
|
||||||
|
;B[er]
|
||||||
|
;W[dr]
|
||||||
|
;B[fq]
|
||||||
|
;W[ir]
|
||||||
|
;B[io]
|
||||||
|
;W[jm]
|
||||||
|
;B[kn]
|
||||||
|
;W[jn]
|
||||||
|
;B[ho]
|
||||||
|
;W[gn]
|
||||||
|
;B[hr]
|
||||||
|
;W[gp]
|
||||||
|
;B[gr]
|
||||||
|
;W[es]
|
||||||
|
;B[fs]
|
||||||
|
;W[ds]
|
||||||
|
;B[eq]
|
||||||
|
;W[hs]
|
||||||
|
;B[go]
|
||||||
|
;W[fp]
|
||||||
|
;B[en]
|
||||||
|
;W[eo]
|
||||||
|
;B[br]
|
||||||
|
;W[fo]
|
||||||
|
;B[mo]
|
||||||
|
;W[mp]
|
||||||
|
;B[lp]
|
||||||
|
;W[lq]
|
||||||
|
;B[ko]
|
||||||
|
;W[jo]
|
||||||
|
;B[km]
|
||||||
|
;W[ql]
|
||||||
|
;B[pl]
|
||||||
|
;W[pm]
|
||||||
|
;B[om]
|
||||||
|
;W[pn]
|
||||||
|
;B[on]
|
||||||
|
;W[oo]
|
||||||
|
;B[no]
|
||||||
|
;W[op]
|
||||||
|
;B[qk]
|
||||||
|
;W[rl]
|
||||||
|
;B[rk]
|
||||||
|
;W[rn]
|
||||||
|
;B[qg]
|
||||||
|
;W[rf]
|
||||||
|
;B[rg]
|
||||||
|
;W[kf]
|
||||||
|
;B[if]
|
||||||
|
;W[kc]
|
||||||
|
;B[lb]
|
||||||
|
;W[lc]
|
||||||
|
;B[kb]
|
||||||
|
;W[jb]
|
||||||
|
;B[ma]
|
||||||
|
;W[ob]
|
||||||
|
;B[nb]
|
||||||
|
;W[pa]
|
||||||
|
;B[ka]
|
||||||
|
;W[je]
|
||||||
|
;B[ie]
|
||||||
|
;W[id]
|
||||||
|
;B[hd]
|
||||||
|
;W[jl]
|
||||||
|
;B[ii]
|
||||||
|
;W[ik]
|
||||||
|
;B[hk]
|
||||||
|
;W[hl]
|
||||||
|
;B[gl]
|
||||||
|
;W[hm]
|
||||||
|
;B[ij]
|
||||||
|
;W[jk]
|
||||||
|
;B[gm]
|
||||||
|
;W[bf]
|
||||||
|
;B[bg]
|
||||||
|
;W[ce]
|
||||||
|
;B[cg]
|
||||||
|
;W[be]
|
||||||
|
;B[fh]
|
||||||
|
;W[jg]
|
||||||
|
;B[ih]
|
||||||
|
;W[em]
|
||||||
|
;B[el]
|
||||||
|
;W[gk]
|
||||||
|
;B[hj]
|
||||||
|
;W[fl]
|
||||||
|
;B[gj]
|
||||||
|
;W[fk]
|
||||||
|
;B[ek]
|
||||||
|
;W[kp]
|
||||||
|
;B[fj]
|
||||||
|
;W[sl]
|
||||||
|
;B[sk]
|
||||||
|
;W[kk]
|
||||||
|
;B[lk]
|
||||||
|
;W[lo]
|
||||||
|
;B[ln]
|
||||||
|
;W[lp]
|
||||||
|
;B[ll]
|
||||||
|
;W[sf]
|
||||||
|
;B[sg]
|
||||||
|
;W[ib]
|
||||||
|
;B[ic]
|
||||||
|
;W[jc]
|
||||||
|
;B[hc]
|
||||||
|
;W[is]
|
||||||
|
;B[bs]
|
||||||
|
;W[fc]
|
||||||
|
;B[ed]
|
||||||
|
;W[ne]
|
||||||
|
;B[na]
|
||||||
|
;W[oa]
|
||||||
|
;B[qa]
|
||||||
|
;W[pb]
|
||||||
|
;B[rc]
|
||||||
|
;W[qe]
|
||||||
|
;B[ag]
|
||||||
|
;W[jf]
|
||||||
|
;B[pf]
|
||||||
|
;W[kl]
|
||||||
|
;B[mm]
|
||||||
|
;W[pg]
|
||||||
|
;B[]
|
||||||
|
;W[pf]
|
||||||
|
;B[]
|
||||||
|
;W[]
|
||||||
|
)(;W[lk]
|
||||||
|
;B[kk]
|
||||||
|
;W[ll]
|
||||||
|
;B[kl]
|
||||||
|
;W[km]
|
||||||
|
;B[jm]
|
||||||
|
;W[kn]
|
||||||
|
))(;W[mj]
|
||||||
|
))(;B[nd]
|
||||||
|
;W[oh]
|
||||||
|
;B[qk]
|
||||||
|
))(;W[qc]
|
||||||
|
(;B[qd]
|
||||||
|
;W[pc]
|
||||||
|
;B[od]
|
||||||
|
;W[rd]
|
||||||
|
;B[re]
|
||||||
|
;W[rc]
|
||||||
|
;B[rf]
|
||||||
|
;W[nc]
|
||||||
|
;B[me]
|
||||||
|
)(;B[pc]TR[jc]
|
||||||
|
;W[qd]
|
||||||
|
;B[pe]
|
||||||
|
(;W[rf]
|
||||||
|
;B[og]
|
||||||
|
)(;W[pf]
|
||||||
|
;B[of]
|
||||||
|
;W[oe]
|
||||||
|
(;B[ne]
|
||||||
|
)(;B[nf]
|
||||||
|
)))))
|
|
@ -0,0 +1,44 @@
|
||||||
|
body {
|
||||||
|
background: hsl(0 0% 85%);
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu {
|
||||||
|
border-right: 1px solid black;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-info {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget {
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-database {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-entry {
|
||||||
|
display: flex;
|
||||||
|
width: 500px;
|
||||||
|
margin: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-entry__icon {
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-analysis {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-analysis__board {
|
||||||
|
flex-shrink: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-analysis__tree {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
|
@ -0,0 +1,564 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_system_properties"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bumpalo"
|
||||||
|
version = "3.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.79"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
|
||||||
|
dependencies = [
|
||||||
|
"iana-time-zone",
|
||||||
|
"js-sys",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "codespan-reporting"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
|
||||||
|
dependencies = [
|
||||||
|
"termcolor",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxx"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"cxxbridge-flags",
|
||||||
|
"cxxbridge-macro",
|
||||||
|
"link-cplusplus",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxx-build"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"codespan-reporting",
|
||||||
|
"once_cell",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"scratch",
|
||||||
|
"syn 2.0.15",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxxbridge-flags"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxxbridge-macro"
|
||||||
|
version = "1.0.94"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.15",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "grid"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0634107a3a005070dd73e27e74ecb691a94e9e5ba7829f434db7fbf73a6b5c47"
|
||||||
|
dependencies = [
|
||||||
|
"no-std-compat",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone"
|
||||||
|
version = "0.1.56"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
|
||||||
|
dependencies = [
|
||||||
|
"android_system_properties",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"iana-time-zone-haiku",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone-haiku"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
|
||||||
|
dependencies = [
|
||||||
|
"cxx",
|
||||||
|
"cxx-build",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "js-sys"
|
||||||
|
version = "0.3.61"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
|
||||||
|
dependencies = [
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kifu-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"grid",
|
||||||
|
"serde",
|
||||||
|
"thiserror",
|
||||||
|
"typeshare",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kifu-wasm"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"kifu-core",
|
||||||
|
"serde",
|
||||||
|
"serde-wasm-bindgen",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.142"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "link-cplusplus"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "no-std-compat"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.17.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.56"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scratch"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.160"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde-wasm-bindgen"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"serde",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.160"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.15",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.96"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.15",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typeshare"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f44d1a2f454cb35fbe05b218c410792697e76bd868f48d3a418f2cd1a7d527d6"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"typeshare-annotation",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typeshare-annotation"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc670d0e358428857cc3b4bf504c691e572fccaec9542ff09212d3f13d74b7a9"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"wasm-bindgen-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-backend"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-futures"
|
||||||
|
version = "0.4.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"web-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro-support"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-shared"
|
||||||
|
version = "0.2.84"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "web-sys"
|
||||||
|
version = "0.3.61"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "kifu-wasm"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
kifu-core = { path = "../../core" }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde-wasm-bindgen = "0.5.0"
|
||||||
|
wasm-bindgen = "0.2"
|
||||||
|
wasm-bindgen-futures = "*"
|
||||||
|
|
||||||
|
[package.metadata.wasm-pack.profile.release]
|
||||||
|
wasm-opt = false
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
all:
|
||||||
|
wasm-pack build --target web
|
|
@ -0,0 +1,26 @@
|
||||||
|
use kifu_core::{CoreRequest, CoreResponse};
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
|
pub fn log(s: &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CoreApp(kifu_core::CoreApp);
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl CoreApp {
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(kifu_core::CoreApp::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn dispatch(&self, param: &JsValue) -> JsValue {
|
||||||
|
let request: CoreRequest = serde_wasm_bindgen::from_value(param.clone()).unwrap();
|
||||||
|
serde_wasm_bindgen::to_value(&self.0.dispatch(request).await).unwrap()
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,32 @@
|
||||||
|
[package]
|
||||||
|
name = "kifu-gtk"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
screenplay = []
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cairo-rs = { version = "0.17" }
|
||||||
|
gio = { version = "0.17" }
|
||||||
|
glib = { version = "0.17" }
|
||||||
|
gtk = { version = "0.6", package = "gtk4" }
|
||||||
|
image = { version = "0.24" }
|
||||||
|
kifu-core = { path = "../core" }
|
||||||
|
tokio = { version = "1.26", features = [ "full" ] }
|
||||||
|
screenplay = { path = "../../screenplay" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
glib-build-tools = "0.17"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "kifu-gtk"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "screenplay"
|
||||||
|
path = "src/bin/screenplay.rs"
|
||||||
|
required-features = [ "screenplay" ]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
release:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
dev:
|
||||||
|
export CONFIG=.
|
||||||
|
cargo watch -x 'run --bin kifu-gtk'
|
||||||
|
|
||||||
|
screenplay:
|
||||||
|
cargo watch -x 'run --bin screenplay --features="screenplay"'
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() {
|
||||||
|
glib_build_tools::compile_resources(
|
||||||
|
&["resources"],
|
||||||
|
"resources/resources.gresources.xml",
|
||||||
|
"com.luminescent-dreams.kifu-gtk.gresource",
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{"Me":{"name":"Savanni","rank":{"Kyu":10}},"DatabasePath":"../core/fixtures/five_games"}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue