diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.sln b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.sln new file mode 100644 index 0000000..f63d09a --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Lelebees.MdkScriptMixin.SpriteCompositor", "Lelebees.MdkScriptMixin.SpriteCompositor\Lelebees.MdkScriptMixin.SpriteCompositor.shproj", "{8A3CDCC5-4B55-4D87-A415-698A0E1FF06F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpriteCompositor.Demo", "SpriteCompositor.Demo\SpriteCompositor.Demo.csproj", "{86DF49B2-74C3-4A4B-8F5D-4F2FBEB0866C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpriteCompositor.Test", "SpriteCompositor.Test\SpriteCompositor.Test.csproj", "{2A7DDEA6-FB3C-47A5-B856-BD0A37FC573C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8A3CDCC5-4B55-4D87-A415-698A0E1FF06F}.Debug|x64.ActiveCfg = Debug|x64 + {8A3CDCC5-4B55-4D87-A415-698A0E1FF06F}.Debug|x64.Build.0 = Debug|x64 + {8A3CDCC5-4B55-4D87-A415-698A0E1FF06F}.Release|x64.ActiveCfg = Release|x64 + {8A3CDCC5-4B55-4D87-A415-698A0E1FF06F}.Release|x64.Build.0 = Release|x64 + {86DF49B2-74C3-4A4B-8F5D-4F2FBEB0866C}.Debug|x64.ActiveCfg = Debug|x64 + {86DF49B2-74C3-4A4B-8F5D-4F2FBEB0866C}.Debug|x64.Build.0 = Debug|x64 + {86DF49B2-74C3-4A4B-8F5D-4F2FBEB0866C}.Release|x64.ActiveCfg = Release|x64 + {86DF49B2-74C3-4A4B-8F5D-4F2FBEB0866C}.Release|x64.Build.0 = Release|x64 + {2A7DDEA6-FB3C-47A5-B856-BD0A37FC573C}.Debug|x64.ActiveCfg = Debug|x64 + {2A7DDEA6-FB3C-47A5-B856-BD0A37FC573C}.Debug|x64.Build.0 = Debug|x64 + {2A7DDEA6-FB3C-47A5-B856-BD0A37FC573C}.Release|x64.ActiveCfg = Release|x64 + {2A7DDEA6-FB3C-47A5-B856-BD0A37FC573C}.Release|x64.Build.0 = Release|x64 + EndGlobalSection +EndGlobal diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING new file mode 100644 index 0000000..ed990f8 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING @@ -0,0 +1,621 @@ + 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 \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING.LESSER b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING.LESSER new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER 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. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser 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 +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.projitems b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.projitems new file mode 100644 index 0000000..9a4f5b8 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.projitems @@ -0,0 +1,32 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 8a3cdcc5-4b55-4d87-a415-698a0e1ff06f + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.shproj b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.shproj new file mode 100644 index 0000000..728c385 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.shproj @@ -0,0 +1,19 @@ + + + + 8a3cdcc5-4b55-4d87-a415-698a0e1ff06f + 14.0 + + + + + + + bin\Debug\ + + + bin\Release\ + + + + diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.shproj.DotSettings b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.shproj.DotSettings new file mode 100644 index 0000000..a208ba0 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor.shproj.DotSettings @@ -0,0 +1,6 @@ + + True + True + True + True + True \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_authors b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_authors new file mode 100644 index 0000000..cd6ba21 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_authors @@ -0,0 +1 @@ +Lelebees \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_description b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_description new file mode 100644 index 0000000..e3889b1 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_description @@ -0,0 +1 @@ +API wrapper simplifying the native Space Engineers LCD Sprite API. Supports composing your own sprites out of a collection of existing sprites. \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_releasenotes b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_releasenotes new file mode 100644 index 0000000..c1a8b81 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_releasenotes @@ -0,0 +1,7 @@ +- 1.0.0 + Support Text and Image sprites. + Support translating sprites and sprite groups. + Support rotating sprites and groups around an arbitrary point or another sprite. + Support scaling sprite groups as if they were one sprite, in multiple dimensions. + Support recoloring groups of sprites + Experimental Clipping Sprite support diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_version b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_version new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/_version @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/documentation/class-diagram.md b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/documentation/class-diagram.md new file mode 100644 index 0000000..8218df0 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/documentation/class-diagram.md @@ -0,0 +1,85 @@ +```mermaid +classDiagram + note "Implemented interface methods\n have been left out for brevity." + class Sprite { + <> + +Translate(float x, float y) Sprite + +Translate(Vector2 vector) void + +SetColor(Color color) void + +SetAlignment(TextAlignment alignment) void + +GetPosition() Vector2 + +Scale(float amount) void + +Rotate(Angle angle, Anchor anchor) void + +Clone() Sprite + } + + Anchor <|-- Sprite + Sprite <|-- SpriteLeaf + Sprite <|--o SpriteGroup + Sprite ..> Angle + + class SpriteLeaf { + <> + #MySprite sprite + +Scale(float amount)* void + +Rotate(Angle angle, Anchor anchor)* void + +Clone()* Sprite + } + + SpriteLeaf <|-- TextSprite + SpriteLeaf <|-- TextureSprite + SpriteLeaf <|-- ClippingSprite + + class TextureSprite { + +float Rotation + +Vector2? Size + +string Texture + +SetTexture(string texture) void + +Scale(float amount) void + +Rotate(Angle angle, Anchor anchor) void + +Mirror() void + +MirrorHorizontal() void + +MirrorVertical() void + } + + class TextSprite { + +string Text + +string FontId + +float TextScale + +TextAlignment alignment + +Scale(float amount) void + +Rotate(Angle angle, Anchor anchor) void + } + + class ClippingSprite { + +Scale(float amount) void + +Rotate(Angle angle, Anchor anchor) void + } + + class SpriteGroup { + -List~Sprite~ sprites + +Mirror() void + +MirrorHorizontal() void + +MirrorVertical() void + } + + class Angle { + -float radians + +float Radians + +float Degrees + } + + note for Angle "Basic arithmetic and\n comparison available" + + class Anchor { + <> + +GetPosition() Vector2 + } + + class PointAnchor { + -Vector2 position + +GetPosition() Vector2 + } + + Anchor <|-- PointAnchor +``` \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/readme.md b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/readme.md new file mode 100644 index 0000000..1c5a648 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/readme.md @@ -0,0 +1,90 @@ +# Sprite Compositing for LCD Scripts + +An API wrapper that supports composing new sprites from multiple existing ones. + +- [Source Code](./src) +- [Demo Project](../SpriteCompositor.Demo/Program.cs) +- [Tests](../SpriteCompositor.Test) + +## Usage + +You can instantiate regular sprites using the helper methods of the `Sprites` class. These return a builder (except for +`Sprites.Group()`, which returns a group directly) that can be used to further configure the initial values of the +sprite. + +All sprites and sprite groups implement the `Sprite` interface, which you can use to `Translate()`, `Rotate()`, or +`Scale()` a sprite after instantiation, among other things. Individual Sprite types may have additional properties and +methods available, like `TextureSprite`'s `Mirror()` functions. + +See the [demo project](../SpriteCompositor.Demo/Program.cs) for a detailed example. + +### Grouping Sprites + +You can group sprites by calling `Sprites.Group()` or creating a `new SimpleSpriteGroup()`. + +If this implementation does +not fit your needs, you can extend the `SpriteGroup` abstract class. If you do, you will be required to implement the +`Clone()` and `GetChildren()` methods. + +**Avoid creating a new list in `GetChildren()`**, as the function is invoked +whenever a transformation is applied to the group. I recommend using the following example as a guide: + +```csharp +public class CustomSpriteGroup : SpriteGroup +{ + private readonly List backingList; + + public Sprite UnspecifiedSprite + { + get { return backingList[0]; } + set { backingList[0] = value; } + } + + public TextureSprite SpecificSprite + { + get { return (TextureSprite) backingList[1]; } + set { backingList[1] = value; } + } + + public CustomSpriteGroup(Sprite unspecifiedSprite, TextureSprite specificSprite) + { + this.backingList = new List { unspecifiedSprite, specificSprite }; + } + + public override Sprite Clone() => new CustomSpriteGroup(backingList.Select(sprite => sprite.Clone()).ToList()); + + protected override List GetChildren() => backingList; +} +``` + +If, for some reason, the abstract `SpriteGroup` class also does not suit your needs, you can implement the `Sprite` +interface directly, though if you feel the need to do so, there may be a structural problem with your program. + +### Anchors + +Some transformation functions take an optional `Anchor` argument. When passed, the transformation will use the anchor as +the center of that transformation. For example, with `Rotate()` transformations, in addition to the regular behavior, +the respective sprite will be rotated around the anchor point, as if it was orbiting it. `Scale()` transformations with +an `Anchor` will also scale the distance to the anchor point. + +### Displaying Sprites + +In order to draw your composed sprites to an LCD screen, you'll need to call the `Sprite.AsRenderable()` method, which will +return an array of `MySprite` objects that your sprite consists of. You can draw these to the screen in one go +using the `MySpriteDrawFrame.AddRange()` method. `AsRenderable()` takes an optional `RectangleF viewport` as parameter. +Supplying this will move the sprites so that (0,0) is the center of the viewport. + +## Legal +`Copyright (c) 2026 Lelebees` + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . + +### License +You can find a copy of the [GNU General Public License](./COPYING) and [GNU Lesser General Public License](./COPYING.LESSER) next to this source code in COPYING and COPYING.LESSER respectively. + +### Reaching out +You can reach me as @lelebees on Discord, or through the project's [Github Repository](https://github.com/Lelebees/mdk2-packages-sprite-compositor). Please note while reaching out on Discord that I generally do not accept random friend requests. @Mention me in the [programmable block channel](https://discord.com/channels/125011928711036928/216219467959500800) of the Keen Software House Discord Server to get a hold of me. \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/anchor/Anchor.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/anchor/Anchor.cs new file mode 100644 index 0000000..2cbe473 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/anchor/Anchor.cs @@ -0,0 +1,25 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using VRageMath; + +namespace IngameScript +{ + /// + /// Classes conforming to this interface can be used as an anchor to rotate around in sprite composition. + /// + public interface Anchor + { + Vector2 GetPosition(); + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/anchor/PointAnchor.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/anchor/PointAnchor.cs new file mode 100644 index 0000000..b31b021 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/anchor/PointAnchor.cs @@ -0,0 +1,34 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using VRageMath; + +namespace IngameScript +{ + public struct PointAnchor : Anchor + { + private readonly Vector2 position; + + public PointAnchor(Vector2 position) + { + this.position = position; + } + + public PointAnchor(float x, float y) : this(new Vector2(x, y)) {} + + public Vector2 GetPosition() + { + return position; + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/angle/Angle.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/angle/Angle.cs new file mode 100644 index 0000000..d8d4d94 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/angle/Angle.cs @@ -0,0 +1,78 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using System; + +namespace IngameScript +{ + /// + /// An unambiguous angle for mathematical equations. + /// + public struct Angle + { + /// + /// A right angle, equal to 90 degrees or 1/2 * PI. + /// + public static readonly Angle Right = new Angle(0.5 * Math.PI); + /// + /// A straight angle, equal to 180 degrees or 1 * PI. + /// + public static readonly Angle Straight = new Angle(Math.PI); + /// + /// A full angle, equal to 360 degrees or 2 * PI. + /// + public static readonly Angle Full = new Angle(2 * Math.PI); + + private Angle(double radians) + { + // Normalize the angle to be within a single rotation + if (radians > 2 * Math.PI || radians < -2 * Math.PI) + { + radians %= 2 * Math.PI; + } + + Radians = radians; + } + /// + /// This angle expressed in radians, positive or negative, limited to one full rotation (0 to 2 * PI) + /// + public double Radians { get; } + + /// + /// This angle expressed in degrees, positive or negative, limited to one full rotation (0 to 360) + /// + public double Degrees => Radians * 180 / Math.PI; + + public static Angle FromDegrees(double degrees) => new Angle(degrees * Math.PI / 180); + + public static Angle FromRadians(double radians) => new Angle(radians); + + public static Angle operator +(Angle left, Angle right) => new Angle(left.Radians + right.Radians); + + public static Angle operator +(Angle angle) => angle; + + public static Angle operator -(Angle left, Angle right) => new Angle(left.Radians - right.Radians); + + public static Angle operator -(Angle angle) => new Angle(-angle.Radians); + + public static Angle operator /(Angle nominator, double divisor) => new Angle(nominator.Radians / divisor); + + public static Angle operator *(Angle angle, double multiplier) => new Angle(angle.Radians * multiplier); + + public static bool operator <(Angle left, Angle right) => left.Radians < right.Radians; + public static bool operator <=(Angle left, Angle right) => left.Radians <= right.Radians; + + public static bool operator >(Angle left, Angle right) => left.Radians > right.Radians; + public static bool operator >=(Angle left, Angle right) => left.Radians >= right.Radians; + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Sprite.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Sprite.cs new file mode 100644 index 0000000..e093636 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Sprite.cs @@ -0,0 +1,77 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace IngameScript +{ + public interface Sprite : Anchor + { + /// + /// Moves a sprite in 2D space. + /// + /// How far the sprite will be moved and in what direction + void Translate(Vector2 vector); + + /// + /// Moves a sprite in 2D space. + /// + /// How far the sprite will be moved on the x-axis + /// How far the sprite will be moved on the y-axis + void Translate(float x, float y); + + void SetColor(Color color); + void SetAlignment(TextAlignment alignment); + + /// + /// Scales a sprite in 2 dimensions according to the scalar. + /// + /// How much to multiply the size of the sprite by + /// If not null, will also scale the sprite's distance from the anchor + void Scale(float scalar, Anchor anchor = null); + + /// + /// Scales a sprite in 2 dimensions according to the scalar. + /// + /// How much to multiply the size of the sprite by. If either x or y is 1, scales in only one dimension (except for text) + /// If not null, will also scale the sprite's distance from the anchor + void Scale(Vector2 scalar, Anchor anchor = null); + + /// + /// Rotates a sprite in clockwise direction around the given anchor + /// + /// The angle of rotation + /// The point in space to rotate around, if no anchor is given, the center of this sprite is used + void Rotate(Angle angle, Anchor positionAnchor = null); + + /// + /// Creates a copy of the sprite that can be modified separately. + /// + /// A new instance of the sprite + Sprite Clone(); + + /// + /// Converts the sprite to a collection of sprites that Space Engineers can actually draw. + /// + /// The size of the screen the sprite(s) are to be drawn to. Moves the sprites so that 0,0 is the center of the screen. + /// A collection of MySprite objects that can be drawn on a screen the size of viewport. + MySprite[] AsDrawableCollection(RectangleF viewport); + + /// + /// Converts the sprite to a collection of sprites that Space Engineers can actually draw + /// + /// A collection of MySprite objects. These have not been adjusted to fit in the viewport. + MySprite[] AsDrawableCollection(); + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/SpriteGroup.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/SpriteGroup.cs new file mode 100644 index 0000000..e4130a1 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/SpriteGroup.cs @@ -0,0 +1,87 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using System.Collections.Generic; +using System.Linq; +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace IngameScript +{ + public abstract class SpriteGroup : Sprite + { + public Vector2 GetPosition() + { + var children = GetChildren(); + return children.Aggregate(Vector2.Zero, (current, child) => current + child.GetPosition()) / children.Count; + } + + public void Translate(Vector2 vector) => GetChildren().ForEach(sprite => sprite.Translate(vector)); + + public void Translate(float x, float y) => Translate(new Vector2(x, y)); + + public void SetColor(Color color) => GetChildren().ForEach(sprite => sprite.SetColor(color)); + + public void SetAlignment(TextAlignment alignment) => + GetChildren().ForEach(sprite => sprite.SetAlignment(alignment)); + + public void Scale(float scalar, Anchor anchor = null) => Scale(new Vector2(scalar, scalar), anchor); + + public void Scale(Vector2 scalar, Anchor anchor = null) + { + // See the rotate function for why we're doing this. + if (anchor == null) + { + anchor = new PointAnchor(GetPosition()); + } + else if (anchor is SpriteGroup) + { + anchor = new PointAnchor(anchor.GetPosition()); + } + + GetChildren().ForEach(sprite => sprite.Scale(scalar, anchor)); + } + + public void Mirror(Anchor anchor = null) => Scale(new Vector2(-1, -1), anchor); + + public void MirrorVertical(Anchor anchor = null) => Scale(new Vector2(1, -1), anchor); + + public void MirrorHorizontal(Anchor anchor = null) => Scale(new Vector2(-1, 1), anchor); + + public void Rotate(Angle angle, Anchor positionAnchor = null) + { + // it is VITALLY important to create a PointAnchor here. If we don't, + // the process of rotating sprites could adjust this (or another) groups center, and therefore its position + // this causes sprites to spiral away from the center of rotation. + if (positionAnchor == null) + { + positionAnchor = new PointAnchor(GetPosition()); + } + if (positionAnchor is SpriteGroup) + { + positionAnchor = new PointAnchor(positionAnchor.GetPosition()); + } + GetChildren().ForEach(sprite => sprite.Rotate(angle, positionAnchor)); + } + + public abstract Sprite Clone(); + + public MySprite[] AsDrawableCollection(RectangleF viewport) => + GetChildren().SelectMany(child => child.AsDrawableCollection(viewport)).ToArray(); + + public MySprite[] AsDrawableCollection() => + GetChildren().SelectMany(child => child.AsDrawableCollection()).ToArray(); + + protected abstract List GetChildren(); + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/SpriteLeaf.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/SpriteLeaf.cs new file mode 100644 index 0000000..d20381f --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/SpriteLeaf.cs @@ -0,0 +1,114 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using System; +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace IngameScript +{ + public abstract class SpriteLeaf : Sprite + { + protected MySprite Sprite; + + public Vector2? Position + { + get { return Sprite.Position; } + set { Sprite.Position = value; } + } + + protected SpriteLeaf(MySprite sprite) + { + Sprite = sprite; + } + + public Vector2 GetPosition() + { + return Sprite.Position ?? Vector2.Zero; + } + + public void Translate(Vector2 vector) + { + var position = GetPosition(); + position.X += vector.X; + position.Y += vector.Y; + Sprite.Position = position; + } + + public void Translate(float x, float y) + { + Translate(new Vector2(x, y)); + } + + public void SetColor(Color color) + { + Sprite.Color = color; + } + + public void SetAlignment(TextAlignment alignment) + { + Sprite.Alignment = alignment; + } + + public virtual void Scale(float scalar, Anchor anchor = null) => Scale(new Vector2(scalar, scalar), anchor); + + public virtual void Scale(Vector2 scalar, Anchor anchor = null) + { + if (anchor == null || anchor == this || anchor.GetPosition() == GetPosition()) return; + + var anchorPos = anchor.GetPosition(); + var distanceFromAnchor = GetPosition() - anchorPos; + distanceFromAnchor *= scalar; + Sprite.Position = anchorPos + distanceFromAnchor; + } + + public virtual void Rotate(Angle angle, Anchor positionAnchor = null) + { + if (positionAnchor == null || positionAnchor == this || + positionAnchor.GetPosition() == GetPosition()) return; + + var cos = Math.Cos(-angle.Radians); + var sin = Math.Sin(-angle.Radians); + + var anchor = positionAnchor.GetPosition(); + + var position = Sprite.Position ?? Vector2.Zero; + var posX = (float)(cos * (position.X - anchor.X) + sin * (position.Y - anchor.Y) + anchor.X); + var posY = (float)(-sin * (position.X - anchor.X) + cos * (position.Y - anchor.Y) + anchor.Y); + Sprite.Position = new Vector2(posX, posY); + } + + public abstract Sprite Clone(); + + public MySprite[] AsDrawableCollection(RectangleF viewport) + { + return new[] + { + new MySprite( + Sprite.Type, + Sprite.Data, + Sprite.Position + viewport.Center, + Sprite.Size, + Sprite.Color, + Sprite.FontId, + Sprite.Alignment, + Sprite.RotationOrScale) + }; + } + + public MySprite[] AsDrawableCollection() + { + return new[] { Sprite }; + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Sprites.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Sprites.cs new file mode 100644 index 0000000..7eb6926 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Sprites.cs @@ -0,0 +1,64 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using System; +using System.Linq; + +namespace IngameScript +{ + public abstract class Sprites + { + /// + /// Clones a sprite a given number of times, places them in a circle and divides the space between sprites evenly. + /// + /// The sprite to clone + /// Number of instances of the sprite there need to be + /// The center of rotation + /// The resulting list of sprites, which includes the original sprite (though no operation has been applied to that sprite) + public static Sprite[] + RepeatRotated(Sprite spriteToRepeat, uint repetitions, Anchor rotationAnchor = null) => + RepeatRotated(spriteToRepeat, repetitions, Angle.Full / repetitions, rotationAnchor); + + /// + /// Clones a sprite a given number of times, rotating each clone with the given angle compared to the previous clone. + /// + /// The sprite to clone + /// Number of instances of the sprite there need to be + /// The center of rotation + /// The angle to rotate each clone compared to the previous one + /// The resulting list of sprites, which includes the original sprite (though no operation has been applied to that sprite) + public static Sprite[] RepeatRotated(Sprite spriteToRepeat, uint repetitions, Angle stepSize, + Anchor rotationAnchor = null) + { + if (repetitions == 0) return Array.Empty(); + Sprite[] resultingSprites = new Sprite[(int)repetitions]; + resultingSprites[0] = spriteToRepeat; + for (var steps = 1; steps < repetitions; steps++) + { + var newSprite = spriteToRepeat.Clone(); + newSprite.Rotate(stepSize * steps, rotationAnchor); + resultingSprites[steps] = newSprite; + } + + return resultingSprites; + } + + public static TextureSprite.TextureSpriteBuilder WithTexture(string texture) => new TextureSprite.TextureSpriteBuilder().Texture(texture); + + public static TextSprite.TextSpriteBuilder WithText(string text) => new TextSprite.TextSpriteBuilder().Text(text); + + public static ClippingSprite.ClippingSpriteBuilder ClipRectangle() => new ClippingSprite.ClippingSpriteBuilder(); + + public static SpriteGroup Group(params Sprite[] sprites) => new SimpleSpriteGroup(sprites.ToList()); + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Textures.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Textures.cs new file mode 100644 index 0000000..fe0617c --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/Textures.cs @@ -0,0 +1,26 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ +namespace IngameScript +{ + public abstract class Textures + { + public const string Circle = "Circle"; + public const string CircleHollow = "CircleHollow"; + public const string RightTriangle = "RightTriangle"; + public const string SemiCircle = "SemiCircle"; + public const string SquareHollow = "SquareHollow"; + public const string SquareSimple = "SquareSimple"; + public const string SquareTapered = "SquareTapered"; + public const string Triangle = "Triangle"; + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/ClippingSprite.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/ClippingSprite.cs new file mode 100644 index 0000000..d0a1fdf --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/ClippingSprite.cs @@ -0,0 +1,79 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace IngameScript +{ + public class ClippingSprite : SpriteLeaf + { + private ClippingSprite(MySprite sprite) : base(sprite) + { + } + + public ClippingSprite() : base(new MySprite(type: SpriteType.CLIP_RECT)) + { + } + + public override void Scale(float scalar, Anchor anchor = null) => Scale(new Vector2(scalar, scalar), anchor); + + public override void Scale(Vector2 scalar, Anchor anchor = null) + { + if (Sprite.Size == null) Sprite.Size = Vector2.One; + + var size = Sprite.Size.Value; + size.X *= scalar.X; + size.Y *= scalar.Y; + Sprite.Size = size; + base.Scale(scalar, anchor); + } + + public override Sprite Clone() => new ClippingSprite(Sprite); + + public class ClippingSpriteBuilder + { + private MySprite sprite = new MySprite(type: SpriteType.CLIP_RECT); + + public ClippingSpriteBuilder Position(float x, float y) => Position(new Vector2(x, y)); + + public ClippingSpriteBuilder Position(Vector2 position) + { + sprite.Position = position; + return this; + } + + public ClippingSpriteBuilder Rotation(Angle rotation) + { + sprite.RotationOrScale = (float) rotation.Radians; + return this; + } + + public ClippingSpriteBuilder Size(float width, float height) => Size(new Vector2(width, height)); + + public ClippingSpriteBuilder Size(Vector2 size) + { + sprite.Size = size; + return this; + } + + public ClippingSpriteBuilder Alignment(TextAlignment alignment) + { + sprite.Alignment = alignment; + return this; + } + + public ClippingSprite Build() => new ClippingSprite(sprite); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/TextSprite.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/TextSprite.cs new file mode 100644 index 0000000..b3a16b7 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/TextSprite.cs @@ -0,0 +1,109 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace IngameScript +{ + public class TextSprite : SpriteLeaf + { + public string Text + { + get { return Sprite.Data;} + set { Sprite.Data = value; } + } + public string FontId + { + get { return Sprite.FontId; } + set { Sprite.FontId = value; } + } + + public float TextScale + { + get { return Sprite.RotationOrScale; } + set { Sprite.RotationOrScale = value; } + } + + public TextAlignment Alignment + { + get { return Sprite.Alignment; } + set { Sprite.Alignment = value; } + } + + private TextSprite(MySprite sprite) : base(sprite) + { + } + + public override void Scale(float scalar, Anchor anchor = null) + { + Sprite.RotationOrScale *= scalar; + base.Scale(new Vector2(scalar, scalar), anchor); + } + + public override void Scale(Vector2 scalar, Anchor anchor = null) + { + // Text sprites don't really scale in 2 dimensions, so instead we'll take the average scale + Sprite.RotationOrScale *= (scalar.X + scalar.Y) / 2; + base.Scale(scalar, anchor); + } + + public override Sprite Clone() => new TextSprite(Sprite); + + public class TextSpriteBuilder + { + private MySprite sprite = new MySprite(type: SpriteType.TEXT, rotation: 1f); + + public TextSpriteBuilder Text(string text) + { + sprite.Data = text; + return this; + } + + public TextSpriteBuilder FontId(string fontId) + { + sprite.FontId = fontId; + return this; + } + + public TextSpriteBuilder Position(float x, float y) => Position(new Vector2(x, y)); + + + public TextSpriteBuilder Position(Vector2 position) + { + sprite.Position = position; + return this; + } + + public TextSpriteBuilder Scale(float scale) + { + sprite.RotationOrScale = scale; + return this; + } + + public TextSpriteBuilder Color(Color color) + { + sprite.Color = color; + return this; + } + + public TextSpriteBuilder Alignment(TextAlignment alignment) + { + sprite.Alignment = alignment; + return this; + } + + public TextSprite Build() => new TextSprite(sprite); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/TextureSprite.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/TextureSprite.cs new file mode 100644 index 0000000..4280f50 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/atoms/TextureSprite.cs @@ -0,0 +1,116 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace IngameScript +{ + public class TextureSprite : SpriteLeaf + { + public float Rotation + { + get { return Sprite.RotationOrScale; } + set { Sprite.RotationOrScale = value; } + } + + public Vector2? Size + { + get { return Sprite.Size; } + set { Sprite.Size = value; } + } + + public string Texture + { + get { return Sprite.Data; } + set { Sprite.Data = value; } + } + + private TextureSprite(MySprite sprite) : base(sprite) + { + } + + public override void Scale(float scalar, Anchor anchor = null) => Scale(new Vector2(scalar, scalar), anchor); + + public override void Scale(Vector2 scalar, Anchor anchor = null) + { + var size = Sprite.Size ?? Vector2.One; + size.X *= scalar.X; + size.Y *= scalar.Y; + Sprite.Size = size; + base.Scale(scalar, anchor); + } + + public void Mirror(Anchor anchor = null) => Scale(new Vector2(-1, -1), anchor); + + public void MirrorVertical(Anchor anchor = null) => Scale(new Vector2(1, -1), anchor); + + public void MirrorHorizontal(Anchor anchor = null) => Scale(new Vector2(-1, 1), anchor); + + public override void Rotate(Angle angle, Anchor positionAnchor = null) + { + Sprite.RotationOrScale += (float)angle.Radians; + base.Rotate(angle, positionAnchor); + } + + public override Sprite Clone() => new TextureSprite(Sprite); + + + public class TextureSpriteBuilder + { + private MySprite sprite = new MySprite(type: SpriteType.TEXTURE); + + public TextureSpriteBuilder Texture(string path) + { + sprite.Data = path; + return this; + } + + public TextureSpriteBuilder Position(float x, float y) => Position(new Vector2(x, y)); + + public TextureSpriteBuilder Position(Vector2 position) + { + sprite.Position = position; + return this; + } + + public TextureSpriteBuilder Rotation(Angle rotation) + { + sprite.RotationOrScale = (float)rotation.Radians; + return this; + } + + public TextureSpriteBuilder Size(float width, float height) => Size(new Vector2(width, height)); + + public TextureSpriteBuilder Size(Vector2 size) + { + sprite.Size = size; + return this; + } + + public TextureSpriteBuilder Color(Color color) + { + sprite.Color = color; + return this; + } + + public TextureSpriteBuilder Alignment(TextAlignment alignment) + { + sprite.Alignment = alignment; + return this; + } + + public TextureSprite Build() => new TextureSprite(sprite); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/molecules/SimpleSpriteGroup.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/molecules/SimpleSpriteGroup.cs new file mode 100644 index 0000000..ef292d9 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src/sprite/molecules/SimpleSpriteGroup.cs @@ -0,0 +1,32 @@ +/* Copyright (c) 2026 Lelebees + This file is part of Sprite Composer. + + Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, + either version 3 of the License, or (at your option) any later version. + + Sprite Composer 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with Sprite Composer. + If not, see . */ + +using System.Collections.Generic; +using System.Linq; + +namespace IngameScript +{ + public class SimpleSpriteGroup : SpriteGroup + { + private readonly List children; + + public SimpleSpriteGroup(List children) + { + this.children = children; + } + + public override Sprite Clone() => new SimpleSpriteGroup(children.Select(sprite => sprite.Clone()).ToList()); + + protected override List GetChildren() => children; + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/.gitignore b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/.gitignore new file mode 100644 index 0000000..5fb0452 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/.gitignore @@ -0,0 +1 @@ +mdk.local.ini \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Instructions.readme b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Instructions.readme new file mode 100644 index 0000000..0b5aa2b --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Instructions.readme @@ -0,0 +1,2 @@ +This program uses SpriteComposer, which is licensed under the GNU LGPL 3.0 or later. You can find the source code and a copy of the license at +Copies of the license are also available at diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Program.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Program.cs new file mode 100644 index 0000000..76873da --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Program.cs @@ -0,0 +1,121 @@ +using Sandbox.Game.EntityComponents; +using Sandbox.ModAPI.Ingame; +using Sandbox.ModAPI.Interfaces; +using SpaceEngineers.Game.ModAPI.Ingame; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using VRage; +using VRage.Collections; +using VRage.Game; +using VRage.Game.Components; +using VRage.Game.GUI.TextPanel; +using VRage.Game.ModAPI.Ingame; +using VRage.Game.ModAPI.Ingame.Utilities; +using VRage.Game.ObjectBuilders.Definitions; +using VRageMath; + +namespace IngameScript +{ + public partial class Program : MyGridProgram + { + private readonly IMyTextSurface surface; + private readonly Sprite sunSprite; + private readonly Sprite textGroup; + private readonly RectangleF viewport; + + public Program() + { + // We prepare a screen like normal + surface = Me.GetSurface(0); + surface.ContentType = ContentType.SCRIPT; + surface.Script = ""; + viewport = new RectangleF( + (surface.TextureSize - surface.SurfaceSize) / 2f, + surface.SurfaceSize + ); + + Runtime.UpdateFrequency = UpdateFrequency.Update10; + // You can create basic sprites using the Sprites class. The Textures class contains texture name constants for basic shapes, for your writing convenience. + var sunRayMiddle = Sprites.WithTexture(Textures.SquareSimple) + .Size(20, 5) + .Build(); + var sunRayCapRight = Sprites.WithTexture(Textures.SemiCircle) + .Size(5, 20) + // Rotations are performed using the Angle struct. Here we're using a predefined right angle (90 degrees, or 0.5 * PI) + // You'll see how to create an arbitrary angle a little later in this demo. + .Rotation(Angle.Right) + .Position(9, 0) + .Build(); + // You can copy a sprite you made earlier and apply different operations to it + TextureSprite sunRayCapLeft = (TextureSprite) sunRayCapRight.Clone(); + // You can mirror texture sprites by calling the Mirror(), MirrorHorizontal() or MirrorVertical() functions on them. + // By passing an anchor, the sprite will also move to the other side of that anchor. + sunRayCapLeft.Mirror(sunRayMiddle); + // Mirroring is functionally equivalent to calling the Scale() function with -1 for the x, y or both axes. + // You'll see a Scale() invocation later in this demo + + // It's possible to group sprites and treat them as if they were one. + var sunRay = Sprites.Group(sunRayCapLeft, sunRayMiddle, sunRayCapRight); + sunRay.Translate(50, 0); + + TextureSprite sunBody = Sprites.WithTexture(Textures.Circle) + .Size(50, 50) + .Build(); + + // Since I don't feel like repeating the above steps for every sun ray, you can easily clone sprites in a circle! + var allRays = Sprites.RepeatRotated(sunRay, 12, sunBody).ToList(); + // You can create, adjust and add sprites after a group has been made by keeping a reference to a list of the group's sprites + sunSprite = new SimpleSpriteGroup(allRays); + /* If this simple sprite group doesn't fulfill your needs, + you can create your own implementation by extending the SpriteGroup abstract class. + If you do, you must implement two methods: Clone() and GetChildren(). + The first method is expected to create a deep copy of the group. + The second method expects to get a list of all sprites that make up the group. (not copies) + This allows the parent class to apply operations such as rotations or translations without needing to know how the sprites are managed by you. + If you need even more control over the group, you should create your own class that implements the Sprite interface. + Which allows you to override the existing transformation functions, and will likely be more performant than extending the existing SpriteGroup class. */ + allRays.Add(sunBody); + sunSprite.SetColor(Color.Yellow); + + var praiseText = Sprites.WithText("Praise") + .FontId("White") + .Position(0, -150) + .Build(); + /* Any sprite can be rotated using the following syntax. + Specifying an anchor point will rotate the sprite around that point, in addition to rotating the sprite itself. + Text can also be rotated around an anchor point, but beware! SE does not support rotating the text itself. + This will therefore not create slanted text! */ + praiseText.Rotate(Angle.FromDegrees(-45), sunSprite); + + var theSunText = Sprites.WithText("the sun") + .FontId("White") + .Position(0, 125) + .Build(); + // Though we don't do it here, you can also use an arbitrary point in space as the anchor by creating a new PointAnchor(). + theSunText.Rotate(Angle.FromDegrees(-50), sunSprite); + textGroup = Sprites.Group(praiseText, theSunText); + // You can also set an initial scale for text using the builder. + // However, here we want to scale the distance the text has to the sun, so we supply the sun as the anchor for the scale operation. + textGroup.Scale(1.5f, sunSprite); + // Any new operations will be applied to the newly grouped sprites as well, but previous operations will not be applied. + sunSprite.Scale(2f); + // It's also possible to scale X and Y separately. + } + + public void Main(string argument, UpdateType updateSource) + { + textGroup.SetColor(surface.ScriptForegroundColor); + var frame = surface.DrawFrame(); + // To simplify use, you can move the Sprite(s) so that 0,0 is the center of the viewport. + frame.AddRange(sunSprite.AsDrawableCollection(viewport)); + frame.AddRange(textGroup.AsDrawableCollection(viewport)); + frame.Dispose(); + // We can animate our sprite by applying transformations during runtime! + sunSprite.Rotate(Angle.FromDegrees(1)); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/SpriteCompositor.Demo.csproj b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/SpriteCompositor.Demo.csproj new file mode 100644 index 0000000..d5606e6 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/SpriteCompositor.Demo.csproj @@ -0,0 +1,31 @@ + + + + netframework48 + IngameScript + 6 + false + Release;Debug + x64 + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/mdk.ini b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/mdk.ini new file mode 100644 index 0000000..bd9cf79 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/mdk.ini @@ -0,0 +1,35 @@ +; This file is project specific and should be checked in to source control. + +[mdk] +; This is a programmable block script project. +; You should not change this. +type=programmableblock + +; Toggle trace (on|off) (verbose output) +trace=off + +; What type of minification to use (none|trim|stripcomments|lite|full) +; none: No minification +; trim: Removes unused types (NOT members). +; stripcomments: trim + removes comments. +; lite: stripcomments + removes leading/trailing whitespace. +; full: lite + renames identifiers to shorter names. +minify=trim + +; Extra options for minification. +; none: No extra options. +; nomembertrimming: Disables member trimming in the 'trim' processor (legacy mode). +minifyextraoptions=none + +; A list of files and folder to ignore when creating the script. +; This is a comma separated list of glob patterns. +; See https://code.visualstudio.com/docs/editor/glob-patterns +ignores=obj/**/*,MDK/**/*,**/*.debug.cs + +; A list of allowed namespaces. All ingame script code should be within one of these namespaces. +; This is a comma separated list. +; +; WARNING: The programmable block strips all namespaces from the final script. +; If you have two types with the same name in different namespaces, there will be a conflict. +; It's recommended to keep all your script code in a single namespace to avoid issues. +namespaces=IngameScript diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/thumb.png b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/thumb.png new file mode 100644 index 0000000..cf36539 Binary files /dev/null and b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/thumb.png differ diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/.gitignore b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/.gitignore new file mode 100644 index 0000000..5fb0452 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/.gitignore @@ -0,0 +1 @@ +mdk.local.ini \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/README.md b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/README.md new file mode 100644 index 0000000..bd75d6d --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/README.md @@ -0,0 +1,9 @@ +# Getting Started + +Before doing anything: +- Add a reference to the script project you want to test. +- Make sure your Program class is `public`. + +This test project will neither compile nor run properly if you don't do this. + +Take a look in Tests/InstancingTests.cs for some simple examples of how to write tests. \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/SpriteCompositor.Test.csproj b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/SpriteCompositor.Test.csproj new file mode 100644 index 0000000..b0862b7 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/SpriteCompositor.Test.csproj @@ -0,0 +1,21 @@ + + + net48 + true + Release;Debug + x64 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/TestUtilities/ProgramBuilder.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/TestUtilities/ProgramBuilder.cs new file mode 100644 index 0000000..ef082fa --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/TestUtilities/ProgramBuilder.cs @@ -0,0 +1,171 @@ +using System; +using System.Runtime.Serialization; +using FakeItEasy; +using Sandbox.ModAPI.Ingame; + +namespace SpriteCompositor.Test.TestUtilities +{ + /// + /// Provides utility methods for setting up and testing Space Engineers' programmable block scripts. + /// + public static class Gateway + { + /// + /// Sets the storage value for a given program instance. + /// + /// A type that implements . + /// The program instance. + /// The storage string to set. + public static void SetStorage(this T program, string storage) + where T : Sandbox.ModAPI.IMyGridProgram + { + program.Storage = storage; + } + + /// + /// Creates a new to construct an instance of a Space Engineers script. + /// + /// The script type, which must inherit from . + /// A instance for configuring and constructing the script. + /// + /// This method utilizes the builder pattern to allow gradual configuration of the script before instantiation. + /// The builder ensures all necessary dependencies are set up for proper execution in a test environment. + /// + /// + /// The following example demonstrates how to create an instance of a script with specific dependencies: + /// + /// var program = Gateway.CreateProgram<MyScript>() + /// .WithGridTerminalSystem(myGridSystem) + /// .WithRuntime(myRuntime) + /// .WithEcho(Console.WriteLine) + /// .Build(); + /// + /// + public static ProgramBuilder CreateProgram() + where T : MyGridProgram, new() + { + return new ProgramBuilder(null, null, null, null, null, null); + } + + /// + /// A builder for constructing instances of Space Engineers scripts with specific dependencies. + /// + /// The script type, which must inherit from . + /// + /// The builder pattern is used to allow flexible configuration of dependencies before final instantiation. + /// Each method (e.g., , ) returns a new builder instance + /// with the specified dependency, ensuring immutability. + /// + /// The `Build` method finalizes the construction, initializing the script with the provided dependencies. + /// + public readonly struct ProgramBuilder where T : MyGridProgram, new() + { + /// + /// Builds the final instance of the script with the configured dependencies. + /// + /// An initialized instance of type . + /// Thrown if the script type or instance fails to be created. + public T Build() + { + // Create an uninitialized instance (bypasses constructor) + var program = FormatterServices.GetUninitializedObject(typeof(T)); + + // Ensure a parameterless constructor exists + var constructor = typeof(T).GetConstructor(Type.EmptyTypes); + if (constructor == null) + throw new InvalidOperationException("No parameterless constructor found."); + + if (!(program is Sandbox.ModAPI.IMyGridProgram backend)) + throw new InvalidOperationException("No IMyGridProgram interface found."); + + // Assign dependencies + backend.Runtime = GetRuntime(); + backend.Echo = GetEcho(); + backend.Me = GetMe(); + backend.Storage = GetStorage(); + backend.GridTerminalSystem = GetGridTerminalSystem(); + backend.IGC_ContextGetter = GetIgcContextGetter(); + + // Run constructor + constructor.Invoke(program, null); + return (T)program; + } + + private readonly IMyIntergridCommunicationSystem _igc; + private readonly IMyGridTerminalSystem _gridTerminalSystem; + private readonly IMyGridProgramRuntimeInfo _runtime; + private readonly IMyProgrammableBlock _me; + private readonly Action _echo; + private readonly string _storage; + + /// + /// Initializes a new builder instance with optional dependencies. + /// + public ProgramBuilder(IMyIntergridCommunicationSystem igc, IMyGridTerminalSystem gridTerminalSystem, + IMyGridProgramRuntimeInfo runtime, IMyProgrammableBlock me, Action echo, string storage) + { + _igc = igc; + _gridTerminalSystem = gridTerminalSystem; + _runtime = runtime; + _me = me; + _echo = echo; + _storage = storage; + } + + /// + /// Specifies a custom Inter-Grid Communication (IGC) system. + /// + public ProgramBuilder WithIgc(IMyIntergridCommunicationSystem igc) => + new ProgramBuilder(igc, _gridTerminalSystem, _runtime, _me, _echo, _storage); + + /// + /// Specifies a custom Grid Terminal System. + /// + public ProgramBuilder WithGridTerminalSystem(IMyGridTerminalSystem gridTerminalSystem) => + new ProgramBuilder(_igc, gridTerminalSystem, _runtime, _me, _echo, _storage); + + /// + /// Specifies a custom runtime environment. + /// + public ProgramBuilder WithRuntime(IMyGridProgramRuntimeInfo runtime) => + new ProgramBuilder(_igc, _gridTerminalSystem, runtime, _me, _echo, _storage); + + /// + /// Specifies a custom programmable block reference. + /// + public ProgramBuilder WithMe(IMyProgrammableBlock me) => + new ProgramBuilder(_igc, _gridTerminalSystem, _runtime, me, _echo, _storage); + + /// + /// Specifies a custom echo function. + /// + public ProgramBuilder WithEcho(Action echo) => + new ProgramBuilder(_igc, _gridTerminalSystem, _runtime, _me, echo, _storage); + + /// + /// Specifies custom storage data. + /// + public ProgramBuilder WithStorage(string storage) => + new ProgramBuilder(_igc, _gridTerminalSystem, _runtime, _me, _echo, storage); + + private Func GetIgcContextGetter() + { + var igc = _igc ?? A.Fake(o => o.Strict()); + return () => igc; + } + + private IMyGridTerminalSystem GetGridTerminalSystem() => + _gridTerminalSystem ?? A.Fake(o => o.Strict()); + + private string GetStorage() => _storage ?? string.Empty; + + private IMyProgrammableBlock GetMe() => + _me ?? A.Fake(o => o.Strict()); + + private Action GetEcho() => _echo ?? Console.WriteLine; + + private IMyGridProgramRuntimeInfo GetRuntime() => + _runtime ?? A.Fake(o => o.Strict()); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/SpriteGroupTest.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/SpriteGroupTest.cs new file mode 100644 index 0000000..e206985 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/SpriteGroupTest.cs @@ -0,0 +1,70 @@ +using FakeItEasy; +using IngameScript; +using NUnit.Framework; + +namespace SpriteCompositor.Test +{ + [TestFixture] + public class SpriteGroupTest + { + [Test] + public void RotateShouldPassNonNullAnchorToChildren() + { + var child1 = A.Fake(); + var child2 = A.Fake(); + + Anchor capturedAnchor1 = null; + Anchor capturedAnchor2 = null; + + A.CallTo(() => child1.Rotate(A._, A._)) + .Invokes((Angle _, Anchor anchor) => capturedAnchor1 = anchor); + + A.CallTo(() => child2.Rotate(A._, A._)) + .Invokes((Angle _, Anchor anchor) => capturedAnchor2 = anchor); + + var group = Sprites.Group(child1, child2); + + + group.Rotate(Angle.Right); + + Assert.That(capturedAnchor1, Is.Not.Null); + Assert.That(capturedAnchor2, Is.Not.Null); + + A.CallTo(() => child1.Rotate(A._, A._)) + .MustHaveHappenedOnceExactly(); + + A.CallTo(() => child2.Rotate(A._, A._)) + .MustHaveHappenedOnceExactly(); + } + + [Test] + public void RotateShouldNotPassSelfAsAnchor() + { + var child1 = A.Fake(); + var child2 = A.Fake(); + + Anchor capturedAnchor1 = null; + Anchor capturedAnchor2 = null; + + A.CallTo(() => child1.Rotate(A._, A._)) + .Invokes((Angle _, Anchor anchor) => capturedAnchor1 = anchor); + + A.CallTo(() => child2.Rotate(A._, A._)) + .Invokes((Angle _, Anchor anchor) => capturedAnchor2 = anchor); + + var group = Sprites.Group(child1, child2); + + + group.Rotate(Angle.Right); + + Assert.That(capturedAnchor1, Is.Not.EqualTo(group)); + Assert.That(capturedAnchor2, Is.Not.EqualTo(group)); + + A.CallTo(() => child1.Rotate(A._, A._)) + .MustHaveHappenedOnceExactly(); + + A.CallTo(() => child2.Rotate(A._, A._)) + .MustHaveHappenedOnceExactly(); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/angle/AngleTest.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/angle/AngleTest.cs new file mode 100644 index 0000000..529b24d --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/angle/AngleTest.cs @@ -0,0 +1,23 @@ +using System; +using IngameScript; +using NUnit.Framework; + +namespace SpriteCompositor.Test.angle +{ + [TestFixture] + public class AngleTest + { + private const double Precision = 0.000000000000000000000000001; + + [TestCase(360, 2 * Math.PI)] + [TestCase(90, 0.5 * Math.PI)] + [TestCase(180, Math.PI)] + [TestCase(270, 1.5 * Math.PI)] + [TestCase(1800, 0)] + [TestCase(0, 0)] + public void DegreesConvertProperly(double degrees, double radians) + { + Assert.That(Angle.FromDegrees(degrees).Radians, Is.InRange(radians - Precision, radians + Precision)); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/SpritesTest.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/SpritesTest.cs new file mode 100644 index 0000000..42f4a1d --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/SpritesTest.cs @@ -0,0 +1,25 @@ +using IngameScript; +using NUnit.Framework; + +namespace SpriteCompositor.Test.sprite +{ + [TestFixture] + public class SpritesTest + { + [TestCase((uint) 10)] + [TestCase((uint) 1)] + [TestCase((uint) 0)] + public void SpritesRepeatCorrectAmountOfTimes(uint repetitions) + { + Assert.That(Sprites.RepeatRotated(Sprites.WithTexture("SquareSimple").Build(), repetitions).Length, Is.EqualTo((int) repetitions)); + } + + [TestCase((uint) 10)] + [TestCase((uint) 1)] + [TestCase((uint) 0)] + public void SpritesWithRotationRepeatCorrectAmountOfTimes(uint repetitions) + { + Assert.That(Sprites.RepeatRotated(Sprites.WithTexture("SquareSimple").Build(), repetitions, Angle.Right).Length, Is.EqualTo((int) repetitions)); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/atoms/TextSpriteTest.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/atoms/TextSpriteTest.cs new file mode 100644 index 0000000..a95eadc --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/atoms/TextSpriteTest.cs @@ -0,0 +1,93 @@ +using System; +using IngameScript; +using NUnit.Framework; +using VRage.Game.GUI.TextPanel; +using VRageMath; +namespace SpriteCompositor.Test.sprite.atoms +{ + [TestFixture] + public class TextSpriteTest + { + private const double Precision = 0.001; + + [TestCase(1, 1)] + [TestCase(0, 0)] + [TestCase(-1, 1)] + [TestCase(1, -1)] + [TestCase(-1, -1)] + public void CanTranslate(float x, float y) + { + Vector2 translation = new Vector2(x, y); + TextSprite sprite = Sprites.WithText("Test").Build(); + sprite.Translate(translation); + Assert.That(sprite.GetPosition(), Is.EqualTo(translation)); + } + + [TestCase(0,0,Math.PI)] + [TestCase(1, 1, 0)] + [TestCase(1, 1, Math.PI)] + [TestCase(1, 1, Math.PI / 2)] + [TestCase(1, 1, -Math.PI / 2)] + [TestCase(5, 0, Math.PI)] + [TestCase(0, 5, Math.PI / 2)] + [TestCase(-3, 4, Math.PI / 4)] + [TestCase(10, -10, Math.PI * 2)] + [TestCase(-7.5f, 2.25f, Math.PI * 1.5)] + [TestCase(0.001f, 0.001f, Math.PI / 6)] + [TestCase(1000, 1000, Math.PI / 3)] + // This Case fails. This is okay in my opinion because the size of the screen will probably never exceed 1000 pixels. (The current largest screen is 512x512), + // and if so, KSH can start using doubles. + // [TestCase(float.MaxValue / 1000, float.MaxValue / 1000, Math.PI / 8)] + public void RotationAroundAnchorMaintainsCorrectDistance(float x, float y, double radians) + { + Vector2 offset = new Vector2(x, y); + TextSprite sprite = Sprites.WithText("Test").Position(offset).Build(); + sprite.Rotate(Angle.FromRadians(radians), new PointAnchor(0, 0)); + Assert.That(sprite.Position.Value.Length(), Is.EqualTo(offset.Length()).Within(Precision)); + } + + [TestCase(0, 0, 5, 5)] + [TestCase(1, 1, 2, 2)] + [TestCase(-1, -1, 2, 2)] + [TestCase(10, 20, 0.5f, 0.5f)] + [TestCase(3, 4, -1, 1)] + [TestCase(3, 4, 1, -1)] + [TestCase(3, 4, -1, -1)] + [TestCase(100, 200, 10, 10)] + [TestCase(0.001f, 0.001f, 1000, 1000)] + [TestCase(50, -25, 1.5f, 2.5f)] + [TestCase(-50, 25, 1.5f, -2.5f)] + [TestCase(5, 10, 0, 1)] + [TestCase(5, 10, 1, 0)] + [TestCase(5, 10, 0, 0)] + [TestCase(float.MaxValue / 1000, float.MaxValue / 1000, 0.5f, 0.5f)] + public void ScalingPositionsCorrectly(float x, float y, float scaleX, float scaleY) + { + TextSprite sprite = Sprites.WithText("Test").Position(x,y).Build(); + sprite.Scale(new Vector2(scaleX, scaleY), new PointAnchor(0, 0)); + Assert.That(sprite.GetPosition().X, Is.EqualTo(x * scaleX).Within(Precision)); + Assert.That(sprite.GetPosition().Y, Is.EqualTo(y * scaleY).Within(Precision)); + } + + [Test] + public void ClonesCantPropagateChanges() + { + TextSprite sprite1 = Sprites.WithText("Test").Build(); + Sprite sprite2 = sprite1.Clone(); + Assert.That(sprite1, Is.Not.EqualTo(sprite2)); + } + + [Test] + public void RenderableDoesNotPropagateChanges() + { + var sprite = Sprites.WithText("Wow").Build(); + var mySprite = sprite.AsDrawableCollection()[0]; + mySprite.Alignment = TextAlignment.RIGHT; + mySprite.Color = Color.Red; + mySprite.Data = "Circle"; + mySprite.RotationOrScale = 99f; + var newDrawable = sprite.AsDrawableCollection()[0]; + Assert.That(newDrawable, Is.Not.EqualTo(mySprite)); + } + } +} \ No newline at end of file diff --git a/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/atoms/TextureSpriteTest.cs b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/atoms/TextureSpriteTest.cs new file mode 100644 index 0000000..ce75959 --- /dev/null +++ b/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test/src/sprite/atoms/TextureSpriteTest.cs @@ -0,0 +1,124 @@ +using System; +using System.Linq; +using IngameScript; +using NUnit.Framework; +using VRage.Game.GUI.TextPanel; +using VRageMath; + +namespace SpriteCompositor.Test.sprite.atoms +{ + [TestFixture] + public class TextureSpriteTest + { + private const double Precision = 0.001; + + [TestCase(0.5 * Math.PI)] + [TestCase(Math.PI)] + [TestCase(0.25 * Math.PI)] + [TestCase(0.75 * Math.PI)] + [TestCase(1.2 * Math.PI)] + [TestCase(0.23 * Math.PI)] + [TestCase(1.93 * Math.PI)] + [TestCase(43 * Math.PI)] + [TestCase(0)] + [TestCase(-1 * Math.PI)] + [TestCase(-1)] + [TestCase(1)] + [TestCase(1, 69, 420)] + [TestCase(0.25 * Math.PI, 0.75 * Math.PI)] + public void ArbitraryRotationsSetCorrectRotation(params double[] radians) + { + Angle[] angles = radians.Select(Angle.FromRadians).ToArray(); + TextureSprite sprite = Sprites.WithTexture(Textures.SquareSimple).Build(); + foreach (var angle in angles) + { + sprite.Rotate(angle); + } + + // Note here (and this is not obvious) that unlike the angle struct, a sprite's rotation value can grow indefinitely + // This means that values above and below 2 * Math.PI are possible. The test keeps this in mind. + var totalAngle = angles.Sum(angle => angle.Radians); + Assert.That(sprite.Rotation, Is.EqualTo(totalAngle).Within(Precision)); + } + + [TestCase(1, 1)] + [TestCase(0, 0)] + [TestCase(-1, 1)] + [TestCase(1, -1)] + [TestCase(-1, -1)] + public void CanTranslate(float x, float y) + { + Vector2 translation = new Vector2(x, y); + TextureSprite sprite = Sprites.WithTexture(Textures.SquareSimple).Build(); + sprite.Translate(translation); + Assert.That(sprite.GetPosition(), Is.EqualTo(translation)); + } + + [TestCase(0,0,Math.PI)] + [TestCase(1, 1, 0)] + [TestCase(1, 1, Math.PI)] + [TestCase(1, 1, Math.PI / 2)] + [TestCase(1, 1, -Math.PI / 2)] + [TestCase(5, 0, Math.PI)] + [TestCase(0, 5, Math.PI / 2)] + [TestCase(-3, 4, Math.PI / 4)] + [TestCase(10, -10, Math.PI * 2)] + [TestCase(-7.5f, 2.25f, Math.PI * 1.5)] + [TestCase(0.001f, 0.001f, Math.PI / 6)] + [TestCase(1000, 1000, Math.PI / 3)] + // This Case fails. This is okay in my opinion because the size of the screen will probably never exceed 1000 pixels. (The current largest screen is 512x512), + // and if so, KSH can start using doubles. + // [TestCase(float.MaxValue / 1000, float.MaxValue / 1000, Math.PI / 8)] + public void RotationAroundAnchorMaintainsCorrectDistance(float x, float y, double radians) + { + Vector2 offset = new Vector2(x, y); + TextureSprite sprite = Sprites.WithTexture(Textures.SquareSimple).Position(offset).Build(); + sprite.Rotate(Angle.FromRadians(radians), new PointAnchor(0, 0)); + Assert.That(sprite.Position.Value.Length(), Is.EqualTo(offset.Length()).Within(Precision)); + } + + [TestCase(0, 0, 5, 5)] + [TestCase(1, 1, 2, 2)] + [TestCase(-1, -1, 2, 2)] + [TestCase(10, 20, 0.5f, 0.5f)] + [TestCase(3, 4, -1, 1)] + [TestCase(3, 4, 1, -1)] + [TestCase(3, 4, -1, -1)] + [TestCase(100, 200, 10, 10)] + [TestCase(0.001f, 0.001f, 1000, 1000)] + [TestCase(50, -25, 1.5f, 2.5f)] + [TestCase(-50, 25, 1.5f, -2.5f)] + [TestCase(5, 10, 0, 1)] + [TestCase(5, 10, 1, 0)] + [TestCase(5, 10, 0, 0)] + [TestCase(float.MaxValue / 1000, float.MaxValue / 1000, 0.5f, 0.5f)] + public void ScalingPositionsCorrectly(float x, float y, float scaleX, float scaleY) + { + TextureSprite sprite = Sprites.WithTexture(Textures.SquareSimple).Position(x,y).Build(); + sprite.Scale(new Vector2(scaleX, scaleY), new PointAnchor(0, 0)); + Assert.That(sprite.GetPosition().X, Is.EqualTo(x * scaleX).Within(Precision)); + Assert.That(sprite.GetPosition().Y, Is.EqualTo(y * scaleY).Within(Precision)); + } + + [Test] + public void ClonesCantPropagateChanges() + { + TextureSprite sprite1 = Sprites.WithTexture(Textures.SquareSimple).Build(); + Sprite sprite2 = sprite1.Clone(); + Assert.That(sprite1, Is.Not.EqualTo(sprite2)); + } + + [Test] + public void RenderableDoesNotPropagateChanges() + { + var sprite = Sprites.WithTexture("SquareSimple").Build(); + var mySprite = sprite.AsDrawableCollection()[0]; + mySprite.Alignment = TextAlignment.RIGHT; + mySprite.Color = Color.Red; + mySprite.Data = "Circle"; + mySprite.RotationOrScale = 99f; + var newDrawable = sprite.AsDrawableCollection()[0]; + Assert.That(newDrawable, Is.Not.EqualTo(mySprite)); + } + } +} \ No newline at end of file