commit ca54c8c96580f0ab901d8287fd92e67113a91388 Author: Kris Date: Sun Jul 5 14:03:13 2026 -0400 Initial LCDPet v1.0 release candidate diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf8a74c --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# Gradle / Android build output +.gradle/ +build/ +app/build/ + +# Local machine config +local.properties + +# Android Studio / IntelliJ +.idea/ +*.iml + +# Generated captures / logs +*.log + +# Signing keys / release secrets +*.jks +*.keystore +keystore.properties + +# OS cruft +.DS_Store +Thumbs.db diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..152d7b8 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,57 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "today.notfeelingit.lcdpet" + compileSdk { + version = release(36) { + minorApiLevel = 1 + } + } + + defaultConfig { + applicationId = "today.notfeelingit.lcdpet" + minSdk = 26 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + optimization { + enable = false + } + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + buildFeatures { + compose = true + } +} + +dependencies { + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.compose.material3) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.graphics) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation("androidx.datastore:datastore-preferences:1.2.1") + testImplementation(libs.junit) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(libs.androidx.junit) + debugImplementation(libs.androidx.compose.ui.test.manifest) + debugImplementation(libs.androidx.compose.ui.tooling) +} diff --git a/app/src/androidTest/java/today/notfeelingit/lcdpet/ExampleInstrumentedTest.kt b/app/src/androidTest/java/today/notfeelingit/lcdpet/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..76834c0 --- /dev/null +++ b/app/src/androidTest/java/today/notfeelingit/lcdpet/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package today.notfeelingit.lcdpet + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("today.notfeelingit.lcdpet", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8c25918 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/audio_credits.txt b/app/src/main/assets/audio_credits.txt new file mode 100644 index 0000000..effbf91 --- /dev/null +++ b/app/src/main/assets/audio_credits.txt @@ -0,0 +1,28 @@ +LCDPet Audio Credits + +Weather Channel music: +“Calm Piano Jazz Loop” by ispeakwaves +Source: Freesound +Sound page: https://freesound.org/people/ispeakwaves/sounds/570316/ +Original file: 570316__ispeakwaves__calm-piano-jazz-loop.wav +App file: weather_channel_jazz.ogg +License: Creative Commons Attribution 4.0 +Use: Watch TV Channel 1 Weather loop + +No Signal static: +“TV_Light_Static.aif” by crcavol +Source: Freesound +Sound page: https://freesound.org/people/crcavol/sounds/154674/ +Original file: 154674__crcavol__tv_light_static.aiff +App file: tv_static_light.ogg +License: Creative Commons 0 / CC0 +Use: Watch TV Channel 2 No Signal static loop + +TV power-off sound: +“Tv 100Hz off.wav” by KnightRider1 +Source: Freesound +Sound page: https://freesound.org/people/KnightRider1/sounds/90682/ +App file: tv_off.ogg +License: Creative Commons 0 / CC0 +Use: Watch TV CRT power-off sound +Edited for length diff --git a/app/src/main/java/today/notfeelingit/lcdpet/DowntimeActivities.kt b/app/src/main/java/today/notfeelingit/lcdpet/DowntimeActivities.kt new file mode 100644 index 0000000..eebd6a0 --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/DowntimeActivities.kt @@ -0,0 +1,557 @@ +package today.notfeelingit.lcdpet + +import android.media.MediaPlayer +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.gestures.detectDragGestures +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shadow +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import kotlinx.coroutines.delay + +@Composable +fun TouchGrassActivityScreen( + lcdDark: Color, + onGrassTap: () -> Unit +) { + var grassFingerColumn by remember { mutableIntStateOf(-1) } + var grassWaveTick by remember { mutableIntStateOf(0) } + var grassWidthPx by remember { mutableIntStateOf(1) } + + val grassColumns = 33 + + fun updateGrassFinger(xPosition: Float) { + val safeWidth = maxOf(grassWidthPx, 1) + grassFingerColumn = ((xPosition / safeWidth.toFloat()) * grassColumns) + .toInt() + .coerceIn(0, grassColumns - 1) + grassWaveTick += 1 + onGrassTap() + } + + Column( + modifier = Modifier + .fillMaxWidth() + .border(2.dp, lcdDark) + .padding(12.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(10.dp) + ) { + Text( + text = fluidGrassText( + fingerColumn = grassFingerColumn, + waveTick = grassWaveTick, + columns = grassColumns + ), + fontFamily = FontFamily.Monospace, + textAlign = TextAlign.Center, + modifier = Modifier + .fillMaxWidth() + .onGloballyPositioned { coordinates -> + grassWidthPx = coordinates.size.width + } + .pointerInput(Unit) { + detectDragGestures( + onDragStart = { offset -> + updateGrassFinger(offset.x) + }, + onDrag = { change, _ -> + updateGrassFinger(change.position.x) + }, + onDragEnd = { + grassFingerColumn = -1 + }, + onDragCancel = { + grassFingerColumn = -1 + } + ) + } + ) + + Text( + text = "Slide through the grass.", + color = lcdDark, + textAlign = TextAlign.Center + ) + + Text( + text = "Pet is taking time alone.", + color = lcdDark, + textAlign = TextAlign.Center + ) + } +} + +@Composable +fun WatchTvActivityScreen( + lcdDark: Color, + selectedChannel: TvChannel, + weatherLabel: String, + onChannelSelected: (TvChannel) -> Unit +) { + var tvFrame by remember { mutableIntStateOf(0) } + var tvPowerState by remember { mutableIntStateOf(1) } + var tvPowerOffSoundRequest by remember { mutableIntStateOf(0) } + // 1 = on, 2 = CRT shutting off, 0 = off + + val context = LocalContext.current + + LaunchedEffect(selectedChannel, tvPowerState) { + tvFrame = 0 + + while (true) { + delay(if (tvPowerState == 2) 120L else 450L) + tvFrame += 1 + } + } + + LaunchedEffect(tvPowerState) { + if (tvPowerState == 2) { + delay(420L) + tvPowerState = 0 + } + } + + + + LaunchedEffect(tvPowerOffSoundRequest) { + if (tvPowerOffSoundRequest > 0) { + val powerOffPlayer = MediaPlayer.create(context, R.raw.tv_off) + + try { + powerOffPlayer?.apply { + isLooping = false + setVolume(0.75f, 0.75f) + start() + } + + while (powerOffPlayer?.isPlaying == true) { + delay(50L) + } + } finally { + powerOffPlayer?.release() + } + } + } + + DisposableEffect(selectedChannel, tvPowerState) { + var player: MediaPlayer? = null + + if (tvPowerState == 1) { + val soundResource = when (selectedChannel) { + TvChannel.Weather -> R.raw.weather_channel_jazz + TvChannel.NoSignal -> R.raw.tv_static_light + } + + val channelVolume = when (selectedChannel) { + TvChannel.Weather -> 0.75f + TvChannel.NoSignal -> 0.60f + } + + player = MediaPlayer.create(context, soundResource)?.apply { + isLooping = true + setVolume(channelVolume, channelVolume) + start() + } + } + + onDispose { + player?.stop() + player?.release() + player = null + } + } + + Column( + modifier = Modifier + .fillMaxWidth() + .border(2.dp, lcdDark) + .padding(8.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(170.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + Column( + modifier = Modifier.width(48.dp), + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + TvChannelButton( + text = "1", + selected = tvPowerState == 1 && selectedChannel == TvChannel.Weather, + lcdDark = lcdDark, + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onClick = { + if (tvPowerState == 1) { + onChannelSelected(TvChannel.Weather) + } + } + ) + + TvChannelButton( + text = "2", + selected = tvPowerState == 1 && selectedChannel == TvChannel.NoSignal, + lcdDark = lcdDark, + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onClick = { + if (tvPowerState == 1) { + onChannelSelected(TvChannel.NoSignal) + } + } + ) + + TvPowerButton( + powerOn = tvPowerState == 1, + lcdDark = lcdDark, + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onClick = { + if (tvPowerState == 1) { + tvPowerOffSoundRequest += 1 + tvPowerState = 2 + } else { + tvPowerState = 1 + } + } + ) + } + + Box( + modifier = Modifier + .weight(1f) + .fillMaxHeight() + .border(2.dp, lcdDark) + .background(if (tvPowerState == 1) Color.Transparent else Color.Black) + .padding(horizontal = 10.dp, vertical = 8.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = if (tvPowerState == 1) { + tvPreviewText( + channel = selectedChannel, + frame = tvFrame, + weatherLabel = weatherLabel + ) + } else { + tvPowerOffPreviewText( + frame = tvFrame, + shuttingDown = tvPowerState == 2 + ) + }, + fontFamily = FontFamily.Monospace, + textAlign = if (tvPowerState == 1) TextAlign.Start else TextAlign.Center, + color = if (tvPowerState == 1) lcdDark else Color.White, + modifier = Modifier.fillMaxWidth(), + softWrap = !(tvPowerState == 1 && selectedChannel == TvChannel.NoSignal) + ) + } + } + + Text( + text = "Pet is outside having alone time.", + color = lcdDark, + textAlign = TextAlign.Center + ) + } +} + +@Composable +private fun TvChannelButton( + text: String, + selected: Boolean, + lcdDark: Color, + modifier: Modifier = Modifier, + onClick: () -> Unit +) { + Box( + modifier = modifier + .border(2.dp, lcdDark) + .clickable { onClick() } + .padding(vertical = 6.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = if (selected) "[$text]" else text, + fontWeight = FontWeight.Bold, + color = lcdDark, + textAlign = TextAlign.Center + ) + } +} + +@Composable +private fun TvPowerButton( + powerOn: Boolean, + lcdDark: Color, + modifier: Modifier = Modifier, + onClick: () -> Unit +) { + val textGlow = if (powerOn) { + Shadow( + color = Color.White.copy(alpha = 0.65f), + offset = Offset.Zero, + blurRadius = 4f + ) + } else { + null + } + + Box( + modifier = modifier + .background(Color.Black) + .border(2.dp, lcdDark) + .clickable { onClick() } + .padding(vertical = 2.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = "Θ", + fontFamily = FontFamily.Monospace, + fontSize = 16.sp, + lineHeight = 16.sp, + fontWeight = FontWeight.Bold, + color = Color.White, + textAlign = TextAlign.Center, + style = TextStyle( + shadow = textGlow + ) + ) + } +} + +private fun fluidGrassText( + fingerColumn: Int, + waveTick: Int, + columns: Int +): AnnotatedString { + val rows = 7 + val grassColor = Color(0xFF2E7D32) + + return buildAnnotatedString { + for (row in 0 until rows) { + for (column in 0 until columns) { + val distance = if (fingerColumn < 0) { + 99 + } else { + kotlin.math.abs(column - fingerColumn) + } + + val phase = (row + column + waveTick) % 4 + + val blade = when { + distance == 0 -> if (phase % 2 == 0) '/' else '\\' + distance == 1 -> if (phase % 2 == 0) '/' else '|' + distance == 2 -> if (phase % 2 == 0) '|' else '\\' + else -> '|' + } + + withStyle(SpanStyle(color = grassColor)) { + append(blade) + } + } + + if (row != rows - 1) { + append("\n") + } + } + } +} + +private fun tvPreviewText( + channel: TvChannel, + frame: Int, + weatherLabel: String +): String { + return when (channel) { + TvChannel.Weather -> weatherPreviewText(weatherLabel) + + TvChannel.NoSignal -> noSignalPreviewText( + channelNumber = 2, + frame = frame + ) + } +} + +private fun weatherPreviewText(weatherLabel: String): String { + val normalizedWeather = weatherLabel.lowercase() + + val conditionText = when { + normalizedWeather.contains("rain") -> "RAINING" + normalizedWeather.contains("cloud") || normalizedWeather.contains("overcast") -> "CLOUDY" + else -> "SUNNY" + } + + val iconLines = when (conditionText) { + "RAINING" -> listOf( + " .--. ", + " (____) ", + " ' ' ' " + ) + + "CLOUDY" -> listOf( + " .--. ", + " (____) ", + " " + ) + + else -> listOf( + " \\ | / ", + " \\|/ ", + " -- o --" + ) + } + + return listOf( + "${iconLines[0]} $conditionText", + "${iconLines[1]} TEMP: 72", + "${iconLines[2]} UNIT: C/F" + ).joinToString("\n") +} + + +private fun tvPowerOffPreviewText( + frame: Int, + shuttingDown: Boolean +): String { + if (!shuttingDown) { + return listOf( + "", + "", + "", + "", + "" + ).joinToString("\n") + } + + return when (frame) { + 0 -> listOf( + "", + "--------------------------------", + "================================", + "--------------------------------", + "" + ).joinToString("\n") + + 1 -> listOf( + "", + "", + " ------------", + "", + "" + ).joinToString("\n") + + 2 -> listOf( + "", + "", + " --*--", + "", + "" + ).joinToString("\n") + + else -> listOf( + "", + "", + "", + "", + "" + ).joinToString("\n") + } +} + +private fun noSignalPreviewText( + channelNumber: Int, + frame: Int +): String { + val width = 34 + val staticLine = if (frame % 2 == 0) { + "|".repeat(width) + } else { + ":".repeat(width) + } + + val secondStaticLine = staticLine + + return listOf( + "CH $channelNumber", + "", + " NO SIGNAL", + staticLine, + secondStaticLine + ).joinToString("\n") +} + +private fun tvTextLine( + width: Int, + vararg parts: Pair, + fill: Char = ' ' +): String { + return tvTextLine( + width = width, + fill = fill, + parts = parts + ) +} + +private fun tvTextLine( + width: Int, + fill: Char, + parts: Array> +): String { + val chars = CharArray(width) { fill } + + parts.forEach { part -> + val start = part.first + val value = part.second + + value.forEachIndexed { index, char -> + val target = start + index + if (target in chars.indices && char != ' ') { + chars[target] = char + } + } + } + + return String(chars) +} diff --git a/app/src/main/java/today/notfeelingit/lcdpet/DowntimeState.kt b/app/src/main/java/today/notfeelingit/lcdpet/DowntimeState.kt new file mode 100644 index 0000000..730ee04 --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/DowntimeState.kt @@ -0,0 +1,12 @@ +package today.notfeelingit.lcdpet + +enum class DowntimeMode { + None, + TouchGrass, + WatchTv +} + +enum class TvChannel { + Weather, + NoSignal +} diff --git a/app/src/main/java/today/notfeelingit/lcdpet/MainActivity.kt b/app/src/main/java/today/notfeelingit/lcdpet/MainActivity.kt new file mode 100644 index 0000000..1dc406b --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/MainActivity.kt @@ -0,0 +1,3525 @@ +package today.notfeelingit.lcdpet +import androidx.core.app.NotificationManagerCompat +import androidx.core.app.NotificationCompat +import android.app.PendingIntent +import android.net.Uri +import android.content.Intent +import android.content.Context +import android.app.NotificationManager +import android.app.NotificationChannel + +import android.Manifest +import android.content.pm.PackageManager +import android.os.Build +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.compose.setContent +import androidx.activity.result.contract.ActivityResultContracts +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.foundation.gestures.detectTapGestures + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.Alignment +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import androidx.compose.ui.platform.LocalContext +import androidx.core.content.ContextCompat +import androidx.compose.ui.platform.LocalLifecycleOwner +import today.notfeelingit.lcdpet.ui.theme.LCDPetTheme + +private const val LCDPET_NOTIFICATION_CHANNEL_ID = "lcdpet_alerts" + +private data class CareJournalEntry( + val category: String, + val action: String, + val met: Boolean, + val responseMs: Long?, + val happenedAtMs: Long +) + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + createLCDPetNotificationChannel() + + setContent { + LCDPetTheme { + Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> + Greeting( + name = "LCDPet", + modifier = Modifier.padding(innerPadding) + ) + } + } + } + } + + private fun createLCDPetNotificationChannel() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val channel = NotificationChannel( + LCDPET_NOTIFICATION_CHANNEL_ID, + "LCDPet Alerts", + NotificationManager.IMPORTANCE_DEFAULT + ).apply { + description = "Pet care reminders and LCDPet status alerts." + } + + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + notificationManager.createNotificationChannel(channel) + } + } +} + + +@Composable +fun ActionLabel( + text: String, + enabled: Boolean, + lcdDark: Color, + lcdFaded: Color, + onClick: () -> Unit +) { + Text( + text = text, + fontWeight = FontWeight.Bold, + color = if (enabled) lcdDark else lcdFaded, + modifier = if (enabled) { + Modifier.clickable { + onClick() + } + } else { + Modifier + } + ) +} + +@Composable +fun LCDActionButton( + text: String, + enabled: Boolean, + lcdDark: Color, + lcdFaded: Color, + onClick: () -> Unit +) { + Box( + modifier = Modifier + .fillMaxWidth() + .border(2.dp, if (enabled) lcdDark else lcdFaded) + .clickable(enabled = enabled) { + onClick() + } + .padding(vertical = 8.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = text, + fontWeight = FontWeight.Bold, + color = if (enabled) lcdDark else lcdFaded, + textAlign = TextAlign.Center + ) + } +} + +@Composable +fun LCDMenuButton( + text: String, + enabled: Boolean, + lcdDark: Color, + lcdFaded: Color, + onClick: () -> Unit +) { + Box( + modifier = Modifier + .fillMaxWidth() + .background(if (enabled) lcdDark else lcdFaded) + .border(2.dp, if (enabled) lcdDark else lcdFaded) + .clickable(enabled = enabled) { + onClick() + } + .padding(vertical = 10.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = text, + fontWeight = FontWeight.Bold, + color = if (enabled) Color.White else lcdDark, + textAlign = TextAlign.Center + ) + } +} + +@Composable +fun LCDSubButton( + text: String, + enabled: Boolean, + lcdDark: Color, + lcdFaded: Color, + onClick: () -> Unit, + modifier: Modifier = Modifier, + fillWidthFraction: Float = 0.86f +) { + Box( + modifier = modifier + .fillMaxWidth(fillWidthFraction) + .border(2.dp, if (enabled) lcdDark else lcdFaded) + .clickable(enabled = enabled) { + onClick() + } + .padding(vertical = 8.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = text, + fontWeight = FontWeight.Bold, + color = if (enabled) lcdDark else lcdFaded, + textAlign = TextAlign.Center + ) + } +} + +@Composable +fun LCDHoldSubButton( + text: String, + enabled: Boolean, + lcdDark: Color, + lcdFaded: Color, + onPress: () -> Unit, + onRelease: () -> Unit +) { + Box( + modifier = Modifier + .fillMaxWidth(0.86f) + .border(2.dp, if (enabled) lcdDark else lcdFaded) + .pointerInput(enabled) { + detectTapGestures( + onPress = { + if (enabled) { + onPress() + try { + tryAwaitRelease() + } finally { + onRelease() + } + } + } + ) + } + .padding(vertical = 8.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = text, + fontWeight = FontWeight.Bold, + color = if (enabled) lcdDark else lcdFaded, + textAlign = TextAlign.Center + ) + } +} + +@Composable +fun LCDSubMenuFrame( + lcdDark: Color, + content: @Composable () -> Unit +) { + Column( + modifier = Modifier + .fillMaxWidth() + .border(2.dp, lcdDark) + .padding(vertical = 8.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(6.dp) + ) { + content() + } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + val lcdBackground = Color(0xFFC4C7B0) + val lcdDark = Color(0xFF2A2A2A) + val sickGreen = Color(0xFF2F7D32) + val lcdFaded = lcdDark.copy(alpha = 0.30f) + + val context = LocalContext.current + val lifecycleOwner = LocalLifecycleOwner.current + val saveScope = rememberCoroutineScope() + val notificationPermissionLauncher = rememberLauncherForActivityResult( + contract = ActivityResultContracts.RequestPermission(), + onResult = {} + ) + + LaunchedEffect(Unit) { + if ( + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && + ContextCompat.checkSelfPermission( + context, + Manifest.permission.POST_NOTIFICATIONS + ) != PackageManager.PERMISSION_GRANTED + ) { + notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) + } + } + val creditsText = remember(context) { + runCatching { + context.assets.open("audio_credits.txt").bufferedReader().use { it.readText() } + }.getOrElse { + "Credits unavailable." + } + } + val newPetWeatherOptions = listOf("Sunny", "Cloudy", "Rain", "Snow") + var location by remember { mutableStateOf("Inside") } + var weather by remember { mutableStateOf(newPetWeatherOptions.random()) } + var status by remember { mutableStateOf("Nervous") } + + var hunger by remember { mutableIntStateOf(5) } + var health by remember { mutableIntStateOf(10) } + var happiness by remember { mutableIntStateOf(5) } + var energy by remember { mutableIntStateOf(5) } + var bond by remember { mutableIntStateOf(0) } + var dirtiness by remember { mutableIntStateOf(0) } + var potty by remember { mutableIntStateOf(0) } + var boredom by remember { mutableIntStateOf(0) } + + var overfeedCount by remember { mutableIntStateOf(0) } + var starvingCount by remember { mutableIntStateOf(0) } + var overfeedNeedWindowOpen by remember { mutableStateOf(false) } + var hungerNeedWindowOpen by remember { mutableStateOf(false) } + var recoveryCount by remember { mutableIntStateOf(0) } + var sickCount by remember { mutableIntStateOf(0) } + var goodFeedCount by remember { mutableIntStateOf(0) } + var feedPottyCount by remember { mutableIntStateOf(0) } + var playEnergyCount by remember { mutableIntStateOf(0) } + var sameActionStreak by remember { mutableIntStateOf(0) } + var boredomTriggerAt by remember { mutableIntStateOf((3..13).random()) } + var boredomPenaltyCount by remember { mutableIntStateOf(0) } + var ultraTrollTriggered by remember { mutableStateOf(false) } + var lastActionName by remember { mutableStateOf("") } + var weakCause by remember { mutableStateOf("") } + var activityMood by remember { mutableStateOf("") } + var frameProp by remember { mutableStateOf("") } + var framePropAnimation by remember { mutableStateOf("") } + var framePropAnimationId by remember { mutableIntStateOf(0) } + var framePropStyle by remember { mutableIntStateOf(0) } + var pottyStain by remember { mutableStateOf("") } + var isSleeping by remember { mutableStateOf(false) } + var sleepMode by remember { mutableStateOf("") } + var roughWakeAlert by remember { mutableStateOf(false) } + var roughWakeDarkFlash by remember { mutableStateOf(false) } + var roughWakeNervousHold by remember { mutableStateOf(false) } + var restoredAutoSleep by remember { mutableStateOf(false) } + var autoSleepWakeAllowed by remember { mutableStateOf(false) } + var autoSleepStartedAtMs by remember { mutableStateOf(0L) } + var isTradingInPet by remember { mutableStateOf(false) } + var isFindingNewPet by remember { mutableStateOf(false) } + var tradeInProgress by remember { mutableIntStateOf(0) } + var tradeInConfirm by remember { mutableStateOf(false) } + var isBathing by remember { mutableStateOf(false) } + var isTalking by remember { mutableStateOf(false) } + var bathBondAtStart by remember { mutableIntStateOf(0) } + var bathWantMatched by remember { mutableStateOf(false) } + var careMenuOpen by remember { mutableStateOf(false) } + var socializeMenuOpen by remember { mutableStateOf(false) } + var statsMenuOpen by remember { mutableStateOf(false) } + var careJournalOpen by remember { mutableStateOf(false) } + var creditsOpen by remember { mutableStateOf(false) } + var creditsCloseButtonCorner by remember { mutableStateOf("BottomRight") } + var careJournalTab by remember { mutableStateOf("All") } + var testWantMenuOpen by remember { mutableStateOf(false) } + var testBondMenuOpen by remember { mutableStateOf(false) } + var downtimeMode by remember { mutableStateOf(DowntimeMode.None) } + var selectedTvChannel by remember { mutableStateOf(TvChannel.Weather) } + + var currentWant by remember { mutableStateOf("") } + var currentWantStartedAtMs by remember { mutableStateOf(0L) } + var hungerNeedNotificationOpen by remember { mutableStateOf(false) } + var pottyNeedNotificationOpen by remember { mutableStateOf(false) } + var dirtinessNeedNotificationOpen by remember { mutableStateOf(false) } + var energyNeedNotificationOpen by remember { mutableStateOf(false) } + var careJournalEntries by remember { mutableStateOf>(emptyList()) } + var pottyFaceOverride by remember { mutableStateOf("") } + var pottyFaceBag by remember { mutableStateOf(emptyList()) } + var petName by remember { mutableStateOf("") } + var pendingPetName by remember { mutableStateOf("") } + var happyOutsideTrip by remember { mutableStateOf(false) } + + var petAgeDays by remember { mutableIntStateOf(0) } + var careScore by remember { mutableIntStateOf(0) } + var neglectScore by remember { mutableIntStateOf(0) } + + val testingMode = (context.applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0 + + val secondMs = 1_000L + val minuteMs = 60L * secondMs + val hourMs = 60L * minuteMs + + val bondCooldownMs = if (testingMode) 60_000L else 6L * hourMs + val sickTickMs = if (testingMode) 12_000L else 30L * minuteMs + val weakRecoveryCheckMs = if (testingMode) 25_000L else 2L * hourMs + val recoverWeakMs = if (testingMode) 25_000L else 2L * hourMs + val recoveringTickMs = if (testingMode) 5_000L else 10L * minuteMs + val hungerTickMs = if (testingMode) 20_000L else 2L * hourMs + val rainHappinessTickMs = if (testingMode) 20_000L else 1L * hourMs + val pottyTickMs = if (testingMode) 30_000L else 3L * hourMs + val dirtyHealthTickMs = if (testingMode) 60_000L else 12L * hourMs + val activityMoodMs = if (testingMode) 2_000L else 2_000L + val propAnimationTickMs = if (testingMode) 180L else 180L + val petDayMs = if (testingMode) 60_000L else 24L * hourMs + val weatherShiftOptionsMs = if (testingMode) { + listOf(45_000L, 60_000L, 90_000L) + } else { + listOf(4L * hourMs, 6L * hourMs, 9L * hourMs, 12L * hourMs) + } + val wantCooldownOptionsMs = if (testingMode) { + listOf(45_000L, 60_000L, 90_000L) + } else { + listOf(8L * hourMs, 12L * hourMs, 18L * hourMs, 24L * hourMs) + } + val wantDurationMs = if (testingMode) 20_000L else 10L * minuteMs + + val lowBondBathMs = if (testingMode) 2_000L else 2L * minuteMs + val mediumBondBathMs = if (testingMode) 4_000L else 4L * minuteMs + val trustedBathMs = if (testingMode) 6_000L else 6L * minuteMs + + val sleepOptionsMs = if (testingMode) { + listOf(8_000L, 11_000L, 14_000L, 18_000L) + } else { + listOf(2L * hourMs, 3L * hourMs, 4L * hourMs, 5L * hourMs) + } + + val autoSleepDelayMs = if (testingMode) 15_000L else 30L * minuteMs + val roughSleepEnergyTickMs = if (testingMode) 30_000L else 60L * 60L * 1000L + val offlineOutsideEnergyDrainTickMs = roughSleepEnergyTickMs + val roughWakeAlertMs = if (testingMode) 4_000L else 30_000L + + val tradeInWaitMs = if (testingMode) 5_000L else 24L * hourMs + val findingNewPetMs = if (testingMode) 2_000L else 5_000L + val tradeInProgressBlocks = 10 + + var bondReady by remember { mutableStateOf(true) } + var saveLoaded by remember { mutableStateOf(false) } + + fun encodeCareJournalEntries(entries: List): String { + return entries.take(50).joinToString("\n") { entry -> + listOf( + entry.category, + entry.action, + entry.met.toString(), + entry.responseMs?.toString().orEmpty(), + entry.happenedAtMs.toString() + ).joinToString("|") + } + } + + fun sendLCDPetNotification(notificationId: Int, title: String, message: String) { + if ( + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && + ContextCompat.checkSelfPermission( + context, + Manifest.permission.POST_NOTIFICATIONS + ) != PackageManager.PERMISSION_GRANTED + ) { + return + } + + val launchIntent = Intent(context, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP + } + + val pendingIntent = PendingIntent.getActivity( + context, + notificationId, + launchIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE + ) + + val notification = NotificationCompat.Builder(context, LCDPET_NOTIFICATION_CHANNEL_ID) + .setSmallIcon(android.R.drawable.ic_dialog_info) + .setContentTitle(title) + .setContentText(message) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) + .setContentIntent(pendingIntent) + .setAutoCancel(true) + .build() + + NotificationManagerCompat.from(context).notify(notificationId, notification) + } + + fun wantNotificationText(wantName: String): String { + val notificationPetName = petName.ifBlank { "Your pet" } + + return when (wantName) { + "Snack" -> "$notificationPetName wants a snack." + "Play" -> "$notificationPetName wants to play." + "Pet" -> "$notificationPetName wants pets." + "Talk" -> "$notificationPetName is looking for you." + "Outside" -> "$notificationPetName wants to go outside." + "Bath" -> "$notificationPetName wants a bath." + else -> "$notificationPetName wants your attention." + } + } + + fun sendWantNotification(wantName: String) { + sendLCDPetNotification( + notificationId = 2001, + title = "LCDPet", + message = wantNotificationText(wantName) + ) + } + + fun sendNeedNotification(notificationId: Int, message: String) { + sendLCDPetNotification( + notificationId = notificationId, + title = "LCDPet", + message = message + ) + } + + fun sendTestNotification() { + sendLCDPetNotification( + notificationId = 1001, + title = "LCDPet", + message = "Test alert: your pet says beep boop." + ) + } + + fun decodeCareJournalEntries(raw: String): List { + return raw.lines() + .mapNotNull { line -> + val parts = line.split("|") + + if (parts.size != 5) { + return@mapNotNull null + } + + val met = when (parts[2]) { + "true" -> true + "false" -> false + else -> return@mapNotNull null + } + + val responseMs = if (parts[3].isBlank()) { + null + } else { + parts[3].toLongOrNull() + } + + val happenedAtMs = parts[4].toLongOrNull() ?: return@mapNotNull null + + CareJournalEntry( + category = parts[0], + action = parts[1], + met = met, + responseMs = responseMs, + happenedAtMs = happenedAtMs + ) + } + .take(50) + } + + LaunchedEffect(Unit) { + context.lcdPetRecordSaveFlow.collect { save -> + // Only hydrate state from storage on the first load. + // After that, saves come from this screen and should not re-trigger restored auto-sleep. + if (saveLoaded) { + return@collect + } + + bond = save.bond + petAgeDays = save.petAgeDays + careScore = save.careScore + neglectScore = save.neglectScore + hunger = save.hunger + health = save.health + happiness = save.happiness + energy = save.energy + dirtiness = save.dirtiness + potty = save.potty + boredom = save.boredom + location = save.location + weather = save.weather + status = save.status + weakCause = save.weakCause + pottyStain = save.pottyStain + happyOutsideTrip = save.happyOutsideTrip + isTradingInPet = save.isTradingInPet + isFindingNewPet = save.isFindingNewPet + tradeInProgress = save.tradeInProgress.coerceIn(0, tradeInProgressBlocks) + currentWant = save.currentWant + petName = save.petName + pendingPetName = save.petName + isSleeping = save.isSleeping + sleepMode = save.sleepMode + roughWakeAlert = save.roughWakeAlert + autoSleepStartedAtMs = save.autoSleepStartedAtMs + careJournalEntries = decodeCareJournalEntries(save.careJournalRaw) + autoSleepWakeAllowed = false + + val nowMs = System.currentTimeMillis() + val elapsedAwayMs = (nowMs - save.lastSavedAtMs).coerceAtLeast(0L) + + if ( + !save.isSleeping && + save.location == "Outside" && + !save.isTradingInPet && + !save.isFindingNewPet && + elapsedAwayMs >= offlineOutsideEnergyDrainTickMs + ) { + val energyLostAway = (elapsedAwayMs / offlineOutsideEnergyDrainTickMs).toInt() + + if (energyLostAway >= save.energy) { + val timeUntilSleepMs = save.energy.toLong() * offlineOutsideEnergyDrainTickMs + energy = 0 + isSleeping = true + sleepMode = "Auto" + autoSleepStartedAtMs = save.lastSavedAtMs + timeUntilSleepMs + restoredAutoSleep = true + } else { + energy = (save.energy - energyLostAway).coerceAtLeast(0) + restoredAutoSleep = false + } + } else { + restoredAutoSleep = save.isSleeping && save.sleepMode == "Auto" + } + + tradeInConfirm = false + saveLoaded = true + } + } + + val hungerBar = "▓".repeat(hunger) + "▒".repeat(10 - hunger) + val healthBar = "\uD83D\uDDA4".repeat(health) + "\uD83E\uDE76".repeat(10 - health) + val happinessBar = "▓".repeat(happiness) + "▒".repeat(10 - happiness) + val energyBar = "▓".repeat(energy) + "▒".repeat(10 - energy) + val bondBlocks = bond / 10 + val bondBar = "▓".repeat(bondBlocks) + "▒".repeat(10 - bondBlocks) + val bondPercent = bond + val dirtinessBar = "▓".repeat(dirtiness) + "▒".repeat(10 - dirtiness) + val pottyBar = "▓".repeat(potty) + "▒".repeat(10 - potty) + val boredomBar = "▓".repeat(boredom) + "▒".repeat(10 - boredom) + + fun statAgeText(days: Int): String { + fun amount(value: Int, single: String, plural: String): String { + return "$value ${if (value == 1) single else plural}" + } + + return when { + days < 7 -> amount(days, "day", "days") + days < 30 -> amount((days / 7).coerceAtLeast(1), "week", "weeks") + days < 365 -> amount((days / 30).coerceAtLeast(1), "month", "months") + else -> amount((days / 365).coerceAtLeast(1), "year", "years") + } + } + + val petAgeText = statAgeText(petAgeDays) + val displayPetName = petName.ifBlank { "Pet" } + val needsPetName = saveLoaded && petName.isBlank() && !isTradingInPet && !isFindingNewPet + val trimmedPendingPetName = pendingPetName.trim() + val normalizedPendingPetName = trimmedPendingPetName.lowercase() + val isNameValidationActive = !testingMode + val reservedPetNames = setOf("patch", "petch") + val isReservedPetName = isNameValidationActive && normalizedPendingPetName in reservedPetNames + val hasValidPetNameLetters = trimmedPendingPetName.isNotEmpty() && trimmedPendingPetName.all { it.isLetter() } + val canKeepPetName = hasValidPetNameLetters && !isReservedPetName + + val bondRelationship = when { + bond >= 100 -> "BFF" + bond >= 80 -> "Best Friend" + bond >= 50 -> "Pal" + bond >= 25 -> "Settled" + else -> "New Pet" + } + + + + val tradeInProgressBar = "▓".repeat(tradeInProgress) + "▒".repeat(tradeInProgressBlocks - tradeInProgress) + + fun addCareJournalEntry( + category: String, + action: String, + met: Boolean, + responseMs: Long? = null + ) { + val nowMs = System.currentTimeMillis() + val entry = CareJournalEntry( + category = category, + action = action, + met = met, + responseMs = responseMs, + happenedAtMs = nowMs + ) + + careJournalEntries = (listOf(entry) + careJournalEntries).take(50) + } + + fun logNeedJournal(action: String, met: Boolean) { + addCareJournalEntry( + category = "Need", + action = action, + met = met, + responseMs = null + ) + } + + fun logWantJournal(action: String, met: Boolean) { + val nowMs = System.currentTimeMillis() + val responseMs = if (met && currentWantStartedAtMs > 0L) { + (nowMs - currentWantStartedAtMs).coerceAtLeast(0L) + } else { + null + } + + addCareJournalEntry( + category = "Want", + action = action, + met = met, + responseMs = responseMs + ) + } + + fun journalResponseText(responseMs: Long?): String { + if (responseMs == null) { + return "N/A" + } + + return when { + responseMs < minuteMs -> "${(responseMs / secondMs).coerceAtLeast(1L)}s" + responseMs < hourMs -> "${(responseMs / minuteMs).coerceAtLeast(1L)}m" + else -> "${(responseMs / hourMs).coerceAtLeast(1L)}h" + } + } + + fun journalDateText(happenedAtMs: Long): String { + val ageMs = (System.currentTimeMillis() - happenedAtMs).coerceAtLeast(0L) + + return when { + ageMs < secondMs -> "now" + ageMs < minuteMs -> "${(ageMs / secondMs).coerceAtLeast(1L)}s ago" + ageMs < hourMs -> "${(ageMs / minuteMs).coerceAtLeast(1L)}m ago" + ageMs < 24L * hourMs -> "${(ageMs / hourMs).coerceAtLeast(1L)}h ago" + ageMs < 7L * 24L * hourMs -> "${(ageMs / (24L * hourMs)).coerceAtLeast(1L)}d ago" + else -> "${(ageMs / (7L * 24L * hourMs)).coerceAtLeast(1L)}w ago" + } + } + + val wantText = when (currentWant) { + "Snack" -> "$displayPetName wants a Snack!" + "Play" -> "$displayPetName wants to Play!" + "Pet" -> "$displayPetName wants Pets!" + "Talk" -> "$displayPetName is looking for you!" + "Outside" -> "$displayPetName wants to go Outside!" + "Bath" -> "$displayPetName wants a Bath!" + else -> "" + } + + val recoveryNeeded = (3 + sickCount - if (happiness >= 8) 1 else 0).coerceAtLeast(1) + val isOutsideGoodWeather = location == "Outside" && weather != "Rain" + val isOutsideRain = location == "Outside" && weather == "Rain" + + val displayStatus = when { + isFindingNewPet -> "Trading" + status in listOf("Sick", "Weak", "Recovering", "RecoverWeak") -> status + roughWakeAlert -> "RoughWake" + roughWakeNervousHold -> "Nervous" + isSleeping -> "Asleep" + status == "Nervous" -> "Nervous" + + // If the pet asked to go outside, the whole outing is exciting. + location == "Outside" && happyOutsideTrip -> "Happy" + + // Rain is scary until full trust. + isOutsideRain && bond < 100 -> "Nervous" + + // Temporary moods, like briefly enjoying good weather, show before fallback mood. + activityMood.isNotEmpty() -> activityMood + + // Outside trust tiers. + isOutsideGoodWeather && bond < 40 -> "Nervous" + isOutsideGoodWeather && bond < 90 -> "Calm" + isOutsideGoodWeather -> "Happy" + + // Inside trust tiers: low bond should not look fully happy yet. + happiness <= 3 -> "Sad" + bond < 30 -> "Nervous" + bond < 80 -> "Calm" + else -> "Happy" + } + val petExpression = pottyFaceOverride.ifBlank { + when (displayStatus) { + "Calm" -> "o_o" + "Excited" -> "^o^" + "Asleep" -> "-.-" + "Sad" -> ";_;" + "Nervous" -> "o_O" + "Sick" -> ">_<" + "Weak" -> "-_-" + "Recovering" -> "o_<" + "RecoverWeak" -> "o_-" + "Trading" -> "..." + else -> "^_^" + } + } + + val petArt = buildAnnotatedString { + append(" /---\\ \n") + append("( ") + withStyle(SpanStyle(fontWeight = if (pottyFaceOverride.isNotEmpty()) FontWeight.Bold else FontWeight.Normal)) { + append(petExpression) + } + append(" )\n") + append(" /| |\\ ") + } + + val petColor = if (status == "Sick") sickGreen else lcdDark + + val alertText = when { + // Locked event moments. + roughWakeAlert -> "Rough wake!" + roughWakeNervousHold -> "Nervous" + isFindingNewPet -> "Finding new pet..." + isTradingInPet -> "Trading pet..." + + // Consequence alerts: show the cause when sickness came from a missed need. + weakCause == "Starving" && status in listOf("Sick", "Weak") -> "$displayPetName is hungry and sick!" + weakCause == "Overfed" && status in listOf("Sick", "Weak") -> "$displayPetName is stuffed and sick!" + weakCause == "Dirty" && status in listOf("Sick", "Weak") -> "$displayPetName needs a bath and is sick!" + + // Need warnings. + energy <= 0 && !isSleeping -> "$displayPetName needs a nap!" + energy == 1 && !isSleeping -> "$displayPetName is exhausted!" + hunger >= 9 -> "$displayPetName is hungry!" + hunger <= 1 -> "$displayPetName is stuffed!" + dirtiness >= 9 -> "$displayPetName needs a bath!" + location == "Inside" && potty >= 9 -> "$displayPetName has to potty!" + pottyStain.isNotEmpty() -> "$displayPetName had an accident!" + + // Health/status consequences. + status == "Weak" -> "$displayPetName is weak!" + status == "Sick" -> "$displayPetName is sick!" + status in listOf("Recovering", "RecoverWeak") -> "$displayPetName is recovering!" + + // Immediate player-action warnings. + location == "Outside" && weather == "Rain" && bond < 100 && !happyOutsideTrip -> "Bring inside!" + + // Wants beat low-priority mood chatter. + wantText.isNotEmpty() -> wantText + + // Low-priority mood alerts. + boredom >= 7 -> "$displayPetName is bored!" + else -> "" + } + + val framePropDisplay = when { + frameProp.isNotEmpty() -> frameProp + pottyStain.isNotEmpty() -> pottyStain + else -> " " + } + + val framePropText = buildAnnotatedString { + when { + framePropAnimation == "Nap" && framePropDisplay == "ZzZ" -> { + framePropDisplay.forEachIndexed { index, character -> + val isDark = if (framePropStyle % 2 == 0) { + index % 2 == 0 + } else { + index % 2 != 0 + } + + withStyle( + SpanStyle( + color = if (isDark) lcdDark else lcdFaded, + fontWeight = FontWeight.Bold + ) + ) { + append(character) + } + } + } + + framePropAnimation == "Bath" && framePropDisplay == "≈≈≈" -> { + framePropDisplay.forEachIndexed { index, character -> + withStyle( + SpanStyle( + fontWeight = if (index == framePropStyle % 3) { + FontWeight.Bold + } else { + FontWeight.Normal + } + ) + ) { + append(character) + } + } + } + + else -> { + append(framePropDisplay) + } + } + } + + fun nextWeather(currentWeather: String): String { + return when (currentWeather) { + "Sunny" -> "Cloudy" + "Cloudy" -> listOf("Sunny", "Rain").random() + "Rain" -> "Cloudy" + else -> "Sunny" + } + } + + fun buildBond(multiplier: Int = 1, force: Boolean = false) { + if ((bondReady || force) && bond < 100) { + val bondGain = when { + bond <= 20 -> 2 + bond <= 50 -> 3 + bond <= 80 -> 5 + else -> 7 + } + + bond = (bond + (bondGain * multiplier)).coerceAtMost(100) + + if (!force) { + bondReady = false + } + } + } + + fun toggleLocation() { + if (isTradingInPet || isFindingNewPet || isSleeping || isBathing || isTalking || framePropAnimation.isNotEmpty() || frameProp.isNotEmpty()) { + return + } + if (location == "Inside" && status in listOf("Weak", "RecoverWeak")) { + return + } + + careMenuOpen = false + socializeMenuOpen = false + statsMenuOpen = false + + if (location == "Inside") { + val outsideWantMatched = currentWant == "Outside" + + if (outsideWantMatched) { + currentWant = "" + happyOutsideTrip = true + } + + location = "Outside" + + val newWeather = weather + + if (outsideWantMatched) { + happiness = 10 + activityMood = "Happy" + buildBond(force = true) + } else { + dirtiness = if (newWeather == "Rain") 10 else (dirtiness + 1).coerceAtMost(10) + happiness = if (newWeather == "Rain") 8 else 10 + } + + if (status !in listOf("Sick", "Recovering", "Weak", "RecoverWeak")) { + status = if (newWeather == "Rain" && !outsideWantMatched) "Nervous" else "Calm" + + if (newWeather != "Rain" || outsideWantMatched) { + activityMood = "Happy" + } + } + } else { + location = "Inside" + weather = "Sunny" + happyOutsideTrip = false + + if (status !in listOf("Sick", "Recovering", "Weak", "RecoverWeak")) { + status = "Calm" + } + } + } + + fun damageHealth(): Int { + val newHealth = (health - 1).coerceAtLeast(0) + health = newHealth + + if (newHealth == 0) { + status = "Weak" + } + + return newHealth + } + + fun startFrameAnimation(animationName: String) { + framePropAnimation = animationName + framePropAnimationId += 1 + } + + fun completeWant(wantName: String): Boolean { + if (currentWant == wantName) { + logWantJournal(wantName, met = true) + currentWant = "" + currentWantStartedAtMs = 0L + return true + } + + return false + } + + fun choosePottyFace() { + val pottyFaces = listOf( + "¬.¬", + "=.=", + "•.•", + ">.>", + "¬_¬", + "=_=", + "•_•", + ">_>", + ) + + if (pottyFaceBag.isEmpty()) { + pottyFaceBag = pottyFaces.shuffled() + } + + pottyFaceOverride = pottyFaceBag.first() + pottyFaceBag = pottyFaceBag.drop(1) + } + + fun forceTestWant(wantName: String) { + location = "Inside" + weather = "Sunny" + happyOutsideTrip = false + + if (status !in listOf("Sick", "Recovering", "Weak", "RecoverWeak")) { + status = "Calm" + } + + currentWant = wantName + currentWantStartedAtMs = System.currentTimeMillis() + sendWantNotification(wantName) + careMenuOpen = false + socializeMenuOpen = false + statsMenuOpen = false + testWantMenuOpen = false + testBondMenuOpen = false + } + + fun applyBoredomPenalty() { + val boredomPenaltyEvery = when { + boredom < 4 -> 4 + boredom < 7 -> 3 + boredom < 9 -> 2 + else -> 1 + } + + boredomPenaltyCount += 1 + + if (boredomPenaltyCount >= boredomPenaltyEvery) { + boredomPenaltyCount = 0 + + val statLoss = if (boredom >= 9) 2 else 1 + happiness = (happiness - statLoss).coerceAtLeast(0) + energy = (energy - statLoss).coerceAtLeast(0) + } + } + + fun recordAction(actionName: String) { + if (lastActionName == actionName) { + sameActionStreak += 1 + + if (sameActionStreak >= boredomTriggerAt) { + boredom = (boredom + 1).coerceAtMost(10) + applyBoredomPenalty() + boredomTriggerAt = sameActionStreak + (3..13).random() + } + + if (sameActionStreak >= 25 && !ultraTrollTriggered) { + bond = (bond - 5).coerceAtLeast(0) + ultraTrollTriggered = true + } + } else { + lastActionName = actionName + sameActionStreak = 1 + boredomTriggerAt = (3..13).random() + ultraTrollTriggered = false + boredom = (boredom - 1).coerceAtLeast(0) + boredomPenaltyCount = (boredomPenaltyCount - 1).coerceAtLeast(0) + } + } + + fun feedPet() { + framePropAnimation = "" + framePropStyle = 0 + frameProp = "[___]" + + if (completeWant("Snack")) { + // Wanted snack is a tiny treat, not a full meal. + // It should not overfeed, fill potty, or create a new care problem. + happiness = (happiness + 1).coerceAtMost(10) + energy = (energy + 1).coerceAtMost(10) + starvingCount = 0 + overfeedCount = 0 + hungerNeedWindowOpen = false + overfeedNeedWindowOpen = false + careScore = (careScore + 1).coerceAtMost(999) + buildBond(force = true) + return + } + + if (hunger <= 0) { + if (!overfeedNeedWindowOpen) { + logNeedJournal("Overfed", met = false) + overfeedNeedWindowOpen = true + } + + overfeedCount += 1 + + if (overfeedCount == 3) { + neglectScore = (neglectScore + 1).coerceAtMost(999) + weakCause = "Overfed" + + if (damageHealth() > 0) { + status = "Sick" + } + } + } else { + hunger -= 1 + logNeedJournal("Feed", met = true) + feedPottyCount += 1 + + if (feedPottyCount >= 3) { + potty = (potty + 1).coerceAtMost(10) + feedPottyCount = 0 + } + + starvingCount = 0 + hungerNeedWindowOpen = false + overfeedNeedWindowOpen = false + careScore = (careScore + 1).coerceAtMost(999) + buildBond() + goodFeedCount += 1 + + if (goodFeedCount >= 2) { + happiness = (happiness + 1).coerceAtMost(10) + goodFeedCount = 0 + } + + if (status == "Sick") { + status = "Recovering" + recoveryCount = 0 + } + } + } + + fun playPet() { + if (energy > 0) { + val wantMatched = completeWant("Play") + + if (!wantMatched) { + recordAction("Play") + } + + activityMood = "Excited" + startFrameAnimation("Ball") + careScore = (careScore + 1).coerceAtMost(999) + + if (wantMatched) { + // Wanted play is an invited burst of fun. + // It should not drain hunger, energy, or build boredom. + happiness = (happiness + 2).coerceAtMost(10) + playEnergyCount = 0 + buildBond(multiplier = 2, force = true) + } else { + happiness = (happiness + 1).coerceAtMost(10) + hunger = (hunger + 1).coerceAtMost(10) + playEnergyCount += 1 + + if (playEnergyCount >= 2) { + energy = (energy - 1).coerceAtLeast(0) + playEnergyCount = 0 + } + } + } + } + + fun petPet() { + val wantMatched = completeWant("Pet") + + if (!wantMatched) { + recordAction("Pet") + } + + activityMood = if (bond >= 100) "Happy" else "Calm" + startFrameAnimation("Hand") + careScore = (careScore + 1).coerceAtMost(999) + happiness = (happiness + 1).coerceAtMost(10) + + if (wantMatched) { + // Wanted pets are requested attention, not repetitive pestering. + buildBond(multiplier = 2, force = true) + } else { + buildBond() + } + } + + fun beginTalk() { + if (!isTradingInPet && !isFindingNewPet && !isSleeping && !isBathing && framePropAnimation.isEmpty()) { + isTalking = true + activityMood = if (bond >= 100) "Happy" else "Calm" + framePropAnimation = "" + framePropStyle = 0 + frameProp = "¢==-" + } + } + + fun endTalk() { + if (isTalking) { + isTalking = false + + if (frameProp == "¢==-") { + frameProp = "" + } + + val wantMatched = completeWant("Talk") + + if (!wantMatched) { + recordAction("Talk") + } + + careScore = (careScore + 1).coerceAtMost(999) + happiness = (happiness + 1).coerceAtMost(10) + + if (wantMatched) { + // Wanted talk is requested attention, not repetitive pestering. + buildBond(multiplier = 5, force = true) + } else { + buildBond() + } + } + } + + fun walkPet() { + if (energy > 0) { + activityMood = "Excited" + startFrameAnimation("Footprints") + careScore = (careScore + 1).coerceAtMost(999) + health = 10 + energy = (energy - 1).coerceAtLeast(0) + hunger = (hunger + 1).coerceAtMost(10) + dirtiness = (dirtiness + 1).coerceAtMost(10) + } + } + + fun napPet() { + roughWakeAlert = false + autoSleepStartedAtMs = 0L + sleepMode = "Nap" + isSleeping = true + activityMood = "Asleep" + startFrameAnimation("Nap") + } + + fun usePotty() { + if (location == "Outside") { + val pottyNeedMet = potty > 0 + choosePottyFace() + startFrameAnimation("PottyClean") + careScore = (careScore + 1).coerceAtMost(999) + potty = 0 + hunger = (hunger + 1).coerceAtMost(10) + + if (pottyNeedMet) { + logNeedJournal("Potty", met = true) + } + } + } + + fun bathePet() { + if (location == "Inside" && (dirtiness > 0 || currentWant == "Bath") && !isTradingInPet && !isFindingNewPet && !isSleeping && !isBathing) { + val bathNeedMet = dirtiness > 0 || pottyStain.isNotEmpty() + bathWantMatched = completeWant("Bath") + bathBondAtStart = bond + pottyStain = "" + isBathing = true + activityMood = when { + bond >= 100 -> "Happy" + bond >= 60 -> "Calm" + else -> "Nervous" + } + startFrameAnimation("Bath") + + if (bathNeedMet) { + logNeedJournal("Bath", met = true) + } + } + } + + fun resetPetAfterTradeIn() { + location = "Inside" + weather = newPetWeatherOptions.random() + status = "Nervous" + hunger = 5 + health = 10 + happiness = 5 + energy = 5 + bond = 0 + dirtiness = 0 + potty = 0 + boredom = 0 + overfeedCount = 0 + starvingCount = 0 + overfeedNeedWindowOpen = false + hungerNeedWindowOpen = false + hungerNeedNotificationOpen = false + pottyNeedNotificationOpen = false + dirtinessNeedNotificationOpen = false + energyNeedNotificationOpen = false + recoveryCount = 0 + sickCount = 0 + goodFeedCount = 0 + feedPottyCount = 0 + playEnergyCount = 0 + sameActionStreak = 0 + boredomTriggerAt = (3..13).random() + boredomPenaltyCount = 0 + ultraTrollTriggered = false + lastActionName = "" + weakCause = "" + activityMood = "" + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + pottyStain = "" + isSleeping = false + sleepMode = "" + autoSleepStartedAtMs = 0L + roughWakeAlert = false + roughWakeDarkFlash = false + roughWakeNervousHold = false + isBathing = false + isTalking = false + bathBondAtStart = 0 + bathWantMatched = false + careMenuOpen = false + socializeMenuOpen = false + statsMenuOpen = false + currentWant = "" + currentWantStartedAtMs = 0L + careJournalOpen = false + creditsOpen = false + careJournalTab = "All" + careJournalEntries = emptyList() + petName = "" + pendingPetName = "" + happyOutsideTrip = false + petAgeDays = 0 + careScore = 0 + neglectScore = 0 + bondReady = true + tradeInConfirm = false + isTradingInPet = false + isFindingNewPet = false + tradeInProgress = 0 + } + + fun beginTradeInPet() { + if (!isTradingInPet && !isFindingNewPet) { + careMenuOpen = false + socializeMenuOpen = false + currentWant = "" + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + pottyStain = "" + isSleeping = false + isBathing = false + isTalking = false + sleepMode = "" + autoSleepStartedAtMs = 0L + tradeInConfirm = false + tradeInProgress = 0 + isTradingInPet = true + + // Force-save trade start immediately so closing the app mid-trade resumes correctly. + saveScope.launch { + context.saveLCDPetStats( + bond = bond, + petAgeDays = petAgeDays, + careScore = careScore, + neglectScore = neglectScore, + hunger = hunger, + health = health, + happiness = happiness, + energy = energy, + dirtiness = dirtiness, + potty = potty, + boredom = boredom, + location = location, + weather = weather, + status = status, + weakCause = weakCause, + pottyStain = pottyStain, + happyOutsideTrip = happyOutsideTrip, + isTradingInPet = true, + isFindingNewPet = false, + tradeInProgress = 0, + currentWant = currentWant, + petName = petName, + isSleeping = isSleeping, + sleepMode = sleepMode, + roughWakeAlert = roughWakeAlert, + autoSleepStartedAtMs = autoSleepStartedAtMs, + careJournalRaw = encodeCareJournalEntries(careJournalEntries) + ) + } + } + } + + fun cancelTradeInPet() { + if (isTradingInPet) { + isTradingInPet = false + tradeInConfirm = false + tradeInProgress = 0 + + // Force-save trade cancel immediately. + saveScope.launch { + context.saveLCDPetStats( + bond = bond, + petAgeDays = petAgeDays, + careScore = careScore, + neglectScore = neglectScore, + hunger = hunger, + health = health, + happiness = happiness, + energy = energy, + dirtiness = dirtiness, + potty = potty, + boredom = boredom, + location = location, + weather = weather, + status = status, + weakCause = weakCause, + pottyStain = pottyStain, + happyOutsideTrip = happyOutsideTrip, + isTradingInPet = false, + isFindingNewPet = false, + tradeInProgress = 0, + currentWant = currentWant, + petName = petName, + isSleeping = isSleeping, + sleepMode = sleepMode, + roughWakeAlert = roughWakeAlert, + autoSleepStartedAtMs = autoSleepStartedAtMs, + careJournalRaw = encodeCareJournalEntries(careJournalEntries) + ) + } + } + } + + fun cleanTestPet() { + if (!testingMode || isTradingInPet || isFindingNewPet) { + return + } + + location = "Inside" + weather = "Sunny" + status = if (bond < 30) "Nervous" else "Calm" + hunger = 5 + health = 10 + happiness = 5 + energy = 10 + dirtiness = 0 + potty = 0 + boredom = 0 + overfeedCount = 0 + starvingCount = 0 + overfeedNeedWindowOpen = false + hungerNeedWindowOpen = false + hungerNeedNotificationOpen = false + pottyNeedNotificationOpen = false + dirtinessNeedNotificationOpen = false + energyNeedNotificationOpen = false + recoveryCount = 0 + sickCount = 0 + goodFeedCount = 0 + feedPottyCount = 0 + playEnergyCount = 0 + sameActionStreak = 0 + boredomTriggerAt = (3..13).random() + boredomPenaltyCount = 0 + ultraTrollTriggered = false + lastActionName = "" + weakCause = "" + activityMood = "" + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + pottyStain = "" + isSleeping = false + sleepMode = "" + autoSleepStartedAtMs = 0L + roughWakeAlert = false + roughWakeDarkFlash = false + roughWakeNervousHold = false + isBathing = false + isTalking = false + bathBondAtStart = 0 + bathWantMatched = false + careMenuOpen = false + socializeMenuOpen = false + statsMenuOpen = false + currentWant = "" + happyOutsideTrip = false + bondReady = true + } + fun wakeFromAutoSleep() { + if (isSleeping && sleepMode == "Auto") { + val sleptOutside = location == "Outside" + val startedAtMs = if (autoSleepStartedAtMs > 0L) autoSleepStartedAtMs else System.currentTimeMillis() + val sleptMs = (System.currentTimeMillis() - startedAtMs).coerceAtLeast(0L) + val energyGain = (sleptMs / roughSleepEnergyTickMs).toInt().coerceAtLeast(1) + + energy = (energy + energyGain).coerceAtMost(10) + + if (sleptOutside) { + location = "Inside" + weather = "Sunny" + bond = (bond - 1).coerceAtLeast(0) + } + + // Keep the pet officially asleep during the dark wake-up pause. + // This prevents the UI from flashing Nervous before Rough Wake appears. + roughWakeDarkFlash = true + activityMood = "Asleep" + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + + saveScope.launch { + delay(if (testingMode) 1_500L else 1_200L) + + if (isSleeping && sleepMode == "Auto") { + isSleeping = false + sleepMode = "" + autoSleepStartedAtMs = 0L + autoSleepWakeAllowed = false + restoredAutoSleep = false + roughWakeDarkFlash = false + roughWakeNervousHold = false + + status = "Nervous" + activityMood = "RoughWake" + roughWakeAlert = true + frameProp = "!?!" + framePropAnimation = "" + framePropStyle = 0 + happiness = (happiness - 1).coerceAtLeast(0) + } + } + } + } + + DisposableEffect(lifecycleOwner, isSleeping, sleepMode, autoSleepWakeAllowed, restoredAutoSleep) { + val observer = LifecycleEventObserver { _, event -> + when (event) { + Lifecycle.Event.ON_PAUSE, + Lifecycle.Event.ON_STOP -> { + if (isSleeping && sleepMode == "Auto") { + autoSleepWakeAllowed = true + } + } + + Lifecycle.Event.ON_RESUME -> { + if ( + isSleeping && + sleepMode == "Auto" && + (autoSleepWakeAllowed || restoredAutoSleep) + ) { + restoredAutoSleep = true + } + } + + else -> Unit + } + } + + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { + lifecycleOwner.lifecycle.removeObserver(observer) + } + } + + LaunchedEffect(saveLoaded, restoredAutoSleep) { + if (saveLoaded && restoredAutoSleep && isSleeping && sleepMode == "Auto") { + activityMood = "Asleep" + roughWakeDarkFlash = true + + if (framePropAnimation != "Nap") { + startFrameAnimation("Nap") + } + + delay(if (testingMode) 1_500L else 2_000L) + + if (isSleeping && sleepMode == "Auto") { + wakeFromAutoSleep() + } + } + } + + LaunchedEffect( + bond, + petAgeDays, + careScore, + neglectScore, + hunger, + health, + happiness, + energy, + dirtiness, + potty, + boredom, + location, + weather, + status, + weakCause, + pottyStain, + happyOutsideTrip, + isTradingInPet, + isFindingNewPet, + tradeInProgress, + currentWant, + petName, + isSleeping, + sleepMode, + roughWakeAlert, + autoSleepStartedAtMs, + careJournalEntries, + saveLoaded + ) { + if (saveLoaded) { + context.saveLCDPetStats( + bond = bond, + petAgeDays = petAgeDays, + careScore = careScore, + neglectScore = neglectScore, + hunger = hunger, + health = health, + happiness = happiness, + energy = energy, + dirtiness = dirtiness, + potty = potty, + boredom = boredom, + location = location, + weather = weather, + status = status, + weakCause = weakCause, + pottyStain = pottyStain, + happyOutsideTrip = happyOutsideTrip, + isTradingInPet = isTradingInPet, + isFindingNewPet = isFindingNewPet, + tradeInProgress = tradeInProgress, + currentWant = currentWant, + petName = petName, + isSleeping = isSleeping, + sleepMode = sleepMode, + roughWakeAlert = roughWakeAlert, + autoSleepStartedAtMs = autoSleepStartedAtMs, + careJournalRaw = encodeCareJournalEntries(careJournalEntries) + ) + } + } + + LaunchedEffect(isTradingInPet) { + if (isTradingInPet) { + val tradeInStepMs = (tradeInWaitMs / tradeInProgressBlocks).coerceAtLeast(1L) + val startingProgress = tradeInProgress.coerceIn(0, tradeInProgressBlocks) + + for (step in startingProgress until tradeInProgressBlocks) { + delay(tradeInStepMs) + tradeInProgress = step + 1 + } + + isTradingInPet = false + tradeInConfirm = false + statsMenuOpen = false + isFindingNewPet = true + + // Force-save finding-new-pet state immediately. + context.saveLCDPetStats( + bond = bond, + petAgeDays = petAgeDays, + careScore = careScore, + neglectScore = neglectScore, + hunger = hunger, + health = health, + happiness = happiness, + energy = energy, + dirtiness = dirtiness, + potty = potty, + boredom = boredom, + location = location, + weather = weather, + status = status, + weakCause = weakCause, + pottyStain = pottyStain, + happyOutsideTrip = happyOutsideTrip, + isTradingInPet = false, + isFindingNewPet = true, + tradeInProgress = tradeInProgressBlocks, + currentWant = currentWant, + petName = petName, + isSleeping = isSleeping, + sleepMode = sleepMode, + roughWakeAlert = roughWakeAlert, + autoSleepStartedAtMs = autoSleepStartedAtMs, + careJournalRaw = encodeCareJournalEntries(careJournalEntries) + ) + } + } + + LaunchedEffect(isFindingNewPet) { + if (isFindingNewPet) { + delay(findingNewPetMs) + resetPetAfterTradeIn() + } + } + + LaunchedEffect(roughWakeAlert) { + if (roughWakeAlert) { + delay(roughWakeAlertMs) + roughWakeAlert = false + if (activityMood == "RoughWake") { + activityMood = "" + } + if (frameProp == "!?!") { + frameProp = "" + } + roughWakeNervousHold = true + } + } + + LaunchedEffect(roughWakeNervousHold) { + if (roughWakeNervousHold) { + delay(if (testingMode) 10_000L else 10_000L) + roughWakeNervousHold = false + } + } + + LaunchedEffect(currentWant, location, isSleeping, isBathing, isTradingInPet, isFindingNewPet, needsPetName) { + if (isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if (currentWant.isEmpty() && !isSleeping && !isBathing) { + delay(wantCooldownOptionsMs.random()) + + if (currentWant.isEmpty() && !isSleeping && !isBathing) { + val possibleWants = if (location == "Inside") { + listOf("Snack", "Play", "Pet", "Talk", "Outside") + if (bond >= 100) listOf("Bath") else emptyList() + } else { + listOf("Play", "Pet", "Talk") + } + + currentWant = possibleWants.random() + currentWantStartedAtMs = System.currentTimeMillis() + sendWantNotification(currentWant) + } + } else if (currentWant.isNotEmpty()) { + delay(wantDurationMs) + + if (currentWant.isNotEmpty()) { + logWantJournal(currentWant, met = false) + currentWant = "" + currentWantStartedAtMs = 0L + } + } + } + + LaunchedEffect(weather, isTradingInPet, isFindingNewPet, needsPetName) { + if (!isTradingInPet && !isFindingNewPet && !needsPetName) { + delay(weatherShiftOptionsMs.random()) + weather = nextWeather(weather) + } + } + + LaunchedEffect(bondReady) { + if (!bondReady) { + delay(bondCooldownMs) + bondReady = true + } + } + + LaunchedEffect(hunger, starvingCount, status, isSleeping, isTradingInPet, isFindingNewPet, needsPetName, saveLoaded) { + val notificationPetName = petName.ifBlank { "Your pet" } + + if (!saveLoaded || isSleeping || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if ( + hunger >= 10 && + starvingCount >= 2 && + status !in listOf("Sick", "Weak", "Recovering", "RecoverWeak") && + !hungerNeedNotificationOpen + ) { + hungerNeedNotificationOpen = true + sendNeedNotification( + notificationId = 3001, + message = "$notificationPetName is really hungry. Feed soon." + ) + } else if (hunger < 10 || status in listOf("Sick", "Weak", "Recovering", "RecoverWeak")) { + hungerNeedNotificationOpen = false + } + } + + LaunchedEffect(location, potty, isSleeping, isTradingInPet, isFindingNewPet, needsPetName, saveLoaded) { + val notificationPetName = petName.ifBlank { "Your pet" } + + if (!saveLoaded || isSleeping || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if (location == "Inside" && potty >= 9 && !pottyNeedNotificationOpen) { + pottyNeedNotificationOpen = true + sendNeedNotification( + notificationId = 3002, + message = "$notificationPetName has to potty soon." + ) + } else if (location != "Inside" || potty < 9) { + pottyNeedNotificationOpen = false + } + } + + LaunchedEffect(dirtiness, status, isSleeping, isTradingInPet, isFindingNewPet, needsPetName, saveLoaded) { + val notificationPetName = petName.ifBlank { "Your pet" } + + if (!saveLoaded || isSleeping || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if ( + dirtiness >= 9 && + status !in listOf("Sick", "Weak", "Recovering", "RecoverWeak") && + !dirtinessNeedNotificationOpen + ) { + dirtinessNeedNotificationOpen = true + sendNeedNotification( + notificationId = 3003, + message = "$notificationPetName needs a bath soon." + ) + } else if (dirtiness < 9 || status in listOf("Sick", "Weak", "Recovering", "RecoverWeak")) { + dirtinessNeedNotificationOpen = false + } + } + + LaunchedEffect(energy, isSleeping, isBathing, isTalking, isTradingInPet, isFindingNewPet, needsPetName, saveLoaded) { + val notificationPetName = petName.ifBlank { "Your pet" } + + if (!saveLoaded || isSleeping || isBathing || isTalking || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if (energy <= 1 && !energyNeedNotificationOpen) { + energyNeedNotificationOpen = true + sendNeedNotification( + notificationId = 3004, + message = "$notificationPetName is exhausted. Nap soon." + ) + } else if (energy > 1 || isSleeping) { + energyNeedNotificationOpen = false + } + } + + LaunchedEffect(hunger, starvingCount, status, recoveryCount, sickCount, happiness, isSleeping, isTradingInPet, isFindingNewPet, needsPetName) { + if (isSleeping || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + if (status == "Sick") { + delay(sickTickMs) + + sickCount += 1 + damageHealth() + if (hunger < 10) { + hunger += 1 + } + + if (status == "Sick" && weakCause == "Overfed" && hunger > 0) { + status = "Recovering" + recoveryCount = 0 + } + } else if (status == "Weak") { + delay(weakRecoveryCheckMs) + + if (location == "Inside" && energy > 0 && hunger < 10) { + status = "RecoverWeak" + health = 1 + } + } else if (status == "RecoverWeak") { + delay(recoverWeakMs) + + if (location == "Inside" && hunger < 10) { + status = "Calm" + recoveryCount = 0 + overfeedCount = 0 + starvingCount = 0 + sickCount = 0 + weakCause = "" + } + } else if (status == "Recovering") { + delay(recoveringTickMs) + + recoveryCount += 1 + + if (recoveryCount >= recoveryNeeded && hunger < 10) { + status = "Calm" + recoveryCount = 0 + overfeedCount = 0 + starvingCount = 0 + sickCount = 0 + weakCause = "" + } + } else { + delay(hungerTickMs) + + if (hunger < 10) { + hunger += 1 + overfeedCount = 0 + overfeedNeedWindowOpen = false + + if (hunger < 10) { + starvingCount = 0 + hungerNeedWindowOpen = false + } + } else { + starvingCount += 1 + + if (starvingCount >= 3 && !hungerNeedWindowOpen) { + logNeedJournal("Hunger", met = false) + hungerNeedWindowOpen = true + neglectScore = (neglectScore + 1).coerceAtMost(999) + weakCause = "Starving" + + val newHealth = (health - 1).coerceAtLeast(0) + health = newHealth + status = if (newHealth == 0) "Weak" else "Sick" + } + } + } + } + + LaunchedEffect(location, weather, happiness, isTradingInPet, isFindingNewPet, needsPetName) { + if (isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if (location == "Outside" && weather == "Rain" && happiness > 0 && !happyOutsideTrip) { + delay(rainHappinessTickMs) + happiness = (happiness - 1).coerceAtLeast(0) + } + } + LaunchedEffect(location, potty, isSleeping, isTradingInPet, isFindingNewPet, needsPetName) { + if (isSleeping || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + delay(pottyTickMs) + + if (potty < 10) { + potty = (potty + 1).coerceAtMost(10) + } else if (location == "Inside") { + logNeedJournal("Potty", met = false) + neglectScore = (neglectScore + 1).coerceAtMost(999) + choosePottyFace() + startFrameAnimation("PottyAccident") + potty = 0 + dirtiness = (dirtiness + 3).coerceAtMost(10) + } else { + pottyStain = "" + choosePottyFace() + startFrameAnimation("PottyClean") + potty = 0 + damageHealth() + } + } + + LaunchedEffect(dirtiness, status, isSleeping, isTradingInPet, isFindingNewPet, needsPetName) { + if (isSleeping || isTradingInPet || isFindingNewPet || needsPetName) { + return@LaunchedEffect + } + + if (dirtiness >= 10 && status !in listOf("Sick", "Weak", "Recovering", "RecoverWeak")) { + delay(dirtyHealthTickMs) + + if (dirtiness >= 10 && status !in listOf("Sick", "Weak", "Recovering", "RecoverWeak")) { + logNeedJournal("Bath", met = false) + neglectScore = (neglectScore + 1).coerceAtMost(999) + weakCause = "Dirty" + val newHealth = damageHealth() + + if (newHealth > 0) { + status = "Sick" + } + } + } + } + + LaunchedEffect(activityMood, isBathing) { + if (activityMood.isNotEmpty() && !isBathing) { + delay(activityMoodMs) + activityMood = "" + } + } + + LaunchedEffect(frameProp, framePropAnimation, isTalking) { + if (frameProp.isNotEmpty() && framePropAnimation.isEmpty() && !isTalking) { + delay(activityMoodMs) + frameProp = "" + } + } + + LaunchedEffect(framePropAnimation, framePropAnimationId, isSleeping, isBathing) { + when (framePropAnimation) { + "Ball" -> { + val frames = listOf( + "o ", + " o ", + " o ", + " o ", + " o", + " o ", + " o ", + " o " + ) + + repeat(2) { + for (frame in frames) { + frameProp = frame + framePropStyle = 0 + delay(propAnimationTickMs) + } + } + + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + } + + "Hand" -> { + val frames = listOf( + "\\☻/", + "-☻/", + "/☻\\", + "\\☻-" + ) + + repeat(3) { + for (frame in frames) { + frameProp = frame + framePropStyle = 0 + delay(propAnimationTickMs) + } + } + + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + } + + "Talk" -> { + val frames = listOf( + "¢==-", + "¢==-)", + "¢==-))", + "¢==-=)" + ) + + repeat(3) { + for (frame in frames) { + frameProp = frame + framePropStyle = 0 + delay(propAnimationTickMs) + } + } + + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + } + + "Footprints" -> { + val frames = listOf( + ". . ", + " . . ", + " . . ", + " . .", + " . . ", + " . . " + ) + + repeat(2) { + for (frame in frames) { + frameProp = frame + framePropStyle = 0 + delay(propAnimationTickMs) + } + } + + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + } + + "PottyClean" -> { + val frames = listOf( + " . ", + " : ", + " ... ", + " . " + ) + + repeat(2) { + for (frame in frames) { + frameProp = frame + framePropStyle = 0 + delay(propAnimationTickMs) + } + } + + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + pottyFaceOverride = "" + } + + "PottyAccident" -> { + val frames = listOf( + " . ", + " : ", + " ... ", + " ..... " + ) + + for (frame in frames) { + frameProp = frame + framePropStyle = 0 + delay(propAnimationTickMs) + } + + frameProp = "" + pottyStain = " ..... " + framePropAnimation = "" + framePropStyle = 0 + pottyFaceOverride = "" + } + + "Nap" -> { + while (isSleeping && framePropAnimation == "Nap") { + frameProp = "ZzZ" + framePropStyle = 0 + delay(propAnimationTickMs * 2) + + frameProp = "ZzZ" + framePropStyle = 1 + delay(propAnimationTickMs * 2) + } + + if (!isSleeping) { + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + pottyFaceOverride = "" + } + } + + "Bath" -> { + while (isBathing && framePropAnimation == "Bath") { + frameProp = "≈≈≈" + framePropStyle = 0 + delay(propAnimationTickMs) + + frameProp = "≈≈≈" + framePropStyle = 1 + delay(propAnimationTickMs) + + frameProp = "≈≈≈" + framePropStyle = 2 + delay(propAnimationTickMs) + } + + if (!isBathing) { + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + } + } + } + } + + LaunchedEffect(isBathing) { + if (isBathing) { + isTalking = false + val bathDuration = when { + bathBondAtStart < 30 -> lowBondBathMs + bathBondAtStart < 60 -> mediumBondBathMs + else -> trustedBathMs + } + + delay(bathDuration) + + val dirtinessBeforeBath = dirtiness + + when { + bathBondAtStart < 30 -> { + dirtiness = (dirtinessBeforeBath - 3).coerceAtLeast(0) + happiness = (happiness - 1).coerceAtLeast(0) + } + + bathBondAtStart < 60 -> { + dirtiness = (dirtinessBeforeBath - 6).coerceAtLeast(0) + } + + bathBondAtStart < 90 -> { + dirtiness = 0 + } + + else -> { + dirtiness = 0 + happiness = (happiness + 1).coerceAtMost(10) + } + } + + if (bathWantMatched) { + dirtiness = 0 + energy = (energy + 2).coerceAtMost(10) + happiness = 10 + boredom = 0 + bathWantMatched = false + } + + if (dirtiness < dirtinessBeforeBath) { + careScore = (careScore + 1).coerceAtMost(999) + } + + if (weakCause == "Dirty" && status == "Sick" && dirtiness < 10) { + status = "Recovering" + recoveryCount = 0 + } + + buildBond() + isBathing = false + activityMood = "" + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + pottyStain = "" + } + } + + LaunchedEffect( + energy, + isSleeping, + isBathing, + isTalking, + isTradingInPet, + isFindingNewPet, + framePropAnimation, + saveLoaded + ) { + if ( + saveLoaded && + energy <= 0 && + !isSleeping && + !isBathing && + !isTalking && + !isTradingInPet && + !isFindingNewPet && + framePropAnimation.isEmpty() + ) { + delay(autoSleepDelayMs) + + if ( + energy <= 0 && + !isSleeping && + !isBathing && + !isTalking && + !isTradingInPet && + !isFindingNewPet && + framePropAnimation.isEmpty() + ) { + autoSleepWakeAllowed = false + autoSleepStartedAtMs = System.currentTimeMillis() + sleepMode = "Auto" + isSleeping = true + activityMood = "Asleep" + startFrameAnimation("Nap") + + // Force-save auto-sleep start immediately so reopening resumes asleep. + saveScope.launch { + context.saveLCDPetStats( + bond = bond, + petAgeDays = petAgeDays, + careScore = careScore, + neglectScore = neglectScore, + hunger = hunger, + health = health, + happiness = happiness, + energy = energy, + dirtiness = dirtiness, + potty = potty, + boredom = boredom, + location = location, + weather = weather, + status = status, + weakCause = weakCause, + pottyStain = pottyStain, + happyOutsideTrip = happyOutsideTrip, + isTradingInPet = isTradingInPet, + isFindingNewPet = isFindingNewPet, + tradeInProgress = tradeInProgress, + currentWant = currentWant, + petName = petName, + isSleeping = true, + sleepMode = "Auto", + roughWakeAlert = roughWakeAlert, + autoSleepStartedAtMs = autoSleepStartedAtMs, + careJournalRaw = encodeCareJournalEntries(careJournalEntries) + ) + } + } + } + } + + LaunchedEffect(isSleeping, sleepMode) { + if (!isSleeping || sleepMode != "Nap") { + return@LaunchedEffect + } + + isTalking = false + + val sleepTime = sleepOptionsMs.random() + val sleepSteps = 5 + val stepDelay = sleepTime / sleepSteps + + val startHealth = health + val startHappiness = happiness + val startEnergy = energy + val startHunger = hunger + val startPotty = potty + + repeat(sleepSteps) { step -> + delay(stepDelay) + + val progress = step + 1 + + health = startHealth + ((10 - startHealth) * progress / sleepSteps) + happiness = startHappiness + ((10 - startHappiness) * progress / sleepSteps) + energy = startEnergy + ((10 - startEnergy) * progress / sleepSteps) + + if (startHunger < 5) { + hunger = startHunger + ((5 - startHunger) * progress / sleepSteps) + } + + if (startPotty < 7) { + potty = startPotty + ((7 - startPotty) * progress / sleepSteps) + } + } + + health = 10 + happiness = 10 + energy = 10 + + if (status in listOf("Sick", "Weak", "Recovering", "RecoverWeak")) { + status = "Calm" + weakCause = "" + overfeedCount = 0 + starvingCount = 0 + overfeedNeedWindowOpen = false + hungerNeedWindowOpen = false + recoveryCount = 0 + sickCount = 0 + } + + isSleeping = false + sleepMode = "" + activityMood = "" + + if (framePropAnimation == "Nap") { + frameProp = "" + framePropAnimation = "" + framePropStyle = 0 + } + } + val screenScrollState = rememberScrollState() + + Box( + modifier = modifier + .fillMaxSize() + .background(lcdBackground) + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .verticalScroll(screenScrollState) + .padding(16.dp) + ) { + if (!needsPetName) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.Top + ) { + Column( + verticalArrangement = Arrangement.spacedBy(2.dp) + ) { + Text( + text = displayPetName, + fontWeight = FontWeight.Bold + ) + + Text( + text = if (statsMenuOpen) "Stats ▲" else "Stats ▼", + fontWeight = FontWeight.Bold, + modifier = Modifier.clickable { + statsMenuOpen = !statsMenuOpen + + if (statsMenuOpen) { + careMenuOpen = false + socializeMenuOpen = false + creditsOpen = false + } else { + careJournalOpen = false + testWantMenuOpen = false + testBondMenuOpen = false + } + } + ) + } + + Column( + horizontalAlignment = Alignment.End, + verticalArrangement = Arrangement.spacedBy(2.dp) + ) { + Text( + text = "$location | $weather", + fontWeight = FontWeight.Bold, + modifier = Modifier.clickable { + toggleLocation() + } + ) + + Text( + text = "Credits / Licenses", + fontSize = 12.sp, + fontWeight = FontWeight.Bold, + modifier = Modifier.clickable { + creditsOpen = !creditsOpen + + if (creditsOpen) { + statsMenuOpen = false + careJournalOpen = false + testWantMenuOpen = false + testBondMenuOpen = false + careMenuOpen = false + socializeMenuOpen = false + } + } + ) + } + } + } + + if (needsPetName) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp, bottom = 6.dp) + .border(2.dp, lcdDark) + .padding(8.dp), + verticalArrangement = Arrangement.spacedBy(6.dp) + ) { + Text( + text = "NAME NEW PET", + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + + Box( + modifier = Modifier + .fillMaxWidth() + .border(1.dp, lcdDark) + .padding(6.dp) + ) { + BasicTextField( + value = pendingPetName, + onValueChange = { typed -> + pendingPetName = typed.filter { it.isLetter() }.take(12) + }, + singleLine = true, + textStyle = TextStyle( + color = lcdDark, + fontSize = 18.sp, + fontWeight = FontWeight.Bold + ), + cursorBrush = SolidColor(lcdDark), + modifier = Modifier.fillMaxWidth() + ) + + if (pendingPetName.isBlank()) { + Text( + text = "type name...", + color = lcdFaded, + fontWeight = FontWeight.Bold + ) + } + } + + if (isReservedPetName) { + Text( + text = "reserved name", + color = lcdFaded, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + } + + LCDSubButton( + text = "KEEP NAME", + enabled = canKeepPetName, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + petName = trimmedPendingPetName.take(12) + pendingPetName = petName + statsMenuOpen = false + careMenuOpen = false + socializeMenuOpen = false + } + ) + } + + return@Column +} + + if (statsMenuOpen) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(top = 6.dp, bottom = 4.dp) + .border(2.dp, lcdDark) + .padding(8.dp), + verticalArrangement = Arrangement.spacedBy(4.dp) + ) { + Text( + text = "PET RECORD", + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + + Row { + Text( + text = "Bond", + modifier = Modifier.width(72.dp) + ) + Text(text = "$bondPercent% $bondRelationship") + } + + Row { + Text( + text = "Age", + modifier = Modifier.width(72.dp) + ) + Text(text = petAgeText) + } + + + + Row { + Text( + text = "Care", + modifier = Modifier.width(72.dp) + ) + Text(text = "$careScore") + } + + Row { + Text( + text = "Neglect", + modifier = Modifier.width(72.dp) + ) + Text(text = "$neglectScore") + } + + + + if (testingMode) { + Row { + Text( + text = "Want", + modifier = Modifier.width(72.dp) + ) + Text(text = currentWant.ifBlank { "None" }) + } + } + + Spacer(modifier = Modifier.height(4.dp)) + + Text( + text = "PET MANAGEMENT", + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + + if (isTradingInPet) { + Text( + text = "[$tradeInProgressBar]", + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + + LCDSubButton( + text = "CHANGE MIND", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + cancelTradeInPet() + } + ) + } else { + LCDSubButton( + text = "TRADE PET IN", + enabled = !isFindingNewPet, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + beginTradeInPet() + } + ) + + if (testingMode) { + Spacer(modifier = Modifier.height(4.dp)) + + Text( + text = "TESTING TOOLS", + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + + LCDSubButton( + text = "TEST NOTIFICATION", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + sendTestNotification() + } + ) + + LCDSubButton( + text = "TEST HUNGER WARNING", + enabled = !isFindingNewPet && !isTradingInPet && !isSleeping, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + hunger = 10 + starvingCount = 2 + hungerNeedNotificationOpen = false + } + ) + + LCDSubButton( + text = "TEST POTTY WARNING", + enabled = !isFindingNewPet && !isTradingInPet && !isSleeping, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + location = "Inside" + potty = 9 + pottyNeedNotificationOpen = false + } + ) + + LCDSubButton( + text = "TEST BATH WARNING", + enabled = !isFindingNewPet && !isTradingInPet && !isSleeping, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + dirtiness = 9 + dirtinessNeedNotificationOpen = false + } + ) + + LCDSubButton( + text = "TEST ENERGY WARNING", + enabled = !isFindingNewPet && !isTradingInPet && !isSleeping, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + energy = 1 + energyNeedNotificationOpen = false + } + ) + + LCDSubButton( + text = "CLEAN TEST PET", + enabled = !isFindingNewPet, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + cleanTestPet() + } + ) + + LCDSubButton( + text = if (testBondMenuOpen) "TEST BOND ▲" else "TEST BOND ▼", + enabled = !isFindingNewPet && !isTradingInPet, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + testBondMenuOpen = !testBondMenuOpen + if (testBondMenuOpen) { + testWantMenuOpen = false + careJournalOpen = false + creditsOpen = false + } + } + ) + + if (testBondMenuOpen) { + LCDSubButton( + text = "SET BOND 0", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { bond = 0 } + ) + + LCDSubButton( + text = "SET BOND 50", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { bond = 50 } + ) + + LCDSubButton( + text = "SET BOND 80", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { bond = 80 } + ) + + LCDSubButton( + text = "SET BOND 100", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { bond = 100 } + ) + } + + + LCDSubButton( + text = if (testWantMenuOpen) "TEST WANTS ▲" else "TEST WANTS ▼", + enabled = !isFindingNewPet && !isTradingInPet && !isSleeping && !isBathing, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + testWantMenuOpen = !testWantMenuOpen + if (testWantMenuOpen) { + testBondMenuOpen = false + careJournalOpen = false + creditsOpen = false + } + } + ) + + if (testWantMenuOpen) { + LCDSubButton( + text = "FORCE SNACK WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { forceTestWant("Snack") } + ) + + LCDSubButton( + text = "FORCE PLAY WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { forceTestWant("Play") } + ) + + LCDSubButton( + text = "FORCE PET WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { forceTestWant("Pet") } + ) + + LCDSubButton( + text = "FORCE TALK WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { forceTestWant("Talk") } + ) + + LCDSubButton( + text = "FORCE OUTSIDE WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { forceTestWant("Outside") } + ) + + LCDSubButton( + text = "FORCE BATH WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { forceTestWant("Bath") } + ) + + LCDSubButton( + text = "TEST TOUCH GRASS", + enabled = !isSleeping && !isBathing && framePropAnimation.isEmpty(), + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + downtimeMode = DowntimeMode.TouchGrass + location = "Outside" + happyOutsideTrip = false + testWantMenuOpen = false + statsMenuOpen = false + } + ) + + LCDSubButton( + text = "TEST WATCH TV", + enabled = !isSleeping && !isBathing && framePropAnimation.isEmpty(), + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + downtimeMode = DowntimeMode.WatchTv + selectedTvChannel = TvChannel.Weather + location = "Inside" + happyOutsideTrip = false + testWantMenuOpen = false + statsMenuOpen = false + } + ) + + LCDSubButton( + text = "CLEAR DOWNTIME", + enabled = downtimeMode != DowntimeMode.None, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + downtimeMode = DowntimeMode.None + testWantMenuOpen = false + } + ) + + LCDSubButton( + text = "TEST POTTY FACE", + enabled = !isSleeping && !isBathing && framePropAnimation.isEmpty(), + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + location = "Outside" + weather = "Sunny" + happyOutsideTrip = false + if (status !in listOf("Sick", "Recovering", "Weak", "RecoverWeak")) { + status = "Calm" + } + usePotty() + testWantMenuOpen = false + statsMenuOpen = false + } + ) + + LCDSubButton( + text = "TEST POTTY ACCIDENT", + enabled = !isSleeping && !isBathing && framePropAnimation.isEmpty(), + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + location = "Inside" + happyOutsideTrip = false + if (status !in listOf("Sick", "Recovering", "Weak", "RecoverWeak")) { + status = "Calm" + } + choosePottyFace() + startFrameAnimation("PottyAccident") + potty = 0 + dirtiness = (dirtiness + 3).coerceAtMost(10) + testWantMenuOpen = false + statsMenuOpen = false + } + ) + + LCDSubButton( + text = "TEST POTTY OVERFLOW", + enabled = !isSleeping && !isBathing && framePropAnimation.isEmpty(), + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + location = "Outside" + weather = "Sunny" + happyOutsideTrip = false + if (status !in listOf("Sick", "Recovering", "Weak", "RecoverWeak")) { + status = "Calm" + } + pottyStain = "" + choosePottyFace() + startFrameAnimation("PottyClean") + potty = 0 + testWantMenuOpen = false + statsMenuOpen = false + } + ) + + LCDSubButton( + text = "CLEAR WANT", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + currentWant = "" + testWantMenuOpen = false + } + ) + } + } + + LCDSubButton( + text = if (careJournalOpen) "CARE JOURNAL ▲" else "CARE JOURNAL ▼", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + careJournalOpen = !careJournalOpen + if (careJournalOpen) { + creditsOpen = false + testWantMenuOpen = false + testBondMenuOpen = false + } + } + ) + + if (careJournalOpen) { + Row( + horizontalArrangement = Arrangement.spacedBy(4.dp), + modifier = Modifier.fillMaxWidth() + ) { + LCDSubButton( + text = "NEEDS", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { careJournalTab = "Needs" }, + modifier = Modifier.weight(1f), + fillWidthFraction = 1f + ) + + LCDSubButton( + text = "WANTS", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { careJournalTab = "Wants" }, + modifier = Modifier.weight(1f), + fillWidthFraction = 1f + ) + + LCDSubButton( + text = "ALL", + enabled = true, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { careJournalTab = "All" }, + modifier = Modifier.weight(1f), + fillWidthFraction = 1f + ) + } + + val visibleJournalEntries = when (careJournalTab) { + "Needs" -> careJournalEntries.filter { it.category == "Need" } + "Wants" -> careJournalEntries.filter { it.category == "Want" } + else -> careJournalEntries + } + + Row { + Text( + text = "Action", + fontWeight = FontWeight.Bold, + modifier = Modifier.width(86.dp) + ) + Text( + text = "Met", + fontWeight = FontWeight.Bold, + modifier = Modifier.width(36.dp) + ) + Text( + text = "Resp", + fontWeight = FontWeight.Bold, + modifier = Modifier.width(48.dp) + ) + Text( + text = "Date", + fontWeight = FontWeight.Bold + ) + } + + if (visibleJournalEntries.isEmpty()) { + Text( + text = "No entries yet.", + color = lcdFaded, + fontWeight = FontWeight.Bold + ) + } else { + visibleJournalEntries.take(8).forEach { entry -> + Row { + Text( + text = entry.action.take(10), + modifier = Modifier.width(86.dp) + ) + Text( + text = if (entry.met) "+" else "-", + modifier = Modifier.width(36.dp) + ) + Text( + text = journalResponseText(entry.responseMs), + modifier = Modifier.width(48.dp) + ) + Text(text = journalDateText(entry.happenedAtMs)) + } + } + } + } + } + + } + } + + Box( + modifier = Modifier + .fillMaxWidth() + .height(235.dp) + .padding(top = 10.dp, bottom = 10.dp) + .border(2.dp, lcdDark), + contentAlignment = Alignment.Center + ) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(top = 12.dp, bottom = 12.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + val downtimeTitle = when { + testingMode && downtimeMode == DowntimeMode.TouchGrass -> "TOUCH GRASS" + testingMode && downtimeMode == DowntimeMode.WatchTv -> "WATCH TV" + else -> "" + } + + if (downtimeTitle.isNotEmpty()) { + Text( + text = downtimeTitle, + fontWeight = FontWeight.Bold, + color = lcdDark + ) + } else { + Text(text = healthBar) + } + + Spacer(modifier = Modifier.height(10.dp)) + + if (testingMode && downtimeMode == DowntimeMode.TouchGrass) { + TouchGrassActivityScreen( + lcdDark = lcdDark, + onGrassTap = {} + ) + } else if (testingMode && downtimeMode == DowntimeMode.WatchTv) { + WatchTvActivityScreen( + lcdDark = lcdDark, + selectedChannel = selectedTvChannel, + weatherLabel = weather, + onChannelSelected = { selectedTvChannel = it } + ) + } else { + Text( + text = petArt, + fontSize = 24.sp, + lineHeight = 24.sp, + fontFamily = FontFamily.Monospace, + textAlign = TextAlign.Center, + color = if (displayStatus == "Recovering") sickGreen else petColor + ) + } + + Spacer(modifier = Modifier.height(8.dp)) + + Text( + text = framePropText, + modifier = Modifier.width(160.dp), + fontSize = 20.sp, + lineHeight = 20.sp, + fontFamily = FontFamily.Monospace, + textAlign = TextAlign.Center, + color = lcdDark, + softWrap = false, + maxLines = 1 + ) + + Spacer(modifier = Modifier.height(8.dp)) + + Text( + text = when { + alertText.isNotEmpty() -> alertText + wantText.isNotEmpty() -> wantText + else -> "Status: $displayStatus" + }, + fontWeight = if (alertText.isNotEmpty() || wantText.isNotEmpty()) FontWeight.Bold else FontWeight.Normal, + textAlign = TextAlign.Center + ) + } + + + if ((isSleeping && location == "Inside") || roughWakeDarkFlash) { + Box( + modifier = Modifier + .fillMaxSize() + .background(Color.Gray.copy(alpha = 0.38f)) + ) + } + + if (isFindingNewPet) { + Box( + modifier = Modifier + .fillMaxSize() + .background(Color.Gray.copy(alpha = 0.28f)), + contentAlignment = Alignment.Center + ) { + Text( + text = "FINDING PET...", + fontWeight = FontWeight.Bold, + color = lcdDark + ) + } + } + + if (creditsOpen) { + androidx.compose.ui.window.Popup( + alignment = Alignment.TopCenter + ) { + Box( + modifier = Modifier + .width(androidx.compose.ui.platform.LocalConfiguration.current.screenWidthDp.dp) + .height(androidx.compose.ui.platform.LocalConfiguration.current.screenHeightDp.dp) + .background(lcdBackground) + .border(2.dp, lcdDark) + .padding(10.dp) + ) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(top = 44.dp, bottom = 54.dp) + .verticalScroll(rememberScrollState()), + verticalArrangement = Arrangement.spacedBy(4.dp) + ) { + Text( + text = "CREDITS / LICENSES", + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth() + ) + + creditsText.lines().forEach { creditLine -> + if (creditLine.startsWith("Sound page: ")) { + val creditUrl = creditLine.removePrefix("Sound page: ").trim() + + Text( + text = "Sound page:", + fontSize = 11.sp, + lineHeight = 13.sp, + fontFamily = FontFamily.Monospace + ) + + Text( + text = creditUrl, + fontSize = 11.sp, + lineHeight = 13.sp, + fontFamily = FontFamily.Monospace, + fontWeight = FontWeight.Bold, + modifier = Modifier.clickable { + context.startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse(creditUrl) + ) + ) + } + ) + } else { + Text( + text = creditLine, + fontSize = 11.sp, + lineHeight = 13.sp, + fontFamily = FontFamily.Monospace + ) + } + } + } + + val creditsCloseOnLeft = creditsCloseButtonCorner in listOf("BottomLeft", "TopLeft") + + Row( + modifier = Modifier.align( + when (creditsCloseButtonCorner) { + "BottomLeft" -> Alignment.BottomStart + "TopLeft" -> Alignment.TopStart + "TopRight" -> Alignment.TopEnd + else -> Alignment.BottomEnd + } + ), + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + if (creditsCloseOnLeft) { + Text( + text = "CLOSE", + fontWeight = FontWeight.Bold, + modifier = Modifier + .background(lcdBackground) + .border(1.dp, lcdDark) + .clickable { + creditsOpen = false + } + .padding(horizontal = 10.dp, vertical = 6.dp) + ) + + Text( + text = "MOVE", + fontWeight = FontWeight.Bold, + modifier = Modifier + .background(lcdBackground) + .border(1.dp, lcdDark) + .clickable { + creditsCloseButtonCorner = when (creditsCloseButtonCorner) { + "BottomRight" -> "BottomLeft" + "BottomLeft" -> "TopLeft" + "TopLeft" -> "TopRight" + else -> "BottomRight" + } + } + .padding(horizontal = 10.dp, vertical = 6.dp) + ) + } else { + Text( + text = "MOVE", + fontWeight = FontWeight.Bold, + modifier = Modifier + .background(lcdBackground) + .border(1.dp, lcdDark) + .clickable { + creditsCloseButtonCorner = when (creditsCloseButtonCorner) { + "BottomRight" -> "BottomLeft" + "BottomLeft" -> "TopLeft" + "TopLeft" -> "TopRight" + else -> "BottomRight" + } + } + .padding(horizontal = 10.dp, vertical = 6.dp) + ) + + Text( + text = "CLOSE", + fontWeight = FontWeight.Bold, + modifier = Modifier + .background(lcdBackground) + .border(1.dp, lcdDark) + .clickable { + creditsOpen = false + } + .padding(horizontal = 10.dp, vertical = 6.dp) + ) + } + } + } + } + } + } + + Column( + modifier = Modifier.padding(top = 16.dp), + verticalArrangement = Arrangement.spacedBy(6.dp) + ) { + Row { + Text( + text = "Happiness", + modifier = Modifier.width(92.dp), + textAlign = TextAlign.End + ) + Text(text = " $happinessBar") + } + + Row { + Text( + text = "Energy", + modifier = Modifier.width(92.dp), + textAlign = TextAlign.End + ) + Text(text = " $energyBar") + } + + Row { + Text( + text = "Hunger", + modifier = Modifier.width(92.dp), + textAlign = TextAlign.End + ) + Text(text = " $hungerBar") + } + + Row { + Text( + text = "Dirtiness", + modifier = Modifier.width(92.dp), + textAlign = TextAlign.End + ) + Text(text = " $dirtinessBar") + } + + Row { + Text( + text = "Potty", + modifier = Modifier.width(92.dp), + textAlign = TextAlign.End + ) + Text(text = " $pottyBar") + } + + Row { + Text( + text = "Boredom", + modifier = Modifier.width(92.dp), + textAlign = TextAlign.End + ) + Text(text = " $boredomBar") + } + } + + Spacer(modifier = Modifier.height(12.dp)) + + Column( + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + val actionInProgress = isTradingInPet || isFindingNewPet || isSleeping || isBathing || framePropAnimation.isNotEmpty() || + (frameProp.isNotEmpty() && !isTalking) + val canAct = !actionInProgress + val canStartAction = canAct && !isTalking + val canBathe = canStartAction && location == "Inside" && (dirtiness > 0 || currentWant == "Bath") + val canFeed = canStartAction && location == "Inside" && + !(status in listOf( + "Sick", + "Weak", + "Recovering", + "RecoverWeak" + ) && weakCause == "Overfed") + val canPlay = canStartAction && location == "Inside" && energy > 0 && status !in listOf( + "Weak", + "RecoverWeak" + ) + val canPet = canStartAction && location == "Inside" + val canTalk = canAct && location == "Inside" + val canNap = canStartAction && location == "Inside" && energy < 10 + + val canPotty = canStartAction && location == "Outside" && potty > 0 + val canWalk = canStartAction && location == "Outside" && energy > 0 && status !in listOf( + "Sick", + "Recovering", + "Weak", + "RecoverWeak" + ) + + if (location == "Inside") { + LCDMenuButton( + text = if (careMenuOpen) "CARE ▲" else "CARE ▼", + enabled = canStartAction, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + careMenuOpen = !careMenuOpen + if (careMenuOpen) { + socializeMenuOpen = false + if (!testingMode) { + statsMenuOpen = false + } + } + } + ) + + if (careMenuOpen) { + LCDSubMenuFrame(lcdDark = lcdDark) { + LCDSubButton( + text = "BATHE", + enabled = canBathe, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + bathePet() + } + ) + + LCDSubButton( + text = "FEED", + enabled = canFeed, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + feedPet() + } + ) + + LCDSubButton( + text = "NAP", + enabled = canNap, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + napPet() + } + ) + } + } + + LCDMenuButton( + text = if (socializeMenuOpen) "SOCIALIZE ▲" else "SOCIALIZE ▼", + enabled = canStartAction, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + socializeMenuOpen = !socializeMenuOpen + if (socializeMenuOpen) { + careMenuOpen = false + if (!testingMode) { + statsMenuOpen = false + } + } + } + ) + + if (socializeMenuOpen) { + LCDSubMenuFrame(lcdDark = lcdDark) { + LCDSubButton( + text = "PET", + enabled = canPet, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + petPet() + } + ) + + LCDSubButton( + text = "PLAY", + enabled = canPlay, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + playPet() + } + ) + + LCDHoldSubButton( + text = "TALK", + enabled = canTalk, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onPress = { + beginTalk() + }, + onRelease = { + endTalk() + } + ) + } + } + } else { + LCDMenuButton( + text = "WALK", + enabled = canWalk, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + walkPet() + } + ) + + LCDMenuButton( + text = "POTTY", + enabled = canPotty, + lcdDark = lcdDark, + lcdFaded = lcdFaded, + onClick = { + usePotty() + } + ) + } + } + } +} + +} + +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + LCDPetTheme { + Greeting("LCDPet") + } +} \ No newline at end of file diff --git a/app/src/main/java/today/notfeelingit/lcdpet/PetStorage.kt b/app/src/main/java/today/notfeelingit/lcdpet/PetStorage.kt new file mode 100644 index 0000000..5ab5055 --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/PetStorage.kt @@ -0,0 +1,172 @@ +package today.notfeelingit.lcdpet + +import android.content.Context +import androidx.datastore.preferences.core.booleanPreferencesKey +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.intPreferencesKey +import androidx.datastore.preferences.core.longPreferencesKey +import androidx.datastore.preferences.core.stringPreferencesKey +import androidx.datastore.preferences.preferencesDataStore +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +val Context.lcdPetDataStore by preferencesDataStore(name = "lcdpet_save") + +data class LCDPetRecordSave( + val bond: Int = 0, + val petAgeDays: Int = 0, + val careScore: Int = 0, + val neglectScore: Int = 0, + val hunger: Int = 5, + val health: Int = 10, + val happiness: Int = 5, + val energy: Int = 5, + val dirtiness: Int = 0, + val potty: Int = 0, + val boredom: Int = 0, + val location: String = "Inside", + val weather: String = "Sunny", + val status: String = "Nervous", + val weakCause: String = "", + val pottyStain: String = "", + val happyOutsideTrip: Boolean = false, + val isTradingInPet: Boolean = false, + val isFindingNewPet: Boolean = false, + val tradeInProgress: Int = 0, + val currentWant: String = "", + val petName: String = "", + val isSleeping: Boolean = false, + val sleepMode: String = "", + val roughWakeAlert: Boolean = false, + val autoSleepStartedAtMs: Long = 0L, + val careJournalRaw: String = "", + val lastSavedAtMs: Long = System.currentTimeMillis() +) + +private object LCDPetSaveKeys { + val BOND = intPreferencesKey("bond") + val PET_AGE_DAYS = intPreferencesKey("pet_age_days") + val CARE_SCORE = intPreferencesKey("care_score") + val NEGLECT_SCORE = intPreferencesKey("neglect_score") + val HUNGER = intPreferencesKey("hunger") + val HEALTH = intPreferencesKey("health") + val HAPPINESS = intPreferencesKey("happiness") + val ENERGY = intPreferencesKey("energy") + val DIRTINESS = intPreferencesKey("dirtiness") + val POTTY = intPreferencesKey("potty") + val BOREDOM = intPreferencesKey("boredom") + val LOCATION = stringPreferencesKey("location") + val WEATHER = stringPreferencesKey("weather") + val STATUS = stringPreferencesKey("status") + val WEAK_CAUSE = stringPreferencesKey("weak_cause") + val POTTY_STAIN = stringPreferencesKey("potty_stain") + val HAPPY_OUTSIDE_TRIP = booleanPreferencesKey("happy_outside_trip") + val IS_TRADING_IN_PET = booleanPreferencesKey("is_trading_in_pet") + val IS_FINDING_NEW_PET = booleanPreferencesKey("is_finding_new_pet") + val TRADE_IN_PROGRESS = intPreferencesKey("trade_in_progress") + val CURRENT_WANT = stringPreferencesKey("current_want") + val PET_NAME = stringPreferencesKey("pet_name") + val IS_SLEEPING = booleanPreferencesKey("is_sleeping") + val SLEEP_MODE = stringPreferencesKey("sleep_mode") + val ROUGH_WAKE_ALERT = booleanPreferencesKey("rough_wake_alert") + val AUTO_SLEEP_STARTED_AT_MS = longPreferencesKey("auto_sleep_started_at_ms") + val CARE_JOURNAL = stringPreferencesKey("care_journal") + val LAST_SAVED_AT_MS = longPreferencesKey("last_saved_at_ms") +} + +val Context.lcdPetRecordSaveFlow: Flow + get() = lcdPetDataStore.data.map { preferences -> + LCDPetRecordSave( + bond = preferences[LCDPetSaveKeys.BOND] ?: 0, + petAgeDays = preferences[LCDPetSaveKeys.PET_AGE_DAYS] ?: 0, + careScore = preferences[LCDPetSaveKeys.CARE_SCORE] ?: 0, + neglectScore = preferences[LCDPetSaveKeys.NEGLECT_SCORE] ?: 0, + hunger = preferences[LCDPetSaveKeys.HUNGER] ?: 5, + health = preferences[LCDPetSaveKeys.HEALTH] ?: 10, + happiness = preferences[LCDPetSaveKeys.HAPPINESS] ?: 5, + energy = preferences[LCDPetSaveKeys.ENERGY] ?: 5, + dirtiness = preferences[LCDPetSaveKeys.DIRTINESS] ?: 0, + potty = preferences[LCDPetSaveKeys.POTTY] ?: 0, + boredom = preferences[LCDPetSaveKeys.BOREDOM] ?: 0, + location = preferences[LCDPetSaveKeys.LOCATION] ?: "Inside", + weather = preferences[LCDPetSaveKeys.WEATHER] ?: "Sunny", + status = preferences[LCDPetSaveKeys.STATUS] ?: "Nervous", + weakCause = preferences[LCDPetSaveKeys.WEAK_CAUSE] ?: "", + pottyStain = preferences[LCDPetSaveKeys.POTTY_STAIN] ?: "", + happyOutsideTrip = preferences[LCDPetSaveKeys.HAPPY_OUTSIDE_TRIP] ?: false, + isTradingInPet = preferences[LCDPetSaveKeys.IS_TRADING_IN_PET] ?: false, + isFindingNewPet = preferences[LCDPetSaveKeys.IS_FINDING_NEW_PET] ?: false, + tradeInProgress = preferences[LCDPetSaveKeys.TRADE_IN_PROGRESS] ?: 0, + currentWant = preferences[LCDPetSaveKeys.CURRENT_WANT] ?: "", + petName = preferences[LCDPetSaveKeys.PET_NAME] ?: "", + isSleeping = preferences[LCDPetSaveKeys.IS_SLEEPING] ?: false, + sleepMode = preferences[LCDPetSaveKeys.SLEEP_MODE] ?: "", + roughWakeAlert = preferences[LCDPetSaveKeys.ROUGH_WAKE_ALERT] ?: false, + autoSleepStartedAtMs = preferences[LCDPetSaveKeys.AUTO_SLEEP_STARTED_AT_MS] ?: 0L, + careJournalRaw = preferences[LCDPetSaveKeys.CARE_JOURNAL] ?: "", + lastSavedAtMs = preferences[LCDPetSaveKeys.LAST_SAVED_AT_MS] ?: System.currentTimeMillis() + ) + } + +suspend fun Context.saveLCDPetStats( + bond: Int, + petAgeDays: Int, + careScore: Int, + neglectScore: Int, + hunger: Int, + health: Int, + happiness: Int, + energy: Int, + dirtiness: Int, + potty: Int, + boredom: Int, + location: String, + weather: String, + status: String, + weakCause: String, + pottyStain: String, + happyOutsideTrip: Boolean, + isTradingInPet: Boolean, + isFindingNewPet: Boolean, + tradeInProgress: Int, + currentWant: String, + petName: String, + isSleeping: Boolean, + sleepMode: String, + roughWakeAlert: Boolean, + autoSleepStartedAtMs: Long, + careJournalRaw: String? = null +) { + lcdPetDataStore.edit { preferences -> + preferences[LCDPetSaveKeys.BOND] = bond + preferences[LCDPetSaveKeys.PET_AGE_DAYS] = petAgeDays + preferences[LCDPetSaveKeys.CARE_SCORE] = careScore + preferences[LCDPetSaveKeys.NEGLECT_SCORE] = neglectScore + preferences[LCDPetSaveKeys.HUNGER] = hunger + preferences[LCDPetSaveKeys.HEALTH] = health + preferences[LCDPetSaveKeys.HAPPINESS] = happiness + preferences[LCDPetSaveKeys.ENERGY] = energy + preferences[LCDPetSaveKeys.DIRTINESS] = dirtiness + preferences[LCDPetSaveKeys.POTTY] = potty + preferences[LCDPetSaveKeys.BOREDOM] = boredom + preferences[LCDPetSaveKeys.LOCATION] = location + preferences[LCDPetSaveKeys.WEATHER] = weather + preferences[LCDPetSaveKeys.STATUS] = status + preferences[LCDPetSaveKeys.WEAK_CAUSE] = weakCause + preferences[LCDPetSaveKeys.POTTY_STAIN] = pottyStain + preferences[LCDPetSaveKeys.HAPPY_OUTSIDE_TRIP] = happyOutsideTrip + preferences[LCDPetSaveKeys.IS_TRADING_IN_PET] = isTradingInPet + preferences[LCDPetSaveKeys.IS_FINDING_NEW_PET] = isFindingNewPet + preferences[LCDPetSaveKeys.TRADE_IN_PROGRESS] = tradeInProgress + preferences[LCDPetSaveKeys.CURRENT_WANT] = currentWant + preferences[LCDPetSaveKeys.PET_NAME] = petName + preferences[LCDPetSaveKeys.IS_SLEEPING] = isSleeping + preferences[LCDPetSaveKeys.SLEEP_MODE] = sleepMode + preferences[LCDPetSaveKeys.ROUGH_WAKE_ALERT] = roughWakeAlert + preferences[LCDPetSaveKeys.AUTO_SLEEP_STARTED_AT_MS] = autoSleepStartedAtMs + if (careJournalRaw != null) { + preferences[LCDPetSaveKeys.CARE_JOURNAL] = careJournalRaw + } + preferences[LCDPetSaveKeys.LAST_SAVED_AT_MS] = System.currentTimeMillis() + } +} diff --git a/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Color.kt b/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Color.kt new file mode 100644 index 0000000..7cbf9f3 --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package today.notfeelingit.lcdpet.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Theme.kt b/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Theme.kt new file mode 100644 index 0000000..4dc1c5c --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package today.notfeelingit.lcdpet.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun LCDPetTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Type.kt b/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Type.kt new file mode 100644 index 0000000..63871d5 --- /dev/null +++ b/app/src/main/java/today/notfeelingit/lcdpet/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package today.notfeelingit.lcdpet.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/app/src/main/keepRules/rules.keep b/app/src/main/keepRules/rules.keep new file mode 100644 index 0000000..d7e081a --- /dev/null +++ b/app/src/main/keepRules/rules.keep @@ -0,0 +1,12 @@ +# Add project specific R8 rules here. +# AGP will combine all keep rule files in src/main/keepRules to pass to R8 +# +# For more details, see +# https://d.android.com/r/tools/r8/keep-rules + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/raw/tv_off.ogg b/app/src/main/res/raw/tv_off.ogg new file mode 100644 index 0000000..c2df0e9 Binary files /dev/null and b/app/src/main/res/raw/tv_off.ogg differ diff --git a/app/src/main/res/raw/tv_static_light.ogg b/app/src/main/res/raw/tv_static_light.ogg new file mode 100644 index 0000000..b87468b Binary files /dev/null and b/app/src/main/res/raw/tv_static_light.ogg differ diff --git a/app/src/main/res/raw/weather_channel_jazz.ogg b/app/src/main/res/raw/weather_channel_jazz.ogg new file mode 100644 index 0000000..401067a Binary files /dev/null and b/app/src/main/res/raw/weather_channel_jazz.ogg differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..5f4ceb9 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + LCDPet + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..73a5b68 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +