├── .gitattributes
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── images
├── logo.png
└── screenshot.png
├── res
├── boot.dol
├── icon.png
└── meta.xml
└── src
├── assets
├── pointer.png
├── rounded-box.png
└── stats
│ ├── box.png
│ └── fade.png
├── data
├── solutions.lua
└── words.lua
├── lib
├── binser.lua
├── date.lua
└── timer.lua
└── main.lua
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto eol=lf
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build
2 | /dist/*
3 |
4 | # Visual Studio Code
5 | /.vscode/*
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------------------------------
2 | # Wiirdle Makefile
3 | #
4 | # Copyright (C) 2022 HTV04
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # --------------------------------------------------------------------------------
19 |
20 | build:
21 | @rm -rf dist
22 | @mkdir -p dist/sd/apps/wiirdle/data
23 |
24 | @cp -r res/* dist/sd/apps/wiirdle
25 | @cp -r src/* dist/sd/apps/wiirdle/data
26 |
27 | @cd dist/sd; zip -r -9 ../wiirdle.zip .
28 |
29 | clean:
30 | @rm -rf dist
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 
2 | Wiirdle is a [Wordle](https://www.nytimes.com/games/wordle/index.html) clone for the Wii, powered by the [WiiLÖVE](https://github.com/HTV04/wiilove) framework.
3 |
4 | Every day, you will have six attempts to guess a five-letter word, with feedback given for each guess indicating when letters match or occupy the correct position.
5 |
6 | *Wordle* by Josh Wardle and the New York Times. Play the original game [here](https://www.nytimes.com/games/wordle/index.html)!
7 |
8 | # Screenshot
9 | 
10 |
--------------------------------------------------------------------------------
/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/images/logo.png
--------------------------------------------------------------------------------
/images/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/images/screenshot.png
--------------------------------------------------------------------------------
/res/boot.dol:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/res/boot.dol
--------------------------------------------------------------------------------
/res/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/res/icon.png
--------------------------------------------------------------------------------
/res/meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Wiirdle
4 | 1.0.0
5 | HTV04
6 | Wordle clone for the Wii
7 | Wiirdle is a Wordle clone for the Wii, powered by the WiiLÖVE framework.
8 |
9 | Every day, you will have six attempts to guess a five-letter word, with feedback given for each guess indicating when letters match or occupy the correct position.
10 |
11 | "Wordle" by Josh Wardle and the New York Times.
12 |
13 |
--------------------------------------------------------------------------------
/src/assets/pointer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/src/assets/pointer.png
--------------------------------------------------------------------------------
/src/assets/rounded-box.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/src/assets/rounded-box.png
--------------------------------------------------------------------------------
/src/assets/stats/box.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/src/assets/stats/box.png
--------------------------------------------------------------------------------
/src/assets/stats/fade.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/htv04/wiilove-wiirdle/4c9bdf8e7bb98cbccb200b5abe13f5ac4e7e1d84/src/assets/stats/fade.png
--------------------------------------------------------------------------------
/src/data/solutions.lua:
--------------------------------------------------------------------------------
1 | --[[----------------------------------------------------------------------------
2 | Wiirdle solution list
3 |
4 | This file is part of Wiirdle.
5 |
6 | Copyright (C) 2022 HTV04
7 |
8 | This program is free software: you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation, either version 3 of the License, or
11 | (at your option) any later version.
12 |
13 | This program is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with this program. If not, see .
20 | ------------------------------------------------------------------------------]]
21 |
22 | -- Don't look!
23 | return {
24 | "AWARE",
25 | "HOBBY",
26 | "GAUGE",
27 | "ELDER",
28 | "GNOME",
29 | "ALIVE",
30 | "SHOOT",
31 | "SOLAR",
32 | "LADEN",
33 | "LEAVE",
34 | "NAVAL",
35 | "RUGBY",
36 | "SHAPE",
37 | "FLOOD",
38 | "SHAKE",
39 | "REHAB",
40 | "MASON",
41 | "MIXER",
42 | "TWIST",
43 | "ORBIT",
44 | "THEIR",
45 | "BELLE",
46 | "LODGE",
47 | "GRAND",
48 | "PATIO",
49 | "CHOIR",
50 | "HOLLY",
51 | "CASEY",
52 | "QUEEN",
53 | "SCALE",
54 | "BUDDY",
55 | "PURSE",
56 | "BOBBY",
57 | "TWIKI",
58 | "TOUGH",
59 | "MEDAL",
60 | "ALIGN",
61 | "NIGER",
62 | "VIRAL",
63 | "DYING",
64 | "QUEUE",
65 | "DICKE",
66 | "LOWER",
67 | "CANDY",
68 | "RADIO",
69 | "SPOKE",
70 | "LIVED",
71 | "DYLAN",
72 | "ANGRY",
73 | "POINT",
74 | "DONNA",
75 | "ACTOR",
76 | "CARLO",
77 | "CURVE",
78 | "QUIET",
79 | "SPINE",
80 | "ALBUM",
81 | "FAVOR",
82 | "DECOR",
83 | "OLDER",
84 | "STACK",
85 | "CLERK",
86 | "SIGMA",
87 | "CREST",
88 | "GUIDE",
89 | "PLAIN",
90 | "IVORY",
91 | "SETUP",
92 | "DELAY",
93 | "BASIC",
94 | "GOING",
95 | "GONNA",
96 | "PROBE",
97 | "STICK",
98 | "FORTY",
99 | "LINED",
100 | "SPARC",
101 | "PENNY",
102 | "MANGA",
103 | "MSGID",
104 | "TIGHT",
105 | "ADMIT",
106 | "PHOTO",
107 | "EMPTY",
108 | "SCOOP",
109 | "CANAL",
110 | "DEVON",
111 | "HINDU",
112 | "BIRTH",
113 | "CLIFF",
114 | "FIXED",
115 | "FIBRE",
116 | "CABIN",
117 | "NOKIA",
118 | "LEONE",
119 | "CITED",
120 | "VOTED",
121 | "SHIFT",
122 | "EBOOK",
123 | "SAMOA",
124 | "LARGE",
125 | "MARIE",
126 | "WIRED",
127 | "CLOSE",
128 | "RELAY",
129 | "UNITY",
130 | "PANIC",
131 | "BURKE",
132 | "ROUGE",
133 | "SLIDE",
134 | "CLARK",
135 | "HOUSE",
136 | "MARSH",
137 | "RALLY",
138 | "SUSAN",
139 | "BERRY",
140 | "EARTH",
141 | "VAULT",
142 | "LOGAN",
143 | "DREAM",
144 | "SMITH",
145 | "TOOTH",
146 | "ARUBA",
147 | "FIRED",
148 | "KINDA",
149 | "MARIA",
150 | "NAMED",
151 | "SANTA",
152 | "AVOID",
153 | "TIMER",
154 | "SHORE",
155 | "TUNER",
156 | "TRACT",
157 | "WILEY",
158 | "FAITH",
159 | "KATIE",
160 | "FINAL",
161 | "CHOSE",
162 | "GUILD",
163 | "SAFER",
164 | "OMAHA",
165 | "FLOOR",
166 | "GRILL",
167 | "THANK",
168 | "SHORT",
169 | "LATEX",
170 | "ISAAC",
171 | "VERSE",
172 | "RULED",
173 | "TREAT",
174 | "OWNER",
175 | "CREEK",
176 | "FLASH",
177 | "HONDA",
178 | "REFER",
179 | "HUMAN",
180 | "LOPEZ",
181 | "MARIO",
182 | "LARRY",
183 | "JULIA",
184 | "PIECE",
185 | "INDEX",
186 | "WITCH",
187 | "PROOF",
188 | "SPEND",
189 | "TIGER",
190 | "AARON",
191 | "YOUNG",
192 | "LOCAL",
193 | "AGAIN",
194 | "UNDER",
195 | "FROST",
196 | "SHEER",
197 | "VOLVO",
198 | "HAIRY",
199 | "FOUND",
200 | "THINK",
201 | "YIELD",
202 | "WATCH",
203 | "SHEEP",
204 | "AGENT",
205 | "FRAUD",
206 | "TRICK",
207 | "STAKE",
208 | "RATED",
209 | "AWARD",
210 | "BREED",
211 | "MEANT",
212 | "CHEVY",
213 | "NORTH",
214 | "RELAX",
215 | "UNCLE",
216 | "PAPUA",
217 | "OXIDE",
218 | "LABOR",
219 | "TEACH",
220 | "PLACE",
221 | "ABOVE",
222 | "TRUCK",
223 | "CARRY",
224 | "CONST",
225 | "PROMO",
226 | "COSTA",
227 | "GRACE",
228 | "HUMOR",
229 | "CLEAN",
230 | "LOBBY",
231 | "UNTIL",
232 | "VSNET",
233 | "RIDER",
234 | "KENNY",
235 | "DIRTY",
236 | "SEVEN",
237 | "YOUTH",
238 | "ROCKY",
239 | "CISCO",
240 | "SPRAY",
241 | "AIMED",
242 | "TONER",
243 | "NYLON",
244 | "HENRY",
245 | "CHILD",
246 | "CLIMB",
247 | "CANON",
248 | "PRIDE",
249 | "KELLY",
250 | "KLEIN",
251 | "RHODE",
252 | "COUNT",
253 | "WHALE",
254 | "UPSET",
255 | "TOWER",
256 | "ITALY",
257 | "WASTE",
258 | "FLYER",
259 | "SPARE",
260 | "SPANK",
261 | "DELTA",
262 | "ALPHA",
263 | "LATER",
264 | "STRIP",
265 | "BUNCH",
266 | "AGING",
267 | "VOICE",
268 | "BUNNY",
269 | "PLAZA",
270 | "BURST",
271 | "RENEW",
272 | "NANCY",
273 | "THETA",
274 | "CUBIC",
275 | "MORAL",
276 | "PRIOR",
277 | "SMELL",
278 | "GLENN",
279 | "HOWTO",
280 | "VISTA",
281 | "ARMOR",
282 | "GIVEN",
283 | "TRIAL",
284 | "TRAIL",
285 | "ARMED",
286 | "MAGIC",
287 | "TRACE",
288 | "ANGEL",
289 | "HAITI",
290 | "LANKA",
291 | "EAGLE",
292 | "SYRIA",
293 | "THEME",
294 | "CHIEF",
295 | "LIMIT",
296 | "SAUDI",
297 | "CLONE",
298 | "CRAFT",
299 | "IRISH",
300 | "WRIST",
301 | "PUPPY",
302 | "MEDIA",
303 | "UNION",
304 | "ENEMY",
305 | "DAISY",
306 | "VERDE",
307 | "AMINO",
308 | "IDAHO",
309 | "HELLO",
310 | "WORLD",
311 | "PRINT",
312 | "ANIME",
313 | "NIKON",
314 | "SERUM",
315 | "NOTRE",
316 | "EXTRA",
317 | "REBEL",
318 | "ALIEN",
319 | "WHICH",
320 | "GRAPH",
321 | "ORGAN",
322 | "MOUTH",
323 | "XHTML",
324 | "RALPH",
325 | "ADOBE",
326 | "LUCIA",
327 | "SOLID",
328 | "CEDAR",
329 | "BRICK",
330 | "ALLOY",
331 | "BUILD",
332 | "SKILL",
333 | "THROW",
334 | "FACED",
335 | "BOOST",
336 | "BLIND",
337 | "CABLE",
338 | "OTHER",
339 | "DERBY",
340 | "BRAKE",
341 | "CZECH",
342 | "BREAD",
343 | "EGYPT",
344 | "WENDY",
345 | "BLOOM",
346 | "ROMAN",
347 | "BEGAN",
348 | "BRUCE",
349 | "FLUSH",
350 | "ALLAH",
351 | "SLOPE",
352 | "DUTCH",
353 | "LASER",
354 | "LIVER",
355 | "GENRE",
356 | "DELHI",
357 | "EQUAL",
358 | "ANGLE",
359 | "FIBER",
360 | "SOUND",
361 | "AWFUL",
362 | "LAURA",
363 | "CAMEL",
364 | "MAPLE",
365 | "AHEAD",
366 | "QUILT",
367 | "PILOT",
368 | "ELITE",
369 | "FATAL",
370 | "STEAL",
371 | "BLINK",
372 | "WELSH",
373 | "INNER",
374 | "FIGHT",
375 | "CHILE",
376 | "ALLOW",
377 | "URBAN",
378 | "BELLY",
379 | "HONEY",
380 | "MAJOR",
381 | "ARROW",
382 | "HORSE",
383 | "PLANT",
384 | "CHART",
385 | "BADGE",
386 | "MUSIC",
387 | "MERGE",
388 | "TUMOR",
389 | "ADOPT",
390 | "ANNEX",
391 | "WHOLE",
392 | "SPEAK",
393 | "ANNIE",
394 | "PEACE",
395 | "NIGHT",
396 | "ASIDE",
397 | "PUNCH",
398 | "TRUTH",
399 | "DIANE",
400 | "SALLY",
401 | "ASSET",
402 | "STYLE",
403 | "DRAWN",
404 | "HOTEL",
405 | "MERCY",
406 | "TOTAL",
407 | "PERRY",
408 | "WAGON",
409 | "COHEN",
410 | "CLOUD",
411 | "FLOYD",
412 | "HAVEN",
413 | "SHARP",
414 | "SQUAD",
415 | "SALEM",
416 | "MONTH",
417 | "ARGUE",
418 | "NOISE",
419 | "LEMON",
420 | "NEPAL",
421 | "TIRED",
422 | "LEVEL",
423 | "SPLIT",
424 | "SHEET",
425 | "EMILY",
426 | "MINOR",
427 | "POKER",
428 | "CLICK",
429 | "RATIO",
430 | "TWICE",
431 | "JAPAN",
432 | "LABEL",
433 | "THUMB",
434 | "MONTE",
435 | "SWING",
436 | "FRAME",
437 | "SKYPE",
438 | "JULIE",
439 | "MALTA",
440 | "WOULD",
441 | "ORDER",
442 | "FILED",
443 | "OFTEN",
444 | "FLESH",
445 | "BOXED",
446 | "HEARD",
447 | "APRIL",
448 | "MICRO",
449 | "FEWER",
450 | "BOUND",
451 | "CHAIR",
452 | "JACOB",
453 | "SMILE",
454 | "TITLE",
455 | "WRITE",
456 | "EXCEL",
457 | "SIGHT",
458 | "DEPOT",
459 | "SIZED",
460 | "STOOD",
461 | "GRAIN",
462 | "PHASE",
463 | "SPICE",
464 | "YAHOO",
465 | "COAST",
466 | "CREAM",
467 | "SHADE",
468 | "LOGIN",
469 | "SHAFT",
470 | "NEVER",
471 | "LIGHT",
472 | "SCOTT",
473 | "HONOR",
474 | "THOSE",
475 | "DRYER",
476 | "THERE",
477 | "PROUD",
478 | "AUDIO",
479 | "PRIZE",
480 | "SHELL",
481 | "DRUNK",
482 | "BIBLE",
483 | "TYLER",
484 | "PIXEL",
485 | "MOUNT",
486 | "OCCUR",
487 | "STORM",
488 | "DEATH",
489 | "MATCH",
490 | "SHAME",
491 | "BLOND",
492 | "ROVER",
493 | "JASON",
494 | "HENCE",
495 | "SPENT",
496 | "ANGER",
497 | "HEATH",
498 | "DENSE",
499 | "YUKON",
500 | "COMIC",
501 | "STAND",
502 | "FENCE",
503 | "TOMMY",
504 | "DRIVE",
505 | "INTER",
506 | "KARMA",
507 | "THICK",
508 | "THIRD",
509 | "NOTED",
510 | "VINYL",
511 | "STATE",
512 | "LUNCH",
513 | "SPERM",
514 | "SAINT",
515 | "LIKED",
516 | "CROWD",
517 | "ROBIN",
518 | "WORSE",
519 | "GREAT",
520 | "NAKED",
521 | "FORTH",
522 | "THREE",
523 | "SENSE",
524 | "STORY",
525 | "MIGHT",
526 | "STAGE",
527 | "RAISE",
528 | "CLAIM",
529 | "COVER",
530 | "TERRY",
531 | "QUOTE",
532 | "WORTH",
533 | "STILL",
534 | "WAYNE",
535 | "TRULY",
536 | "PAPER",
537 | "TULSA",
538 | "BILLY",
539 | "CIVIC",
540 | "SPACE",
541 | "GUARD",
542 | "GRADE",
543 | "BROWN",
544 | "FRANK",
545 | "NASTY",
546 | "VENUE",
547 | "JIMMY",
548 | "SINGH",
549 | "ESSAY",
550 | "CARGO",
551 | "CRIME",
552 | "SHARE",
553 | "METAL",
554 | "KEITH",
555 | "WEIRD",
556 | "WORST",
557 | "FIFTH",
558 | "FIELD",
559 | "TOKEN",
560 | "LYING",
561 | "DUBAI",
562 | "MODEM",
563 | "KAREN",
564 | "STAMP",
565 | "RURAL",
566 | "IDEAL",
567 | "INDIE",
568 | "PANEL",
569 | "DEBUT",
570 | "ENTER",
571 | "LYRIC",
572 | "STUCK",
573 | "FRUIT",
574 | "OLIVE",
575 | "ENJOY",
576 | "SCREW",
577 | "WOMAN",
578 | "WROTE",
579 | "JUICE",
580 | "SUITE",
581 | "WOUND",
582 | "SILLY",
583 | "SPEED",
584 | "LEASE",
585 | "FERRY",
586 | "POUND",
587 | "ABUSE",
588 | "ROUTE",
589 | "TROUT",
590 | "BORED",
591 | "UPPER",
592 | "OCEAN",
593 | "SPAIN",
594 | "JOINT",
595 | "BASIN",
596 | "TEETH",
597 | "DIGIT",
598 | "ALONG",
599 | "NEWLY",
600 | "BLANK",
601 | "ULTRA",
602 | "PHPBB",
603 | "ROGER",
604 | "SWORD",
605 | "EVENT",
606 | "CHASE",
607 | "WIDTH",
608 | "INTRO",
609 | "COULD",
610 | "HAPPY",
611 | "COLON",
612 | "DIARY",
613 | "LEAST",
614 | "AMONG",
615 | "TAMIL",
616 | "GLOBE",
617 | "MERIT",
618 | "THING",
619 | "CORAL",
620 | "CHEAT",
621 | "STEVE",
622 | "PEARL",
623 | "TURBO",
624 | "SARAH",
625 | "SALAD",
626 | "ALIKE",
627 | "EIGHT",
628 | "THESE",
629 | "VOCAL",
630 | "MERRY",
631 | "METRO",
632 | "CLOTH",
633 | "LAYER",
634 | "PITCH",
635 | "EXIST",
636 | "HEART",
637 | "YACHT",
638 | "SUGAR",
639 | "LINUX",
640 | "HIRED",
641 | "THONG",
642 | "BUILT",
643 | "PATCH",
644 | "KNOCK",
645 | "CRAZY",
646 | "TOUCH",
647 | "LOVER",
648 | "LEGAL",
649 | "ABOUT",
650 | "KENYA",
651 | "CASIO",
652 | "TASTE",
653 | "BATCH",
654 | "DOVER",
655 | "STOCK",
656 | "BEGIN",
657 | "DIEGO",
658 | "YEAST",
659 | "SALON",
660 | "CHECK",
661 | "CYBER",
662 | "GUEST",
663 | "FLOAT",
664 | "EARLY",
665 | "DOING",
666 | "EPSON",
667 | "CLEAR",
668 | "ALICE",
669 | "TRUNK",
670 | "VALVE",
671 | "COMBO",
672 | "TAHOE",
673 | "RESET",
674 | "BLAME",
675 | "DROVE",
676 | "ISLAM",
677 | "CHEAP",
678 | "INPUT",
679 | "LUCKY",
680 | "BEGUN",
681 | "PLATE",
682 | "SANDY",
683 | "PIANO",
684 | "PLANE",
685 | "OUGHT",
686 | "CIVIL",
687 | "ELLEN",
688 | "ASKED",
689 | "QUEST",
690 | "RETRO",
691 | "ADMIN",
692 | "STRAP",
693 | "DRINK",
694 | "EBONY",
695 | "BEACH",
696 | "DAIRY",
697 | "USAGE",
698 | "KNOWN",
699 | "GROVE",
700 | "DRAIN",
701 | "PULSE",
702 | "STONE",
703 | "ALLEN",
704 | "SMART",
705 | "ONION",
706 | "FEVER",
707 | "CRASH",
708 | "MEYER",
709 | "NOBLE",
710 | "FUNKY",
711 | "RIVER",
712 | "BROOK",
713 | "SUDAN",
714 | "FIFTY",
715 | "ROYAL",
716 | "TREND",
717 | "WORRY",
718 | "INDIA",
719 | "QUITE",
720 | "ADDED",
721 | "SWIFT",
722 | "THEFT",
723 | "GLORY",
724 | "APNIC",
725 | "GAMMA",
726 | "GROUP",
727 | "MIAMI",
728 | "JENNY",
729 | "MOORE",
730 | "SIXTH",
731 | "TRIED",
732 | "VIDEO",
733 | "CONGO",
734 | "FUNNY",
735 | "AMEND",
736 | "SHALL",
737 | "FRONT",
738 | "CACHE",
739 | "TRUST",
740 | "FANCY",
741 | "STAFF",
742 | "ADULT",
743 | "APPLY",
744 | "ALTER",
745 | "ACUTE",
746 | "SINCE",
747 | "SCUBA",
748 | "QUICK",
749 | "QATAR",
750 | "NOVEL",
751 | "KATHY",
752 | "REPLY",
753 | "PROVE",
754 | "FOCAL",
755 | "ALONE",
756 | "FLUID",
757 | "INTEL",
758 | "BETTY",
759 | "POWER",
760 | "STEEL",
761 | "BUYER",
762 | "DONOR",
763 | "ROBOT",
764 | "CAREY",
765 | "XANAX",
766 | "KITTY",
767 | "BRAVE",
768 | "TODAY",
769 | "WHITE",
770 | "LOVED",
771 | "SOLVE",
772 | "MACRO",
773 | "EXACT",
774 | "LEARN",
775 | "SHARK",
776 | "BEAST",
777 | "STUFF",
778 | "LINDA",
779 | "SIMON",
780 | "BRIAN",
781 | "DISCO",
782 | "VITAL",
783 | "SWEET",
784 | "DOZEN",
785 | "SHIRT",
786 | "MAINE",
787 | "CAUSE",
788 | "MAYBE",
789 | "LAUGH",
790 | "SKIRT",
791 | "COURT",
792 | "RAPID",
793 | "AFTER",
794 | "IMAGE",
795 | "PASTE",
796 | "FORUM",
797 | "CLOCK",
798 | "HELEN",
799 | "OUTER",
800 | "OSCAR",
801 | "BELOW",
802 | "DRIED",
803 | "MOVIE",
804 | "RADAR",
805 | "OPERA",
806 | "EVERY",
807 | "SATIN",
808 | "TOKYO",
809 | "KOREA",
810 | "MIXED",
811 | "FIRST",
812 | "ARBOR",
813 | "BRIEF",
814 | "SPORT",
815 | "HANDY",
816 | "PAXIL",
817 | "WHERE",
818 | "MARCH",
819 | "COACH",
820 | "TAKEN",
821 | "WHEAT",
822 | "SANYO",
823 | "MYSQL",
824 | "PERTH",
825 | "ARISE",
826 | "OFFER",
827 | "SORRY",
828 | "KERRY",
829 | "VALID",
830 | "KODAK",
831 | "ISSUE",
832 | "MAZDA",
833 | "JAMIE",
834 | "HARRY",
835 | "DEVEL",
836 | "BRYAN",
837 | "BREAK",
838 | "DOUBT",
839 | "WRONG",
840 | "BADLY",
841 | "BRAIN",
842 | "BRUSH",
843 | "SMALL",
844 | "DATED",
845 | "XEROX",
846 | "BOOTH",
847 | "CATCH",
848 | "RANCH",
849 | "EMAIL",
850 | "AMBER",
851 | "BLADE",
852 | "DEREK",
853 | "SLAVE",
854 | "SUNNY",
855 | "YEMEN",
856 | "FRESH",
857 | "FLOUR",
858 | "DEALT",
859 | "GHANA",
860 | "CYCLE",
861 | "BRING",
862 | "COLOR",
863 | "DEPTH",
864 | "CLARA",
865 | "SBJCT",
866 | "MAMBO",
867 | "SAUCE",
868 | "MOTEL",
869 | "DEBUG",
870 | "MOVED",
871 | "PAINT",
872 | "MOUSE",
873 | "SAGEM",
874 | "IRAQI",
875 | "AGREE",
876 | "TOPIC",
877 | "CHAIN",
878 | "BLACK",
879 | "SHELF",
880 | "PROXY",
881 | "DRAFT",
882 | "SONIC",
883 | "ROUND",
884 | "MOTOR",
885 | "SHINE",
886 | "BRIDE",
887 | "BAKER",
888 | "BLAKE",
889 | "STUDY",
890 | "USING",
891 | "POLAR",
892 | "BLAST",
893 | "APART",
894 | "KNIFE",
895 | "ASIAN",
896 | "MODEL",
897 | "REMIX",
898 | "RIDGE",
899 | "CONDO",
900 | "GRANT",
901 | "JERRY",
902 | "SCORE",
903 | "FAULT",
904 | "QUERY",
905 | "LATIN",
906 | "BROAD",
907 | "LOOSE",
908 | "USUAL",
909 | "MULTI",
910 | "SURGE",
911 | "CHARM",
912 | "TABLE",
913 | "BLEND",
914 | "WHILE",
915 | "STORE",
916 | "FLAME",
917 | "MANOR",
918 | "FULLY",
919 | "BRAND",
920 | "WOMEN",
921 | "TAMPA",
922 | "RICKY",
923 | "ARENA",
924 | "ALERT",
925 | "METER",
926 | "GREEN",
927 | "BINGO",
928 | "PETER",
929 | "DAILY",
930 | "BLAIR",
931 | "JUDGE",
932 | "HEAVY",
933 | "DAVID",
934 | "BARRY",
935 | "REACH",
936 | "OZONE",
937 | "INBOX",
938 | "BEING",
939 | "SPELL",
940 | "MARCO",
941 | "ERROR",
942 | "DANCE",
943 | "SHOWN",
944 | "JEWEL",
945 | "AUDIT",
946 | "GREEK",
947 | "EDDIE",
948 | "VALUE",
949 | "FORGE",
950 | "SCARY",
951 | "ASCII",
952 | "ZDNET",
953 | "SERVE",
954 | "CHUCK",
955 | "KEVIN",
956 | "BLOCK",
957 | "BLOOD",
958 | "CAROL",
959 | "TEDDY",
960 | "WHEEL",
961 | "SCOPE",
962 | "CROWN",
963 | "JANET",
964 | "EDGAR",
965 | "GOTTA",
966 | "CRUDE",
967 | "READY",
968 | "SMOKE",
969 | "JESSE",
970 | "COLIN",
971 | "CRAIG",
972 | "FUZZY",
973 | "STEAM",
974 | "SCOUT",
975 | "FATTY",
976 | "SAVER",
977 | "TOXIC",
978 | "TRACY",
979 | "DIANA",
980 | "ENTRY",
981 | "GROWN",
982 | "SUPER",
983 | "FILME",
984 | "CINDY",
985 | "ALLAN",
986 | "ROUGH",
987 | "ELECT",
988 | "TRADE",
989 | "BACON",
990 | "MILAN",
991 | "APPLE",
992 | "GHOST",
993 | "FLEET",
994 | "ALARM",
995 | "BROKE",
996 | "PRIME",
997 | "SAMBA",
998 | "PRICE",
999 | "GRAVE",
1000 | "DEVIL",
1001 | "PARTY",
1002 | "BASED",
1003 | "BOARD",
1004 | "PIZZA",
1005 | "DRILL",
1006 | "BENCH",
1007 | "REALM",
1008 | "MAYOR",
1009 | "LLOYD",
1010 | "FAIRY",
1011 | "SHOCK",
1012 | "NEWER",
1013 | "DODGE",
1014 | "OMEGA",
1015 | "OWNED",
1016 | "DADDY",
1017 | "DRAMA",
1018 | "DANNY",
1019 | "JOYCE",
1020 | "TRIBE",
1021 | "CRACK",
1022 | "PHONE",
1023 | "MAKER",
1024 | "CHINA",
1025 | "MARDI",
1026 | "START",
1027 | "CHEST",
1028 | "VILLA",
1029 | "NERVE",
1030 | "RIGHT",
1031 | "SAVED",
1032 | "WHOSE",
1033 | "SOUTH",
1034 | "FALSE",
1035 | "WIDER",
1036 | "FORCE",
1037 | "SLEEP",
1038 | "LANCE",
1039 | "RANDY",
1040 | "ARRAY",
1041 | "WANNA",
1042 | "GIANT",
1043 | "TRAIN",
1044 | "PASTA",
1045 | "RANGE",
1046 | "TRACK",
1047 | "CHICK",
1048 | "HOPED",
1049 | "NURSE",
1050 | "SCENE",
1051 | "TRASH",
1052 | "ESSEX",
1053 | "BOOTY",
1054 | "SNAKE",
1055 | "VISIT",
1056 | "ENDED",
1057 | "ENDIF",
1058 | "LOGIC",
1059 | "MONEY",
1060 | "WATER"
1061 | }
1062 |
--------------------------------------------------------------------------------
/src/lib/binser.lua:
--------------------------------------------------------------------------------
1 | -- binser.lua
2 |
3 | --[[
4 | Copyright (c) 2016-2019 Calvin Rose
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | ]]
23 |
24 | local assert = assert
25 | local error = error
26 | local select = select
27 | local pairs = pairs
28 | local getmetatable = getmetatable
29 | local setmetatable = setmetatable
30 | local type = type
31 | local loadstring = loadstring or load
32 | local concat = table.concat
33 | local char = string.char
34 | local byte = string.byte
35 | local format = string.format
36 | local sub = string.sub
37 | local dump = string.dump
38 | local floor = math.floor
39 | local frexp = math.frexp
40 | local unpack = unpack or table.unpack
41 |
42 | -- Lua 5.3 frexp polyfill
43 | -- From https://github.com/excessive/cpml/blob/master/modules/utils.lua
44 | if not frexp then
45 | local log, abs, floor = math.log, math.abs, math.floor
46 | local log2 = log(2)
47 | frexp = function(x)
48 | if x == 0 then return 0, 0 end
49 | local e = floor(log(abs(x)) / log2 + 1)
50 | return x / 2 ^ e, e
51 | end
52 | end
53 |
54 | local function pack(...)
55 | return {...}, select("#", ...)
56 | end
57 |
58 | local function not_array_index(x, len)
59 | return type(x) ~= "number" or x < 1 or x > len or x ~= floor(x)
60 | end
61 |
62 | local function type_check(x, tp, name)
63 | assert(type(x) == tp,
64 | format("Expected parameter %q to be of type %q.", name, tp))
65 | end
66 |
67 | local bigIntSupport = false
68 | local isInteger
69 | if math.type then -- Detect Lua 5.3
70 | local mtype = math.type
71 | bigIntSupport = loadstring[[
72 | local char = string.char
73 | return function(n)
74 | local nn = n < 0 and -(n + 1) or n
75 | local b1 = nn // 0x100000000000000
76 | local b2 = nn // 0x1000000000000 % 0x100
77 | local b3 = nn // 0x10000000000 % 0x100
78 | local b4 = nn // 0x100000000 % 0x100
79 | local b5 = nn // 0x1000000 % 0x100
80 | local b6 = nn // 0x10000 % 0x100
81 | local b7 = nn // 0x100 % 0x100
82 | local b8 = nn % 0x100
83 | if n < 0 then
84 | b1, b2, b3, b4 = 0xFF - b1, 0xFF - b2, 0xFF - b3, 0xFF - b4
85 | b5, b6, b7, b8 = 0xFF - b5, 0xFF - b6, 0xFF - b7, 0xFF - b8
86 | end
87 | return char(212, b1, b2, b3, b4, b5, b6, b7, b8)
88 | end]]()
89 | isInteger = function(x)
90 | return mtype(x) == 'integer'
91 | end
92 | else
93 | isInteger = function(x)
94 | return floor(x) == x
95 | end
96 | end
97 |
98 | -- Copyright (C) 2012-2015 Francois Perrad.
99 | -- number serialization code modified from https://github.com/fperrad/lua-MessagePack
100 | -- Encode a number as a big-endian ieee-754 double, big-endian signed 64 bit integer, or a small integer
101 | local function number_to_str(n)
102 | if isInteger(n) then -- int
103 | if n <= 100 and n >= -27 then -- 1 byte, 7 bits of data
104 | return char(n + 27)
105 | elseif n <= 8191 and n >= -8192 then -- 2 bytes, 14 bits of data
106 | n = n + 8192
107 | return char(128 + (floor(n / 0x100) % 0x100), n % 0x100)
108 | elseif bigIntSupport then
109 | return bigIntSupport(n)
110 | end
111 | end
112 | local sign = 0
113 | if n < 0.0 then
114 | sign = 0x80
115 | n = -n
116 | end
117 | local m, e = frexp(n) -- mantissa, exponent
118 | if m ~= m then
119 | return char(203, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
120 | elseif m == 1/0 then
121 | if sign == 0 then
122 | return char(203, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
123 | else
124 | return char(203, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
125 | end
126 | end
127 | e = e + 0x3FE
128 | if e < 1 then -- denormalized numbers
129 | m = m * 2 ^ (52 + e)
130 | e = 0
131 | else
132 | m = (m * 2 - 1) * 2 ^ 52
133 | end
134 | return char(203,
135 | sign + floor(e / 0x10),
136 | (e % 0x10) * 0x10 + floor(m / 0x1000000000000),
137 | floor(m / 0x10000000000) % 0x100,
138 | floor(m / 0x100000000) % 0x100,
139 | floor(m / 0x1000000) % 0x100,
140 | floor(m / 0x10000) % 0x100,
141 | floor(m / 0x100) % 0x100,
142 | m % 0x100)
143 | end
144 |
145 | -- Copyright (C) 2012-2015 Francois Perrad.
146 | -- number deserialization code also modified from https://github.com/fperrad/lua-MessagePack
147 | local function number_from_str(str, index)
148 | local b = byte(str, index)
149 | if not b then error("Expected more bytes of input.") end
150 | if b < 128 then
151 | return b - 27, index + 1
152 | elseif b < 192 then
153 | local b2 = byte(str, index + 1)
154 | if not b2 then error("Expected more bytes of input.") end
155 | return b2 + 0x100 * (b - 128) - 8192, index + 2
156 | end
157 | local b1, b2, b3, b4, b5, b6, b7, b8 = byte(str, index + 1, index + 8)
158 | if (not b1) or (not b2) or (not b3) or (not b4) or
159 | (not b5) or (not b6) or (not b7) or (not b8) then
160 | error("Expected more bytes of input.")
161 | end
162 | if b == 212 then
163 | local flip = b1 >= 128
164 | if flip then -- negative
165 | b1, b2, b3, b4 = 0xFF - b1, 0xFF - b2, 0xFF - b3, 0xFF - b4
166 | b5, b6, b7, b8 = 0xFF - b5, 0xFF - b6, 0xFF - b7, 0xFF - b8
167 | end
168 | local n = ((((((b1 * 0x100 + b2) * 0x100 + b3) * 0x100 + b4) *
169 | 0x100 + b5) * 0x100 + b6) * 0x100 + b7) * 0x100 + b8
170 | if flip then
171 | return (-n) - 1, index + 9
172 | else
173 | return n, index + 9
174 | end
175 | end
176 | if b ~= 203 then
177 | error("Expected number")
178 | end
179 | local sign = b1 > 0x7F and -1 or 1
180 | local e = (b1 % 0x80) * 0x10 + floor(b2 / 0x10)
181 | local m = ((((((b2 % 0x10) * 0x100 + b3) * 0x100 + b4) * 0x100 + b5) * 0x100 + b6) * 0x100 + b7) * 0x100 + b8
182 | local n
183 | if e == 0 then
184 | if m == 0 then
185 | n = sign * 0.0
186 | else
187 | n = sign * (m / 2 ^ 52) * 2 ^ -1022
188 | end
189 | elseif e == 0x7FF then
190 | if m == 0 then
191 | n = sign * (1/0)
192 | else
193 | n = 0.0/0.0
194 | end
195 | else
196 | n = sign * (1.0 + m / 2 ^ 52) * 2 ^ (e - 0x3FF)
197 | end
198 | return n, index + 9
199 | end
200 |
201 |
202 | local function newbinser()
203 |
204 | -- unique table key for getting next value
205 | local NEXT = {}
206 | local CTORSTACK = {}
207 |
208 | -- NIL = 202
209 | -- FLOAT = 203
210 | -- TRUE = 204
211 | -- FALSE = 205
212 | -- STRING = 206
213 | -- TABLE = 207
214 | -- REFERENCE = 208
215 | -- CONSTRUCTOR = 209
216 | -- FUNCTION = 210
217 | -- RESOURCE = 211
218 | -- INT64 = 212
219 | -- TABLE WITH META = 213
220 |
221 | local mts = {}
222 | local ids = {}
223 | local serializers = {}
224 | local deserializers = {}
225 | local resources = {}
226 | local resources_by_name = {}
227 | local types = {}
228 |
229 | types["nil"] = function(x, visited, accum)
230 | accum[#accum + 1] = "\202"
231 | end
232 |
233 | function types.number(x, visited, accum)
234 | accum[#accum + 1] = number_to_str(x)
235 | end
236 |
237 | function types.boolean(x, visited, accum)
238 | accum[#accum + 1] = x and "\204" or "\205"
239 | end
240 |
241 | function types.string(x, visited, accum)
242 | local alen = #accum
243 | if visited[x] then
244 | accum[alen + 1] = "\208"
245 | accum[alen + 2] = number_to_str(visited[x])
246 | else
247 | visited[x] = visited[NEXT]
248 | visited[NEXT] = visited[NEXT] + 1
249 | accum[alen + 1] = "\206"
250 | accum[alen + 2] = number_to_str(#x)
251 | accum[alen + 3] = x
252 | end
253 | end
254 |
255 | local function check_custom_type(x, visited, accum)
256 | local res = resources[x]
257 | if res then
258 | accum[#accum + 1] = "\211"
259 | types[type(res)](res, visited, accum)
260 | return true
261 | end
262 | local mt = getmetatable(x)
263 | local id = mt and ids[mt]
264 | if id then
265 | local constructing = visited[CTORSTACK]
266 | if constructing[x] then
267 | error("Infinite loop in constructor.")
268 | end
269 | constructing[x] = true
270 | accum[#accum + 1] = "\209"
271 | types[type(id)](id, visited, accum)
272 | local args, len = pack(serializers[id](x))
273 | accum[#accum + 1] = number_to_str(len)
274 | for i = 1, len do
275 | local arg = args[i]
276 | types[type(arg)](arg, visited, accum)
277 | end
278 | visited[x] = visited[NEXT]
279 | visited[NEXT] = visited[NEXT] + 1
280 | -- We finished constructing
281 | constructing[x] = nil
282 | return true
283 | end
284 | end
285 |
286 | function types.userdata(x, visited, accum)
287 | if visited[x] then
288 | accum[#accum + 1] = "\208"
289 | accum[#accum + 1] = number_to_str(visited[x])
290 | else
291 | if check_custom_type(x, visited, accum) then return end
292 | error("Cannot serialize this userdata.")
293 | end
294 | end
295 |
296 | function types.table(x, visited, accum)
297 | if visited[x] then
298 | accum[#accum + 1] = "\208"
299 | accum[#accum + 1] = number_to_str(visited[x])
300 | else
301 | if check_custom_type(x, visited, accum) then return end
302 | visited[x] = visited[NEXT]
303 | visited[NEXT] = visited[NEXT] + 1
304 | local xlen = #x
305 | local mt = getmetatable(x)
306 | if mt then
307 | accum[#accum + 1] = "\213"
308 | types.table(mt, visited, accum)
309 | else
310 | accum[#accum + 1] = "\207"
311 | end
312 | accum[#accum + 1] = number_to_str(xlen)
313 | for i = 1, xlen do
314 | local v = x[i]
315 | types[type(v)](v, visited, accum)
316 | end
317 | local key_count = 0
318 | for k in pairs(x) do
319 | if not_array_index(k, xlen) then
320 | key_count = key_count + 1
321 | end
322 | end
323 | accum[#accum + 1] = number_to_str(key_count)
324 | for k, v in pairs(x) do
325 | if not_array_index(k, xlen) then
326 | types[type(k)](k, visited, accum)
327 | types[type(v)](v, visited, accum)
328 | end
329 | end
330 | end
331 | end
332 |
333 | types["function"] = function(x, visited, accum)
334 | if visited[x] then
335 | accum[#accum + 1] = "\208"
336 | accum[#accum + 1] = number_to_str(visited[x])
337 | else
338 | if check_custom_type(x, visited, accum) then return end
339 | visited[x] = visited[NEXT]
340 | visited[NEXT] = visited[NEXT] + 1
341 | local str = dump(x)
342 | accum[#accum + 1] = "\210"
343 | accum[#accum + 1] = number_to_str(#str)
344 | accum[#accum + 1] = str
345 | end
346 | end
347 |
348 | types.cdata = function(x, visited, accum)
349 | if visited[x] then
350 | accum[#accum + 1] = "\208"
351 | accum[#accum + 1] = number_to_str(visited[x])
352 | else
353 | if check_custom_type(x, visited, #accum) then return end
354 | error("Cannot serialize this cdata.")
355 | end
356 | end
357 |
358 | types.thread = function() error("Cannot serialize threads.") end
359 |
360 | local function deserialize_value(str, index, visited)
361 | local t = byte(str, index)
362 | if not t then return nil, index end
363 | if t < 128 then
364 | return t - 27, index + 1
365 | elseif t < 192 then
366 | local b2 = byte(str, index + 1)
367 | if not b2 then error("Expected more bytes of input.") end
368 | return b2 + 0x100 * (t - 128) - 8192, index + 2
369 | elseif t == 202 then
370 | return nil, index + 1
371 | elseif t == 203 or t == 212 then
372 | return number_from_str(str, index)
373 | elseif t == 204 then
374 | return true, index + 1
375 | elseif t == 205 then
376 | return false, index + 1
377 | elseif t == 206 then
378 | local length, dataindex = number_from_str(str, index + 1)
379 | local nextindex = dataindex + length
380 | if not (length >= 0) then error("Bad string length") end
381 | if #str < nextindex - 1 then error("Expected more bytes of string") end
382 | local substr = sub(str, dataindex, nextindex - 1)
383 | visited[#visited + 1] = substr
384 | return substr, nextindex
385 | elseif t == 207 or t == 213 then
386 | local mt, count, nextindex
387 | local ret = {}
388 | visited[#visited + 1] = ret
389 | nextindex = index + 1
390 | if t == 213 then
391 | mt, nextindex = deserialize_value(str, nextindex, visited)
392 | if type(mt) ~= "table" then error("Expected table metatable") end
393 | end
394 | count, nextindex = number_from_str(str, nextindex)
395 | for i = 1, count do
396 | local oldindex = nextindex
397 | ret[i], nextindex = deserialize_value(str, nextindex, visited)
398 | if nextindex == oldindex then error("Expected more bytes of input.") end
399 | end
400 | count, nextindex = number_from_str(str, nextindex)
401 | for i = 1, count do
402 | local k, v
403 | local oldindex = nextindex
404 | k, nextindex = deserialize_value(str, nextindex, visited)
405 | if nextindex == oldindex then error("Expected more bytes of input.") end
406 | oldindex = nextindex
407 | v, nextindex = deserialize_value(str, nextindex, visited)
408 | if nextindex == oldindex then error("Expected more bytes of input.") end
409 | if k == nil then error("Can't have nil table keys") end
410 | ret[k] = v
411 | end
412 | if mt then setmetatable(ret, mt) end
413 | return ret, nextindex
414 | elseif t == 208 then
415 | local ref, nextindex = number_from_str(str, index + 1)
416 | return visited[ref], nextindex
417 | elseif t == 209 then
418 | local count
419 | local name, nextindex = deserialize_value(str, index + 1, visited)
420 | count, nextindex = number_from_str(str, nextindex)
421 | local args = {}
422 | for i = 1, count do
423 | local oldindex = nextindex
424 | args[i], nextindex = deserialize_value(str, nextindex, visited)
425 | if nextindex == oldindex then error("Expected more bytes of input.") end
426 | end
427 | if not name or not deserializers[name] then
428 | error(("Cannot deserialize class '%s'"):format(tostring(name)))
429 | end
430 | local ret = deserializers[name](unpack(args))
431 | visited[#visited + 1] = ret
432 | return ret, nextindex
433 | elseif t == 210 then
434 | local length, dataindex = number_from_str(str, index + 1)
435 | local nextindex = dataindex + length
436 | if not (length >= 0) then error("Bad string length") end
437 | if #str < nextindex - 1 then error("Expected more bytes of string") end
438 | local ret = loadstring(sub(str, dataindex, nextindex - 1))
439 | visited[#visited + 1] = ret
440 | return ret, nextindex
441 | elseif t == 211 then
442 | local resname, nextindex = deserialize_value(str, index + 1, visited)
443 | if resname == nil then error("Got nil resource name") end
444 | local res = resources_by_name[resname]
445 | if res == nil then
446 | error(("No resources found for name '%s'"):format(tostring(resname)))
447 | end
448 | return res, nextindex
449 | else
450 | error("Could not deserialize type byte " .. t .. ".")
451 | end
452 | end
453 |
454 | local function serialize(...)
455 | local visited = {[NEXT] = 1, [CTORSTACK] = {}}
456 | local accum = {}
457 | for i = 1, select("#", ...) do
458 | local x = select(i, ...)
459 | types[type(x)](x, visited, accum)
460 | end
461 | return concat(accum)
462 | end
463 |
464 | local function make_file_writer(file)
465 | return setmetatable({}, {
466 | __newindex = function(_, _, v)
467 | file:write(v)
468 | end
469 | })
470 | end
471 |
472 | local function serialize_to_file(path, mode, ...)
473 | local file, err = io.open(path, mode)
474 | assert(file, err)
475 | local visited = {[NEXT] = 1, [CTORSTACK] = {}}
476 | local accum = make_file_writer(file)
477 | for i = 1, select("#", ...) do
478 | local x = select(i, ...)
479 | types[type(x)](x, visited, accum)
480 | end
481 | -- flush the writer
482 | file:flush()
483 | file:close()
484 | end
485 |
486 | local function writeFile(path, ...)
487 | return serialize_to_file(path, "wb", ...)
488 | end
489 |
490 | local function appendFile(path, ...)
491 | return serialize_to_file(path, "ab", ...)
492 | end
493 |
494 | local function deserialize(str, index)
495 | assert(type(str) == "string", "Expected string to deserialize.")
496 | local vals = {}
497 | index = index or 1
498 | local visited = {}
499 | local len = 0
500 | local val
501 | while true do
502 | local nextindex
503 | val, nextindex = deserialize_value(str, index, visited)
504 | if nextindex > index then
505 | len = len + 1
506 | vals[len] = val
507 | index = nextindex
508 | else
509 | break
510 | end
511 | end
512 | return vals, len
513 | end
514 |
515 | local function deserializeN(str, n, index)
516 | assert(type(str) == "string", "Expected string to deserialize.")
517 | n = n or 1
518 | assert(type(n) == "number", "Expected a number for parameter n.")
519 | assert(n > 0 and floor(n) == n, "N must be a poitive integer.")
520 | local vals = {}
521 | index = index or 1
522 | local visited = {}
523 | local len = 0
524 | local val
525 | while len < n do
526 | local nextindex
527 | val, nextindex = deserialize_value(str, index, visited)
528 | if nextindex > index then
529 | len = len + 1
530 | vals[len] = val
531 | index = nextindex
532 | else
533 | break
534 | end
535 | end
536 | vals[len + 1] = index
537 | return unpack(vals, 1, n + 1)
538 | end
539 |
540 | local function readFile(path)
541 | local file, err = io.open(path, "rb")
542 | assert(file, err)
543 | local str = file:read("*all")
544 | file:close()
545 | return deserialize(str)
546 | end
547 |
548 | -- Resources
549 |
550 | local function registerResource(resource, name)
551 | type_check(name, "string", "name")
552 | assert(not resources[resource],
553 | "Resource already registered.")
554 | assert(not resources_by_name[name],
555 | format("Resource %q already exists.", name))
556 | resources_by_name[name] = resource
557 | resources[resource] = name
558 | return resource
559 | end
560 |
561 | local function unregisterResource(name)
562 | type_check(name, "string", "name")
563 | assert(resources_by_name[name], format("Resource %q does not exist.", name))
564 | local resource = resources_by_name[name]
565 | resources_by_name[name] = nil
566 | resources[resource] = nil
567 | return resource
568 | end
569 |
570 | -- Templating
571 |
572 | local function normalize_template(template)
573 | local ret = {}
574 | for i = 1, #template do
575 | ret[i] = template[i]
576 | end
577 | local non_array_part = {}
578 | -- The non-array part of the template (nested templates) have to be deterministic, so they are sorted.
579 | -- This means that inherently non deterministicly sortable keys (tables, functions) should NOT be used
580 | -- in templates. Looking for way around this.
581 | for k in pairs(template) do
582 | if not_array_index(k, #template) then
583 | non_array_part[#non_array_part + 1] = k
584 | end
585 | end
586 | table.sort(non_array_part)
587 | for i = 1, #non_array_part do
588 | local name = non_array_part[i]
589 | ret[#ret + 1] = {name, normalize_template(template[name])}
590 | end
591 | return ret
592 | end
593 |
594 | local function templatepart_serialize(part, argaccum, x, len)
595 | local extras = {}
596 | local extracount = 0
597 | for k, v in pairs(x) do
598 | extras[k] = v
599 | extracount = extracount + 1
600 | end
601 | for i = 1, #part do
602 | local name
603 | if type(part[i]) == "table" then
604 | name = part[i][1]
605 | len = templatepart_serialize(part[i][2], argaccum, x[name], len)
606 | else
607 | name = part[i]
608 | len = len + 1
609 | argaccum[len] = x[part[i]]
610 | end
611 | if extras[name] ~= nil then
612 | extracount = extracount - 1
613 | extras[name] = nil
614 | end
615 | end
616 | if extracount > 0 then
617 | argaccum[len + 1] = extras
618 | else
619 | argaccum[len + 1] = nil
620 | end
621 | return len + 1
622 | end
623 |
624 | local function templatepart_deserialize(ret, part, values, vindex)
625 | for i = 1, #part do
626 | local name = part[i]
627 | if type(name) == "table" then
628 | local newret = {}
629 | ret[name[1]] = newret
630 | vindex = templatepart_deserialize(newret, name[2], values, vindex)
631 | else
632 | ret[name] = values[vindex]
633 | vindex = vindex + 1
634 | end
635 | end
636 | local extras = values[vindex]
637 | if extras then
638 | for k, v in pairs(extras) do
639 | ret[k] = v
640 | end
641 | end
642 | return vindex + 1
643 | end
644 |
645 | local function template_serializer_and_deserializer(metatable, template)
646 | return function(x)
647 | local argaccum = {}
648 | local len = templatepart_serialize(template, argaccum, x, 0)
649 | return unpack(argaccum, 1, len)
650 | end, function(...)
651 | local ret = {}
652 | local args = {...}
653 | templatepart_deserialize(ret, template, args, 1)
654 | return setmetatable(ret, metatable)
655 | end
656 | end
657 |
658 | -- Used to serialize classes withh custom serializers and deserializers.
659 | -- If no _serialize or _deserialize (or no _template) value is found in the
660 | -- metatable, then the metatable is registered as a resources.
661 | local function register(metatable, name, serialize, deserialize)
662 | if type(metatable) == "table" then
663 | name = name or metatable.name
664 | serialize = serialize or metatable._serialize
665 | deserialize = deserialize or metatable._deserialize
666 | if (not serialize) or (not deserialize) then
667 | if metatable._template then
668 | -- Register as template
669 | local t = normalize_template(metatable._template)
670 | serialize, deserialize = template_serializer_and_deserializer(metatable, t)
671 | else
672 | -- Register the metatable as a resource. This is semantically
673 | -- similar and more flexible (handles cycles).
674 | registerResource(metatable, name)
675 | return
676 | end
677 | end
678 | elseif type(metatable) == "string" then
679 | name = name or metatable
680 | end
681 | type_check(name, "string", "name")
682 | type_check(serialize, "function", "serialize")
683 | type_check(deserialize, "function", "deserialize")
684 | assert((not ids[metatable]) and (not resources[metatable]),
685 | "Metatable already registered.")
686 | assert((not mts[name]) and (not resources_by_name[name]),
687 | ("Name %q already registered."):format(name))
688 | mts[name] = metatable
689 | ids[metatable] = name
690 | serializers[name] = serialize
691 | deserializers[name] = deserialize
692 | return metatable
693 | end
694 |
695 | local function unregister(item)
696 | local name, metatable
697 | if type(item) == "string" then -- assume name
698 | name, metatable = item, mts[item]
699 | else -- assume metatable
700 | name, metatable = ids[item], item
701 | end
702 | type_check(name, "string", "name")
703 | mts[name] = nil
704 | if (metatable) then
705 | resources[metatable] = nil
706 | ids[metatable] = nil
707 | end
708 | serializers[name] = nil
709 | deserializers[name] = nil
710 | resources_by_name[name] = nil;
711 | return metatable
712 | end
713 |
714 | local function registerClass(class, name)
715 | name = name or class.name
716 | if class.__instanceDict then -- middleclass
717 | register(class.__instanceDict, name)
718 | else -- assume 30log or similar library
719 | register(class, name)
720 | end
721 | return class
722 | end
723 |
724 | return {
725 | VERSION = "0.0-8",
726 | -- aliases
727 | s = serialize,
728 | d = deserialize,
729 | dn = deserializeN,
730 | r = readFile,
731 | w = writeFile,
732 | a = appendFile,
733 |
734 | serialize = serialize,
735 | deserialize = deserialize,
736 | deserializeN = deserializeN,
737 | readFile = readFile,
738 | writeFile = writeFile,
739 | appendFile = appendFile,
740 | register = register,
741 | unregister = unregister,
742 | registerResource = registerResource,
743 | unregisterResource = unregisterResource,
744 | registerClass = registerClass,
745 |
746 | newbinser = newbinser
747 | }
748 | end
749 |
750 | return newbinser()
751 |
--------------------------------------------------------------------------------
/src/lib/date.lua:
--------------------------------------------------------------------------------
1 | ---------------------------------------------------------------------------------------
2 | -- Module for date and time calculations
3 | --
4 | -- Version 2.2
5 | -- Copyright (C) 2005-2006, by Jas Latrix (jastejada@yahoo.com)
6 | -- Copyright (C) 2013-2021, by Thijs Schreijer
7 | -- Licensed under MIT, http://opensource.org/licenses/MIT
8 |
9 | --[[ CONSTANTS ]]--
10 | local HOURPERDAY = 24
11 | local MINPERHOUR = 60
12 | local MINPERDAY = 1440 -- 24*60
13 | local SECPERMIN = 60
14 | local SECPERHOUR = 3600 -- 60*60
15 | local SECPERDAY = 86400 -- 24*60*60
16 | local TICKSPERSEC = 1000000
17 | local TICKSPERDAY = 86400000000
18 | local TICKSPERHOUR = 3600000000
19 | local TICKSPERMIN = 60000000
20 | local DAYNUM_MAX = 365242500 -- Sat Jan 01 1000000 00:00:00
21 | local DAYNUM_MIN = -365242500 -- Mon Jan 01 1000000 BCE 00:00:00
22 | local DAYNUM_DEF = 0 -- Mon Jan 01 0001 00:00:00
23 | local _;
24 | --[[ GLOBAL SETTINGS ]]--
25 | local centuryflip = 0 -- year >= centuryflip == 1900, < centuryflip == 2000
26 | --[[ LOCAL ARE FASTER ]]--
27 | local type = type
28 | local pairs = pairs
29 | local error = error
30 | local assert = assert
31 | local tonumber = tonumber
32 | local tostring = tostring
33 | local string = string
34 | local math = math
35 | local os = os
36 | local unpack = unpack or table.unpack
37 | local setmetatable = setmetatable
38 | local getmetatable = getmetatable
39 | --[[ EXTRA FUNCTIONS ]]--
40 | local fmt = string.format
41 | local lwr = string.lower
42 | local rep = string.rep
43 | local len = string.len -- luacheck: ignore
44 | local sub = string.sub
45 | local gsub = string.gsub
46 | local gmatch = string.gmatch or string.gfind
47 | local find = string.find
48 | local ostime = os.time
49 | local osdate = os.date
50 | local floor = math.floor
51 | local ceil = math.ceil
52 | local abs = math.abs
53 | -- removes the decimal part of a number
54 | local function fix(n) n = tonumber(n) return n and ((n > 0 and floor or ceil)(n)) end
55 | -- returns the modulo n % d;
56 | local function mod(n,d) return n - d*floor(n/d) end
57 | -- is `str` in string list `tbl`, `ml` is the minimun len
58 | local function inlist(str, tbl, ml, tn)
59 | local sl = len(str)
60 | if sl < (ml or 0) then return nil end
61 | str = lwr(str)
62 | for k, v in pairs(tbl) do
63 | if str == lwr(sub(v, 1, sl)) then
64 | if tn then tn[0] = k end
65 | return k
66 | end
67 | end
68 | end
69 | local function fnil() end
70 | --[[ DATE FUNCTIONS ]]--
71 | local DATE_EPOCH -- to be set later
72 | local sl_weekdays = {
73 | [0]="Sunday",[1]="Monday",[2]="Tuesday",[3]="Wednesday",[4]="Thursday",[5]="Friday",[6]="Saturday",
74 | [7]="Sun",[8]="Mon",[9]="Tue",[10]="Wed",[11]="Thu",[12]="Fri",[13]="Sat",
75 | }
76 | local sl_meridian = {[-1]="AM", [1]="PM"}
77 | local sl_months = {
78 | [00]="January", [01]="February", [02]="March",
79 | [03]="April", [04]="May", [05]="June",
80 | [06]="July", [07]="August", [08]="September",
81 | [09]="October", [10]="November", [11]="December",
82 | [12]="Jan", [13]="Feb", [14]="Mar",
83 | [15]="Apr", [16]="May", [17]="Jun",
84 | [18]="Jul", [19]="Aug", [20]="Sep",
85 | [21]="Oct", [22]="Nov", [23]="Dec",
86 | }
87 | -- added the '.2' to avoid collision, use `fix` to remove
88 | local sl_timezone = {
89 | [000]="utc", [0.2]="gmt",
90 | [300]="est", [240]="edt",
91 | [360]="cst", [300.2]="cdt",
92 | [420]="mst", [360.2]="mdt",
93 | [480]="pst", [420.2]="pdt",
94 | }
95 | -- set the day fraction resolution
96 | local function setticks(t)
97 | TICKSPERSEC = t;
98 | TICKSPERDAY = SECPERDAY*TICKSPERSEC
99 | TICKSPERHOUR= SECPERHOUR*TICKSPERSEC
100 | TICKSPERMIN = SECPERMIN*TICKSPERSEC
101 | end
102 | -- is year y leap year?
103 | local function isleapyear(y) -- y must be int!
104 | return (mod(y, 4) == 0 and (mod(y, 100) ~= 0 or mod(y, 400) == 0))
105 | end
106 | -- day since year 0
107 | local function dayfromyear(y) -- y must be int!
108 | return 365*y + floor(y/4) - floor(y/100) + floor(y/400)
109 | end
110 | -- day number from date, month is zero base
111 | local function makedaynum(y, m, d)
112 | local mm = mod(mod(m,12) + 10, 12)
113 | return dayfromyear(y + floor(m/12) - floor(mm/10)) + floor((mm*306 + 5)/10) + d - 307
114 | --local yy = y + floor(m/12) - floor(mm/10)
115 | --return dayfromyear(yy) + floor((mm*306 + 5)/10) + (d - 1)
116 | end
117 | -- date from day number, month is zero base
118 | local function breakdaynum(g)
119 | local g = g + 306
120 | local y = floor((10000*g + 14780)/3652425)
121 | local d = g - dayfromyear(y)
122 | if d < 0 then y = y - 1; d = g - dayfromyear(y) end
123 | local mi = floor((100*d + 52)/3060)
124 | return (floor((mi + 2)/12) + y), mod(mi + 2,12), (d - floor((mi*306 + 5)/10) + 1)
125 | end
126 | --[[ for floats or int32 Lua Number data type
127 | local function breakdaynum2(g)
128 | local g, n = g + 306;
129 | local n400 = floor(g/DI400Y);n = mod(g,DI400Y);
130 | local n100 = floor(n/DI100Y);n = mod(n,DI100Y);
131 | local n004 = floor(n/DI4Y); n = mod(n,DI4Y);
132 | local n001 = floor(n/365); n = mod(n,365);
133 | local y = (n400*400) + (n100*100) + (n004*4) + n001 - ((n001 == 4 or n100 == 4) and 1 or 0)
134 | local d = g - dayfromyear(y)
135 | local mi = floor((100*d + 52)/3060)
136 | return (floor((mi + 2)/12) + y), mod(mi + 2,12), (d - floor((mi*306 + 5)/10) + 1)
137 | end
138 | ]]
139 | -- day fraction from time
140 | local function makedayfrc(h,r,s,t)
141 | return ((h*60 + r)*60 + s)*TICKSPERSEC + t
142 | end
143 | -- time from day fraction
144 | local function breakdayfrc(df)
145 | return
146 | mod(floor(df/TICKSPERHOUR),HOURPERDAY),
147 | mod(floor(df/TICKSPERMIN ),MINPERHOUR),
148 | mod(floor(df/TICKSPERSEC ),SECPERMIN),
149 | mod(df,TICKSPERSEC)
150 | end
151 | -- weekday sunday = 0, monday = 1 ...
152 | local function weekday(dn) return mod(dn + 1, 7) end
153 | -- yearday 0 based ...
154 | local function yearday(dn)
155 | return dn - dayfromyear((breakdaynum(dn))-1)
156 | end
157 | -- parse v as a month
158 | local function getmontharg(v)
159 | local m = tonumber(v);
160 | return (m and fix(m - 1)) or inlist(tostring(v) or "", sl_months, 2)
161 | end
162 | -- get daynum of isoweek one of year y
163 | local function isow1(y)
164 | local f = makedaynum(y, 0, 4) -- get the date for the 4-Jan of year `y`
165 | local d = weekday(f)
166 | d = d == 0 and 7 or d -- get the ISO day number, 1 == Monday, 7 == Sunday
167 | return f + (1 - d)
168 | end
169 | local function isowy(dn)
170 | local w1;
171 | local y = (breakdaynum(dn))
172 | if dn >= makedaynum(y, 11, 29) then
173 | w1 = isow1(y + 1);
174 | if dn < w1 then
175 | w1 = isow1(y);
176 | else
177 | y = y + 1;
178 | end
179 | else
180 | w1 = isow1(y);
181 | if dn < w1 then
182 | w1 = isow1(y-1)
183 | y = y - 1
184 | end
185 | end
186 | return floor((dn-w1)/7)+1, y
187 | end
188 | local function isoy(dn)
189 | local y = (breakdaynum(dn))
190 | return y + (((dn >= makedaynum(y, 11, 29)) and (dn >= isow1(y + 1))) and 1 or (dn < isow1(y) and -1 or 0))
191 | end
192 | local function makedaynum_isoywd(y,w,d)
193 | return isow1(y) + 7*w + d - 8 -- simplified: isow1(y) + ((w-1)*7) + (d-1)
194 | end
195 | --[[ THE DATE MODULE ]]--
196 | local fmtstr = "%x %X";
197 | --#if not DATE_OBJECT_AFX then
198 | local date = {}
199 | setmetatable(date, date)
200 | -- Version: VMMMRRRR; V-Major, M-Minor, R-Revision; e.g. 5.45.321 == 50450321
201 | do
202 | local major = 2
203 | local minor = 2
204 | local revision = 0
205 | date.version = major * 10000000 + minor * 10000 + revision
206 | end
207 | --#end -- not DATE_OBJECT_AFX
208 | --[[ THE DATE OBJECT ]]--
209 | local dobj = {}
210 | dobj.__index = dobj
211 | dobj.__metatable = dobj
212 | -- shout invalid arg
213 | local function date_error_arg() return error("invalid argument(s)",0) end
214 | -- create new date object
215 | local function date_new(dn, df)
216 | return setmetatable({daynum=dn, dayfrc=df}, dobj)
217 | end
218 |
219 | --#if not NO_LOCAL_TIME_SUPPORT then
220 | -- magic year table
221 | local date_epoch, yt;
222 | local function getequivyear(y)
223 | assert(not yt)
224 | yt = {}
225 | local de = date_epoch:copy()
226 | local dw, dy
227 | for _ = 0, 3000 do
228 | de:setyear(de:getyear() + 1, 1, 1)
229 | dy = de:getyear()
230 | dw = de:getweekday() * (isleapyear(dy) and -1 or 1)
231 | if not yt[dw] then yt[dw] = dy end --print(de)
232 | if yt[1] and yt[2] and yt[3] and yt[4] and yt[5] and yt[6] and yt[7] and yt[-1] and yt[-2] and yt[-3] and yt[-4] and yt[-5] and yt[-6] and yt[-7] then
233 | getequivyear = function(y) return yt[ (weekday(makedaynum(y, 0, 1)) + 1) * (isleapyear(y) and -1 or 1) ] end
234 | return getequivyear(y)
235 | end
236 | end
237 | end
238 | -- TimeValue from date and time
239 | local function totv(y,m,d,h,r,s)
240 | return (makedaynum(y, m, d) - DATE_EPOCH) * SECPERDAY + ((h*60 + r)*60 + s)
241 | end
242 | -- TimeValue from TimeTable
243 | local function tmtotv(tm)
244 | return tm and totv(tm.year, tm.month - 1, tm.day, tm.hour, tm.min, tm.sec)
245 | end
246 | -- Returns the bias in seconds of utc time daynum and dayfrc
247 | local function getbiasutc2(self)
248 | local y,m,d = breakdaynum(self.daynum)
249 | local h,r,s = breakdayfrc(self.dayfrc)
250 | local tvu = totv(y,m,d,h,r,s) -- get the utc TimeValue of date and time
251 | local tml = osdate("*t", tvu) -- get the local TimeTable of tvu
252 | if (not tml) or (tml.year > (y+1) or tml.year < (y-1)) then -- failed try the magic
253 | y = getequivyear(y)
254 | tvu = totv(y,m,d,h,r,s)
255 | tml = osdate("*t", tvu)
256 | end
257 | local tvl = tmtotv(tml)
258 | if tvu and tvl then
259 | return tvu - tvl, tvu, tvl
260 | else
261 | return error("failed to get bias from utc time")
262 | end
263 | end
264 | -- Returns the bias in seconds of local time daynum and dayfrc
265 | local function getbiasloc2(daynum, dayfrc)
266 | local tvu
267 | -- extract date and time
268 | local y,m,d = breakdaynum(daynum)
269 | local h,r,s = breakdayfrc(dayfrc)
270 | -- get equivalent TimeTable
271 | local tml = {year=y, month=m+1, day=d, hour=h, min=r, sec=s}
272 | -- get equivalent TimeValue
273 | local tvl = tmtotv(tml)
274 |
275 | local function chkutc()
276 | tml.isdst = nil; local tvug = ostime(tml) if tvug and (tvl == tmtotv(osdate("*t", tvug))) then tvu = tvug return end
277 | tml.isdst = true; local tvud = ostime(tml) if tvud and (tvl == tmtotv(osdate("*t", tvud))) then tvu = tvud return end
278 | tvu = tvud or tvug
279 | end
280 | chkutc()
281 | if not tvu then
282 | tml.year = getequivyear(y)
283 | tvl = tmtotv(tml)
284 | chkutc()
285 | end
286 | return ((tvu and tvl) and (tvu - tvl)) or error("failed to get bias from local time"), tvu, tvl
287 | end
288 | --#end -- not NO_LOCAL_TIME_SUPPORT
289 |
290 | --#if not DATE_OBJECT_AFX then
291 | -- the date parser
292 | local strwalker = {} -- ^Lua regular expression is not as powerful as Perl$
293 | strwalker.__index = strwalker
294 | local function newstrwalker(s)return setmetatable({s=s, i=1, e=1, c=len(s)}, strwalker) end
295 | function strwalker:aimchr() return "\n" .. self.s .. "\n" .. rep(".",self.e-1) .. "^" end
296 | function strwalker:finish() return self.i > self.c end
297 | function strwalker:back() self.i = self.e return self end
298 | function strwalker:restart() self.i, self.e = 1, 1 return self end
299 | function strwalker:match(s) return (find(self.s, s, self.i)) end
300 | function strwalker:__call(s, f)-- print("strwalker:__call "..s..self:aimchr())
301 | local is, ie; is, ie, self[1], self[2], self[3], self[4], self[5] = find(self.s, s, self.i)
302 | if is then self.e, self.i = self.i, 1+ie; if f then f(unpack(self)) end return self end
303 | end
304 | local function date_parse(str)
305 | local y,m,d, h,r,s, z, w,u, j, e, x,c, dn,df
306 | local sw = newstrwalker(gsub(gsub(str, "(%b())", ""),"^(%s*)","")) -- remove comment, trim leading space
307 | --local function error_out() print(y,m,d,h,r,s) end
308 | local function error_dup(q) --[[error_out()]] error("duplicate value: " .. (q or "") .. sw:aimchr()) end
309 | local function error_syn(q) --[[error_out()]] error("syntax error: " .. (q or "") .. sw:aimchr()) end
310 | local function error_inv(q) --[[error_out()]] error("invalid date: " .. (q or "") .. sw:aimchr()) end
311 | local function sety(q) y = y and error_dup() or tonumber(q); end
312 | local function setm(q) m = (m or w or j) and error_dup(m or w or j) or tonumber(q) end
313 | local function setd(q) d = d and error_dup() or tonumber(q) end
314 | local function seth(q) h = h and error_dup() or tonumber(q) end
315 | local function setr(q) r = r and error_dup() or tonumber(q) end
316 | local function sets(q) s = s and error_dup() or tonumber(q) end
317 | local function adds(q) s = s + tonumber(q) end
318 | local function setj(q) j = (m or w or j) and error_dup() or tonumber(q); end
319 | local function setz(q) z = (z ~= 0 and z) and error_dup() or q end
320 | local function setzn(zs,zn) zn = tonumber(zn); setz( ((zn<24) and (zn*60) or (mod(zn,100) + floor(zn/100) * 60))*( zs=='+' and -1 or 1) ) end
321 | local function setzc(zs,zh,zm) setz( ((tonumber(zh)*60) + tonumber(zm))*( zs=='+' and -1 or 1) ) end
322 |
323 | if not (sw("^(%d%d%d%d)",sety) and (sw("^(%-?)(%d%d)%1(%d%d)",function(_,a,b) setm(tonumber(a)); setd(tonumber(b)) end) or sw("^(%-?)[Ww](%d%d)%1(%d?)",function(_,a,b) w, u = tonumber(a), tonumber(b or 1) end) or sw("^%-?(%d%d%d)",setj) or sw("^%-?(%d%d)",function(a) setm(a);setd(1) end))
324 | and ((sw("^%s*[Tt]?(%d%d):?",seth) and sw("^(%d%d):?",setr) and sw("^(%d%d)",sets) and sw("^(%.%d+)",adds))
325 | or sw:finish() or (sw"^%s*$" or sw"^%s*[Zz]%s*$" or sw("^%s-([%+%-])(%d%d):?(%d%d)%s*$",setzc) or sw("^%s*([%+%-])(%d%d)%s*$",setzn))
326 | ) )
327 | then --print(y,m,d,h,r,s,z,w,u,j)
328 | sw:restart(); y,m,d,h,r,s,z,w,u,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil
329 | repeat -- print(sw:aimchr())
330 | if sw("^[tT:]?%s*(%d%d?):",seth) then --print("$Time")
331 | _ = sw("^%s*(%d%d?)",setr) and sw("^%s*:%s*(%d%d?)",sets) and sw("^(%.%d+)",adds)
332 | elseif sw("^(%d+)[/\\%s,-]?%s*") then --print("$Digits")
333 | x, c = tonumber(sw[1]), len(sw[1])
334 | if (x >= 70) or (m and d and (not y)) or (c > 3) then
335 | sety( x + ((x >= 100 or c>3) and 0 or x 12) or (h < 0) then return error_inv() end
357 | if x == 'a' and h == 12 then h = 0 end -- am
358 | if x == 'p' and h ~= 12 then h = h + 12 end -- pm
359 | else error_syn() end
360 | end
361 | elseif not(sw("^([+-])(%d%d?):(%d%d)",setzc) or sw("^([+-])(%d+)",setzn) or sw("^[Zz]%s*$")) then -- sw{"([+-])",{"(%d%d?):(%d%d)","(%d+)"}}
362 | error_syn("?")
363 | end
364 | sw("^%s*") until sw:finish()
365 | --else print("$Iso(Date|Time|Zone)")
366 | end
367 | -- if date is given, it must be complete year, month & day
368 | if (not y and not h) or ((m and not d) or (d and not m)) or ((m and w) or (m and j) or (j and w)) then return error_inv("!") end
369 | -- fix month
370 | if m then m = m - 1 end
371 | -- fix year if we are on BCE
372 | if e and e < 0 and y > 0 then y = 1 - y end
373 | -- create date object
374 | dn = (y and ((w and makedaynum_isoywd(y,w,u)) or (j and makedaynum(y, 0, j)) or makedaynum(y, m, d))) or DAYNUM_DEF
375 | df = makedayfrc(h or 0, r or 0, s or 0, 0) + ((z or 0)*TICKSPERMIN)
376 | --print("Zone",h,r,s,z,m,d,y,df)
377 | return date_new(dn, df) -- no need to :normalize();
378 | end
379 | local function date_fromtable(v)
380 | local y, m, d = fix(v.year), getmontharg(v.month), fix(v.day)
381 | local h, r, s, t = tonumber(v.hour), tonumber(v.min), tonumber(v.sec), tonumber(v.ticks)
382 | -- atleast there is time or complete date
383 | if (y or m or d) and (not(y and m and d)) then return error("incomplete table") end
384 | return (y or h or r or s or t) and date_new(y and makedaynum(y, m, d) or DAYNUM_DEF, makedayfrc(h or 0, r or 0, s or 0, t or 0))
385 | end
386 | local tmap = {
387 | ['number'] = function(v) return date_epoch:copy():addseconds(v) end,
388 | ['string'] = function(v) return date_parse(v) end,
389 | ['boolean']= function(v) return date_fromtable(osdate(v and "!*t" or "*t")) end,
390 | ['table'] = function(v) local ref = getmetatable(v) == dobj; return ref and v or date_fromtable(v), ref end
391 | }
392 | local function date_getdobj(v)
393 | local o, r = (tmap[type(v)] or fnil)(v);
394 | return (o and o:normalize() or error"invalid date time value"), r -- if r is true then o is a reference to a date obj
395 | end
396 | --#end -- not DATE_OBJECT_AFX
397 | local function date_from(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
398 | local y, m, d = fix(arg1), getmontharg(arg2), fix(arg3)
399 | local h, r, s, t = tonumber(arg4 or 0), tonumber(arg5 or 0), tonumber(arg6 or 0), tonumber(arg7 or 0)
400 | if y and m and d and h and r and s and t then
401 | return date_new(makedaynum(y, m, d), makedayfrc(h, r, s, t)):normalize()
402 | else
403 | return date_error_arg()
404 | end
405 | end
406 |
407 | --[[ THE DATE OBJECT METHODS ]]--
408 | function dobj:normalize()
409 | local dn, df = fix(self.daynum), self.dayfrc
410 | self.daynum, self.dayfrc = dn + floor(df/TICKSPERDAY), mod(df, TICKSPERDAY)
411 | return (dn >= DAYNUM_MIN and dn <= DAYNUM_MAX) and self or error("date beyond imposed limits:"..self)
412 | end
413 |
414 | function dobj:getdate() local y, m, d = breakdaynum(self.daynum) return y, m+1, d end
415 | function dobj:gettime() return breakdayfrc(self.dayfrc) end
416 |
417 | function dobj:getclockhour() local h = self:gethours() return h>12 and mod(h,12) or (h==0 and 12 or h) end
418 |
419 | function dobj:getyearday() return yearday(self.daynum) + 1 end
420 | function dobj:getweekday() return weekday(self.daynum) + 1 end -- in lua weekday is sunday = 1, monday = 2 ...
421 |
422 | function dobj:getyear() local r,_,_ = breakdaynum(self.daynum) return r end
423 | function dobj:getmonth() local _,r,_ = breakdaynum(self.daynum) return r+1 end-- in lua month is 1 base
424 | function dobj:getday() local _,_,r = breakdaynum(self.daynum) return r end
425 | function dobj:gethours() return mod(floor(self.dayfrc/TICKSPERHOUR),HOURPERDAY) end
426 | function dobj:getminutes() return mod(floor(self.dayfrc/TICKSPERMIN), MINPERHOUR) end
427 | function dobj:getseconds() return mod(floor(self.dayfrc/TICKSPERSEC ),SECPERMIN) end
428 | function dobj:getfracsec() return mod(floor(self.dayfrc/TICKSPERSEC ),SECPERMIN)+(mod(self.dayfrc,TICKSPERSEC)/TICKSPERSEC) end
429 | function dobj:getticks(u) local x = mod(self.dayfrc,TICKSPERSEC) return u and ((x*u)/TICKSPERSEC) or x end
430 |
431 | function dobj:getweeknumber(wdb)
432 | local wd, yd = weekday(self.daynum), yearday(self.daynum)
433 | if wdb then
434 | wdb = tonumber(wdb)
435 | if wdb then
436 | wd = mod(wd-(wdb-1),7)-- shift the week day base
437 | else
438 | return date_error_arg()
439 | end
440 | end
441 | return (yd < wd and 0) or (floor(yd/7) + ((mod(yd, 7)>=wd) and 1 or 0))
442 | end
443 |
444 | function dobj:getisoweekday() return mod(weekday(self.daynum)-1,7)+1 end -- sunday = 7, monday = 1 ...
445 | function dobj:getisoweeknumber() return (isowy(self.daynum)) end
446 | function dobj:getisoyear() return isoy(self.daynum) end
447 | function dobj:getisodate()
448 | local w, y = isowy(self.daynum)
449 | return y, w, self:getisoweekday()
450 | end
451 | function dobj:setisoyear(y, w, d)
452 | local cy, cw, cd = self:getisodate()
453 | if y then cy = fix(tonumber(y))end
454 | if w then cw = fix(tonumber(w))end
455 | if d then cd = fix(tonumber(d))end
456 | if cy and cw and cd then
457 | self.daynum = makedaynum_isoywd(cy, cw, cd)
458 | return self:normalize()
459 | else
460 | return date_error_arg()
461 | end
462 | end
463 |
464 | function dobj:setisoweekday(d) return self:setisoyear(nil, nil, d) end
465 | function dobj:setisoweeknumber(w,d) return self:setisoyear(nil, w, d) end
466 |
467 | function dobj:setyear(y, m, d)
468 | local cy, cm, cd = breakdaynum(self.daynum)
469 | if y then cy = fix(tonumber(y))end
470 | if m then cm = getmontharg(m) end
471 | if d then cd = fix(tonumber(d))end
472 | if cy and cm and cd then
473 | self.daynum = makedaynum(cy, cm, cd)
474 | return self:normalize()
475 | else
476 | return date_error_arg()
477 | end
478 | end
479 |
480 | function dobj:setmonth(m, d)return self:setyear(nil, m, d) end
481 | function dobj:setday(d) return self:setyear(nil, nil, d) end
482 |
483 | function dobj:sethours(h, m, s, t)
484 | local ch,cm,cs,ck = breakdayfrc(self.dayfrc)
485 | ch, cm, cs, ck = tonumber(h or ch), tonumber(m or cm), tonumber(s or cs), tonumber(t or ck)
486 | if ch and cm and cs and ck then
487 | self.dayfrc = makedayfrc(ch, cm, cs, ck)
488 | return self:normalize()
489 | else
490 | return date_error_arg()
491 | end
492 | end
493 |
494 | function dobj:setminutes(m,s,t) return self:sethours(nil, m, s, t) end
495 | function dobj:setseconds(s, t) return self:sethours(nil, nil, s, t) end
496 | function dobj:setticks(t) return self:sethours(nil, nil, nil, t) end
497 |
498 | function dobj:spanticks() return (self.daynum*TICKSPERDAY + self.dayfrc) end
499 | function dobj:spanseconds() return (self.daynum*TICKSPERDAY + self.dayfrc)/TICKSPERSEC end
500 | function dobj:spanminutes() return (self.daynum*TICKSPERDAY + self.dayfrc)/TICKSPERMIN end
501 | function dobj:spanhours() return (self.daynum*TICKSPERDAY + self.dayfrc)/TICKSPERHOUR end
502 | function dobj:spandays() return (self.daynum*TICKSPERDAY + self.dayfrc)/TICKSPERDAY end
503 |
504 | function dobj:addyears(y, m, d)
505 | local cy, cm, cd = breakdaynum(self.daynum)
506 | if y then y = fix(tonumber(y))else y = 0 end
507 | if m then m = fix(tonumber(m))else m = 0 end
508 | if d then d = fix(tonumber(d))else d = 0 end
509 | if y and m and d then
510 | self.daynum = makedaynum(cy+y, cm+m, cd+d)
511 | return self:normalize()
512 | else
513 | return date_error_arg()
514 | end
515 | end
516 |
517 | function dobj:addmonths(m, d)
518 | return self:addyears(nil, m, d)
519 | end
520 |
521 | local function dobj_adddayfrc(self,n,pt,pd)
522 | n = tonumber(n)
523 | if n then
524 | local x = floor(n/pd);
525 | self.daynum = self.daynum + x;
526 | self.dayfrc = self.dayfrc + (n-x*pd)*pt;
527 | return self:normalize()
528 | else
529 | return date_error_arg()
530 | end
531 | end
532 | function dobj:adddays(n) return dobj_adddayfrc(self,n,TICKSPERDAY,1) end
533 | function dobj:addhours(n) return dobj_adddayfrc(self,n,TICKSPERHOUR,HOURPERDAY) end
534 | function dobj:addminutes(n) return dobj_adddayfrc(self,n,TICKSPERMIN,MINPERDAY) end
535 | function dobj:addseconds(n) return dobj_adddayfrc(self,n,TICKSPERSEC,SECPERDAY) end
536 | function dobj:addticks(n) return dobj_adddayfrc(self,n,1,TICKSPERDAY) end
537 | local tvspec = {
538 | -- Abbreviated weekday name (Sun)
539 | ['%a']=function(self) return sl_weekdays[weekday(self.daynum) + 7] end,
540 | -- Full weekday name (Sunday)
541 | ['%A']=function(self) return sl_weekdays[weekday(self.daynum)] end,
542 | -- Abbreviated month name (Dec)
543 | ['%b']=function(self) return sl_months[self:getmonth() - 1 + 12] end,
544 | -- Full month name (December)
545 | ['%B']=function(self) return sl_months[self:getmonth() - 1] end,
546 | -- Year/100 (19, 20, 30)
547 | ['%C']=function(self) return fmt("%.2d", fix(self:getyear()/100)) end,
548 | -- The day of the month as a number (range 1 - 31)
549 | ['%d']=function(self) return fmt("%.2d", self:getday()) end,
550 | -- year for ISO 8601 week, from 00 (79)
551 | ['%g']=function(self) return fmt("%.2d", mod(self:getisoyear() ,100)) end,
552 | -- year for ISO 8601 week, from 0000 (1979)
553 | ['%G']=function(self) return fmt("%.4d", self:getisoyear()) end,
554 | -- same as %b
555 | ['%h']=function(self) return self:fmt0("%b") end,
556 | -- hour of the 24-hour day, from 00 (06)
557 | ['%H']=function(self) return fmt("%.2d", self:gethours()) end,
558 | -- The hour as a number using a 12-hour clock (01 - 12)
559 | ['%I']=function(self) return fmt("%.2d", self:getclockhour()) end,
560 | -- The day of the year as a number (001 - 366)
561 | ['%j']=function(self) return fmt("%.3d", self:getyearday()) end,
562 | -- Month of the year, from 01 to 12
563 | ['%m']=function(self) return fmt("%.2d", self:getmonth()) end,
564 | -- Minutes after the hour 55
565 | ['%M']=function(self) return fmt("%.2d", self:getminutes())end,
566 | -- AM/PM indicator (AM)
567 | ['%p']=function(self) return sl_meridian[self:gethours() > 11 and 1 or -1] end, --AM/PM indicator (AM)
568 | -- The second as a number (59, 20 , 01)
569 | ['%S']=function(self) return fmt("%.2d", self:getseconds()) end,
570 | -- ISO 8601 day of the week, to 7 for Sunday (7, 1)
571 | ['%u']=function(self) return self:getisoweekday() end,
572 | -- Sunday week of the year, from 00 (48)
573 | ['%U']=function(self) return fmt("%.2d", self:getweeknumber()) end,
574 | -- ISO 8601 week of the year, from 01 (48)
575 | ['%V']=function(self) return fmt("%.2d", self:getisoweeknumber()) end,
576 | -- The day of the week as a decimal, Sunday being 0
577 | ['%w']=function(self) return self:getweekday() - 1 end,
578 | -- Monday week of the year, from 00 (48)
579 | ['%W']=function(self) return fmt("%.2d", self:getweeknumber(2)) end,
580 | -- The year as a number without a century (range 00 to 99)
581 | ['%y']=function(self) return fmt("%.2d", mod(self:getyear() ,100)) end,
582 | -- Year with century (2000, 1914, 0325, 0001)
583 | ['%Y']=function(self) return fmt("%.4d", self:getyear()) end,
584 | -- Time zone offset, the date object is assumed local time (+1000, -0230)
585 | ['%z']=function(self) local b = -self:getbias(); local x = abs(b); return fmt("%s%.4d", b < 0 and "-" or "+", fix(x/60)*100 + floor(mod(x,60))) end,
586 | -- Time zone name, the date object is assumed local time
587 | ['%Z']=function(self) return self:gettzname() end,
588 | -- Misc --
589 | -- Year, if year is in BCE, prints the BCE Year representation, otherwise result is similar to "%Y" (1 BCE, 40 BCE)
590 | ['%\b']=function(self) local x = self:getyear() return fmt("%.4d%s", x>0 and x or (-x+1), x>0 and "" or " BCE") end,
591 | -- Seconds including fraction (59.998, 01.123)
592 | ['%\f']=function(self) local x = self:getfracsec() return fmt("%s%.9f",x >= 10 and "" or "0", x) end,
593 | -- percent character %
594 | ['%%']=function(self) return "%" end,
595 | -- Group Spec --
596 | -- 12-hour time, from 01:00:00 AM (06:55:15 AM); same as "%I:%M:%S %p"
597 | ['%r']=function(self) return self:fmt0("%I:%M:%S %p") end,
598 | -- hour:minute, from 01:00 (06:55); same as "%I:%M"
599 | ['%R']=function(self) return self:fmt0("%I:%M") end,
600 | -- 24-hour time, from 00:00:00 (06:55:15); same as "%H:%M:%S"
601 | ['%T']=function(self) return self:fmt0("%H:%M:%S") end,
602 | -- month/day/year from 01/01/00 (12/02/79); same as "%m/%d/%y"
603 | ['%D']=function(self) return self:fmt0("%m/%d/%y") end,
604 | -- year-month-day (1979-12-02); same as "%Y-%m-%d"
605 | ['%F']=function(self) return self:fmt0("%Y-%m-%d") end,
606 | -- The preferred date and time representation; same as "%x %X"
607 | ['%c']=function(self) return self:fmt0("%x %X") end,
608 | -- The preferred date representation, same as "%a %b %d %\b"
609 | ['%x']=function(self) return self:fmt0("%a %b %d %\b") end,
610 | -- The preferred time representation, same as "%H:%M:%\f"
611 | ['%X']=function(self) return self:fmt0("%H:%M:%\f") end,
612 | -- GroupSpec --
613 | -- Iso format, same as "%Y-%m-%dT%T"
614 | ['${iso}'] = function(self) return self:fmt0("%Y-%m-%dT%T") end,
615 | -- http format, same as "%a, %d %b %Y %T GMT"
616 | ['${http}'] = function(self) return self:fmt0("%a, %d %b %Y %T GMT") end,
617 | -- ctime format, same as "%a %b %d %T GMT %Y"
618 | ['${ctime}'] = function(self) return self:fmt0("%a %b %d %T GMT %Y") end,
619 | -- RFC850 format, same as "%A, %d-%b-%y %T GMT"
620 | ['${rfc850}'] = function(self) return self:fmt0("%A, %d-%b-%y %T GMT") end,
621 | -- RFC1123 format, same as "%a, %d %b %Y %T GMT"
622 | ['${rfc1123}'] = function(self) return self:fmt0("%a, %d %b %Y %T GMT") end,
623 | -- asctime format, same as "%a %b %d %T %Y"
624 | ['${asctime}'] = function(self) return self:fmt0("%a %b %d %T %Y") end,
625 | }
626 | function dobj:fmt0(str) return (gsub(str, "%%[%a%%\b\f]", function(x) local f = tvspec[x];return (f and f(self)) or x end)) end
627 | function dobj:fmt(str)
628 | str = str or self.fmtstr or fmtstr
629 | return self:fmt0((gmatch(str, "${%w+}")) and (gsub(str, "${%w+}", function(x)local f=tvspec[x];return (f and f(self)) or x end)) or str)
630 | end
631 |
632 | function dobj.__lt(a, b) if (a.daynum == b.daynum) then return (a.dayfrc < b.dayfrc) else return (a.daynum < b.daynum) end end
633 | function dobj.__le(a, b) if (a.daynum == b.daynum) then return (a.dayfrc <= b.dayfrc) else return (a.daynum <= b.daynum) end end
634 | function dobj.__eq(a, b)return (a.daynum == b.daynum) and (a.dayfrc == b.dayfrc) end
635 | function dobj.__sub(a,b)
636 | local d1, d2 = date_getdobj(a), date_getdobj(b)
637 | local d0 = d1 and d2 and date_new(d1.daynum - d2.daynum, d1.dayfrc - d2.dayfrc)
638 | return d0 and d0:normalize()
639 | end
640 | function dobj.__add(a,b)
641 | local d1, d2 = date_getdobj(a), date_getdobj(b)
642 | local d0 = d1 and d2 and date_new(d1.daynum + d2.daynum, d1.dayfrc + d2.dayfrc)
643 | return d0 and d0:normalize()
644 | end
645 | function dobj.__concat(a, b) return tostring(a) .. tostring(b) end
646 | function dobj:__tostring() return self:fmt() end
647 |
648 | function dobj:copy() return date_new(self.daynum, self.dayfrc) end
649 |
650 | --[[ THE LOCAL DATE OBJECT METHODS ]]--
651 | function dobj:tolocal()
652 | local dn,df = self.daynum, self.dayfrc
653 | local bias = getbiasutc2(self)
654 | if bias then
655 | -- utc = local + bias; local = utc - bias
656 | self.daynum = dn
657 | self.dayfrc = df - bias*TICKSPERSEC
658 | return self:normalize()
659 | else
660 | return nil
661 | end
662 | end
663 |
664 | function dobj:toutc()
665 | local dn,df = self.daynum, self.dayfrc
666 | local bias = getbiasloc2(dn, df)
667 | if bias then
668 | -- utc = local + bias;
669 | self.daynum = dn
670 | self.dayfrc = df + bias*TICKSPERSEC
671 | return self:normalize()
672 | else
673 | return nil
674 | end
675 | end
676 |
677 | function dobj:getbias() return (getbiasloc2(self.daynum, self.dayfrc))/SECPERMIN end
678 |
679 | function dobj:gettzname()
680 | local _, tvu, _ = getbiasloc2(self.daynum, self.dayfrc)
681 | return tvu and osdate("%Z",tvu) or ""
682 | end
683 |
684 | --#if not DATE_OBJECT_AFX then
685 | function date.time(h, r, s, t)
686 | h, r, s, t = tonumber(h or 0), tonumber(r or 0), tonumber(s or 0), tonumber(t or 0)
687 | if h and r and s and t then
688 | return date_new(DAYNUM_DEF, makedayfrc(h, r, s, t))
689 | else
690 | return date_error_arg()
691 | end
692 | end
693 |
694 | function date:__call(arg1, ...)
695 | local arg_count = select("#", ...) + (arg1 == nil and 0 or 1)
696 | if arg_count > 1 then return (date_from(arg1, ...))
697 | elseif arg_count == 0 then return (date_getdobj(false))
698 | else local o, r = date_getdobj(arg1); return r and o:copy() or o end
699 | end
700 |
701 | date.diff = dobj.__sub
702 |
703 | function date.isleapyear(v)
704 | local y = fix(v);
705 | if not y then
706 | y = date_getdobj(v)
707 | y = y and y:getyear()
708 | end
709 | return isleapyear(y+0)
710 | end
711 |
712 | function date.epoch() return date_epoch:copy() end
713 |
714 | function date.isodate(y,w,d) return date_new(makedaynum_isoywd(y + 0, w and (w+0) or 1, d and (d+0) or 1), 0) end
715 | function date.setcenturyflip(y)
716 | if y ~= floor(y) or y < 0 or y > 100 then date_error_arg() end
717 | centuryflip = y
718 | end
719 | function date.getcenturyflip() return centuryflip end
720 |
721 | -- Internal functions
722 | function date.fmt(str) if str then fmtstr = str end; return fmtstr end
723 | function date.daynummin(n) DAYNUM_MIN = (n and n < DAYNUM_MAX) and n or DAYNUM_MIN return n and DAYNUM_MIN or date_new(DAYNUM_MIN, 0):normalize()end
724 | function date.daynummax(n) DAYNUM_MAX = (n and n > DAYNUM_MIN) and n or DAYNUM_MAX return n and DAYNUM_MAX or date_new(DAYNUM_MAX, 0):normalize()end
725 | function date.ticks(t) if t then setticks(t) end return TICKSPERSEC end
726 | --#end -- not DATE_OBJECT_AFX
727 |
728 | local tm = osdate("!*t", 0);
729 | if tm then
730 | date_epoch = date_new(makedaynum(tm.year, tm.month - 1, tm.day), makedayfrc(tm.hour, tm.min, tm.sec, 0))
731 | -- the distance from our epoch to os epoch in daynum
732 | DATE_EPOCH = date_epoch and date_epoch:spandays()
733 | else -- error will be raise only if called!
734 | date_epoch = setmetatable({},{__index = function() error("failed to get the epoch date") end})
735 | end
736 |
737 | --#if not DATE_OBJECT_AFX then
738 | return date
739 | --#else
740 | --$return date_from
741 | --#end
742 |
--------------------------------------------------------------------------------
/src/lib/timer.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | Copyright (c) 2010-2013 Matthias Richter
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | Except as contained in this notice, the name(s) of the above copyright holders
15 | shall not be used in advertising or otherwise to promote the sale, use or
16 | other dealings in this Software without prior written authorization.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ]]--
26 |
27 | local Timer = {}
28 | Timer.__index = Timer
29 |
30 | local function _nothing_() end
31 | local unpack = unpack or table.unpack
32 |
33 | local function updateTimerHandle(handle, dt)
34 | -- handle: {
35 | -- time = ,
36 | -- after = ,
37 | -- during = ,
38 | -- limit = ,
39 | -- count = ,
40 | -- }
41 | handle.time = handle.time + dt
42 | handle.during(dt, math.max(handle.limit - handle.time, 0))
43 |
44 | while handle.time >= handle.limit and handle.count > 0 do
45 | if handle.after(handle.after) == false then
46 | handle.count = 0
47 | break
48 | end
49 | handle.time = handle.time - handle.limit
50 | handle.count = handle.count - 1
51 | end
52 | end
53 |
54 | function Timer:update(dt)
55 | -- timers may create new timers, which leads to undefined behavior
56 | -- in pairs() - so we need to put them in a different table first
57 | local to_update = {}
58 | for handle in pairs(self.functions) do
59 | to_update[handle] = handle
60 | end
61 |
62 | for handle in pairs(to_update) do
63 | if self.functions[handle] then
64 | updateTimerHandle(handle, dt)
65 | if handle.count == 0 then
66 | self.functions[handle] = nil
67 | end
68 | end
69 | end
70 | end
71 |
72 | function Timer:during(delay, during, after)
73 | local handle = { time = 0, during = during, after = after or _nothing_, limit = delay, count = 1 }
74 | self.functions[handle] = true
75 | return handle
76 | end
77 |
78 | function Timer:after(delay, func)
79 | return self:during(delay, _nothing_, func)
80 | end
81 |
82 | function Timer:every(delay, after, count)
83 | local count = count or math.huge -- exploit below: math.huge - 1 = math.huge
84 | local handle = { time = 0, during = _nothing_, after = after, limit = delay, count = count }
85 | self.functions[handle] = true
86 | return handle
87 | end
88 |
89 | function Timer:cancel(handle)
90 | self.functions[handle] = nil
91 | end
92 |
93 | function Timer:clear()
94 | self.functions = {}
95 | end
96 |
97 | function Timer:script(f)
98 | local co = coroutine.wrap(f)
99 | co(function(t)
100 | self:after(t, co)
101 | coroutine.yield()
102 | end)
103 | end
104 |
105 | local function func_tween(tween, self, len, subject, target, method, after,
106 | setters_and_getters, ...)
107 | -- recursively collects fields that are defined in both subject and target into a flat list
108 | -- re-use of ref is confusing
109 | local to_func_tween = {}
110 | local function set_and_get(subject, k, v)
111 | setters_and_getters = setters_and_getters or {}
112 |
113 | local setter, getter
114 | if setters_and_getters[k] then
115 | setter, getter = unpack(setters_and_getters[k])
116 | else
117 | setter = subject['set'..k]
118 | getter = subject['get'..k]
119 | end
120 | assert(setter and getter,
121 | "key's value in subject is nil with no set/getter")
122 |
123 | if to_func_tween[subject] == nil then
124 | to_func_tween[subject] = {}
125 | end
126 |
127 | ref = {getter(subject)}
128 | to_func_tween[subject][k] = {ref, setter}
129 | if type(v) == 'number' or #ref == 1 then
130 | v = {v}
131 | end
132 | return ref, v
133 | end
134 |
135 | local function tween_collect_payload(subject, target, out)
136 | for k,v in pairs(target) do
137 |
138 | -- this might not be the smoothest way to do this
139 | local ref = subject[k]
140 | if ref == nil then
141 | ref, v = set_and_get(subject, k, v)
142 | end
143 | assert(type(v) == type(ref), 'Type mismatch in field "'..k..'". '
144 | ..type(v)..' vs '.. type(ref))
145 | if type(v) == 'table' then
146 | tween_collect_payload(ref, v, out)
147 | else
148 | local ok, delta = pcall(function() return (v-ref)*1 end)
149 | assert(ok, 'Field "'..k..'" does not support arithmetic operations')
150 | out[#out+1] = {subject, k, delta}
151 | end
152 | end
153 | return out
154 | end
155 |
156 | method = tween[method or 'linear'] -- see __index
157 | local payload, t, args = tween_collect_payload(subject, target, {}), 0, {...}
158 |
159 | local last_s = 0
160 | return self:during(len, function(dt)
161 | t = t + dt
162 | local s = method(math.min(1, t/len), unpack(args))
163 | local ds = s - last_s
164 | last_s = s
165 | for _, info in ipairs(payload) do
166 | local ref, key, delta = unpack(info)
167 | ref[key] = ref[key] + delta * ds
168 | end
169 | for ref, t in pairs(to_func_tween) do
170 | for key, value in pairs(t) do
171 | local setter_args, setter = unpack(value)
172 | if not pcall(function() setter(ref, unpack(setter_args)) end) then
173 | setter(unpack(setter_args))
174 | end
175 | end
176 | end
177 | end, after)
178 | end
179 |
180 | local function plain_tween(tween, self, len, subject, target, method, after, ...)
181 | return func_tween(tween, self, len, subject, target, method, after, nil, ...)
182 | end
183 |
184 |
185 | local function def_tween(func)
186 | return setmetatable(
187 | {
188 | -- helper functions
189 | out = function(f) -- 'rotates' a function
190 | return function(s, ...) return 1 - f(1-s, ...) end
191 | end,
192 | chain = function(f1, f2) -- concatenates two functions
193 | return function(s, ...) return (s < .5 and f1(2*s, ...) or 1 + f2(2*s-1, ...)) * .5 end
194 | end,
195 |
196 | -- useful tweening functions
197 | linear = function(s) return s end,
198 | quad = function(s) return s*s end,
199 | cubic = function(s) return s*s*s end,
200 | quart = function(s) return s*s*s*s end,
201 | quint = function(s) return s*s*s*s*s end,
202 | sine = function(s) return 1-math.cos(s*math.pi/2) end,
203 | expo = function(s) return 2^(10*(s-1)) end,
204 | circ = function(s) return 1 - math.sqrt(1-s*s) end,
205 |
206 | back = function(s,bounciness)
207 | bounciness = bounciness or 1.70158
208 | return s*s*((bounciness+1)*s - bounciness)
209 | end,
210 |
211 | bounce = function(s) -- magic numbers ahead
212 | local a,b = 7.5625, 1/2.75
213 | return math.min(a*s^2, a*(s-1.5*b)^2 + .75, a*(s-2.25*b)^2 + .9375, a*(s-2.625*b)^2 + .984375)
214 | end,
215 |
216 | elastic = function(s, amp, period)
217 | amp, period = amp and math.max(1, amp) or 1, period or .3
218 | return (-amp * math.sin(2*math.pi/period * (s-1) - math.asin(1/amp))) * 2^(10*(s-1))
219 | end,
220 |
221 |
222 | }, {
223 |
224 | -- register new tween
225 | __call = func,
226 |
227 | -- fetches function and generated compositions for method `key`
228 | __index = function(tweens, key)
229 | if type(key) == 'function' then return key end
230 |
231 | assert(type(key) == 'string', 'Method must be function or string.')
232 | if rawget(tweens, key) then return rawget(tweens, key) end
233 |
234 | local function construct(pattern, f)
235 | local method = rawget(tweens, key:match(pattern))
236 | if method then return f(method) end
237 | return nil
238 | end
239 |
240 | local out, chain = rawget(tweens,'out'), rawget(tweens,'chain')
241 | return construct('^in%-([^-]+)$', function(...) return ... end)
242 | or construct('^out%-([^-]+)$', out)
243 | or construct('^in%-out%-([^-]+)$', function(f) return chain(f, out(f)) end)
244 | or construct('^out%-in%-([^-]+)$', function(f) return chain(out(f), f) end)
245 | or error('Unknown interpolation method: ' .. key)
246 | end})
247 | end
248 |
249 |
250 | Timer.tween = def_tween(plain_tween)
251 | Timer.func_tween = def_tween(func_tween)
252 |
253 | -- Timer instancing
254 | function Timer.new()
255 | return setmetatable({functions = {}, tween = Timer.tween}, Timer)
256 | end
257 |
258 | -- default instance
259 | local default = Timer.new()
260 |
261 | -- module forwards calls to default instance
262 | local module = {}
263 | for k in pairs(Timer) do
264 | if k ~= "__index" then
265 | module[k] = function(...) return default[k](default, ...) end
266 | end
267 | end
268 | module.tween = setmetatable({}, {
269 | __index = Timer.tween,
270 | __newindex = function(k,v) Timer.tween[k] = v end,
271 | __call = function(t, ...) return default:tween(...) end,
272 | })
273 |
274 | return setmetatable(module, {__call = Timer.new})
275 |
--------------------------------------------------------------------------------
/src/main.lua:
--------------------------------------------------------------------------------
1 | --[[----------------------------------------------------------------------------
2 | Wiirdle v1.0.0
3 |
4 | Copyright (C) 2022 HTV04
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | ------------------------------------------------------------------------------]]
19 |
20 | -- Libraries
21 | local date, timer, binser
22 |
23 | -- Game setup variables
24 | local curDate, firstDate, day, words, solutions, solution, nextDate, save
25 |
26 | -- Floater variables
27 | local floaterWords, floaterWordsLen, floaters
28 |
29 | -- Wiimote variables
30 | local wiimote, wiimotePressed, pointer
31 |
32 | -- Rumble variables and functions
33 | local rumbleTimer, rumbleStop, rumble
34 |
35 | -- Fonts
36 | local logoFont, textFont, tileFont
37 |
38 | -- Font functions
39 | local shadowText
40 |
41 | -- Stats menu
42 | local statsMenu
43 |
44 | -- Keyboard variables
45 | local keys, keyCol, keyRow, keySize, keyFuncs
46 |
47 | -- Tile drawing functions
48 | local tileColorFuncs, drawTile, drawAttemptedTile
49 |
50 | -- Textures
51 | local roundedBox
52 |
53 | function love.load()
54 | local function packToStr(table)
55 | local str = ""
56 |
57 | for _, v in ipairs(table) do
58 | str = str .. v
59 | end
60 |
61 | return str
62 | end
63 |
64 | local function hideStatsMenu() -- For stats menu timers
65 | statsMenu.shown = false
66 | end
67 |
68 | local function newFloater()
69 | table.insert(floaters, {
70 | x = 640,
71 | y = math.random(0, 480),
72 |
73 | text = floaterWords[love.math.random(floaterWordsLen)],
74 | speed = love.math.random(10, 20)
75 | })
76 |
77 | timer.after(3, newFloater)
78 | end
79 |
80 | local letterPos = {
81 | [" "] = 0,
82 | ["A"] = 16,
83 | ["B"] = 19,
84 | ["C"] = 17,
85 | ["D"] = 17,
86 | ["E"] = 19,
87 | ["F"] = 19,
88 | ["G"] = 16,
89 | ["H"] = 17,
90 | ["I"] = 24,
91 | ["J"] = 22,
92 | ["K"] = 17,
93 | ["L"] = 19,
94 | ["M"] = 16,
95 | ["N"] = 17,
96 | ["O"] = 16,
97 | ["P"] = 19,
98 | ["Q"] = 16,
99 | ["R"] = 18,
100 | ["S"] = 18,
101 | ["T"] = 16,
102 | ["U"] = 17,
103 | ["V"] = 16,
104 | ["W"] = 13,
105 | ["X"] = 16,
106 | ["Y"] = 16,
107 | ["Z"] = 17
108 | }
109 |
110 | love.graphics.setBackgroundColor(24, 24, 24)
111 |
112 | date = require("lib.date")
113 | timer = require("lib.timer")
114 | binser = require("lib.binser")
115 |
116 | curDate = date()
117 | firstDate = date(2022, 4, 16)
118 | day = math.floor(date.diff(curDate, firstDate):spandays())
119 | words = require("data.words")
120 | solutions = require("data.solutions")
121 | solution = solutions[day]
122 | nextDate = date(curDate:getyear(), curDate:getmonth(), curDate:getday() + 1)
123 | if love.filesystem.exists("save.bin") then
124 | save = binser.deserializeN(love.filesystem.read("save.bin"))
125 | else
126 | save = {
127 | -- Game setup variables
128 | day = 0, -- Forces day update, which will populate the save table
129 |
130 | -- Stats variables
131 | played = 0,
132 | won = 0,
133 | streak = 0,
134 | maxStreak = 0,
135 | guesses = {0, 0, 0, 0, 0, 0},
136 |
137 | -- Settings
138 | rumble = true
139 | }
140 | end
141 |
142 | floaterWords = {}
143 | for k, _ in pairs(words) do
144 | table.insert(floaterWords, k)
145 | end
146 | floaterWordsLen = #floaterWords
147 | floaters = {}
148 |
149 | wiimote = love.wiimote.getWiimotes()[1]
150 | pointer = love.graphics.newTexture("assets/pointer.png")
151 |
152 | function rumbleStop()
153 | wiimote:setRumble(false)
154 | end
155 | function rumble(duration)
156 | if not save.rumble then return end
157 |
158 | if rumbleTimer then timer.cancel(rumbleTimer) end
159 |
160 | if not duration then
161 | wiimote:setRumble(true)
162 | elseif duration > 0 then
163 | wiimote:setRumble(true)
164 |
165 | rumbleTimer = timer.after(duration, rumbleStop)
166 | else
167 | wiimote:setRumble(false)
168 | end
169 | end
170 |
171 | logoFont = love.graphics.newFont(25)
172 | textFont = love.graphics.newFont(12)
173 | tileFont = love.graphics.newFont(30)
174 |
175 | function shadowText(text, x, y, r, sx, sy, ox, oy)
176 | local r = r or 0
177 | local sx, sy = sx or 1, sy or 1
178 | local ox, oy = ox or 0, oy or 0
179 |
180 | love.graphics.setColor(0, 0, 0)
181 | love.graphics.print(text, x + 1, y + 1, r, sx, sy, ox, oy)
182 | love.graphics.setColor(255, 255, 255)
183 | love.graphics.print(text, x, y, r, sx, sy, ox, oy)
184 | end
185 |
186 | statsMenu = {
187 | -- Variables
188 | shown = false,
189 | fadeValue = 0,
190 | position = -480,
191 | shareScreen = false,
192 |
193 | -- Textures
194 | fade = love.graphics.newTexture("assets/stats/fade.png"),
195 | box = love.graphics.newTexture("assets/stats/box.png"),
196 |
197 | -- Functions
198 | show = function()
199 | statsMenu.shown = true
200 |
201 | if statsMenu.fadeTimer then timer.cancel(statsMenu.fadeTimer) end
202 | if statsMenu.boxTimer then timer.cancel(statsMenu.boxTimer) end
203 |
204 | timer.tween(0.5, statsMenu, {fadeValue = 64})
205 | timer.tween(0.5, statsMenu, {position = 0}, "out-cubic")
206 | end,
207 | hide = function()
208 | if statsMenu.fadeTimer then timer.cancel(statsMenu.fadeTimer) end
209 | if statsMenu.boxTimer then timer.cancel(statsMenu.boxTimer) end
210 |
211 | timer.tween(0.25, statsMenu, {fadeValue = 0})
212 | timer.tween(0.25, statsMenu, {position = -480}, "in-cubic", hideStatsMenu)
213 | end
214 | }
215 |
216 | -- QWERTY layout, may be customizable in the future
217 | keys = {
218 | {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"},
219 | {"a", "s", "d", "f", "g", "h", "j", "k", "l"},
220 | {"enter", "z", "x", "c", "v", "b", "n", "m", "< (B)"}
221 | }
222 | keyCol, keyRow = 0, 0
223 | keySize = {factor = 1} -- Will also have "timer" value
224 | keyFuncs = {
225 | -- Enter attempt
226 | ["enter"] = function()
227 | local attempt = save.attempts[save.curAttempt]
228 | local curAttempt = save.curAttempt
229 | local keyStates = save.keyStates
230 |
231 | if save.curPosition < 6 or not words[packToStr(attempt)] then return end
232 |
233 | local attemptState = save.attemptStates[curAttempt]
234 |
235 | local letterCounts = {} -- Store number of times letter appears
236 | local correctCount = 0 -- Number of correct letters
237 |
238 | -- Pass 1: Correct letters
239 | for i = 1, 5 do
240 | local letter = attempt[i]
241 | local key = string.lower(letter)
242 |
243 | if not letterCounts[letter] then letterCounts[letter] = 0 end
244 |
245 | if letter == string.sub(solution, i, i) then -- Letter is in the correct position
246 | attemptState[i] = 3
247 | if keyStates[key] < 3 then keyStates[key] = 3 end
248 |
249 | letterCounts[letter] = letterCounts[letter] + 1
250 | correctCount = correctCount + 1
251 | end
252 | end
253 |
254 | -- Pass 2: Detemine win and check wrong letters
255 | if correctCount == 5 then -- Won :)
256 | save.completed = true
257 |
258 | save.played = save.played + 1
259 | save.won = save.won + 1
260 | save.streak = save.streak + 1
261 | save.maxStreak = math.max(save.streak, save.maxStreak)
262 |
263 | save.guesses[save.curAttempt] = save.guesses[save.curAttempt] + 1
264 |
265 | statsMenu.show()
266 | else
267 | for i = 1, 5 do
268 | if attemptState[i] == 0 then -- Only check if the letter state is uninitialized
269 | local letter = attempt[i]
270 | local _, appearances = string.gsub(solution, letter, "")
271 | local key = string.lower(letter)
272 |
273 | if letterCounts[letter] < appearances then -- Letter is in the wrong place, false if appearances == 0
274 | attemptState[i] = 2
275 | if keyStates[key] < 2 then keyStates[key] = 2 end
276 |
277 | letterCounts[letter] = letterCounts[letter] + 1
278 | else -- Letter is not in the solution
279 | attemptState[i] = 1
280 | if keyStates[key] < 1 then keyStates[key] = 1 end
281 | end
282 | end
283 | end
284 |
285 | if curAttempt == 6 then -- Lost :(
286 | save.completed = true
287 |
288 | save.played = save.played + 1
289 | save.streak = 0
290 |
291 | statsMenu.show()
292 | end
293 | end
294 |
295 | -- Advance to next attempt
296 | save.curAttempt = curAttempt + 1
297 | save.curPosition = 1
298 | end,
299 |
300 | -- Clear last letter (backspace)
301 | ["< (B)"] = function()
302 | local curPosition = save.curPosition
303 |
304 | if curPosition > 1 then save.curPosition = curPosition - 1 end
305 |
306 | save.attempts[save.curAttempt][curPosition - 1] = " "
307 | end
308 | }
309 |
310 | tileColorFuncs = {
311 | function(modifier) -- Wrong
312 | local modifier = modifier or 0
313 |
314 | love.graphics.setColor(58 + modifier, 58 + modifier, 60 + modifier) -- Gray
315 | end,
316 | function(modifier) -- Letter in wrong place
317 | local modifier = modifier or 0
318 |
319 | love.graphics.setColor(181 + modifier, 159 + modifier, 59 + modifier) -- Yellow
320 | end,
321 | function(modifier) -- Correct
322 | local modifier = modifier or 0
323 |
324 | love.graphics.setColor(83 + modifier, 141 + modifier, 78 + modifier) -- Green
325 | end,
326 |
327 | [0] = function(modifier) -- Uninitialized or other
328 | local modifier = modifier or 0
329 |
330 | love.graphics.setColor(129 + modifier, 131 + modifier, 132 + modifier) -- Light gray
331 | end
332 | }
333 | function drawTile(letter, x, y)
334 | love.graphics.rectangle(false, x, y, 55, 55)
335 | shadowText(letter, x + letterPos[letter], y + 38)
336 | end
337 | function drawAttemptedTile(state, letter, x, y)
338 | tileColorFuncs[state]()
339 |
340 | love.graphics.rectangle(true, x, y, 55, 55)
341 |
342 | love.graphics.setColor(255, 255, 255)
343 | shadowText(letter, x + letterPos[letter], y + 38)
344 | end
345 |
346 | roundedBox = love.graphics.newTexture("assets/rounded-box.png")
347 |
348 | newFloater() -- Inits floater cycle
349 |
350 | if save.completed then statsMenu.show() end
351 | end
352 |
353 | function love.homepressed()
354 | if statsMenu.shown then
355 | if statsMenu.shareScreen then
356 | statsMenu.shareScreen = false
357 |
358 | return true -- Don't exit
359 | end
360 |
361 | love.filesystem.write("save.bin", binser.serialize(save))
362 |
363 | return false -- Safe to exit
364 | else
365 | statsMenu.show()
366 |
367 | return true -- Don't exit
368 | end
369 | end
370 |
371 | function love.update(dt)
372 | local wiimoteX, wiimoteY = wiimote:getPosition()
373 | local oldKeyCol, oldKeyRow = keyCol, keyRow
374 |
375 | timer.update(dt)
376 |
377 | curDate = date()
378 | day = math.floor(date.diff(curDate, firstDate):spandays())
379 |
380 | -- Update save data for day
381 | if save.day ~= day then
382 | solution = solutions[day]
383 | nextDate = date(curDate:getyear(), curDate:getmonth(), curDate:getday() + 1)
384 |
385 | -- Game setup variables
386 | save.day = day
387 | save.completed = false
388 |
389 | -- Gameplay variables
390 | save.attempts = {
391 | {" ", " ", " ", " ", " "},
392 | {" ", " ", " ", " ", " "},
393 | {" ", " ", " ", " ", " "},
394 | {" ", " ", " ", " ", " "},
395 | {" ", " ", " ", " ", " "},
396 | {" ", " ", " ", " ", " "}
397 | }
398 | -- 1: wrong, 2: letter in wrong place, 3: correct
399 | -- 0 is used as a placeholder until the attempt is made
400 | save.attemptStates = {
401 | {0, 0, 0, 0, 0},
402 | {0, 0, 0, 0, 0},
403 | {0, 0, 0, 0, 0},
404 | {0, 0, 0, 0, 0},
405 | {0, 0, 0, 0, 0},
406 | {0, 0, 0, 0, 0}
407 | }
408 | save.curAttempt = 1
409 | save.curPosition = 1
410 | save.keyStates = {
411 | ["a"] = 0,
412 | ["b"] = 0,
413 | ["c"] = 0,
414 | ["d"] = 0,
415 | ["e"] = 0,
416 | ["f"] = 0,
417 | ["g"] = 0,
418 | ["h"] = 0,
419 | ["i"] = 0,
420 | ["j"] = 0,
421 | ["k"] = 0,
422 | ["l"] = 0,
423 | ["m"] = 0,
424 | ["n"] = 0,
425 | ["o"] = 0,
426 | ["p"] = 0,
427 | ["q"] = 0,
428 | ["r"] = 0,
429 | ["s"] = 0,
430 | ["t"] = 0,
431 | ["u"] = 0,
432 | ["v"] = 0,
433 | ["w"] = 0,
434 | ["x"] = 0,
435 | ["y"] = 0,
436 | ["z"] = 0,
437 |
438 | ["enter"] = 0,
439 | ["< (B)"] = 0
440 | }
441 |
442 | if statsMenu.shown then statsMenu.hide() end
443 | end
444 |
445 | -- Floater cleanup
446 | for i = #floaters, 1, -1 do
447 | local floater = floaters[i]
448 |
449 | floater.x = floater.x - floater.speed * dt
450 |
451 | if floater.x <= -110 then table.remove(floaters, i) end
452 | end
453 |
454 | keyCol, keyRow = 0, 0 -- Reset highlighted key
455 |
456 | if statsMenu.shown then
457 | if statsMenu.shareScreen then
458 | if not wiimotePressed and wiimote:isDown("b") then
459 | wiimotePressed = true
460 |
461 | statsMenu.shareScreen = false
462 | elseif not wiimote:isDown("b") then
463 | wiimotePressed = false
464 | end
465 |
466 | return
467 | end
468 |
469 | if not wiimotePressed then
470 | if save.completed and wiimote:isDown("a") then
471 | wiimotePressed = true
472 |
473 | statsMenu.shareScreen = true
474 | elseif wiimote:isDown("b") then
475 | wiimotePressed = true
476 |
477 | statsMenu.hide()
478 | elseif wiimote:isDown("1") then
479 | wiimotePressed = true
480 |
481 | save.rumble = not save.rumble
482 |
483 | rumble(0.1)
484 | end
485 | elseif not wiimote:isDown("a") and not wiimote:isDown("b") and not wiimote:isDown("1") then
486 | wiimotePressed = false
487 | end
488 |
489 | return
490 | end
491 |
492 | -- Process keyboard keys
493 | for i, row in ipairs(keys) do
494 | local start = math.floor((641 - 53 * (#row + 2)) / 2)
495 |
496 | for j, key in ipairs(row) do
497 | local posX, posY = start + j * 53, 330 + i * 37
498 |
499 | if wiimoteX >= posX and wiimoteX <= posX + 48 and wiimoteY >= posY and wiimoteY <= posY + 32 then
500 | keyCol, keyRow = i, j -- Set highlighted key
501 |
502 | -- Only redo tween if the key has changed
503 | if keyCol ~= oldKeyCol or keyRow ~= oldKeyRow then
504 | rumble(0.1)
505 |
506 | if keySize.timer then timer.cancel(keySize.timer) end
507 | keySize.factor = 1
508 | keySize.timer = timer.tween(0.1, keySize, {factor = 1.25})
509 | end
510 |
511 | if not save.completed and not wiimotePressed and wiimote:isDown("a") then
512 | wiimotePressed = true
513 |
514 | if keySize.timer then timer.cancel(keySize.timer) end
515 | keySize.factor = 1
516 | keySize.timer = timer.tween(0.1, keySize, {factor = 1.25})
517 |
518 | if keyFuncs[key] then
519 | keyFuncs[key]()
520 | else
521 | if save.curPosition <= 5 then
522 | save.attempts[save.curAttempt][save.curPosition] = string.upper(key)
523 |
524 | save.curPosition = save.curPosition + 1
525 | end
526 | end
527 | end
528 | end
529 | end
530 |
531 | if not save.completed and not wiimotePressed and wiimote:isDown("b") then
532 | wiimotePressed = true
533 |
534 | keyFuncs["< (B)"]()
535 | elseif not wiimote:isDown("a") and not wiimote:isDown("b") then
536 | wiimotePressed = false
537 | end
538 |
539 | if keyCol == 0 then -- Assume keyRow == 0
540 | rumble(0)
541 | end
542 | end
543 | end
544 |
545 | function love.draw()
546 | local attempts, attemptStates = save.attempts, save.attemptStates
547 | local keyColor
548 |
549 | if statsMenu.shown and statsMenu.shareScreen then
550 | -- Background
551 | tileColorFuncs[0](-32)
552 | love.graphics.draw(statsMenu.fade, 0, 0)
553 | love.graphics.setColor(255, 255, 255)
554 |
555 | -- Info
556 | love.graphics.setFont(logoFont)
557 | shadowText("Wiirdle #" .. save.day .. ": " .. solution, 195, 45)
558 | shadowText("https://github.com/HTV04/wiirdle", 115, 455)
559 | love.graphics.setFont(textFont)
560 | shadowText("Press B to exit", 550, 475)
561 |
562 | -- Tiles
563 | for i = 1, 6 do
564 | for j = 1, 5 do
565 | tileColorFuncs[attemptStates[i][j]]()
566 |
567 | love.graphics.rectangle(true, 112 + j * 60, i * 60, 55, 55)
568 | end
569 | end
570 | love.graphics.setColor(255, 255, 255)
571 |
572 | -- Pointer
573 | love.graphics.draw(pointer, wiimote:getX(), wiimote:getY(), wiimote:getAngle(), 1, 1, 48, 48)
574 |
575 | return
576 | end
577 |
578 | local keyStates = save.keyStates
579 |
580 | -- Floaters
581 | love.graphics.setColor(0, 0, 0)
582 | love.graphics.setFont(tileFont)
583 | for _, v in ipairs(floaters) do
584 | love.graphics.print(v.text, v.x, v.y)
585 | end
586 | love.graphics.setColor(255, 255, 255)
587 |
588 | -- Title, version, and instructions
589 | love.graphics.setFont(logoFont)
590 | love.graphics.print("WiiRDLE", 30, 27)
591 | love.graphics.setFont(textFont)
592 | love.graphics.print("v1.0.0", 92, 43)
593 |
594 | love.graphics.print("Press HOME to view stats", 10, 82)
595 | love.graphics.print("and change settings", 10, 95)
596 |
597 | -- Credits
598 | love.graphics.print(tostring("==Credits=="), 480, 17)
599 |
600 | love.graphics.print("By HTV04", 480, 43)
601 | love.graphics.print("Powered by WiiLÖVE", 480, 56)
602 |
603 | love.graphics.print("\"Wordle\" by Josh Wardle", 480, 82)
604 | love.graphics.print("and The New York Times", 480, 95)
605 |
606 | -- Tiles
607 | love.graphics.setFont(tileFont)
608 | for i = 1, 6 do
609 | if i >= save.curAttempt then
610 | for j = 1, 5 do
611 | drawTile(attempts[i][j], 112 + j * 60, -55 + i * 60)
612 | end
613 | else
614 | for j = 1, 5 do
615 | drawAttemptedTile(attemptStates[i][j], attempts[i][j], 112 + j * 60, -55 + i * 60)
616 | end
617 | end
618 | end
619 |
620 | -- Keyboard keys
621 | love.graphics.setFont(textFont)
622 | for i, row in ipairs(keys) do
623 | local start = math.floor((641 - 53 * (#row + 2)) / 2)
624 |
625 | for j, key in ipairs(row) do
626 | if i ~= keyCol or j ~= keyRow then
627 | tileColorFuncs[keyStates[key]]()
628 | love.graphics.draw(roundedBox, start + j * 53, 330 + i * 37)
629 |
630 | shadowText(key, 4 + start + j * 53, 344 + i * 37)
631 | end
632 | end
633 | end
634 |
635 | -- Highlighted keyboard key
636 | if keyCol ~= 0 then -- Assume keyRow ~= 0
637 | local row = keys[keyCol]
638 |
639 | local start = math.floor((689 - 53 * (#row + 2)) / 2)
640 | local key = row[keyRow]
641 |
642 | keyColor = keyStates[key]
643 |
644 | tileColorFuncs[keyColor](24)
645 | love.graphics.draw(roundedBox, start + keyRow * 53, 346 + keyCol * 37, 0, keySize.factor, keySize.factor, 24, 16)
646 |
647 | shadowText(key, 4 + start + keyRow * 53, 360 + keyCol * 37, 0, keySize.factor, keySize.factor, 24, 16)
648 | end
649 |
650 | -- Stats menu
651 | if statsMenu.shown then
652 | local guesses, maxGuess, maxGuessNum = save.guesses, 1, 0
653 |
654 | local played = save.played
655 |
656 | for i = 2, 6 do
657 | if guesses[i] > guesses[maxGuess] then
658 | maxGuess = i
659 | end
660 | end
661 | maxGuessNum = guesses[maxGuess]
662 |
663 | love.graphics.setColor(255, 255, 255, math.floor(statsMenu.fadeValue))
664 | love.graphics.draw(statsMenu.fade, 0, 0)
665 |
666 | love.graphics.push()
667 | love.graphics.translate(106, 80 + statsMenu.position)
668 |
669 | tileColorFuncs[0]()
670 | love.graphics.draw(statsMenu.box, 0, 0)
671 |
672 | shadowText("Statistics", 185, 20)
673 |
674 | love.graphics.setFont(tileFont)
675 | shadowText(tostring(save.played), 70, 70)
676 | shadowText(tostring(played ~= 0 and math.floor((save.won / played) * 100) or 0), 143, 70)
677 | shadowText(tostring(save.streak), 217, 70)
678 | shadowText(tostring(save.maxStreak), 290, 70)
679 |
680 | love.graphics.setFont(textFont)
681 | shadowText("Played", 70, 90)
682 | shadowText("% Won", 143, 90)
683 | shadowText("Streak", 217, 90)
684 | shadowText("Max Streak", 290, 90)
685 |
686 | for i = 1, 6 do
687 | shadowText(tostring(i), 50, 100 + i * 20)
688 |
689 | if maxGuessNum > 0 then
690 | local guessNum = guesses[i]
691 | local guessPercent = guessNum / maxGuessNum
692 |
693 | if i == maxGuess then
694 | tileColorFuncs[3]()
695 | else
696 | tileColorFuncs[1]()
697 | end
698 | love.graphics.rectangle(true, 60, 91 + i * 20, 15 + 298 * guessPercent, 10)
699 |
700 | love.graphics.print(tostring(guessNum), 78 + 298 * guessPercent, 100 + i * 20)
701 | else
702 | tileColorFuncs[1]()
703 | love.graphics.rectangle(true, 60, 91 + i * 20, 15, 10)
704 |
705 | love.graphics.print("0", 78, 100 + i * 20)
706 | end
707 | end
708 |
709 | shadowText("Next Wiirdle:", 50, 250)
710 | love.graphics.setFont(logoFont)
711 | shadowText(date.diff(nextDate, curDate):fmt("%H:%M:%S"), 135, 254)
712 |
713 | love.graphics.setFont(textFont)
714 | shadowText("==Controls==", 50, 274)
715 | if save.completed then
716 | shadowText("A: Share B: Return to game HOME: Return to loader", 50, 287)
717 | else
718 | shadowText("B: Return to game HOME: Return to loader", 50, 287)
719 | end
720 | if save.rumble then
721 | shadowText("1: Toggle rumble (enabled)", 50, 300)
722 | else
723 | shadowText("1: Toggle rumble (disabled)", 50, 300)
724 | end
725 | love.graphics.pop()
726 | end
727 |
728 | -- Pointer
729 | if keyColor then
730 | tileColorFuncs[keyColor](64)
731 | else
732 | love.graphics.setColor(255, 255, 255)
733 | end
734 | love.graphics.draw(pointer, wiimote:getX(), wiimote:getY(), wiimote:getAngle(), 1, 1, 48, 48)
735 | love.graphics.setColor(255, 255, 255)
736 | end
737 |
--------------------------------------------------------------------------------