[
  {
    "path": ".gitignore",
    "content": ".DS_Store"
  },
  {
    "path": "LICENSE",
    "content": "Attribution 4.0 International\n\n=======================================================================\n\nCreative Commons Corporation (\"Creative Commons\") is not a law firm and\ndoes not provide legal services or legal advice. Distribution of\nCreative Commons public licenses does not create a lawyer-client or\nother relationship. Creative Commons makes its licenses and related\ninformation available on an \"as-is\" basis. Creative Commons gives no\nwarranties regarding its licenses, any material licensed under their\nterms and conditions, or any related information. Creative Commons\ndisclaims all liability for damages resulting from their use to the\nfullest extent possible.\n\nUsing Creative Commons Public Licenses\n\nCreative Commons public licenses provide a standard set of terms and\nconditions that creators and other rights holders may use to share\noriginal works of authorship and other material subject to copyright\nand certain other rights specified in the public license below. The\nfollowing considerations are for informational purposes only, are not\nexhaustive, and do not form part of our licenses.\n\n     Considerations for licensors: Our public licenses are\n     intended for use by those authorized to give the public\n     permission to use material in ways otherwise restricted by\n     copyright and certain other rights. Our licenses are\n     irrevocable. Licensors should read and understand the terms\n     and conditions of the license they choose before applying it.\n     Licensors should also secure all rights necessary before\n     applying our licenses so that the public can reuse the\n     material as expected. Licensors should clearly mark any\n     material not subject to the license. This includes other CC-\n     licensed material, or material used under an exception or\n     limitation to copyright. More considerations for licensors:\n     wiki.creativecommons.org/Considerations_for_licensors\n\n     Considerations for the public: By using one of our public\n     licenses, a licensor grants the public permission to use the\n     licensed material under specified terms and conditions. If\n     the licensor's permission is not necessary for any reason--for\n     example, because of any applicable exception or limitation to\n     copyright--then that use is not regulated by the license. Our\n     licenses grant only permissions under copyright and certain\n     other rights that a licensor has authority to grant. Use of\n     the licensed material may still be restricted for other\n     reasons, including because others have copyright or other\n     rights in the material. A licensor may make special requests,\n     such as asking that all changes be marked or described.\n     Although not required by our licenses, you are encouraged to\n     respect those requests where reasonable. More considerations\n     for the public:\n     wiki.creativecommons.org/Considerations_for_licensees\n\n=======================================================================\n\nCreative Commons Attribution 4.0 International Public License\n\nBy exercising the Licensed Rights (defined below), You accept and agree\nto be bound by the terms and conditions of this Creative Commons\nAttribution 4.0 International Public License (\"Public License\"). To the\nextent this Public License may be interpreted as a contract, You are\ngranted the Licensed Rights in consideration of Your acceptance of\nthese terms and conditions, and the Licensor grants You such rights in\nconsideration of benefits the Licensor receives from making the\nLicensed Material available under these terms and conditions.\n\n\nSection 1 -- Definitions.\n\n  a. Adapted Material means material subject to Copyright and Similar\n     Rights that is derived from or based upon the Licensed Material\n     and in which the Licensed Material is translated, altered,\n     arranged, transformed, or otherwise modified in a manner requiring\n     permission under the Copyright and Similar Rights held by the\n     Licensor. For purposes of this Public License, where the Licensed\n     Material is a musical work, performance, or sound recording,\n     Adapted Material is always produced where the Licensed Material is\n     synched in timed relation with a moving image.\n\n  b. Adapter's License means the license You apply to Your Copyright\n     and Similar Rights in Your contributions to Adapted Material in\n     accordance with the terms and conditions of this Public License.\n\n  c. Copyright and Similar Rights means copyright and/or similar rights\n     closely related to copyright including, without limitation,\n     performance, broadcast, sound recording, and Sui Generis Database\n     Rights, without regard to how the rights are labeled or\n     categorized. For purposes of this Public License, the rights\n     specified in Section 2(b)(1)-(2) are not Copyright and Similar\n     Rights.\n\n  d. Effective Technological Measures means those measures that, in the\n     absence of proper authority, may not be circumvented under laws\n     fulfilling obligations under Article 11 of the WIPO Copyright\n     Treaty adopted on December 20, 1996, and/or similar international\n     agreements.\n\n  e. Exceptions and Limitations means fair use, fair dealing, and/or\n     any other exception or limitation to Copyright and Similar Rights\n     that applies to Your use of the Licensed Material.\n\n  f. Licensed Material means the artistic or literary work, database,\n     or other material to which the Licensor applied this Public\n     License.\n\n  g. Licensed Rights means the rights granted to You subject to the\n     terms and conditions of this Public License, which are limited to\n     all Copyright and Similar Rights that apply to Your use of the\n     Licensed Material and that the Licensor has authority to license.\n\n  h. Licensor means the individual(s) or entity(ies) granting rights\n     under this Public License.\n\n  i. Share means to provide material to the public by any means or\n     process that requires permission under the Licensed Rights, such\n     as reproduction, public display, public performance, distribution,\n     dissemination, communication, or importation, and to make material\n     available to the public including in ways that members of the\n     public may access the material from a place and at a time\n     individually chosen by them.\n\n  j. Sui Generis Database Rights means rights other than copyright\n     resulting from Directive 96/9/EC of the European Parliament and of\n     the Council of 11 March 1996 on the legal protection of databases,\n     as amended and/or succeeded, as well as other essentially\n     equivalent rights anywhere in the world.\n\n  k. You means the individual or entity exercising the Licensed Rights\n     under this Public License. Your has a corresponding meaning.\n\n\nSection 2 -- Scope.\n\n  a. License grant.\n\n       1. Subject to the terms and conditions of this Public License,\n          the Licensor hereby grants You a worldwide, royalty-free,\n          non-sublicensable, non-exclusive, irrevocable license to\n          exercise the Licensed Rights in the Licensed Material to:\n\n            a. reproduce and Share the Licensed Material, in whole or\n               in part; and\n\n            b. produce, reproduce, and Share Adapted Material.\n\n       2. Exceptions and Limitations. For the avoidance of doubt, where\n          Exceptions and Limitations apply to Your use, this Public\n          License does not apply, and You do not need to comply with\n          its terms and conditions.\n\n       3. Term. The term of this Public License is specified in Section\n          6(a).\n\n       4. Media and formats; technical modifications allowed. The\n          Licensor authorizes You to exercise the Licensed Rights in\n          all media and formats whether now known or hereafter created,\n          and to make technical modifications necessary to do so. The\n          Licensor waives and/or agrees not to assert any right or\n          authority to forbid You from making technical modifications\n          necessary to exercise the Licensed Rights, including\n          technical modifications necessary to circumvent Effective\n          Technological Measures. For purposes of this Public License,\n          simply making modifications authorized by this Section 2(a)\n          (4) never produces Adapted Material.\n\n       5. Downstream recipients.\n\n            a. Offer from the Licensor -- Licensed Material. Every\n               recipient of the Licensed Material automatically\n               receives an offer from the Licensor to exercise the\n               Licensed Rights under the terms and conditions of this\n               Public License.\n\n            b. No downstream restrictions. You may not offer or impose\n               any additional or different terms or conditions on, or\n               apply any Effective Technological Measures to, the\n               Licensed Material if doing so restricts exercise of the\n               Licensed Rights by any recipient of the Licensed\n               Material.\n\n       6. No endorsement. Nothing in this Public License constitutes or\n          may be construed as permission to assert or imply that You\n          are, or that Your use of the Licensed Material is, connected\n          with, or sponsored, endorsed, or granted official status by,\n          the Licensor or others designated to receive attribution as\n          provided in Section 3(a)(1)(A)(i).\n\n  b. Other rights.\n\n       1. Moral rights, such as the right of integrity, are not\n          licensed under this Public License, nor are publicity,\n          privacy, and/or other similar personality rights; however, to\n          the extent possible, the Licensor waives and/or agrees not to\n          assert any such rights held by the Licensor to the limited\n          extent necessary to allow You to exercise the Licensed\n          Rights, but not otherwise.\n\n       2. Patent and trademark rights are not licensed under this\n          Public License.\n\n       3. To the extent possible, the Licensor waives any right to\n          collect royalties from You for the exercise of the Licensed\n          Rights, whether directly or through a collecting society\n          under any voluntary or waivable statutory or compulsory\n          licensing scheme. In all other cases the Licensor expressly\n          reserves any right to collect such royalties.\n\n\nSection 3 -- License Conditions.\n\nYour exercise of the Licensed Rights is expressly made subject to the\nfollowing conditions.\n\n  a. Attribution.\n\n       1. If You Share the Licensed Material (including in modified\n          form), You must:\n\n            a. retain the following if it is supplied by the Licensor\n               with the Licensed Material:\n\n                 i. identification of the creator(s) of the Licensed\n                    Material and any others designated to receive\n                    attribution, in any reasonable manner requested by\n                    the Licensor (including by pseudonym if\n                    designated);\n\n                ii. a copyright notice;\n\n               iii. a notice that refers to this Public License;\n\n                iv. a notice that refers to the disclaimer of\n                    warranties;\n\n                 v. a URI or hyperlink to the Licensed Material to the\n                    extent reasonably practicable;\n\n            b. indicate if You modified the Licensed Material and\n               retain an indication of any previous modifications; and\n\n            c. indicate the Licensed Material is licensed under this\n               Public License, and include the text of, or the URI or\n               hyperlink to, this Public License.\n\n       2. You may satisfy the conditions in Section 3(a)(1) in any\n          reasonable manner based on the medium, means, and context in\n          which You Share the Licensed Material. For example, it may be\n          reasonable to satisfy the conditions by providing a URI or\n          hyperlink to a resource that includes the required\n          information.\n\n       3. If requested by the Licensor, You must remove any of the\n          information required by Section 3(a)(1)(A) to the extent\n          reasonably practicable.\n\n       4. If You Share Adapted Material You produce, the Adapter's\n          License You apply must not prevent recipients of the Adapted\n          Material from complying with this Public License.\n\n\nSection 4 -- Sui Generis Database Rights.\n\nWhere the Licensed Rights include Sui Generis Database Rights that\napply to Your use of the Licensed Material:\n\n  a. for the avoidance of doubt, Section 2(a)(1) grants You the right\n     to extract, reuse, reproduce, and Share all or a substantial\n     portion of the contents of the database;\n\n  b. if You include all or a substantial portion of the database\n     contents in a database in which You have Sui Generis Database\n     Rights, then the database in which You have Sui Generis Database\n     Rights (but not its individual contents) is Adapted Material; and\n\n  c. You must comply with the conditions in Section 3(a) if You Share\n     all or a substantial portion of the contents of the database.\n\nFor the avoidance of doubt, this Section 4 supplements and does not\nreplace Your obligations under this Public License where the Licensed\nRights include other Copyright and Similar Rights.\n\n\nSection 5 -- Disclaimer of Warranties and Limitation of Liability.\n\n  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE\n     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS\n     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF\n     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,\n     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,\n     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR\n     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,\n     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT\n     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT\n     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.\n\n  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE\n     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,\n     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,\n     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,\n     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR\n     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN\n     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR\n     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR\n     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.\n\n  c. The disclaimer of warranties and limitation of liability provided\n     above shall be interpreted in a manner that, to the extent\n     possible, most closely approximates an absolute disclaimer and\n     waiver of all liability.\n\n\nSection 6 -- Term and Termination.\n\n  a. This Public License applies for the term of the Copyright and\n     Similar Rights licensed here. However, if You fail to comply with\n     this Public License, then Your rights under this Public License\n     terminate automatically.\n\n  b. Where Your right to use the Licensed Material has terminated under\n     Section 6(a), it reinstates:\n\n       1. automatically as of the date the violation is cured, provided\n          it is cured within 30 days of Your discovery of the\n          violation; or\n\n       2. upon express reinstatement by the Licensor.\n\n     For the avoidance of doubt, this Section 6(b) does not affect any\n     right the Licensor may have to seek remedies for Your violations\n     of this Public License.\n\n  c. For the avoidance of doubt, the Licensor may also offer the\n     Licensed Material under separate terms or conditions or stop\n     distributing the Licensed Material at any time; however, doing so\n     will not terminate this Public License.\n\n  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public\n     License.\n\n\nSection 7 -- Other Terms and Conditions.\n\n  a. The Licensor shall not be bound by any additional or different\n     terms or conditions communicated by You unless expressly agreed.\n\n  b. Any arrangements, understandings, or agreements regarding the\n     Licensed Material not stated herein are separate from and\n     independent of the terms and conditions of this Public License.\n\n\nSection 8 -- Interpretation.\n\n  a. For the avoidance of doubt, this Public License does not, and\n     shall not be interpreted to, reduce, limit, restrict, or impose\n     conditions on any use of the Licensed Material that could lawfully\n     be made without permission under this Public License.\n\n  b. To the extent possible, if any provision of this Public License is\n     deemed unenforceable, it shall be automatically reformed to the\n     minimum extent necessary to make it enforceable. If the provision\n     cannot be reformed, it shall be severed from this Public License\n     without affecting the enforceability of the remaining terms and\n     conditions.\n\n  c. No term or condition of this Public License will be waived and no\n     failure to comply consented to unless expressly agreed to by the\n     Licensor.\n\n  d. Nothing in this Public License constitutes or may be interpreted\n     as a limitation upon, or waiver of, any privileges and immunities\n     that apply to the Licensor or You, including from the legal\n     processes of any jurisdiction or authority.\n\n\n=======================================================================\n\nCreative Commons is not a party to its public licenses.\nNotwithstanding, Creative Commons may elect to apply one of its public\nlicenses to material it publishes and in those instances will be\nconsidered the “Licensor.” The text of the Creative Commons public\nlicenses is dedicated to the public domain under the CC0 Public Domain\nDedication. Except for the limited purpose of indicating that material\nis shared under a Creative Commons public license or as otherwise\npermitted by the Creative Commons policies published at\ncreativecommons.org/policies, Creative Commons does not authorize the\nuse of the trademark \"Creative Commons\" or any other trademark or logo\nof Creative Commons without its prior written consent including,\nwithout limitation, in connection with any unauthorized modifications\nto any of its public licenses or any other arrangements,\nunderstandings, or agreements concerning use of licensed material. For\nthe avoidance of doubt, this paragraph does not form part of the public\nlicenses.\n\nCreative Commons may be contacted at creativecommons.org."
  },
  {
    "path": "Panels.lua",
    "content": "-- Panels version 2.2\n-- https://cadin.github.io/panels/\n\nimport \"CoreLibs/object\"\nimport \"CoreLibs/graphics\"\nimport \"CoreLibs/sprites\"\nimport \"CoreLibs/timer\"\nimport \"CoreLibs/animation\"\nimport \"CoreLibs/crank\"\n\nlocal gfx <const> = playdate.graphics\nlocal ScreenHeight <const> = playdate.display.getHeight()\nlocal ScreenWidth <const> = playdate.display.getWidth()\n\nPanels = {}\nPanels.comicData = {}\nPanels.credits = {}\nPanels.vars = {}\nPanels.persistentVars = {}\nPanels.percentageComplete = 0\nPanels.unlockedSequences = {}\nPanels.visitedSequences = {}\n\nimport \"./modules/Font\"\nimport \"./modules/Audio\"\nimport \"./modules/Settings\"\nimport \"./modules/ScrollConstants\"\nimport \"./modules/ButtonIndicator\"\nimport \"./modules/Color\"\nimport \"./modules/Effect\"\nimport \"./modules/Input\"\nimport \"./modules/Image\"\nimport \"./modules/Menus\"\nimport \"./modules/Alert\"\nimport \"./modules/Panel\"\nimport \"./modules/Layer\"\nimport \"./modules/ChoiceList\"\n\nimport \"./modules/TextAlignment\"\nimport \"./modules/Utils\"\nimport \"./modules/Credits\"\n\n-- PD function shortcuts=\nlocal pdUpdateTimers = playdate.timer.updateTimers\nlocal pdEaseInOutQuad = playdate.easingFunctions.inOutQuad\nlocal pdButtonJustPressed = playdate.buttonJustPressed\n\nlocal sequenceDidStart = false\nlocal sequenceIsFinishing = false\n\nlocal currentSeqIndex = 1\nlocal sequences = nil\nlocal sequence = {}\nlocal panels = {}\n\nlocal scrollPos = 0\nlocal scrollAcceleration = 0.25\nlocal maxScrollVelocity = 8\nlocal scrollVelocity = 0\nlocal maxScroll = 0\n\nlocal snapStrength = 1.5\n\nlocal panelBoundaries = {}\nlocal transitionOutAnimator = nil\nlocal transitionInAnimator = nil\n\nlocal buttonIndicator = nil\n\nlocal numMenusOpen = 0\nlocal numMenusFullScreen = 0\nlocal menusAreFullScreen = false\nlocal chapterDidSelect = false\n\nlocal panelTransitionAnimator = nil\nlocal previousBGColor = nil\nlocal transitionFader = nil\nlocal shouldFadeBG = false\n\nlocal gameDidFinish = false\nlocal numSequencesUnlocked = 0\n\nlocal alert = nil\n\nlocal isCutscene = false\nlocal cutsceneFinishCallback = nil\n\nlocal targetSequence = nil\n\nlocal mainCanvas = gfx.image.new(ScreenWidth, ScreenHeight, gfx.kColorBlack)\n\nlocal function setUpPanels(seq)\n\tpanels = {}\n\tlocal pos = 0\n\tlocal j = 1\n\n\tif seq.panels == nil then\n\t\tprintError(seq.title or \"Untitled sequence\", \"No panel data found in sequence:\")\n\tend\n\n\tlocal list = table.shallowcopy(seq.panels)\n\tif seq.scrollingIsReversed then\n\t\treverseTable(list)\n\tend\n\n\tfor i, panel in ipairs(list) do\n\t\tif panel.frame == nil then\n\t\t\tpanel.frame = table.shallowcopy(seq.defaultFrame)\n\t\tend\n\n\t\tpanel.axis = seq.axis\n\t\tpanel.scrollingIsReversed = seq.scrollingIsReversed or false\n\t\tpanel.direction = seq.direction\n\n\t\tif panel.advanceControl == nil then\n\t\t\tif panel.advanceControlSequence and #panel.advanceControlSequence >= 1 then\n\t\t\t\tpanel.advanceControl = panel.advanceControlSequence[1]\n\t\t\telse\n\t\t\t\tpanel.advanceControl = sequence.advanceControl\n\t\t\tend\n\t\tend\n\n\t\tif panel.advanceControlSequence == nil then\n\t\t\tpanel.advanceControlSequence = { panel.advanceControl }\n\t\tend\n\n\t\tif panel.backControl == nil then\n\t\t\tpanel.backControl = sequence.backControl\n\t\tend\n\n\t\tif panel.preventBacktracking == nil then\n\t\t\tpanel.preventBacktracking = sequence.preventBacktracking or false\n\t\tend\n\n\t\tif sequence.font and panel.font == nil then\n\t\t\tpanel.font = sequence.font\n\t\tend\n\n\t\tif sequence.fontFamily and panel.fontFamily == nil then\n\t\t\tpanel.fontFamily = sequence.fontFamily\n\t\tend\n\n\t\tlocal p = Panels.Panel.new(panel)\n\n\t\tif panel.choiceList then\n\t\t\tp.onChoiceListSelectionChange = function(index, button)\n\t\t\t\t-- when the choice list selection changes, we can run a callback\n\t\t\t\t-- to update any panel state based on the selected choice\n\t\t\t\tif button.var then \n\t\t\t\t\tPanels.vars[button.var.key] = button.var.value\n\t\t\t\tend\n\n\t\t\t\tif button.target then \n\t\t\t\t\tsequence.nextSequence = button.target\n\t\t\t\tend\n\n\t\t\t\tif panel.choiceList.onSelectionChangeUserCallback then\n\t\t\t\t\tpanel.choiceList.onSelectionChangeUserCallback(index, button)\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\t\tif p.frame.margin then\n\t\t\tpos = pos + p.frame.margin\n\t\tend\n\n\t\tif p.frame.gap and i > 1 then\n\t\t\tpos = pos + p.frame.gap\n\t\tend\n\n\t\tif seq.axis == Panels.ScrollAxis.VERTICAL then\n\t\t\tp.frame.y = pos\n\t\t\tpos = pos + p.frame.height\n\t\t\tmaxScroll = pos - ScreenHeight + p.frame.margin\n\n\t\t\tif i > 1 then\n\t\t\t\tpanelBoundaries[j] = -(p.frame.y - p.frame.margin)\n\t\t\t\tj = j + 1\n\t\t\tend\n\t\t\tif p.frame.height > ScreenHeight then\n\t\t\t\tpanelBoundaries[j] = -(p.frame.y + p.frame.height - ScreenHeight + p.frame.margin)\n\t\t\t\tj = j + 1\n\t\t\tend\n\t\telse\n\t\t\tp.frame.x = pos\n\t\t\tpos = pos + p.frame.width\n\t\t\tmaxScroll = pos - ScreenWidth + p.frame.margin\n\n\t\t\tif i > 1 then\n\t\t\t\tpanelBoundaries[j] = -(p.frame.x - p.frame.margin)\n\t\t\t\tj = j + 1\n\t\t\tend\n\t\t\tif p.frame.width > ScreenWidth then\n\t\t\t\tpanelBoundaries[j] = -(p.frame.x + p.frame.width - ScreenWidth + p.frame.margin)\n\t\t\t\tj = j + 1\n\t\t\tend\n\t\tend\n\t\tpanels[i] = p\n\tend\nend\n\nlocal function lastPanelIsShowing()\n\tlocal threshold = 24\n\tif (sequence.scrollingIsReversed and scrollPos >= -threshold)\n\t\tor (not sequence.scrollingIsReversed and scrollPos <= -(maxScroll - threshold)) then\n\t\treturn true\n\tend\n\treturn false\nend\n\n-- -------------------------------------------------\n-- BUTTON INDICATOR\n\nlocal function createButtonIndicators()\n\tbuttonIndicators = {}\n\tif sequence.advanceControls == nil then\n\t\tbuttonIndicators = { Panels.ButtonIndicator.new(sequence.advanceControlSize) }\n\telse\n\t\tfor i, value in ipairs(sequence.advanceControls) do\n\t\t\tbuttonIndicators[i] = Panels.ButtonIndicator.new(sequence.advanceControlSize)\n\t\tend\n\tend\nend\n\nlocal function drawButtonIndicators(offset)\n\tif transitionOutAnimator == nil then\n\t\tif lastPanelIsShowing() and sequenceDidStart and not sequenceIsFinishing then\n\t\t\tfor key, button in pairs(buttonIndicators) do\n\t\t\t\tbutton:show()\n\t\t\tend\n\t\telse\n\t\t\tfor key, button in pairs(buttonIndicators) do\n\t\t\t\tbutton:hide()\n\t\t\tend\n\t\tend\n\tend\n\tif sequence.showAdvanceControls and sequenceDidStart then\n\t\tfor i, button in ipairs(buttonIndicators) do\n\t\t\tif sequence.advanceControls[i].anchor then\n\t\t\t\tlocal lastPanel = panels[#panels]\n\t\t\t\tbutton:draw(button.x + lastPanel.frame.x + offset.x , button.y + lastPanel.frame.y + offset.y)\n\t\t\telse\n\t\t\t\tbutton:draw()\n\t\t\tend\n\t\tend\n\tend\nend\n\nlocal function getAdvanceControlForScrollDirection(dir)\n\tif dir == Panels.ScrollDirection.LEFT_TO_RIGHT then\n\t\treturn Panels.Input.RIGHT\n\telseif dir == Panels.ScrollDirection.TOP_DOWN then\n\t\treturn Panels.Input.DOWN\n\telseif dir == Panels.ScrollDirection.BOTTOM_UP then\n\t\treturn Panels.Input.UP\n\telseif dir == Panels.ScrollDirection.NONE then\n\t\treturn nil\n\telse\n\t\treturn Panels.Input.LEFT\n\tend\nend\n\nlocal function getBackControlForScrollDirection(dir)\n\tif dir == Panels.ScrollDirection.LEFT_TO_RIGHT then\n\t\treturn Panels.Input.LEFT\n\telseif dir == Panels.ScrollDirection.TOP_DOWN then\n\t\treturn Panels.Input.UP\n\telseif dir == Panels.ScrollDirection.BOTTOM_UP then\n\t\treturn Panels.Input.DOWN\n\telseif dir == Panels.ScrollDirection.NONE then\n\t\treturn nil\n\telse\n\t\treturn Panels.Input.RIGHT\n\tend\nend\n\n-- -------------------------------------------------\n-- SCROLLING\n\nlocal function prepareScrolling(reversed)\n\tif reversed then\n\t\tpanelNum = #panels\n\t\tscrollPos = -maxScroll\n\telse\n\t\tscrollPos = 0\n\t\tpanelNum = 1\n\tend\nend\n\nlocal function snapScrollToPanel()\n\tfor i, b in ipairs(panelBoundaries) do\n\t\tif scrollPos > b - 20 and scrollPos < b + 20 then\n\t\t\tlocal diff = scrollPos - b\n\t\t\tscrollPos = round(scrollPos - (diff - (diff / 1.25)), 2)\n\t\tend\n\tend\nend\n\nlocal function updateScroll()\n\tif panelTransitionAnimator then\n\t\tscrollPos = panelTransitionAnimator:currentValue()\n\t\tif panelTransitionAnimator:ended() then\n\t\t\tpanelTransitionAnimator = nil\n\t\t\tpanels[panelNum]:enableInput(true)\n\t\tend\n\telse\n\t\tif scrollPos > 0 then\n\t\t\tscrollPos = math.floor(scrollPos / snapStrength)\n\t\telseif scrollPos < -maxScroll then\n\t\t\tlocal diff = scrollPos + maxScroll\n\t\t\tscrollPos = math.floor(scrollPos - (diff - (diff / snapStrength)))\n\t\tend\n\n\t\tif Panels.Settings.snapToPanels then snapScrollToPanel() end\n\tend\nend\n\n-- -------------------------------------------------\n-- PANEL TRANSITIONS\n\nlocal function isLastPanel(num)\n\tif (num == #panels and not sequence.scrollingIsReversed) or (sequence.scrollingIsReversed and num <= 1) then\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nlocal function isFirstPanel(num)\n\tif (num == 1 and not sequence.scrollingIsReversed) or (sequence.scrollingIsReversed and num == #panels) then\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nfunction getPanelScrollLocation(panel, isTrailingEdge)\n\tif sequence.axis == Panels.ScrollAxis.VERTICAL then\n\t\tif isTrailingEdge == true then\n\t\t\treturn (panel.frame.y + panel.frame.margin + panel.frame.height - ScreenHeight) * -1\n\t\telse\n\t\t\treturn (panel.frame.y - panel.frame.margin) * -1\n\t\tend\n\telse\n\t\tif isTrailingEdge == true then\n\t\t\treturn (panel.frame.x + panel.frame.margin + panel.frame.width - ScreenWidth) * -1\n\t\telse\n\t\t\treturn (panel.frame.x - panel.frame.margin) * -1\n\t\tend\n\tend\nend\n\nlocal function scrollToNextPanel()\n\tif not isLastPanel(panelNum) then\n\t\tif not sequence.rapidAdvance and panelTransitionAnimator and panelTransitionAnimator:progress() < 1 then\n\t\t\tprint(\"aborting scroll to next panel, transition in progress\") \n\t\t\treturn \n\t\tend\n\t\tlocal p = panels[panelNum]\n\t\tp:enableInput(false)\n\t\tp.buttonsPressed = {}\n\t\tlocal target = 0\n\t\tif p.frame.height > ScreenHeight and scrollPos > p.frame.y * -1 then\n\t\t\ttarget = getPanelScrollLocation(p, true)\n\t\telseif p.frame.width > ScreenWidth and scrollPos > p.frame.x * -1 then\n\t\t\ttarget = getPanelScrollLocation(p, true)\n\t\telse\n\t\t\tif sequence.scrollingIsReversed then\n\t\t\t\tpanelNum = panelNum - 1\n\t\t\telse\n\t\t\t\tpanelNum = panelNum + 1\n\t\t\tend\n\t\t\ttarget = getPanelScrollLocation(panels[panelNum])\n\t\tend\n\t\tif sequence.direction == Panels.ScrollDirection.NONE then\n\t\t\tscrollPos = target\n\t\t\tpanels[panelNum]:enableInput(true)\n\t\telse\n\t\t\tprint(\"starting panel transition\")\n\t\t\tlocal duration = sequence.transitionDuration or 500\n\t\t\tlocal ease = sequence.transitionEase or pdEaseInOutQuad\n\t\t\tpanelTransitionAnimator = gfx.animator.new(duration, scrollPos, target, ease)\n\t\tend\n\tend\nend\n\nlocal function scrollToPreviousPanel()\n\tif not isFirstPanel(panelNum) then\n\t\tlocal p = panels[panelNum]\n\t\tp:enableInput(false)\n\t\tlocal target = 0\n\t\tif p.frame.height > ScreenHeight and scrollPos < p.frame.y * -1 then\n\t\t\ttarget = getPanelScrollLocation(p)\n\t\telseif p.frame.width > ScreenWidth and scrollPos < p.frame.x * -1 then\n\t\t\ttarget = getPanelScrollLocation(p)\n\t\telse\n\t\t\tif sequence.scrollingIsReversed then\n\t\t\t\tpanelNum = panelNum + 1\n\t\t\telse\n\t\t\t\tpanelNum = panelNum - 1\n\t\t\tend\n\t\t\ttarget = getPanelScrollLocation(panels[panelNum], true)\n\t\tend\n\t\tlocal duration = sequence.transitionDuration or 500\n\t\tlocal ease = sequence.transitionEase or pdEaseInOutQuad\n\t\tpanelTransitionAnimator = gfx.animator.new(duration, scrollPos, target, ease)\n\tend\nend\n\n-- -------------------------------------------------\n-- SEQUENCE TRANSITIONS\n\nlocal function startTransitionIn(direction, delay, duration, ease)\n\tlocal target = scrollPos\n\tlocal start\n\n\tif direction == Panels.ScrollDirection.BOTTOM_UP then\n\t\tstart = scrollPos - ScreenHeight\n\telseif direction == Panels.ScrollDirection.TOP_DOWN then\n\t\tstart = scrollPos + ScreenHeight\n\telseif direction == Panels.ScrollDirection.LEFT_TO_RIGHT then\n\t\tstart = scrollPos + ScreenWidth\n\telseif direction == Panels.ScrollDirection.NONE then\n\t\tstart = scrollPos\n\telse\n\t\tstart = scrollPos - ScreenWidth\n\tend\n\n\tscrollPos = start\n\n\t-- make a dummy animator to hold scroll pos until delayed transition starts\n\ttransitionInAnimator = playdate.graphics.animator.new(math.max(delay * 2, 2000), start, start)\n\n\tif previousBGColor then\n\t\tgfx.lockFocus(transitionFader)\n\t\tgfx.setColor(previousBGColor)\n\t\tgfx.fillRect(0, 0, ScreenWidth, ScreenHeight)\n\t\tgfx.unlockFocus()\n\tend\n\tshouldFadeBG = previousBGColor ~= nil and previousBGColor ~= sequence.backgroundColor\n\n\tlocal function delayedStart()\n\t\tduration = duration or Panels.Settings.sequenceTransitionDuration\n\t\tease = ease or playdate.easingFunctions.inOutQuart\n\t\ttransitionInAnimator = playdate.graphics.animator.new(duration, start, target, ease)\n\tend\n\n\tplaydate.timer.performAfterDelay(delay, delayedStart)\nend\n\nlocal function startTransitionOut(direction, duration, ease)\n\tlocal target\n\tlocal start = scrollPos\n\tlocal duration = duration or Panels.Settings.sequenceTransitionDuration\n\n\tif direction == Panels.ScrollDirection.TOP_DOWN then\n\t\ttarget = -maxScroll - ScreenHeight\n\telseif direction == Panels.ScrollDirection.BOTTOM_UP then\n\t\ttarget = maxScroll + ScreenHeight\n\telseif direction == Panels.ScrollDirection.RIGHT_TO_LEFT then\n\t\ttarget = maxScroll + ScreenWidth\n\telseif direction == Panels.ScrollDirection.NONE then\n\t\ttarget = scrollPos\n\t\tduration = 200\n\telse\n\t\ttarget = -maxScroll - ScreenWidth\n\tend\n\n\tease = ease or playdate.easingFunctions.inOutQuart\n\ttransitionOutAnimator = playdate.graphics.animator.new(duration, start, target, ease)\nend\n\nlocal function getAxisForScrollDirection(dir)\n\tif dir == Panels.ScrollDirection.TOP_TO_BOTTOM or dir == Panels.ScrollDirection.BOTTOM_UP then\n\t\treturn Panels.ScrollAxis.VERTICAL\n\telse\n\t\treturn Panels.ScrollAxis.HORIZONTAL\n\tend\nend\n\n-- -------------------------------------------------\n-- SEQUENCE LIFECYCLE\n\nlocal function setSequenceScrollDirection()\n\tif sequence.axis == nil and sequence.direction == nil then\n\t\tsequence.axis = Panels.ScrollAxis.HORIZONTAL\n\tend\n\n\tif sequence.axis == nil then\n\t\tsequence.axis = getAxisForScrollDirection(sequence.direction)\n\tend\n\n\tif sequence.direction == nil then\n\t\tif sequence.axis == Panels.ScrollAxis.VERTICAL then\n\t\t\tsequence.direction = Panels.ScrollDirection.TOP_DOWN\n\t\telse\n\t\t\tsequence.direction = Panels.ScrollDirection.LEFT_TO_RIGHT\n\t\tend\n\telseif sequence.direction == Panels.ScrollDirection.NONE then\n\t\tsequence.axis = Panels.ScrollAxis.HORIZONTAL\n\telseif sequence.direction == Panels.ScrollDirection.RIGHT_TO_LEFT\n\t\tor sequence.direction == Panels.ScrollDirection.BOTTOM_UP then\n\t\tsequence.scrollingIsReversed = true\n\tend\nend\n\nlocal function setSequenceColors()\n\tif sequence.backgroundColor == nil then\n\t\tif sequence.foregroundColor then\n\t\t\tsequence.backgroundColor = Panels.Color.invert(sequence.foregroundColor)\n\t\telse\n\t\t\tsequence.foregroundColor = Panels.Color.BLACK\n\t\t\tsequence.backgroundColor = Panels.Color.WHITE\n\t\tend\n\telse\n\t\tif sequence.foregroundColor == nil then\n\t\t\tsequence.foregroundColor = Panels.Color.invert(sequence.backgroundColor)\n\t\tend\n\tend\nend\n\nlocal function countVisitedSequences(unlocked)\n\tlocal count = 0\n\tfor i, v in ipairs(unlocked) do\n\t\tif v then count = count + 1 end\n\tend\n\treturn count\nend\n\nlocal function calculatePercentageComplete() \n\tnumSequencesVisited = countVisitedSequences(Panels.visitedSequences)\n\tPanels.percentageComplete = math.floor((numSequencesVisited / #sequences) * 100)\n\t-- print(\"This comic has \" .. #sequences .. \" sequences.\")\nend\n\nlocal function markSequenceAsVisited(num)\n\tfor i = 1, num, 1 do\n\t\tif not Panels.visitedSequences[i]  then\n\t\t\tPanels.visitedSequences[i] = false\n\t\tend\n\tend\n\n\tPanels.visitedSequences[num] = true\n\tcalculatePercentageComplete()\nend\n\nlocal function unlockSequence(num)\n\tfor i = 1, num, 1 do\n\t\tif not Panels.unlockedSequences[i]  then\n\t\t\tPanels.unlockedSequences[i] = false\n\t\tend\n\tend\n\n\tPanels.unlockedSequences[num] = true\n\tmarkSequenceAsVisited(num)\nend\n\nlocal function loadSequence(num)\n\tcurrentSeqIndex = num\n\tsequence = sequences[num]\n\tcreateButtonIndicators()\n\tunlockSequence(num)\n\n\t-- set default scroll direction for each axis if not specified\n\tsetSequenceScrollDirection()\n\tsetSequenceColors()\n\n\tif sequence.scrollType == nil then\n\t\tsequence.scrollType = Panels.ScrollType.MANUAL\n\tend\n\n\tif sequence.defaultFrame == nil then\n\t\tsequence.defaultFrame = Panels.Settings.defaultFrame\n\tend\n\n\tif sequence.advanceControls == nil then\n\t\tlocal control\n\t\tif sequence.advanceControl == nil then\n\t\t\tlocal _input = getAdvanceControlForScrollDirection(sequence.direction)\n\t\t\tcontrol = {input = _input}\n\t\t\tsequence.advanceControl = _input\n\t\telse\n\t\t\tcontrol = {input = sequence.advanceControl}\n\t\tend\n\n\t\tif sequence.advanceControlPosition == nil then\n\t\t\tlocal x, y = Panels.ButtonIndicator.getPosititonForScrollDirection(sequence.direction, sequence.advanceControlSize)\n\t\t\tcontrol.x = x\n\t\t\tcontrol.y = y\n\t\telse\n\t\t\tcontrol.x = sequence.advanceControlPosition.x\n\t\t\tcontrol.y = sequence.advanceControlPosition.y\n\t\tend\n\n\t\tsequence.advanceControls = { control }\n\n\tend\n\n\tif sequence.showAdvanceControls == nil then\n\t\tif sequence.showAdvanceControl == nil then\n\t\t\tsequence.showAdvanceControls = true\n\t\telse\n\t\t\tsequence.showAdvanceControls = sequence.showAdvanceControl\n\t\tend\n\tend\n\n\tif sequence.backControl == nil then\n\t\tsequence.backControl = getBackControlForScrollDirection(sequence.direction)\n\tend\n\n\tif sequence.audio then\n\t\tif sequence.audio.continuePrevious and (Panels.Audio.fileIsPlaying(sequence.audio.file) or sequence.audio.file == nil) then\n\t\t\t-- only continue playing if the specified file is already playing\n\t\t\t-- or no file is specified\n\t\telse\n\t\t\tif sequence.audio.file then\n\t\t\t\tPanels.Audio.startBGAudio(\n\t\t\t\t\tPanels.Settings.audioFolder .. sequence.audio.file,\n\t\t\t\t\tsequence.audio.loop or false,\n\t\t\t\t\tsequence.audio.volume or 1\n\t\t\t\t)\n\t\t\telse\n\t\t\t\tPanels.Audio.fadeOutAndKill()\n\t\t\tend\n\t\tend\n\telse\n\t\tPanels.Audio.fadeOutAndKill()\n\tend\n\n\tsetUpPanels(sequence)\n\tprepareScrolling(sequence.scrollingIsReversed)\n\n\tfor i, control in ipairs(sequence.advanceControls) do\n\t\tbuttonIndicators[i]:setButton(control.input)\n\n\t\tif sequence.showAdvanceControls and (control.x == nil or control.y == nil) then\n\t\t\tlocal err = sequence.title or \"Untitled sequence (\" .. num .. \")\"\n\t\t\tprintError(err, \"Invalid position for advance control\")\n\t\tend\n\t\tbuttonIndicators[i]:setPosition(control.x or (i-1) * 40, control.y or 0)\n\tend\n\n\tif sequence.scrollType == Panels.ScrollType.MANUAL then \n\t\tfor i, p in ipairs(panels) do\n\t\t\tp:enableInput(true)\n\t\tend\n\tend\n\n\tstartTransitionIn(sequence.direction, sequence.delay or 0, sequence.transitionDuration, sequence.transitionEase)\n\nend\n\nlocal function unloadSequence()\n\t\n\tif(sequence.direction == Panels.ScrollDirection.NONE) then\n\t\t-- because the lack of scroll causes these not to get called\n\t\tlocal lastPanel = panels[#panels]\n\t\tif lastPanel.targetSequenceFunction then targetSequence = lastPanel.targetSequenceFunction() end\n\t\tlastPanel:reset()\n\tend\n\n\tfor i, p in ipairs(panels) do\n\t\tp:killTypingEffects()\n\t\tif p.wasOnScreen then\n\t\t\tp:reset()\n\t\tend\n\t\tp.sfxPlayer = nil\n\t\tif p.layers then\n\t\t\tfor j, l in ipairs(p.layers) do\n\t\t\t\tif l.timer then\n\t\t\t\t\tl.timer:remove()\n\t\t\t\t\tl.timer = nil\n\t\t\t\tend\n\n\t\t\t\tl.sfxPlayer = nil\n\n\t\t\t\tif l.animationLoop then\n\t\t\t\t\tl.animationLoop = nil\n\t\t\t\tend\n\t\t\t\tl.img = nil\n\t\t\t\tl.imgTable = nil\n\t\t\t\tl = nil\n\t\t\tend\n\t\t\t-- p.layers = nil\n\t\tend\n\t\tp = nil\n\tend\n\n\tpanelTransitionAnimator = nil\n\tPanels.Image.clearCache()\n\tsequence.didFinish = false\n\tpreviousBGColor = sequence.backgroundColor\n\n\tif targetSequence == nil and sequence.nextSequence then\n\t\ttargetSequence = sequence.nextSequence\n\tend\nend\n\nlocal function getIndexForTarget(target)\n\t-- if target is a number, return it\n\tif type(target) == \"number\" then\n\t\treturn target\n\tend\n\n\t-- if target is a string, find the index of the sequence with that id\n\tif type(target) == \"string\" then\n\t\tfor i, seq in ipairs(sequences) do\n\t\t\tif seq.id == target then\n\t\t\t\treturn i\n\t\t\tend\n\t\tend\n\tend\n\n\tprintError(\"The target sequence '\".. target ..\"' could not be found.\", \"Invalid target sequence ID\")\nend\n\nlocal function nextSequence()\n\tlocal isDeadEnd = sequence.endSequence or false\n\tunloadSequence()\n\n\tlocal targetIndex = targetSequence and getIndexForTarget(targetSequence) or nil\n\n\tif targetSequence then\n\t\tloadSequence(targetIndex)\n\t\ttargetSequence = nil\n\t\tupdateMenuData(sequences, gameDidFinish, currentSeqIndex > 1)\n\telseif currentSeqIndex < #sequences and not isDeadEnd then\n\t\tcurrentSeqIndex = currentSeqIndex + 1\n\t\tloadSequence(currentSeqIndex)\n\t\tupdateMenuData(sequences, gameDidFinish, currentSeqIndex > 1)\n\telseif isCutscene then\n\t\tplaydate.inputHandlers.pop()\n\t\tgameDidFinish = true\n\t\tcutsceneFinishCallback(targetIndex)\n\t\tPanels.Audio.killBGAudio()\n\t\tpreviousBGColor = nil -- prevent future cross-fade attempt\n\telse\n\t\tgameDidFinish = true\n\t\tupdateMenuData(sequences, gameDidFinish, currentSeqIndex > 1)\n\t\tmenusAreFullScreen = true\n\n\t\tif Panels.Settings.resetVarsOnGameOver then\n\t\t\tPanels.vars = {}\n\t\tend\n\t\tPanels.Audio.killBGAudio()\n\t\tPanels.mainMenu:show()\n\tend\nend\n\nlocal function updateSequenceTransition()\n\n\tif transitionOutAnimator then\n\t\tscrollPos = transitionOutAnimator:currentValue()\n\t\tif transitionOutAnimator:ended() then\n\t\t\ttransitionOutAnimator = nil\n\t\t\tsequenceDidStart = false\n\t\t\tplaydate.timer.performAfterDelay(1, nextSequence) -- prevent flash before transition in\n\t\tend\n\telseif transitionInAnimator then\n\t\tscrollPos = transitionInAnimator:currentValue()\n\t\tif transitionInAnimator:ended() then\n\t\t\tsequenceDidStart = true\n\t\t\tsequenceIsFinishing = false\n\t\t\ttransitionInAnimator = nil\n\t\t\tshouldFadeBG = false\n\n\t\t\tpanels[panelNum]:enableInput(true)\n\t\tend\n\tend\nend\n\nlocal function finishSequence()\n\tif not sequence.didFinish then\n\t\tsequence.didFinish = true\n\t\tstartTransitionOut(sequence.direction, sequence.transitionDuration, sequence.transitionEase)\n\tend\nend\n\n-- -------------------------------------------------\n-- INPUTS\nlocal function shouldGoBack(panel)\n\tlocal should = true\n\tif panel.preventBacktracking then\n\t\tif panel.frame.height > ScreenHeight and scrollPos < panel.frame.y * -1 or\n\t\t\tpanel.frame.width > ScreenWidth and scrollPos < panel.frame.x * -1 then\n\t\t\t-- same frame, allow it\n\t\t\tshould = true\n\t\telse\n\t\t\tshould = false\n\t\tend\n\tend\n\treturn should\nend\n\nfunction Panels.cranked(change, accChange)\n\tif sequence.scrollType == Panels.ScrollType.MANUAL or sequence.autoAdvanceWithCrank then\n\t\tif sequence.axis == Panels.ScrollAxis.VERTICAL and sequence.scrollingIsReversed then\n\t\t\tscrollPos = scrollPos + change\n\t\telse\n\t\t\tscrollPos = scrollPos - change\n\t\tend\n\tend\n\tif sequence.scrollType == Panels.ScrollType.AUTO and sequence.autoAdvanceWithCrank then\n\t\tlocal ticks = playdate.getCrankTicks(sequence.autoAdvanceTicks or 6)\n\t\tif ticks > 0 then\n\t\t\tscrollToNextPanel()\n\t\telseif ticks < 0 then\n\t\t\tlocal p = panels[panelNum]\n\t\t\tif shouldGoBack(p) then\n\t\t\t\tscrollToPreviousPanel()\n\t\t\tend\n\t\tend\n\tend\nend\n\nlocal function hideOtherAdvanceControls(pressedIndex)\n\tfor i, button in ipairs(buttonIndicators) do\n\t\tif i ~= pressedIndex then\n\t\t\tbutton:hide()\n\t\tend\n\tend\nend\n\nlocal function checkAdvanceControlSequence(panel, callback)\n\tlocal didTrigger = false\n\tlocal trigger = panel.advanceControlSequence[#panel.buttonsPressed + 1]\n\tif pdButtonJustPressed(trigger) and panel.inputEnabled then\n\t\tpanel.buttonsPressed[#panel.buttonsPressed + 1] = trigger\n\t\tif #panel.buttonsPressed == #panel.advanceControlSequence then\n\t\t\tif panel.advanceDelay then\n\t\t\t\tpanel:exit()\n\t\t\t\tplaydate.timer.performAfterDelay(panel.advanceDelay, callback)\n\t\t\telse\n\t\t\t\tcallback()\n\t\t\tend\n\t\telse \n\t\t\tplaydate.timer.performAfterDelay(500, function () \n\t\t\t\tpanel:nextAdvanceControl(#panel.buttonsPressed + 1, true)\n\t\t\tend\n\t\t\t)\n\t\tend\n\t\tdidTrigger = true\n\tend\n\n\treturn didTrigger\nend\n\nlocal function checkInputs()\n\tlocal p = panels[panelNum]\n\tif sequenceIsFinishing then return end\n\tif lastPanelIsShowing() then\n\t\tp = panels[#panels] -- make sure we're dealing with the last panel\n\t\tif p.advanceFunction == nil then\n\n\t\t\tif #p.advanceControlSequence > 1 then\n\t\t\t\tlocal didTrigger = checkAdvanceControlSequence(p, finishSequence)\n\t\t\t\tif didTrigger then return end\n\t\t\telse\n\t\t\t\tfor i, button in ipairs(buttonIndicators) do\n\t\t\t\t\tif pdButtonJustPressed(sequence.advanceControls[i].input) then\n\t\t\t\t\t\tif sequence.advanceControls[i].target then\n\t\t\t\t\t\t\ttargetSequence = sequence.advanceControls[i].target\n\t\t\t\t\t\tend\n\t\t\t\t\t\tbutton:press()\n\t\t\t\t\t\thideOtherAdvanceControls(i)\n\t\t\t\t\t\tsequenceIsFinishing = true\n\t\t\t\t\t\tif p.advanceDelay then\n\t\t\t\t\t\t\tp:exit()\n\t\t\t\t\t\t\tplaydate.timer.performAfterDelay(p.advanceDelay, finishSequence)\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tfinishSequence()\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tif sequence.scrollType == Panels.ScrollType.AUTO then\n\t\tif p.advanceFunction == nil then\n\t\t\tif p.advanceControlSequence then\n\t\t\t\tlocal didTrigger = checkAdvanceControlSequence(p, scrollToNextPanel)\n\t\t\t\tif didTrigger then return end\n\t\t\telse\n\t\t\t\tif pdButtonJustPressed(p.advanceControl) and p.inputEnabled then\n\t\t\t\t\tscrollToNextPanel()\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tif pdButtonJustPressed(p.backControl) then\n\t\t\tif shouldGoBack(p) then\n\t\t\t\tscrollToPreviousPanel()\n\t\t\tend\n\t\tend\n\tend\nend\n\nlocal function updateArrowControls()\n\tif (sequence.axis == Panels.ScrollAxis.VERTICAL\n\t\tand playdate.buttonIsPressed(Panels.Input.UP))\n\t\tor (sequence.axis == Panels.ScrollAxis.HORIZONTAL\n\t\t\tand playdate.buttonIsPressed(Panels.Input.LEFT)) then\n\t\tscrollVelocity = scrollVelocity + scrollAcceleration\n\n\telseif (sequence.axis == Panels.ScrollAxis.VERTICAL\n\t\tand playdate.buttonIsPressed(Panels.Input.DOWN))\n\t\tor (sequence.axis == Panels.ScrollAxis.HORIZONTAL\n\t\t\tand playdate.buttonIsPressed(Panels.Input.RIGHT)) then\n\t\tscrollVelocity = scrollVelocity - scrollAcceleration\n\telse\n\t\tscrollVelocity = scrollVelocity / 2\n\tend\n\n\tif scrollVelocity > maxScrollVelocity then\n\t\tscrollVelocity = maxScrollVelocity\n\telseif scrollVelocity < -maxScrollVelocity then\n\t\tscrollVelocity = -maxScrollVelocity\n\tend\n\tscrollPos = scrollPos + scrollVelocity\nend\n\n-- -------------------------------------------------\n-- GAME LOOP\n\nlocal function getScrollOffset()\n\tlocal offset = { x = 0, y = 0 }\n\tif sequence.axis == Panels.ScrollAxis.HORIZONTAL then\n\t\toffset.x = scrollPos\n\telse\n\t\toffset.y = scrollPos\n\tend\n\n\treturn offset\nend\n\nlocal function updateComic(offset)\n\n\tif transitionInAnimator or transitionOutAnimator then\n\t\tupdateSequenceTransition()\n\telse\n\t\tif panels and #panels < 1 then\n\t\t\tprintError(\"`panels` table is empty\", \"This sequence has invalid panel definitions.\")\n\t\tend\n\n\t\tif panels and panels[panelNum]:shouldAutoAdvance() then\n\t\t\tif not isLastPanel(panelNum) then\n\t\t\t\tprint(\"auto advancing to next panel\")\n\t\t\t\tscrollToNextPanel()\n\t\t\telse\n\t\t\t\tfinishSequence()\n\t\t\tend\n\t\tend\n\n\t\tupdateScroll()\n\t\tif sequence.scrollType == Panels.ScrollType.MANUAL then\n\t\t\tupdateArrowControls()\n\t\tend\n\t\tcheckInputs()\n\n\tend\nend\n\nlocal function drawComic(offset)\n\tgfx.pushContext(mainCanvas)\n\tgfx.clear(sequence.backgroundColor)\n\n\tif shouldFadeBG then\n\t\tlocal pct = 1 -\n\t\t\t(transitionInAnimator:currentValue() - transitionInAnimator.startValue) /\n\t\t\t(transitionInAnimator.endValue - transitionInAnimator.startValue)\n\t\ttransitionFader:drawFaded(0, 0, pct, gfx.image.kDitherTypeBayer8x8)\n\tend\n\n\tfor i, panel in ipairs(panels) do\n\t\tif panel:isOnScreen(offset) then\n\t\t\t\n\t\t\tif panel.wasOnScreen ~= true then\n\t\t\t\tpanel:setup()\n\t\t\tend\n\t\t\tpanel:render(offset, sequence.foregroundColor, sequence.backgroundColor)\n\t\telseif panel.wasOnScreen then\n\t\t\tif panel.targetSequenceFunction then\n\t\t\t\ttargetSequence = panel.targetSequenceFunction()\n\t\t\tend\n\n\t\t\tpanel:reset()\n\t\t\tpanel.wasOnScreen = false\n\t\tend\n\tend\n\n\tgfx.popContext()\n\tmainCanvas:draw(0, 0)\n\n\tif Panels.Settings.showFPS then\n\t\tplaydate.drawFPS(0,0)\n\tend\nend\n\n-- Playdate update loop\nfunction Panels.update()\n\n\tif not menusAreFullScreen then\n\t\tlocal offset = getScrollOffset()\n\t\tupdateComic(offset)\n\t\tdrawComic(offset)\n\t\tdrawButtonIndicators(offset)\n\tend\n\n\tif numMenusOpen > 0 then\n\t\tupdateMenus()\n\tend\n\n\tif alert.isActive then\n\t\talert:udpate()\n\tend\n\n\tpdUpdateTimers()\nend\n\n-- -------------------------------------------------\n-- SAVE & LOAD GAME PROGRESS\n\nlocal function loadGameData()\n\tlocal data = playdate.datastore.read()\n\tif data then\n\t\tcurrentSeqIndex = data.sequence or 1\n\t\tPanels.unlockedSequences = data.unlockedSequences or {}\n\t\tPanels.visitedSequences = data.visitedSequences or {}\n\t\tcalculatePercentageComplete()\n\t\tgameDidFinish = data.gameDidFinish\n\t\tPanels.vars = data.vars or {}\n\t\tPanels.persistentVars = data.persistentVars or {}\n\tend\nend\n\nlocal function saveGameData()\n\tplaydate.datastore.write({ sequence = currentSeqIndex, unlockedSequences = Panels.unlockedSequences, visitedSequences = Panels.visitedSequences, gameDidFinish = gameDidFinish, vars = Panels.vars, persistentVars = Panels.persistentVars })\nend\n\nfunction playdate.gameWillTerminate()\n\tsaveGameData()\nend\n\nfunction playdate.deviceWillSleep()\n\tsaveGameData()\nend\n\nfunction playdate.deviceWillLock()\n\tsaveGameData()\nend\n\n-- -------------------------------------------------\n-- MENU HANDLERS\n\nfunction Panels.onChapterSelected(chapter)\n\tchapterDidSelect = true\n\tPanels.Audio.stopBGAudio()\n\tunloadSequence()\n\tcurrentSeqIndex = chapter\n\tloadSequence(currentSeqIndex)\nend\n\nfunction Panels.onMenuWillShow(menu)\n\tnumMenusOpen = numMenusOpen + 1\n\tPanels.Audio.pauseBGAudio()\n\tPanels.Audio.muteTypingSounds()\n\n\tif panels then\n\t\tfor i, p in ipairs(panels) do\n\t\t\tif p.wasOnScreen then\n\t\t\t\tp:pauseSounds()\n\t\t\tend\n\t\tend\n\tend\nend\n\nfunction Panels.onMenuDidShow()\n\tmenusAreFullScreen = true\n\tnumMenusFullScreen = numMenusFullScreen + 1\nend\n\nfunction Panels.onMenuWillHide(menu)\n\tif menu == Panels.mainMenu then\n\t\tif not chapterDidSelect then\n\t\t\tPanels.Audio.unmuteTypingSounds()\n\t\t\tloadSequence(currentSeqIndex)\n\t\tend\n\tend\n\tnumMenusFullScreen = numMenusFullScreen - 1\n\n\tif numMenusFullScreen < 1 then\n\t\tmenusAreFullScreen = false\n\tend\nend\n\nfunction Panels.onMenuDidHide(menu)\n\tnumMenusOpen = numMenusOpen - 1\n\tif numMenusOpen < 1 then\n\t\tPanels.Audio.resumeBGAudio()\n\t\tPanels.Audio.unmuteTypingSounds()\n\t\tif panels then\n\t\t\tfor i, p in ipairs(panels) do\n\t\t\t\tif p.wasOnScreen then\n\t\t\t\t\tp:unPauseSounds()\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tchapterDidSelect = false\n\tend\nend\n\nfunction Panels.onMenuDidStartOver()\n\tif not Panels.Settings.useChapterMenu and gameDidFinish then\n\t\tonAlertDidStartOver()\n\telse\n\t\talert:show()\n\tend\nend\n\nfunction onAlertDidStartOver()\n\tPanels.Audio.stopBGAudio()\n\tPanels.unlockedSequences = {}\n\tgameDidFinish = false\n\tsaveGameData()\n\tunloadSequence()\n\tcurrentSeqIndex = 1\n\n\tPanels.vars = {}\n\tPanels.mainMenu:hide()\n\tcreateMenus(sequences, gameDidFinish, currentSeqIndex > 1)\nend\n\nfunction onAlertDidHide()\n\tif alert.selection == 2 then\n\t\tonAlertDidStartOver()\n\tend\nend\n\nfunction shouldShowMainMenu()\n\tlocal should = false\n\tif Panels.Settings.showMenuOnLaunch then\n\t\tif (currentSeqIndex and currentSeqIndex > 1) or Panels.Settings.skipMenuOnFirstLaunch == false then\n\t\t\tshould = true\n\t\tend\n\tend\n\tif gameDidFinish then should = true end\n\treturn should\nend\n\n-- -------------------------------------------------\n-- START GAME\n\nlocal function updateSystemMenu()\n\tlocal sysMenu = playdate.getSystemMenu()\n\tif Panels.Settings.useChapterMenu then\n\t\tlocal chaptersMenuItem, error = sysMenu:addMenuItem(\"Chapters\",\n\t\t\tfunction()\n\t\t\t\tPanels.creditsMenu:hide()\n\t\t\t\tPanels.chapterMenu:show()\n\t\t\tend\n\t\t)\n\t\tprintError(error, \"Error adding Chapters to system menu\")\n\tend\n\n\tif Panels.Settings.showMainMenuOption then\n\t\tlocal homeMenuItem, error = sysMenu:addMenuItem(Panels.Settings.mainMenuOptionLabel or \"Main Menu\",\n\t\t\tfunction()\n\t\t\t\tPanels.creditsMenu:hide()\n\t\t\t\tif Panels.chapterMenu then Panels.chapterMenu:hide() end\n\t\t\t\tmenusAreFullScreen = true\n\t\t\t\tPanels.mainMenu:show()\n\t\t\tend\n\t\t)\n\t\tprintError(error, \"Error adding Main Menu to system menu\")\n\tend\n\n\n\tif Panels.Settings.useCreditsMenu then\n\t\tlocal creditsItem, error2 = sysMenu:addMenuItem(\"Credits\",\n\t\t\tfunction()\n\t\t\t\tif Panels.chapterMenu then Panels.chapterMenu:hide() end\n\t\t\t\tPanels.creditsMenu:show()\n\t\t\tend\n\t\t)\n\t\tprintError(error2, \"Error adding Credits to system menu:\")\n\tend\n\nend\n\nlocal function createCreditsSequence()\n\tlocal credits = Panels.Credits.new()\n\tlocal img = gfx.image.new(400, credits.height + 44)\n\tgfx.lockFocus(img)\n\tcredits:redraw(0)\n\tgfx.unlockFocus()\n\n\tcredits = nil\n\n\tlocal seq = {\n\t\tdelay = 1000,\n\t\ttransitionDuration = 1000,\n\t\tdirection = Panels.ScrollDirection.TOP_DOWN,\n\t\tadvanceControl = Panels.Input.A,\n\n\t\tpanels = {\n\t\t\t{\n\t\t\t\tframe = { height = img.height, margin = 4 },\n\t\t\t\tborderless = true,\n\n\t\t\t\tlayers = {\n\t\t\t\t\t{ img = img, y = 10 }\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n\n\ttable.insert(Panels.comicData, seq)\nend\n\nfunction setDefaultFont()\n\tif Panels.Settings.defaultFontFamily then\n\t\tgfx.setFontFamily(Panels.Font.getFamily(Panels.Settings.defaultFontFamily))\n\telseif Panels.Settings.defaultFont then\n\t\tgfx.setFont(Panels.Font.get(Panels.Settings.defaultFont))\n\tend\nend\n\n-- call this if you need to interrupt a cutscene (from a menu option for example)\n-- this should clean up panel and sequence audio that normally happens when the cutscene completes\nfunction Panels.haltCutscene()\n\tPanels.Audio.killBGAudio()\n\tunloadSequence()\n\tpreviousBGColor = nil -- prevent future cross-fade attempt\n\tplaydate.inputHandlers.pop()\nend\n\nfunction Panels.startCutscene(comicData, callback)\n\tsetDefaultFont()\n\tisCutscene = true\n\tcutsceneFinishCallback = callback\n\tPanels.comicData = comicData\n\tmaxScrollVelocity = Panels.Settings.maxScrollSpeed\n\talert = Panels.Alert.new(\"Start Over?\", \"All progress will be lost.\", { \"Cancel\", \"Start Over\" })\n\talert.onHide = onAlertDidHide\n\n\tPanels.Audio.createTypingSound()\n\tvalidateSettings()\n\n\tsequences = Panels.comicData\n\tcurrentSeqIndex = 1\n\n\tloadSequence(currentSeqIndex)\n\tplaydate.inputHandlers.push({\n\t\tcranked = Panels.cranked\n\t})\nend\n\nfunction Panels.start(comicData)\n\tsetDefaultFont()\n\tPanels.comicData = comicData\n\tmaxScrollVelocity = Panels.Settings.maxScrollSpeed\n\talert = Panels.Alert.new(\"Start Over?\", \"All progress will be lost.\", { \"Cancel\", \"Start Over\" })\n\talert.onHide = onAlertDidHide\n\tPanels.Audio.createTypingSound()\n\tif Panels.Settings.showCreditsOnGameOver then\n\t\tcreateCreditsSequence()\n\tend\n\n\ttransitionFader = gfx.image.new(ScreenWidth, ScreenHeight)\n\n\tsequences = Panels.comicData\n\n\tloadGameData()\n\tvalidateSettings()\n\tupdateSystemMenu()\n\n\tcreateMenus(sequences, gameDidFinish, currentSeqIndex and currentSeqIndex > 1)\n\n\tif shouldShowMainMenu() then\n\t\tmenusAreFullScreen = true\n\t\tPanels.mainMenu:show()\n\telse\n\t\tloadSequence(currentSeqIndex)\n\tend\n\n\tplaydate.update = Panels.update\n\tplaydate.cranked = Panels.cranked\nend\n\n-- -------------------------------------------------\n-- DEBUG\n\nlocal function unlockAll()\n\tprint(\"Levels unlocked. Restart game.\")\n\tPanels.unlockedSequences = {}\n\tfor i = 1, #sequences, 1 do\n\t\ttable.insert(Panels.unlockedSequences, true)\n\tend\n\tgameDidFinish = true\n\tsaveGameData()\nend\n\nfunction playdate.keyPressed(key)\n\tif key == \"0\" then\n\t\tif Panels.Settings.debugControlsEnabled then unlockAll() end\n\tend\nend\n"
  },
  {
    "path": "README.md",
    "content": "# Panels\n\nBuild interactive comics for the Playdate console.\n\n![Banner](./assets/images/panelsBanner.gif)\n\nProvide Panels with a Lua table that describes the sequences in your comic (scroll direction, panel sizes, text, animation and effects) along with your layered graphics. Panels will handle layout, scrolling, animation, and even chapter navigation for you.\n\nComics built with Panels can support these features:\n\n-   layered, parallax scrolling\n-   nested panels\n-   sequences with different scroll directions\n-   manual (crank) scrolling and auto advancing (panel-by-panel)\n-   panel effects like shake and blink\n-   animated transitions between sequences\n-   animations and transitions within panels based on scroll position\n-   animated text layers\n-   panels with fully custom render functions\n-   branching \"choose-your-own-adventure\" storylines\n\n## Documentation\nCheck out the full set of documentation here:\n### [📄 Panels Documentation](//cadin.github.io/panels)\n### [📺 Tutorial Videos](https://www.youtube.com/playlist?list=PLvk_cJkKCihbN4Q61lopDtSQMbx4vNLvv)\n\n## Requirements\n\n-   [Playdate SDK](https://play.date/dev/)\n-   [Playdate Console](https://shop.play.date) (optional)\n\n## Setup\n\n### From Template Project\n\n1. Clone the [Panels Project Template](https://github.com/cadin/panels-project-template).\n    This is a [Template Repo](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). Click \"Use this template\" to create your own fresh repo with all the contents of the project template.\n2. The template project includes the Panels framework as a git submodule. Be sure to properly [initialize the submodule](https://www.w3docs.com/snippets/git/how-to-clone-including-submodules.html) when cloning the repo.\n3. Start editing table in `myComicData.lua`.\n\n### Manual Setup\n\n1. Clone this repo into your project into a `libraries` folder.\n2. Inside your `main.lua` file import Panels.\n3. Create or import your [`comicData`](http://cadin.github.io/panels/docs/comic-data) table.\n4. Start Panels with your `comicData` table as the sole argument.\n\n### Example `main.lua` File:\n\n```lua\nimport \"libraries/panels/Panels\"\nlocal comicData = {\n    -- comic data goes here...\n}\nPanels.start(comicData)\n```\n\n## Support\n### Get Help\n- 📺 Watch these **[Tutorial Videos](https://www.youtube.com/playlist?list=PLvk_cJkKCihbN4Q61lopDtSQMbx4vNLvv)** to get up to speed quickly.  \n- 🤖 Chat with the **[Panels Partner custom GPT](https://chat.openai.com/g/g-QU76MOCLl-panels-partner)** to get answers to questions about your specific project.\n- 💬 Post your question in the **[Playdate Squad Discord](https://discord.com/channels/675983554655551509/1163630567393341461)**.\n\n\n\n### Feature Requests\n\nAdd feature requests to the [Issues](https://github.com/cadin/panels/issues) page.\n\nInclude a description of the general functionality you need, along with your preferred implementation (if you have one). Please search first to see if someone else has already created an issue for your feature. If so, you can add a vote or comment to show your support.\n\n### Bug Reports\n\nFile bug reports on the [Issues](https://github.com/cadin/panels/issues) page.\n\nEach bug should be listed as a separate issue. Please search first to see if someone else has already filed the bug, and list all steps needed to reproduce the issue in the smallest possible project.\n\n### Contribute\n\nIf you would like to contribute a feature or bug fix please contact me first and let me know which issue you want work on. If there isn't yet an issue for your proposed change, go ahead and write one.\n\n## License\n\nPanels is licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).\n\n**TLDR:** You can use this code (or modified versions) to create anything you want, public or private, free or commercial. For attribution, please retain the Panels credit (with URL and QR code) on the Credits page of your game so that others may find their way here.\n\n---\n\n👨🏻‍🦲❤️🛠\n"
  },
  {
    "path": "assets/fonts/Asheville-Narrow-14-Bold.fnt",
    "content": "--metrics={\"baseline\":0,\"xHeight\":0,\"capHeight\":0,\"left\":[\"BDEFHIKLMNPRbhkl\",\"GO\",\"aceo\",\"mnr\"],\"right\":[\"DO\",\"HIMNdl\",\"JU\",\"gy\"],\"pairs\":{\"Fa\":[-1,1],\"Fc\":[-1,1],\"Fe\":[-1,1],\"Fo\":[-1,1],\"Fm\":[-1,1],\"Fn\":[-1,1],\"Fr\":[-1,1],\"Ta\":[-3,1],\"Tc\":[-3,1],\"Te\":[-3,1],\"To\":[-3,1],\"Tm\":[-3,1],\"Tn\":[-3,1],\"Tr\":[-3,1],\"Dj\":[-2,2],\"Oj\":[-2,2],\"Hj\":[-2,2],\"Ij\":[-2,2],\"Mj\":[-2,2],\"Nj\":[-2,2],\"dj\":[-2,2],\"lj\":[-2,2],\"Jj\":[-2,2],\"Uj\":[-2,2],\"gT\":[-3,2],\"yT\":[-3,2],\"AT\":[-2,0],\"AV\":[-1,0],\"AW\":[-1,0],\"AY\":[-1,0],\"Af\":[-1,0],\"Aj\":[-2,0],\"At\":[-1,0],\"BT\":[-1,0],\"BV\":[-1,0],\"BW\":[-1,0],\"BY\":[-1,0],\"Bf\":[-1,0],\"Bj\":[-2,0],\"Bt\":[-1,0],\"Cj\":[-2,0],\"Ef\":[-1,0],\"Ej\":[-2,0],\"Et\":[-1,0],\"Ev\":[-1,0],\"FA\":[-1,0],\"FJ\":[-4,0],\"Fd\":[-1,0],\"Ff\":[-1,0],\"Fg\":[-1,0],\"Fj\":[-2,0],\"Fp\":[-1,0],\"Fq\":[-1,0],\"Fs\":[-1,0],\"Ft\":[-1,0],\"Fu\":[-1,0],\"Fv\":[-1,0],\"Fw\":[-1,0],\"Fx\":[-1,0],\"Fy\":[-1,0],\"Fz\":[-1,0],\"Gj\":[-2,0],\"Kf\":[-1,0],\"Kj\":[-2,0],\"Kt\":[-1,0],\"Kv\":[-1,0],\"LT\":[-3,0],\"LV\":[-2,0],\"LW\":[-2,0],\"LY\":[-2,0],\"Lf\":[-1,0],\"Lj\":[-2,0],\"Lt\":[-1,0],\"Lv\":[-1,0],\"PA\":[-1,0],\"PJ\":[-5,0],\"Pj\":[-2,0],\"Rj\":[-2,0],\"Sj\":[-2,0],\"TA\":[-2,0],\"TJ\":[-3,0],\"Td\":[-3,0],\"Tf\":[-1,0],\"Tg\":[-3,0],\"Tj\":[-2,0],\"Tp\":[-3,0],\"Tq\":[-3,0],\"Ts\":[-3,0],\"Tt\":[-1,0],\"Tu\":[-3,0],\"Tv\":[-3,0],\"Tw\":[-3,0],\"Tx\":[-3,0],\"Ty\":[-3,0],\"Tz\":[-3,0],\"VA\":[-1,0],\"VJ\":[-2,0],\"Vj\":[-2,0],\"WA\":[-1,0],\"WJ\":[-1,0],\"Wj\":[-2,0],\"Xf\":[-1,0],\"Xj\":[-2,0],\"Xt\":[-1,0],\"Xv\":[-1,0],\"YA\":[-1,0],\"YJ\":[-2,0],\"Yj\":[-2,0],\"Zj\":[-2,0],\"aT\":[-3,0],\"aj\":[-2,0],\"bT\":[-3,0],\"bj\":[-2,0],\"cT\":[-3,0],\"cj\":[-2,0],\"eT\":[-3,0],\"ej\":[-2,0],\"fA\":[-1,0],\"fJ\":[-2,0],\"fj\":[-2,0],\"hT\":[-3,0],\"hj\":[-2,0],\"ij\":[-2,0],\"kT\":[-3,0],\"kj\":[-2,0],\"mT\":[-3,0],\"mj\":[-2,0],\"nT\":[-3,0],\"nj\":[-2,0],\"oT\":[-3,0],\"oj\":[-2,0],\"pT\":[-3,0],\"pj\":[-2,0],\"qT\":[-3,0],\"rA\":[-1,0],\"rJ\":[-3,0],\"rT\":[-3,0],\"rX\":[-1,0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t8\nE\t6\nF\t6\nG\t8\nH\t7\nI\t2\nJ\t7\nK\t8\nL\t6\nM\t11\nN\t8\nO\t8\nP\t8\nQ\t8\nR\t7\nS\t7\nT\t8\nU\t8\nV\t8\nW\t12\nX\t8\nY\t6\nZ\t6\n[\t3\n\\\t6\n]\t3\n^\t6\n_\t7\n`\t3\na\t7\nb\t7\nc\t7\nd\t7\ne\t7\nf\t5\ng\t7\nh\t7\ni\t2\nj\t4\nk\t7\nl\t2\nm\t10\nn\t7\no\t7\np\t7\nq\t7\nr\t5\ns\t6\nt\t4\nu\t7\nv\t6\nw\t10\nx\t7\ny\t7\nz\t6\n{\t5\n|\t2\n}\t5\n~\t8\n…\t8\n¥\t8\n‼\t5\n™\t8\n©\t11\n®\t11\n。\t16\n、\t16\nぁ\t16\nあ\t16\nぃ\t16\nい\t16\nぅ\t16\nう\t16\nぇ\t16\nえ\t16\nぉ\t16\nお\t16\nか\t16\nが\t16\nき\t16\nぎ\t16\nく\t16\nぐ\t16\nけ\t16\nげ\t16\nこ\t16\nご\t16\nさ\t16\nざ\t16\nし\t16\nじ\t16\nす\t16\nず\t16\nせ\t16\nぜ\t16\nそ\t16\nぞ\t16\nた\t16\nだ\t16\nち\t16\nぢ\t16\nっ\t16\nつ\t16\nづ\t16\nて\t16\nで\t16\nと\t16\nど\t16\nな\t16\nに\t16\nぬ\t16\nね\t16\nの\t16\nは\t16\nば\t16\nぱ\t16\nひ\t16\nび\t16\nぴ\t16\nふ\t16\nぶ\t16\nぷ\t16\nへ\t16\nべ\t16\nぺ\t16\nほ\t16\nぼ\t16\nぽ\t16\nま\t16\nみ\t16\nむ\t16\nめ\t16\nも\t16\nゃ\t16\nや\t16\nゅ\t16\nゆ\t16\nょ\t16\nよ\t16\nら\t16\nり\t16\nる\t16\nれ\t16\nろ\t16\nゎ\t16\nわ\t16\nゐ\t16\nゑ\t16\nを\t16\nん\t16\nゔ\t16\nゕ\t16\nゖ\t16\n゛\t1\n゜\t0\nゝ\t16\nゞ\t16\nゟ\t16\n゠\t16\nァ\t16\nア\t16\nィ\t16\nイ\t16\nゥ\t16\nウ\t16\nェ\t16\nエ\t16\nォ\t16\nオ\t16\nカ\t16\nガ\t16\nキ\t16\nギ\t16\nク\t16\nグ\t16\nケ\t16\nゲ\t16\nコ\t16\nゴ\t16\nサ\t16\nザ\t16\nシ\t16\nジ\t16\nス\t16\nズ\t16\nセ\t16\nゼ\t16\nソ\t16\nゾ\t16\nタ\t16\nダ\t16\nチ\t16\nヂ\t16\nッ\t16\nツ\t16\nヅ\t16\nテ\t16\nデ\t16\nト\t16\nド\t16\nナ\t16\nニ\t16\nヌ\t16\nネ\t16\nノ\t16\nハ\t16\nバ\t16\nパ\t16\nヒ\t16\nビ\t16\nピ\t16\nフ\t16\nブ\t16\nプ\t16\nヘ\t16\nベ\t16\nペ\t16\nホ\t16\nボ\t16\nポ\t16\nマ\t16\nミ\t16\nム\t16\nメ\t16\nモ\t16\nャ\t16\nヤ\t16\nュ\t16\nユ\t16\nョ\t16\nヨ\t16\nラ\t16\nリ\t16\nル\t16\nレ\t16\nロ\t16\nヮ\t16\nワ\t16\nヰ\t16\nヱ\t16\nヲ\t16\nン\t16\nヴ\t16\nヵ\t16\nヶ\t16\nヷ\t16\nヸ\t16\nヹ\t16\nヺ\t16\n・\t16\nー\t16\nヽ\t16\nヾ\t16\nヿ\t16\n「\t16\n」\t16\n円\t16\n�\t13\n\nFa\t-1\nFc\t-1\nFe\t-1\nFo\t-1\nFm\t-1\nFn\t-1\nFr\t-1\nTa\t-3\nTc\t-3\nTe\t-3\nTo\t-3\nTm\t-3\nTn\t-3\nTr\t-3\nDj\t-2\nOj\t-2\nHj\t-2\nIj\t-2\nMj\t-2\nNj\t-2\ndj\t-2\nlj\t-2\nJj\t-2\nUj\t-2\ngT\t-3\nyT\t-3\nAT\t-2\nAV\t-1\nAW\t-1\nAY\t-1\nAf\t-1\nAj\t-2\nAt\t-1\nBT\t-1\nBV\t-1\nBW\t-1\nBY\t-1\n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local ScreenWidth <const> = playdate.display.getWidth()\nlocal ScreenHeight <const> = playdate.display.getHeight()\n\nPanels.Alert = {}\n\nlocal titleFont = gfx.getSystemFont(\"bold\")\nlocal textFont = gfx.getSystemFont()\nlocal listFont = gfx.getSystemFont()\nlocal animator = nil\nlocal dimScreen = gfx.image.new(ScreenWidth, ScreenHeight, Panels.Color.BLACK)\nlocal gridView = nil\n\nlocal selectionSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/selection.wav\")\nlocal selectionRevSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/selection-reverse.wav\")\nlocal denialSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/denial.wav\")\nlocal confirmSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/confirm.wav\")\n\nlocal hideSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/swish-out.wav\")\nlocal showSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/swish-in.wav\")\n\n\nfunction Panels.Alert.new(title, text, options, callback, selection)\n    local width = 320\n    local height = 150\n    local x = (ScreenWidth - width) / 2\n    local y = (ScreenHeight - height) / 2 - 8\n    local offset = 0\n    \n    if Panels.Settings.menuFontFamily then \n        local family = Panels.Font.getFamily(Panels.Settings.menuFontFamily)\n        titleFont = family\n        textFont = family\n        listFont = family\n        \n    elseif Panels.Settings.defaultFontFamily then \n        local family = Panels.Font.getFamily(Panels.Settings.defaultFontFamily)\n        titleFont = family\n        textFont = family\n        listFont = family\n    end\n\n    gridView = playdate.ui.gridview.new((width - 32) / 2 - 8, 32)\n    gridView:setNumberOfRows(1)\n\tgridView:setNumberOfColumns(#options)\n\tgridView:setCellPadding(4,4, 4, 4)\n\tgridView:setSelection(1, 1, selection or 1)\n\n    local alert = {\n        isActive = false,\n        title = title,\n        text = text,\n        options = options,\n        selection = selection or 1,\n        state = \"hidden\"\n    }\n\n    function alert:getSelection()\n        return self.selection\n    end\n\n    function gridView:drawCell(section, row, column, selected, x, y, width, height)\n        gfx.pushContext()\n        local text = alert.options[column]\n        if selected then\n            gfx.setColor(gfx.kColorBlack)\n            gfx.fillRoundRect(x + offset, y, width, height, 4)\n            gfx.setImageDrawMode(gfx.kDrawModeFillWhite)\n            text = \"*\" .. text .. \"*\"\n            offset = 0\n        else\n            gfx.setImageDrawMode(gfx.kDrawModeCopy)\n        end\n        \n        gfx.setFont(listFont)\n        gfx.drawTextInRect(text, x, y+8, width, height+2, nil, \"...\", kTextAlignment.center)\n        gfx.popContext()\n    end\n\n    function alert:drawBG(progress) \n        local w = width * progress\n        local h = height * progress\n\n        local _x = x + (width - w) / 2\n        local _y =  y + (height - h) / 2\n\n        gfx.pushContext()\n        gfx.setColor(Panels.Color.WHITE)\n        gfx.setLineWidth(6)\n        gfx.drawRoundRect(_x, _y, w, h, 10)\n        gfx.fillRoundRect(_x, _y, w, h, 8)\n        gfx.setColor(Panels.Color.BLACK)\n        gfx.setLineWidth(2)\n        gfx.drawRoundRect(_x, _y, w, h, 8)\n        gfx.popContext()\n    end\n\n    function alert:drawText()\n        gfx.setFont(titleFont)\n        gfx.drawTextInRect(\"*\".. self.title .. \"*\", x + 16, y + 16, width - 32, 32, nil, \"...\", kTextAlignment.center)\n        gfx.setFont(textFont)\n        gfx.drawTextInRect(self.text, x + 16, y + 48, width - 32, height - 128, nil, \"...\", kTextAlignment.center)\n    end\n\n    function alert:hide()\n        self.state = \"hiding\"\n        animator = gfx.animator.new(200, 1, 0, playdate.easingFunctions.inOutQuad)\n        playdate.inputHandlers.pop()\n\n        if Panels.Settings.playMenuSounds then\n            hideSound:play()\n        end\n    end\n\n    function alert:show() \n        self.state = \"showing\"\n        local inputHandlers = {\n            rightButtonUp = function()\n                local s, r, column = gridView:getSelection()\n                if Panels.Settings.playMenuSounds then \n                    if column == #self.options then\n                        denialSound:play()\n                    else\n                        selectionSound:play()\n                    end\n                end\n                offset = 4\n                gridView:selectNextColumn(false)\n\n            end,\n            \n            leftButtonUp = function()\n                local s, r, column = gridView:getSelection()\n                if Panels.Settings.playMenuSounds then \n                    if column == 1 then\n                        denialSound:play()\n                    else\n                        selectionRevSound:play()\n                    end\n                end\n\n                offset = -4\n                gridView:selectPreviousColumn(false)\n            end,\n            \n            AButtonDown = function()\n                local s, r, column = gridView:getSelection()\n                self.selection = column\n                self:hide()\n\n                if Panels.Settings.playMenuSounds then\n                    confirmSound:play()\n                end\n            end,\n    \n            BButtonDown = function()\n                self.selection = 1\n                self:hide()\n            end,\n    \n        }\n\n        self.isActive = true\n        animator = gfx.animator.new(250, 0, 1, playdate.easingFunctions.inOutQuad)\n        playdate.inputHandlers.push(inputHandlers, true)\n        if Panels.Settings.playMenuSounds then\n            showSound:play()\n        end\n    end\n\n    function alert:udpate()\n        local progress = animator:currentValue()\n\n        dimScreen:drawFaded(0, 0, 0.5 * progress, gfx.image.kDitherTypeBayer8x8)\n        self:drawBG(progress)\n        if progress >= 1 then \n            self:drawText()\n            gridView:drawInRect(x + 16, y + height - 42 - 8, width - 32, 42)\n            self.state = \"visible\"\n        end\n\n        if self.state ~= \"hidden\" and progress <= 0 and animator:ended() then\n            if self.onHide then\n                self.state = \"hidden\"\n                self:onHide()\n            end\n        end\n    end\n\n    return alert\nend"
  },
  {
    "path": "modules/Audio.lua",
    "content": "local bgAudioPlayer = nil\nlocal shouldResume = false\nlocal repeatCount = 1\nlocal typingRetainCount = 0\nlocal typingSamplePlayer\n\nlocal typingIsMuted = false\n\nlocal bgAudioFile = \"\"\n\nPanels.Audio = {\n\tTypingSound = {\n\t\tDEFAULT = \"default\",\n\t\tNONE = \"none\"\n\t}\n}\n\nfunction Panels.Audio.createTypingSound()\n\tlocal path = Panels.Settings.path .. \"assets/audio/typingBeep\"\n\tif Panels.Settings.typingSound ~= Panels.Audio.TypingSound.NONE then\n\t\tif Panels.Settings.typingSound ~= Panels.Audio.TypingSound.DEFAULT then\n\t\t\tpath = Panels.Settings.audioFolder .. Panels.Settings.typingSound\n\t\tend\n\t\ttypingSamplePlayer = playdate.sound.sampleplayer.new(path)\n\tend\nend\n\nfunction onBGFinished(player)\n\tif player:didUnderrun() then \n\t\tprintError(\"\", \"Background audio fileplayer stopped due to buffer underrun\")\n\tend\nend\n\n\nfunction Panels.Audio.fileIsPlaying(path)\n\tif path == nil then return false end\n\n\tif string.sub(path, -4) == \".wav\" then\n\t\tpath = string.sub(path, 0, -5)\n\tend\n\tpath = Panels.Settings.audioFolder .. path\n\treturn bgAudioFile == path and bgAudioPlayer and bgAudioPlayer:isPlaying()\nend\n\nfunction Panels.Audio.startBGAudio(path, loop, volume)\n\tif string.sub(path, -4) == \".wav\" then\n\t\tpath = string.sub(path, 0, -5)\n\tend\n\n\tbgAudioFile = path\n\n\tif bgAudioPlayer then\n\t\tPanels.Audio.fadeOut(bgAudioPlayer)\n\tend\n\tbgAudioPlayer, error = playdate.sound.fileplayer.new(path, 2)\n\tif bgAudioPlayer then\n\t\tbgAudioPlayer:setFinishCallback(onBGFinished, bgAudioPlayer)\n\t\tif loop then repeatCount = 0 else repeatCount = 1 end\n\t\tsuccess, e = bgAudioPlayer:play(repeatCount)\n\t\tif e then\n\t\t\tprintError(e, \"Error playing bg audio:\")\n\t\telse\n\t\t\tbgAudioPlayer:setVolume(volume or 1)\n\t\tend\n\n\telse\n\t\tprintError(error, \"Error loading background audio:\")\n\tend\n\nend\n\nfunction Panels.Audio.stopBGAudio()\n\tif bgAudioPlayer then\n\t\tbgAudioPlayer:stop()\n\t\tshouldResume = false\n\tend\nend\n\nfunction Panels.Audio.killBGAudio()\n\tif bgAudioPlayer then\n\t\tbgAudioPlayer:stop()\n\t\tshouldResume = false\n\t\tbgAudioPlayer = nil\n\tend\nend\n\nfunction Panels.Audio.fadeOutAndKill()\n\tif bgAudioPlayer then\n\n\t\tlocal function onFadeComplete(player)\n\t\t\tplayer:stop()\n\t\t\tshouldResume = false\n\t\t\tplayer = nil\n\t\tend\n\n\t\tbgAudioPlayer:setVolume(0, 0, 0.5, onFadeComplete, bgAudioPlayer)\n\n\tend\nend\n\n\nfunction Panels.Audio.pauseBGAudio()\n\tif bgAudioPlayer and (bgAudioPlayer:isPlaying() or shouldResume) then\n\t\tshouldResume = true\n\t\tbgAudioPlayer:pause()\n\telse\n\t\tshouldResume = false\n\tend\nend\n\nfunction Panels.Audio.resumeBGAudio()\n\tif bgAudioPlayer and shouldResume then\n\t\tbgAudioPlayer:play(repeatCount)\n\tend\nend\n\nfunction Panels.Audio.bgAudioIsPlaying()\n\treturn bgAudioPlayer and bgAudioPlayer:isPlaying()\nend\n\nfunction Panels.Audio.startTypingSound()\n\tif not typingIsMuted and typingSamplePlayer then\n\t\ttypingRetainCount = typingRetainCount + 1\n\t\ttypingSamplePlayer:play(0)\n\tend\nend\n\nfunction Panels.Audio.stopTypingSound()\n\ttypingRetainCount = typingRetainCount - 1\n\n\tif typingSamplePlayer and typingRetainCount <= 0 then\n\t\ttypingRetainCount = 0\n\t\ttypingSamplePlayer:stop()\n\tend\nend\n\nfunction Panels.Audio.muteTypingSounds()\n\tif typingSamplePlayer then\n\t\ttypingIsMuted = true\n\t\ttypingRetainCount = 0\n\t\ttypingSamplePlayer:stop()\n\tend\nend\n\nfunction Panels.Audio.unmuteTypingSounds()\n\ttypingIsMuted = false\nend\n\nfunction Panels.Audio.fadeOut(player)\n\tlocal function onFadeComplete(player)\n\t\tplayer:stop()\n\tend\n\n\tplayer:setVolume(0, 0, 1, onFadeComplete, player)\n\nend\n"
  },
  {
    "path": "modules/ButtonIndicator.lua",
    "content": "Panels.ButtonIndicator = {}\n\nlocal ScreenWidth <const> = playdate.display.getWidth()\nlocal ScreenHeight <const> = playdate.display.getHeight()\n\nlocal gfx <const> = playdate.graphics\n\nPanels.ControlSize = {\n\tLARGE = 40,\n\tMEDIUM = 30,\n\tSMALL = 20,\n}\n\nfunction Panels.ButtonIndicator.getPosititonForScrollDirection(direction, _size)\n\tlocal size = _size or Panels.ControlSize.LARGE\n\n\tlocal x = ScreenWidth - size - 2\n\t\tlocal y = (ScreenHeight - size) / 2\n\t\tif direction == Panels.ScrollDirection.RIGHT_TO_LEFT then\n\t\t\tx = 2\n\t\telseif direction == Panels.ScrollDirection.TOP_DOWN then\n\t\t\tx = (ScreenWidth - size ) / 2\n\t\t\ty = ScreenHeight - size - 2\n\t\telseif direction == Panels.ScrollDirection.BOTTOM_UP then\n\t\t\tx = (ScreenWidth - size ) / 2\n\t\t\ty = 2\n\t\tend\n\n\treturn x, y\nend\n\nfunction Panels.ButtonIndicator.new(size)\n\tlocal button = {imageTable = nil, holdFrame = 4}\n\tbutton.currentFrame = 1\n\tbutton.step = 1\n\tbutton.state = \"hidden\"\n\tbutton.x = 0\n\tbutton.y = 0\n\tbutton.button = \"0\"\n\tbutton.size = size or Panels.ControlSize.LARGE\n\t\n\tbutton.timer = playdate.timer.new(\n\t\t50, \n\t\tfunction()\n\t\t\tbutton:updateTimer()\n\t\tend\n\t)\n\tbutton.timer.repeats = true\n\tbutton.timer.paused = true\n\t\n\tfunction button:setPosition(x, y)\n\t\tself.x = x\n\t\tself.y = y\n\tend\n\t\n\tfunction button:setButton(input)\n\t\tif self.button ~= input then\n\t\t\tlocal imageName = \"\"\n\t\t\tif input == Panels.Input.A then\n\t\t\t\timageName = \"buttonA\"\n\t\t\telseif input == Panels.Input.B then\n\t\t\t\timageName = \"buttonB\"\n\t\t\telseif input == Panels.Input.UP then\n\t\t\t\timageName = \"buttonUP\"\n\t\t\telseif input == Panels.Input.RIGHT then\n\t\t\t\timageName = \"buttonRT\"\n\t\t\telseif input == Panels.Input.DOWN then\n\t\t\t\timageName = \"buttonDN\"\n\t\t\telse\n\t\t\t\timageName = \"buttonLT\"\n\t\t\tend\n\n\t\t\tlocal imagePathSuffix = \"-table-40-40.png\"\n\t\t\tif self.size == Panels.ControlSize.SMALL then imagePathSuffix = \"-SM-table-20-20.png\" end\n\t\t\tif self.size == Panels.ControlSize.MEDIUM then imagePathSuffix = \"-MD-table-30-30.png\" end\n\t\t\t\n\t\t\tself.imageTable = gfx.imagetable.new(\n\t\t\t\tPanels.Settings.path .. \"assets/images/\" .. imageName .. imagePathSuffix)\n\t\tend\n\tend\n\t\n\tfunction button:setPositionForScrollDirection(direction)\n\t\tprint(\"Setting position for scroll direction. size: \" .. self.size)\n\t\tlocal x, y = Panels.ButtonIndicator.getPosititonForScrollDirection(direction, self.size)\n\t\tself:setPosition(x, y)\n\tend\n\t\n\tfunction button:reset() \n\t\tself.state = \"hidden\"\n\t\tself.currentFrame = 1\n\t\tself.timer:pause()\n\t\tself.step = 1\n\tend\n\n\tfunction button:show()\n\t\tif self.currentFrame == 1 and self.state ~= \"showing\" then \n\t\t\tself.state = \"showing\"\n\t\t\tself.step = 1\n\t\t\tself.timer:start()\n\t\tend\n\tend\n\t\n\tfunction button:hide()\n\t\tif self.currentFrame <= self.holdFrame and self.state ~= \"hiding\" then\n\t\t\tself.state = \"hiding\"\n\t\t\tself.step = -1\n\t\t\tself.timer:start()\n\t\tend\n\tend\n\t\n\tfunction button:press()\n\t\tself.state = \"pressing\"\n\t\tself.timer:pause()\n\t\tself.step = 1\n\t\tself.currentFrame = self.holdFrame + 1\n\t\tself.timer:start()\n\tend\n\t\n\tfunction button:updateTimer()\n\t\tif self.imageTable then \n\t\t\tself.currentFrame = self.currentFrame + self.step\n\t\n\t\t\tif self.currentFrame < 1 or self.currentFrame >= #self.imageTable then\n\t\t\t\tself.currentFrame = 1\n\t\t\t\tself.timer:pause()\n\t\t\t\tself.state = \"hidden\"\n\t\t\telseif self.currentFrame == self.holdFrame then\n\t\t\t\tself.timer:pause() \n\t\t\tend\n\t\tend\n\tend\n\t\n\tfunction button:draw(x, y)\n\t\tif self.imageTable then \n\t\t\tself.imageTable:drawImage(self.currentFrame, x or self.x, y or self.y)\n\t\tend\n\tend\n\t\n\treturn button\nend"
  },
  {
    "path": "modules/ChoiceList.lua",
    "content": "\nlocal gfx<const> = playdate.graphics\nPanels.ChoiceList = {}\n\nlocal function renderChoiceButton(text, x, y, w, h, radius, fontFamily, selected)\n\tif selected then text = \"*\" .. text .. \"*\" end\n\n\tgfx.pushContext()\n\t\t-- draw button background with inverted color\n\t\tif gfx.getColor() == Panels.Color.WHITE then \n\t\t\tgfx.setColor(Panels.Color.BLACK)\n\t\telse\n\t\t\tgfx.setColor(Panels.Color.WHITE)\n\t\tend\n\t\tgfx.fillRoundRect(x + 3, y + 3, w - 6, h - 6, radius)\n\tgfx.popContext()\n\n\tgfx.pushContext()\n\t\tgfx.setLineWidth(1)\n\t\tgfx.drawRoundRect(x + 3, y + 3, w - 6, h - 6, radius)\n\n\t\tlocal _tw, textHeight = gfx.getTextSizeForMaxWidth(text, w -6)\n\n\t\tgfx.drawTextAligned(text, x + (w /2), y + (h / 2) - textHeight/2, Panels.TextAlignment.CENTER)\n\t\t\n\t\tif selected then \n\t\t\tgfx.setLineWidth(2)\n\t\t\tgfx.drawRoundRect(x, y, w, h, radius + 2)\n\t\tend\n\tgfx.popContext()\nend\n\nlocal function getDefaultSelection(buttons)\n\tfor i, button in ipairs(buttons) do\n\t\tif button.selected then\n\t\t\treturn i\n\t\tend\n\tend\n\treturn 1\nend\n\nlocal function getButtonAutoSize(buttons, maxWidth, fontFamily\t)\n\tlocal buttonW = 0\n\tlocal buttonH = 0\n\n\tgfx.pushContext()\n\t\tif(fontFamily) then\n\t\t\tgfx.setFontFamily(Panels.Font.getFamily(fontFamily))\n\t\tend\n\tfor i, button in ipairs(buttons) do\n\t\t-- we have to test both normal and selected sizes\n\t\t-- because sometimes bold is wider and sometimes normal is wider\n\t\tlocal tw, th = gfx.getTextSize(button.label)\n\t\tlocal bw, bh = gfx.getTextSize(\"*\" .. button.label .. \"*\")\n\t\tlocal w = math.max(tw, bw)\n\t\tlocal h = math.max(th, bh)\n\n\t\tif w > buttonW then\n\t\t\tbuttonW = w\n\t\tend\n\t\tif h > buttonH then\n\t\t\tbuttonH = h\n\t\tend\n\tend\n\tgfx.popContext()\n\treturn math.min(buttonW + 40, maxWidth), buttonH + 30\nend\n\nfunction createPointerTimer(choiceList)\n\tpointerTimer = playdate.timer.new(600, 0, 8, playdate.easingFunctions.inOutSine)\n\tpointerTimer.reverses = true\n\tpointerTimer.repeats = true\n\tpointerTimer.updateCallback = function(timer)\n\t\tchoiceList.pointerX = timer.value\n\tend\nend\n\n\nfunction Panels.ChoiceList.new(data, frame, selectionCallback)\n\n\tlocal choiceList = {\n\t\tbuttons = data.buttons,\n\t\tselectedIndex = getDefaultSelection(data.buttons),\n\t\tfontFamily = data.fontFamily,\n\t\tonSelectionChangePanelCallback = selectionCallback,\n\t\tonSelectionChangeUserCallback = data.onSelectionChange,\n\t\trenderButton = data.buttonRenderFunction or renderChoiceButton,\n\t\tdidInit = false\n\t}\n\n\tchoiceList.pointer = gfx.image.new(Panels.Settings.path .. \"assets/images/pointer.png\")\n\tchoiceList.pointerX = 0\n\n\tlocal color = data.color or Panels.Color.BLACK\n\tlocal autoW, autoH = getButtonAutoSize(choiceList.buttons, math.min(frame.width, 380), choiceList.fontFamily)\n\n\tlocal w = data.width or autoW\n\tlocal h = data.height or autoH\n\tlocal spacing = data.spacing or 6\n\tlocal borderRadius = data.borderRadius or 4\n\t\n\tlocal x = data.x or (frame.width - w) / 2\n\n\tlocal totalHeight = (#choiceList.buttons * h) + ((#choiceList.buttons -1) * (spacing))\n\tlocal y = data.y or (frame.height - totalHeight) / 2\n\n\n\tfunction choiceList:render()\n\t\tif(pointerTimer == nil) then\n\t\t\tcreatePointerTimer(self)\n\t\tend\n\n\t\tif not self.didInit then\n\t\t\tself.didInit = true\n\t\t\tself.onSelectionChangePanelCallback(self.selectedIndex, self.buttons[self.selectedIndex])\n\t\tend\n\n\t\tself:checkInput()\n\n\t\tgfx.pushContext()\n\t\t\tif(self.fontFamily) then\n\t\t\t\tgfx.setFontFamily(Panels.Font.getFamily(self.fontFamily))\n\t\t\tend\n\n\t\t\tgfx.setColor(color)\n\t\t\tif color == Panels.Color.WHITE then \n\t\t\t\tgfx.setImageDrawMode(gfx.kDrawModeFillWhite)\n\t\t\telse\n\t\t\t\tgfx.setImageDrawMode(gfx.kDrawModeCopy)\n\t\t\tend\n\t\t\n\t\t\tfor i, button in ipairs(self.buttons) do\n\t\t\t\tself.renderButton(button.label, x, y + (h + spacing) * (i-1), w, h, borderRadius, self.fontFamily, self.selectedIndex == i)\n\t\t\tend\n\t\tgfx.popContext()\n\t\t\n\t\tlocal pointerY = y + (self.selectedIndex -1) * (h + spacing) + (h -self.pointer.height )/2\n\t\tself.pointer:draw(x + w - 16 + self.pointerX, pointerY)\n\tend\n\n\n\tfunction choiceList:checkInput()\n\t\tif playdate.buttonJustPressed(Panels.Input.UP) then\n\t\t\tif self.selectedIndex > 1 then \n\t\t\t\tself.selectedIndex = self.selectedIndex - 1\n\n\t\t\t\tself.onSelectionChangePanelCallback(self.selectedIndex, self.buttons[self.selectedIndex])\n\t\t\tend\n\n\t\telseif playdate.buttonJustPressed(Panels.Input.DOWN) then\n\t\t\tif self.selectedIndex < #self.buttons then \n\t\t\t\tself.selectedIndex = self.selectedIndex + 1\n\t\t\t\tself.onSelectionChangePanelCallback(self.selectedIndex, self.buttons[self.selectedIndex])\n\t\t\tend\n\t\tend\n\tend\n\n\tfunction choiceList:reset() \n\t\tpointerTimer:remove()\n\t\tpointerTimer = nil\n\tend\n\n\treturn choiceList\n\nend\n\n"
  },
  {
    "path": "modules/Color.lua",
    "content": "Panels.Color = {\n\tWHITE = playdate.graphics.kColorWhite,\n\tBLACK = playdate.graphics.kColorBlack,\n\tCLEAR = playdate.graphics.kColorClear,\n}\n\nfunction Panels.Color.invert(color)\n\tif color == Panels.Color.BLACK then\n\t\treturn Panels.Color.WHITE\n\telse\n\t\treturn Panels.Color.BLACK\n\tend\nend"
  },
  {
    "path": "modules/Credits.lua",
    "content": "local gfx <const> = playdate.graphics\nlocal ScreenWidth <const> = playdate.display.getWidth()\nlocal ScreenHeight <const> = playdate.display.getHeight()\n\nPanels.Credits = {}\n\nlocal qrCode = gfx.image.new(Panels.Settings.path .. \"assets/images/panelsPagesQR.png\")\nlocal url = \"cadin.github.io/panels\"\n\n\nlocal maxScroll = 0\nlocal scrollAcceleration = 0.25\nlocal maxScrollVelocity = 6\nlocal scrollVelocity = 0\nlocal snapStrength = 1.5\n\nlocal headerHeight = 48\nlocal bottomPadding = 24\nlocal panelsCreditHeight = 78\n\nlocal function createPanelsCredits()\n\tlocal img = gfx.image.new(244, 54, Panels.Color.BLACK)\n\tgfx.pushContext(img)\n\tgfx.setImageDrawMode(gfx.kDrawModeInverted)\n\t\n\tqrCode:draw(0, 0)\n\tgfx.drawText(\"*Built with Panels*\", 64, 7)\n\tgfx.drawText(url, 64, 29)\n\t\n\tgfx.popContext()\n\treturn img\nend\n\nlocal function measureCreditsHeight(credits)\n\tlocal height = 1\n\tif credits.lines == nil then return height end\n\n\tfor i, line in ipairs(credits.lines) do\n\t\tif line.text then \n\t\t\tlocal w, h = gfx.getTextSize(line.text)\n\t\t\theight = height + h + (line.spacing or 0)\n\t\telseif line.image then\n\t\t\tlocal img = gfx.image.new(Panels.Settings.imageFolder .. line.image)\n\t\t\tlocal w, h = img:getSize()\n\t\t\theight = height + h + (line.spacing or 0)\n\t\tend\n\tend\n\t\n\treturn height\nend\n\nlocal function getPositionForAlignment(alignment)\n\tlocal x = 32\n\tif alignment == kTextAlignment.center then\n\t\tx = ScreenWidth / 2\n\telseif alignment == kTextAlignment.right then\n\t\tx = ScreenWidth - 32\n\tend\n\n\treturn x\nend\n\nlocal function getAnchorForAlignment(alignment)\n\tlocal anchor = 0\n\tif alignment == kTextAlignment.center then\n\t\tanchor = 0.5\n\telseif alignment == kTextAlignment.right then\n\t\tanchor = 1\n\t\t\n\tend\n\treturn anchor\nend\n\nlocal function createGameCredits(credits)\n\t\n\tlocal textAlignment = credits.alignment or kTextAlignment.center\n\tlocal creditsHeight = measureCreditsHeight(credits)\n\tlocal img = gfx.image.new(400, creditsHeight)\n\tlocal defaultX = getPositionForAlignment(textAlignment)\n\tlocal alignment = textAlignment\n\tgfx.pushContext(img)\n\n\tlocal font = gfx.getSystemFont()\n\tif credits.font then \n\t\tfont = Panels.Font.get(credits.font)\n\t\tgfx.setFont(font)\n\telseif credits.fontFamily then\n\t\tlocal family  = Panels.Font.getFamily(credits.fontFamily)\n\t\tgfx.setFontFamily(family)\n\n\telseif Panels.Settings.menuFontFamily then\n\t\tlocal family  = Panels.Font.getFamily(Panels.Settings.menuFontFamily)\n\t\tgfx.setFontFamily(family)\n\telse\n\t\tgfx.setFont(font)\n\tend\n\tlocal y = 0\n\t\n\tif credits.lines then \n\t\tfor i, line in ipairs(credits.lines) do\n\t\t\n\t\t\tlocal f = font\n\t\t\tif line.font then\n\t\t\t\tf = Panels.Font.get(line.font)\n\t\t\t\tgfx.setFont(f)\n\t\t\tend\n\n\t\t\ty = y +  (line.spacing or 0)\n\t\t\tif line.alignment then \n\t\t\t\talignment = line.alignment\n\t\t\t\tx = getPositionForAlignment(line.alignment)\n\t\t\telse\n\t\t\t\talignment = textAlignment\n\t\t\t\tx = defaultX\n\t\t\tend\n\t\t\t\n\t\t\tif line.text then \n\t\t\t\tgfx.drawTextAligned(line.text, x, y, alignment)\n\t\t\t\tlocal w, h = gfx.getTextSize(line.text)\n\t\t\t\ty = y + h\n\t\t\t\t\n\t\t\telseif line.image then\n\t\t\t\tlocal img = gfx.image.new(Panels.Settings.imageFolder .. line.image)\n\t\t\t\tlocal w, h = img:getSize()\n\t\t\t\tlocal anchorX = getAnchorForAlignment(alignment)\n\t\t\t\timg:drawAnchored(x, y, anchorX, 0)\n\t\t\t\t\n\t\t\t\ty = y + h\n\t\t\tend\n\t\tend\n\tend\n\tgfx.popContext()\n\t\n\treturn img\nend\n\nlocal autoScrollTimeout = nil\nlocal isAutoScrolling = false\n\nlocal function startAutoScroll()\n\tisAutoScrolling = true\nend\n\nlocal function killAutoScrolling()\n\tisAutoScrolling = false\n\tif autoScrollTimeout then \n\t\tautoScrollTimeout:reset()\n\tend\nend\n\n\nfunction Panels.Credits.new()\n\t\n\tlocal data = Panels.credits\n\tif data.hideStandardHeader then headerHeight = 8 end\n\t\n\tlocal gameCreditsHeight = math.max(measureCreditsHeight(data), 138 - headerHeight)\n\n\tlocal credits = {\n\t\tgameCredits = createGameCredits(data),\n\t\tpanelsImg = createPanelsCredits(),\n\t\tshowHeader = not data.hideStandardHeader,\n\t\tscrollPos = 0,\n\t\tisScrollable = false,\n\t\tshouldAutoScroll = data.autoScroll or false,\n\t\theight = gameCreditsHeight + headerHeight + bottomPadding + panelsCreditHeight\n\t}\n\t\n\tif gameCreditsHeight > 138 - headerHeight then \n\t\tcredits.isScrollable = true\n\tend\n\t\n\tmaxScroll = -(gameCreditsHeight + headerHeight + bottomPadding + panelsCreditHeight - ScreenHeight)\n\n\n\tfunction credits:drawPanelsCredits(x, y) \n\t\tgfx.drawLine(0, y, 400, y)\n\t\tgfx.setColor(Panels.Color.BLACK)\n\t\tgfx.fillRect(0, y, 400, 180) -- 78\n\t\tself.panelsImg:draw(90, y + 12)\n\tend\n\t\n\tfunction credits:drawHeader(posY)\n\t\tgfx.drawTextAligned(\"*Credits*\", 200, posY + 12, kTextAlignment.center)\n\t\tgfx.setLineWidth(1)\n\t\tgfx.drawLine(32, posY + 20, 32 + 120, posY + 20)\n\t\tgfx.drawLine(368 - 120, posY + 20, 368, posY + 20)\n\tend\n\t\n\tfunction credits:cranked(change)\n\t\tif self.isScrollable then \n\t\t\tself.scrollPos += change\n\t\t\tkillAutoScrolling()\n\t\tend\n\tend\n\t\n\tfunction credits:onDidShow()\n\t\tif self.shouldAutoScroll then \n\t\t\tautoScrollTimeout = playdate.timer.new(1500, startAutoScroll)\n\t\t\tautoScrollTimeout.discardOnCompletion = false\n\t\tend\n\tend\n\t\n\tfunction credits:checkForInput()\n\t\t-- button input\n\t\tif playdate.buttonIsPressed(Panels.Input.DOWN) then\n\t\t\tscrollVelocity = scrollVelocity - scrollAcceleration\n\t\t\tkillAutoScrolling()\n\t\telseif playdate.buttonIsPressed(Panels.Input.UP) then\n\t\t\tscrollVelocity = scrollVelocity + scrollAcceleration \n\t\t\tkillAutoScrolling()\n\t\telse\n\t\t\tscrollVelocity = scrollVelocity / 2\n\t\tend\n\t\t\n\t\t-- constrain to min/max\n\t\tif scrollVelocity > maxScrollVelocity then \t\n\t\t\tscrollVelocity = maxScrollVelocity \t\n\t\telseif scrollVelocity < -maxScrollVelocity then\n\t\t\tscrollVelocity = -maxScrollVelocity\n\t\tend\n\t\t\n\t\tself.scrollPos = self.scrollPos + scrollVelocity\n\t\t\n\t\t-- snap to bounds\n\t\tif self.scrollPos > 0 then\n\t\t\tself.scrollPos = math.floor(self.scrollPos / snapStrength)\t\t\n\t\telseif self.scrollPos < maxScroll then\n\t\t\tlocal diff = self.scrollPos - maxScroll\n\t\t\tself.scrollPos = math.floor(self.scrollPos - (diff - (diff / snapStrength )))\n\t\tend\n\tend\n\t\n\tfunction credits:redraw(yPos)\n\t\tif self.isScrollable then \n\t\t\tself:checkForInput()\n\t\t\tif isAutoScrolling then \n\t\t\t\tself.scrollPos = self.scrollPos - 1\n\t\t\tend\n\t\tend\n\t\t\n\t\tif self.showHeader then \n\t\t\tself:drawHeader(self.scrollPos + yPos)\n\t\tend\n\t\tself.gameCredits:draw(0, self.scrollPos + headerHeight + yPos)\n\t\tself:drawPanelsCredits(0, self.scrollPos + gameCreditsHeight + bottomPadding + headerHeight + yPos)\n\tend\n\t\n\t\n\treturn credits\nend"
  },
  {
    "path": "modules/Effect.lua",
    "content": "Panels.Effect = {\n\tSHAKE_UNISON = 1,\n\tSHAKE_INDIVIDUAL = 2,\n\tBLINK = 3,\n\tTYPE_ON = 4,\n\n\tSHAKE = 2,\n\tSHAKE_LAYER = 2,\n}"
  },
  {
    "path": "modules/Font.lua",
    "content": "Panels.Font = {\n\tNORMAL = playdate.graphics.font.kVariantNormal,\n\tBOLD = playdate.graphics.font.kVariantBold,\n\tITALIC = playdate.graphics.font.kVariantItalic\n}\n\nlocal function clipExtension(path)\n\tif string.sub(path, -4) == \".fnt\" then\n\t\tprint(\"Panels: Don't include '.fnt' extension in font paths\")\n\t\tprint(\"- '\" .. path .. \"'\")\n\t\tpath = string.sub(path, 0, -5)\n\tend\n\n\treturn path\nend\n\nlocal cache = {}\nfunction Panels.Font.get(path)\n\tpath = clipExtension(path)\n\n\tif cache[path] == nil then\n\t\tcache[path] = playdate.graphics.font.new(path)\n\tend\n\treturn cache[path]\nend\n\nlocal function clipExtensions(paths)\n\tfor key, value in pairs(paths) do\n\t\tpaths[key] = clipExtension(value)\n\tend\n\n\treturn paths\nend\n\nlocal families = {}\nfunction Panels.Font.getFamily(paths)\n\tlocal key = paths[Panels.Font.NORMAL]\n\tif key == nil then key = paths[Panels.Font.BOLD] end\n\tif key == nil then key = paths[Panels.Font.ITALIC] end\n\n\tif families[key] == nil then\n\t\tclipExtensions(paths)\n\t\tfamilies[key] = playdate.graphics.font.newFamily(paths)\n\tend\n\treturn families[key]\nend\n"
  },
  {
    "path": "modules/Image.lua",
    "content": "Panels.Image = { }\n\nlocal cache = {}\nfunction Panels.Image.get(path)\n    local error = nil\n\tif cache[path] == nil then\n\t\tcache[path], error = playdate.graphics.image.new(path)\n\tend\n\treturn cache[path], error\nend\n\nfunction Panels.Image.clearCache()\n    cache = {}\nend"
  },
  {
    "path": "modules/Input.lua",
    "content": "Panels.Input = {\n\tA = playdate.kButtonA,\n\tB = playdate.kButtonB,\n\tUP = playdate.kButtonUp,\n\tDOWN = playdate.kButtonDown,\n\tLEFT = playdate.kButtonLeft,\n\tRIGHT = playdate.kButtonRight\n}"
  },
  {
    "path": "modules/Layer.lua",
    "content": "local gfx <const> = playdate.graphics\nlocal ScreenHeight <const> = playdate.display.getHeight()\nlocal ScreenWidth <const> = playdate.display.getWidth()\n\nfunction Panels.renderLayerInPanel(layer, panel, offset)\n\n\tlocal pct = getScrollPercentages(panel.frame, offset, panel.axis)\n\tlocal cntrlPct = calculateControlPercent(pct, panel)\n\tlocal p = layer.parallax or 0\n\tlocal startValues = table.shallow_copy(layer)\n\tif layer.isExiting and layer.animate then\n\t\tfor k, v in pairs(layer.animate) do startValues[k] = v end\n\tend\n\n\tlocal xPos = math.floor(startValues.x + (panel.parallaxDistance * pct.x - panel.parallaxDistance / 2) * p)\n\tlocal yPos = math.floor(startValues.y + (panel.parallaxDistance * pct.y - panel.parallaxDistance / 2) * p)\n\tlocal rotation = 0\n\n\tif layer.animate or layer.isExiting then\n\t\tlocal anim = layer.animate\n\n\t\tif layer.isExiting then\n\t\t\tanim = layer.exit\n\t\t\tanim.scrollTrigger = 0\n\t\tend\n\n\t\tif (anim.triggerSequence or anim.scrollTrigger ~= nil) and not layer.animator then\n\n\t\t\tif layer.buttonsPressed == nil then layer.buttonsPressed = {} end\n\t\t\tlocal triggerButton = nil\n\t\t\tif not anim.scrollTrigger then\n\t\t\t\ttriggerButton = anim.triggerSequence[#layer.buttonsPressed + 1]\n\t\t\tend\n\n\t\t\tif anim.scrollTrigger ~= nil or pdButtonJustPressed(triggerButton) then\n\t\t\t\tlayer.buttonsPressed[#layer.buttonsPressed + 1] = triggerButton\n\t\t\t\tif (anim.scrollTrigger ~= nil and cntrlPct >= anim.scrollTrigger) or\n\t\t\t\t\t(anim.triggerSequence and #layer.buttonsPressed == #anim.triggerSequence) then\n\t\t\t\t\tlayer.animator = gfx.animator.new((anim.duration or 200), 0, 1, anim.ease, anim.delay)\n\t\t\t\t\tif layer.sfxPlayer then\n\t\t\t\t\t\tlocal count = anim.audio.repeatCount or 1\n\t\t\t\t\t\tif anim.audio.loop then count = 0 end\n\t\t\t\t\t\tplaydate.timer.performAfterDelay(anim.delay + (anim.audio.delay or 0), function()\n\t\t\t\t\t\t\tlayer.sfxPlayer:play(count)\n\t\t\t\t\t\tend)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\telse\n\t\t\tlocal layerPct = cntrlPct\n\t\t\tif layer.animator then\n\t\t\t\tlayerPct = layer.animator:currentValue()\n\t\t\tend\n\n\t\t\tif anim.x then xPos = math.floor(xPos + ((anim.x - startValues.x) * layerPct)) end\n\t\t\tif anim.y then yPos = math.floor(yPos + ((anim.y - startValues.y) * layerPct)) end\n\t\t\tif anim.rotation then rotation = anim.rotation * layerPct end\n\t\t\tif anim.opacity then\n\t\t\t\tlocal o = (anim.opacity - layer.opacity) * layerPct + layer.opacity\n\t\t\t\tlayer.alpha = o\n\t\t\t\tif o <= 0 then\n\t\t\t\t\tlayer.visible = false\n\t\t\t\telse\n\t\t\t\t\tlayer.visible = true\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\n\n\tif panel:layerShouldShake(layer) then\n\t\tif panel.effect and panel.effect.type == Panels.Effect.SHAKE_INDIVIDUAL then\n\t\t\tshake = calculateShake(panel.effect.strength or 2)\n\t\telseif layer.effect and layer.effect.type == Panels.Effect.SHAKE then\n\t\t\tshake = calculateShake(layer.effect.strength or 2)\n\t\tend\n\n\t\txPos = xPos + shake.x * (1 - p * p)\n\t\tyPos = yPos + shake.y * (1 - p * p)\n\tend\n\n\tif layer.effect then\n\t\tdoLayerEffect(layer, xPos, yPos)\n\tend\n\n\n\tlocal img\n\tif layer.img then\n\t\timg = layer.img\n\telseif layer.imgs then\n\t\tif layer.advanceControl then\n\t\t\tif pdButtonJustPressed(layer.advanceControl) then\n\t\t\t\tif layer.currentImage < #layer.imgs then\n\t\t\t\t\tlayer.currentImage = layer.currentImage + 1\n\t\t\t\tend\n\t\t\tend\n\t\t\timg = layer.imgs[layer.currentImage]\n\t\telse\n\t\t\tlocal p = cntrlPct\n\t\t\tp = p - (panel.transitionOffset or 0)\n\t\t\tp = p - (layer.transitionOffset or 0)\n\t\t\tlocal j = math.max(math.min(math.ceil(p * #layer.imgs), #layer.imgs), 1)\n\t\t\timg = layer.imgs[j]\n\t\tend\n\tend\n\n\tlocal globalX = xPos + offset.x + panel.frame.x\n\tlocal globalY = yPos + offset.y + panel.frame.y\n\n\tif img then\n\t\tif layer.visible then\n\n\t\t\tif globalX + img.width > 0 and globalX < ScreenWidth and globalY + img.height > 0 and globalY < ScreenHeight then\n\n\t\t\t\tif layer.alpha and layer.alpha < 1 then\n\t\t\t\t\timg:drawFaded(xPos, yPos, layer.alpha, playdate.graphics.image.kDitherTypeBayer8x8)\n\t\t\t\telse\n\t\t\t\t\tif layer.maskImg then\n\t\t\t\t\t\tlocal maskX = math.floor((panel.parallaxDistance * pct.x - panel.parallaxDistance / 2) * p) - panel.frame.margin\n\t\t\t\t\t\tlocal maskY = math.floor((panel.parallaxDistance * pct.y - panel.parallaxDistance / 2) * p) - panel.frame.margin\n\n\t\t\t\t\t\tlocal maskImg = gfx.image.new(ScreenWidth, ScreenHeight)\n\t\t\t\t\t\tgfx.lockFocus(maskImg)\n\t\t\t\t\t\tlayer.maskImg:draw(maskX, maskY)\n\t\t\t\t\t\tgfx.unlockFocus()\n\n\t\t\t\t\t\tgfx.setStencilImage(maskImg)\n\t\t\t\t\t\timg:draw(xPos, yPos)\n\t\t\t\t\t\tgfx.clearStencil()\n\t\t\t\t\telse\n\t\t\t\t\t\timg:draw(xPos, yPos)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\telseif layer.text then\n\t\tif layer.visible then\n\t\t\tif globalX + ScreenWidth > 0 and globalX < ScreenWidth and globalY + ScreenHeight > 0 and globalY < ScreenHeight then\n\t\t\t\tif layer.alpha == nil or layer.alpha > 0 then\n\t\t\t\t\tpanel:drawTextLayer(layer, xPos, yPos, cntrlPct)\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\telseif layer.animationLoop then\n\t\tif layer.visible then\n\t\t\tif layer.trigger then\n\t\t\t\tif pdButtonJustPressed(layer.trigger) then\n\t\t\t\t\tlayer.animationLoop.paused = false\n\t\t\t\tend\n\t\t\telseif layer.startDelay then\n\t\t\t\tif layer.startDelayTriggered == nil then\n\t\t\t\t\tplaydate.timer.performAfterDelay(layer.startDelay, function()\n\t\t\t\t\t\tif layer.animationLoop then layer.animationLoop.paused = false end\n\t\t\t\t\tend)\n\t\t\t\t\tlayer.startDelayTriggered = true\n\t\t\t\tend\n\t\t\telseif cntrlPct >= layer.scrollTrigger then\n\t\t\t\tlayer.animationLoop.paused = false\n\t\t\tend\n\t\t\tlayer.animationLoop:draw(xPos, yPos)\n\t\tend\n\tend\n\nend\n"
  },
  {
    "path": "modules/Menus.lua",
    "content": "import 'CoreLibs/ui/gridview.lua'\n\nlocal gfx <const> = playdate.graphics\n\nlocal ScreenWidth <const> = playdate.display.getWidth()\nlocal ScreenHeight <const> = playdate.display.getHeight()\n\nlocal selectionSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/selection.wav\")\nlocal selectionRevSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/selection-reverse.wav\")\nlocal denialSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/denial.wav\")\nlocal confirmSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/confirm.wav\")\n\nlocal hideSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/swish-out.wav\")\nlocal showSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. \"assets/audio/swish-in.wav\")\n\nlocal headerFont = gfx.getSystemFont(\"bold\")\nlocal listFont = gfx.getSystemFont()\n\nPanels.Menu = {}\n\n-- -------------------------------------------------\n-- GENERIC MENU\n\nlocal menuAnimationDuration <const> = 200\n\nlocal MenuState = {\n\tSHOWING = 0,\n\tOPEN = 1,\n\tHIDING = 2,\n\tCLOSED = 3\n}\n\nfunction Panels.Menu.new(height, redrawContent, inputHandlers)\n\tlocal menu = {}\n\t\n\tmenu.animator = nil\n\tmenu.state = MenuState.CLOSED\n\tmenu.isFullScreen = false\n\tmenu.onWillShow = nil\n\tmenu.onDidShow = nil\n\tmenu.onDidHide = nil\n\t\n\tif Panels.Settings.menuFontFamily then \n\t\tlocal family = Panels.Font.getFamily(Panels.Settings.menuFontFamily)\n\t\theaderFont = family\n\t\tlistFont = family\n\t\t\n\telseif Panels.Settings.defaultFontFamily then \n\t\tlocal family = Panels.Font.getFamily(Panels.Settings.defaultFontFamily)\n\t\theaderFont = family\n\t\tlistFont = family\n\tend\n\t\n\tlocal function drawBG(yPos)\n\t\tgfx.setColor(Panels.Color.WHITE)\n\t\tgfx.fillRoundRect(0, yPos, 400, ScreenHeight + 5, 4)\n\t\t\n\tend\n\t\n\tlocal function drawOutline(yPos)\n\t\tgfx.setColor(Panels.Color.BLACK)\n\t\tgfx.setLineWidth(2)\n\t\tgfx.drawRoundRect(0, yPos, 400, ScreenHeight + 5, 4)\n\tend\n\t\n\tfunction menu:show()\n\t\tif self.state == MenuState.SHOWING or self.state == MenuState.OPEN then\n\t\t\treturn\n\t\tend\n\t\t\n\t\tif self.onWillShow then self:onWillShow() end\n\t\tPanels.onMenuWillShow(self)\n\t\tself.state = MenuState.SHOWING\n\t\tplaydate.inputHandlers.push(inputHandlers, true)\n\t\tself.animator = gfx.animator.new(menuAnimationDuration, 0, 1, playdate.easingFunctions.inOutQuad)\n\n\t\tif Panels.Settings.playMenuSounds then\n\t\t\tif self ~= Panels.mainMenu  then\n\t\t\t\tshowSound:play()\n\t\t\tend\n\t\tend\n\tend\n\t\n\tfunction menu:hide()\n\t\tif self.state == MenuState.HIDING or self.state == MenuState.CLOSED then\n\t\t\treturn \n\t\tend\n\t\tPanels.onMenuWillHide(self)\n\t\tself.state = MenuState.HIDING\n\t\tplaydate.inputHandlers.pop()\n\t\tself.animator = gfx.animator.new(menuAnimationDuration, 1, 0, playdate.easingFunctions.inOutQuad)\n\n\t\tif Panels.Settings.playMenuSounds then\n\t\t\thideSound:play()\n\t\tend\n\tend\n\t\n\tfunction menu:isActive()\n\t\treturn self.state ~= MenuState.CLOSED \n\tend\n\t\n\tfunction menu:updateState()\n\t\tif self.animator:ended() then\n\t\t\tif self.state == MenuState.SHOWING then\n\t\t\t\tself.state = MenuState.OPEN\n\t\t\t\tPanels.onMenuDidShow(self)\n\t\t\t\tif self.onDidShow then self:onDidShow() end\n\t\t\telseif self.state == MenuState.HIDING then\n\t\t\t\tself.state = MenuState.CLOSED\n\t\t\t\tPanels.onMenuDidHide(self)\n\t\t\tend\n\t\tend\n\tend\n\t\n\tfunction menu:update()\t\t\n\t\tlocal animatorVal = self.animator:currentValue()\n\t\tlocal yPos = ScreenHeight - animatorVal * height\n\t\t\n\t\tif yPos < ScreenHeight then\n\t\t\tdrawBG(yPos)\n\t\t\tredrawContent(yPos)\n\t\t\tdrawOutline(yPos)\n\t\tend\n\t\t\n\t\tself:updateState()\n\tend\n\t\n\treturn menu\nend\n\n\n-- -------------------------------------------------\n-- MAIN MENU\n\nlocal mainMenuList = nil\nlocal menuOptions = { \"Start Over\" }\nlocal mainMenuImage = nil\n\nlocal function displayMenuImage(val)\n\tlocal y = 240 - (val * ScreenHeight)\n\tmainMenuImage:drawFaded(0, 0, val, gfx.image.kDitherTypeBayer8x8)\nend\n\nlocal function loadMenuImage()\n\timg, error = gfx.image.new(Panels.Settings.imageFolder .. Panels.Settings.menuImage)\n\tprintError(error, \"Error loading main menu image:\")\n\t\n\tif img == nil then \n\t\timg = gfx.image.new(ScreenWidth, ScreenHeight, Panels.Color.WHITE)\n\tend\n\treturn img\nend\n\nlocal function redrawMainMenu(yPos)\n\tmainMenuList:drawInRect(8, yPos + 3, 384, 42)\nend\nlocal mainOffset = 0\nlocal function updateMainMenu(gameDidFinish, gameDidStart)\n\tmenuOptions = { \"Start Over\" }\n\n\tif Panels.Settings.useChapterMenu then\n\t\tmenuOptions[#menuOptions+1] = \"Chapters\"\n\tend\n\n\tif not gameDidFinish then\n\t\tif gameDidStart then\n\t\t\tmenuOptions[#menuOptions+1] = \"Resume\"\n\t\tend\n\tend\n\n\tif #menuOptions == 1 then \n\t\tif gameDidFinsish then\n\t\t\tmenuOptions = { \"Play Again\" } \n\t\telse\n\t\t\tmenuOptions = { \"Start\" } \n\t\tend\n\tend\n\n\tmainMenuList = playdate.ui.gridview.new(math.floor((ScreenWidth - 16) / #menuOptions) - 8, 32)\n\tmainMenuList:setNumberOfRows(1)\n\tmainMenuList:setNumberOfColumns(#menuOptions)\n\tmainMenuList:setCellPadding(4, 4, 4, 4)\n\tmainMenuList:setSelection(1, 1, #menuOptions)\n\n\tfunction mainMenuList:drawCell(section, row, column, selected, x, y, width, height)\n\t\tgfx.pushContext()\n\t\tlocal text = menuOptions[column]\n\t\tif selected then\n\t\t\tgfx.setColor(gfx.kColorBlack)\n\t\t\tgfx.fillRoundRect(x + mainOffset, y, width , height, 4)\n\t\t\tgfx.setImageDrawMode(gfx.kDrawModeFillWhite)\n\t\t\ttext = \"*\" .. text .. \"*\"\n\t\t\tmainOffset = 0\n\t\telse\n\t\t\tgfx.setImageDrawMode(gfx.kDrawModeCopy)\n\t\tend\n\t\t\n\t\tgfx.setFont(listFont)\n\t\tgfx.drawTextInRect(text, x, y+8, width, height+2, nil, \"...\", kTextAlignment.center)\n\t\tgfx.popContext()\n\tend\nend\n\nfunction createMainMenu(gameDidFinish, gameDidStart)\n\tmainMenuImage = loadMenuImage()\n\tupdateMainMenu(gameDidFinish, gameDidStart)\n\n\t\n\t\n\tlocal inputHandlers = {\n\t\trightButtonUp = function()\n\t\t\tlocal s, r, column = mainMenuList:getSelection()\n\t\t\tif Panels.Settings.playMenuSounds then \n\t\t\t\tif column == #menuOptions then\n\t\t\t\t\tdenialSound:play()\n\t\t\t\telse\n\t\t\t\t\tselectionSound:play()\n\t\t\t\tend\n\t\t\tend\n\t\t\tmainOffset = 4\n\t\t\tmainMenuList:selectNextColumn(false)\n\t\tend,\n\t\t\n\t\tleftButtonUp = function()\n\t\t\tlocal s, r, column = mainMenuList:getSelection()\n\t\t\tif Panels.Settings.playMenuSounds then \n\t\t\t\tif column == 1 then\n\t\t\t\t\tdenialSound:play()\n\t\t\t\telse\n\t\t\t\t\tselectionRevSound:play()\n\t\t\t\tend\n\t\t\tend\n\t\t\tmainOffset = -4\n\t\t\tmainMenuList:selectPreviousColumn(false)\n\t\tend,\n\t\t\n\t\tAButtonDown = function()\n\t\t\tlocal s, r, column = mainMenuList:getSelection()\n\t\t\tlocal label\n\n\t\t\tif Panels.Settings.playMenuSounds then\n\t\t\t\tconfirmSound:play()\n\t\t\tend\n\n\t\t\tif column == #menuOptions and not gameDidFinish then  -- Continue\n\t\t\t\tPanels.mainMenu:hide()\n\t\t\telseif column == 1 then         -- Start Over\n\t\t\t\tPanels.onMenuDidStartOver()\n\t\t\telseif Panels.Settings.useChapterMenu then                           -- Chapters\n\t\t\t\tPanels.chapterMenu:show()\n\t\t\tend\t\n\t\tend,\n\t}\n\t\n\tlocal menu = Panels.Menu.new(45, redrawMainMenu, inputHandlers)\n\treturn menu\nend\n\n\n-- -------------------------------------------------\n-- CHAPTER MENU\n\nlocal chapterList = playdate.ui.gridview.new(0, 32)\nlocal headerImage = nil\nlocal maxUnlockedChapter = 0\n\nlocal function createSectionsFromData(data)\n\tsections = {}\n\tmaxUnlockedChapter = 0\n\tfor i, seq in ipairs(data) do\n\t\tif (seq.title or Panels.Settings.listUnnamedSequences) \n\t\tand (Panels.unlockedSequences[i] == true or Panels.Settings.listLockedSequences) then\n\t\t\tlocal title = seq.title or \"--\"\n\t\t\tif Panels.unlockedSequences[i] == true then \n\t\t\t\ttitle = \"*\" .. title .. \"*\" \n\t\t\t\tmaxUnlockedChapter = maxUnlockedChapter + 1\n\t\t\tend\n\t\t\tsections[#sections + 1] = {title = title, index = i}\n\t\tend\n\tend\nend\n\nlocal function redrawChapterMenu(yPos)\n\tchapterList:drawInRect(13, yPos +1, 374, 240)\nend\n\nlocal function onChapterMenuWillShow() \n\tchapterList:setSelectedRow(1)\n\tchapterList:selectPreviousRow()\nend\n\nlocal function updateChapterMenu(data)\n\tcreateSectionsFromData(data)\n\tchapterList:setNumberOfRows(#sections)\nend\n\nlocal function isLastUnlockedSequence(index)\n\tfor i = index + 1, #Panels.unlockedSequences, 1 do\n\tif i > #sections then return true end\n\t\tlocal sectionIndex = sections[i].index\n\t\tif Panels.unlockedSequences[sectionIndex] == true then\n\t\t\treturn false\n\t\tend\n\tend\n\treturn true\nend\n\nlocal function isFirstUnlockedSequence(index)\n\tfor i = index - 1, 1, -1 do\n\t\tlocal sectionIndex = sections[i].index\n\t\tif Panels.unlockedSequences[sectionIndex] == true then\n\t\t\treturn false\n\t\tend\n\tend\n\treturn true\nend\n\nlocal function getNextUnlockedSequence(index)\n\tfor i = index + 1, #Panels.unlockedSequences, 1 do\n\t\tlocal sectionIndex = sections[i].index\n\t\tif Panels.unlockedSequences[sectionIndex] == true then\n\t\t\treturn i\n\t\tend\n\tend\n\treturn nil\nend\n\nlocal function getPreviousUnlockedSequence(index)\n\tfor i = index - 1, 1, -1 do\n\t\tlocal sectionIndex = sections[i].index\n\t\tif Panels.unlockedSequences[sectionIndex] == true then\n\t\t\treturn i\n\t\tend\n\tend\n\treturn nil\nend\n\nlocal function getRowForSequenceIndex(index)\n\tfor i, sec in ipairs(sections) do\n\t\tif sec.index == index then\n\t\t\treturn i\n\t\tend\n\tend\n\treturn nil\nend\n\nlocal chapterOffset = 0\nlocal function createChapterMenu(data)\n\tupdateChapterMenu(data)\n\t\n\tif Panels.Settings.chapterMenuHeaderImage then\n\t\theaderImage = gfx.image.new(Panels.Settings.imageFolder .. Panels.Settings.chapterMenuHeaderImage)\n\t\tlocal w, h = headerImage:getSize()\n\t\tchapterList:setSectionHeaderHeight(h + 24)\n\telse \n\t\tchapterList:setSectionHeaderHeight(48)\n\tend\n\tchapterList:setCellPadding(0, 0, 0, 8)\n\t\n\tlocal inputHandlers = {\n\t\tdownButtonUp = function()\n\t\t\tchapterOffset = 4\n\t\t\tlocal selectedRow = chapterList:getSelectedRow()\n\t\t\tif not isLastUnlockedSequence(selectedRow) then\n\t\t\t\tlocal next = getNextUnlockedSequence(selectedRow)\n\t\t\t\tchapterList:setSelectedRow(next)\n\t\t\t\tchapterList:scrollToRow(next)\n\t\t\t\tif Panels.Settings.playMenuSounds then \n\t\t\t\t\tselectionSound:play()\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tif Panels.Settings.playMenuSounds then \n\t\t\t\t\tdenialSound:play()\n\t\t\t\tend\n\t\t\tend\n\t\tend,\n\t\t\n\t\tupButtonUp = function()\n\t\t\tchapterOffset = -4\n\t\t\tlocal selectedRow = chapterList:getSelectedRow()\n\t\t\tif not isFirstUnlockedSequence(selectedRow) then\n\t\t\t\tlocal prev = getPreviousUnlockedSequence(selectedRow)\n\t\t\t\tchapterList:setSelectedRow(prev)\n\t\t\t\tchapterList:scrollToRow(prev)\n\t\t\t\tif Panels.Settings.playMenuSounds then \n\t\t\t\t\tselectionRevSound:play()\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tif Panels.Settings.playMenuSounds then \n\t\t\t\t\tdenialSound:play()\n\t\t\t\tend\n\t\t\tend\n\t\t\t\n\t\tend,\n\t\t\n\t\tAButtonDown = function()\n\t\t\tlocal item = sections[chapterList:getSelectedRow()] \n\t\t\tPanels.onChapterSelected( item.index )\n\t\t\tPanels.chapterMenu:hide()\n\t\t\tif Panels.mainMenu then Panels.mainMenu:hide() end\n\t\t\tif Panels.Settings.playMenuSounds then\n\t\t\t\tconfirmSound:play()\n\t\t\tend\n\t\tend,\n\t\t\n\t\tBButtonDown = function()\n\t\t\tPanels.chapterMenu:hide()\n\t\tend\n\t}\n\t\n\tlocal menu = Panels.Menu.new(ScreenHeight, redrawChapterMenu, inputHandlers)\n\tmenu.onWillShow = onChapterMenuWillShow\n\treturn menu\nend\n\nfunction chapterList:drawCell(section, row, column, selected, x, y, width, height)\n\tgfx.pushContext()\n\t\tif selected then\n\t\t\tgfx.setColor(gfx.kColorBlack)\n\t\t\tgfx.fillRoundRect(x, y + chapterOffset, width, height, 4)\n\t\t\tgfx.setImageDrawMode(gfx.kDrawModeFillWhite)\n\t\t\tchapterOffset = 0\n\t\telse\n\t\t\tgfx.setImageDrawMode(gfx.kDrawModeCopy)\n\t\tend\n\t\t\n\t\tgfx.setFont(listFont)\n\t\tgfx.drawTextInRect(\"\" .. sections[row].title.. \"\", x + 16, y+8, width -32, height+2, nil, \"...\", kTextAlignment.left)\n\tgfx.popContext()\nend\n\nfunction chapterList:drawSectionHeader(section, x, y, width, height)\n\tgfx.pushContext()\n\tif Panels.Settings.chapterMenuHeaderImage then\n\t\theaderImage:drawAnchored(x + width / 2, y + 7, 0.5, 0)\n\telse\n\t\tgfx.setColor(gfx.kColorBlack)\n\t\tgfx.setFont(headerFont)\n\t\tgfx.drawTextInRect(\"Chapters\", x, y+12, width, height, nil, \"...\", kTextAlignment.center)\n\t\tgfx.setLineWidth(1)\n\t\tgfx.drawLine(x, y + 20, x + 120, y + 20)\n\t\tgfx.drawLine(x + width - 120, y + 20, x + width, y + 20)\n\tend\n\tgfx.popContext()\nend\n\n\n-- -------------------------------------------------\n-- CREDITS MENU\n\nlocal credits = nil\n\nlocal function redrawCreditsMenu(yPos)\n\tcredits:redraw(yPos)\nend\n\nlocal function onCreditsMenuWillShow()\n\tcredits.scrollPos = 0\nend\n\nlocal function onCreditsMenuDidShow()\n\tcredits:onDidShow()\nend\n\nlocal function createCreditsMenu()\n\tcredits = Panels.Credits.new()\n\t\n\tlocal inputHandlers = {\n\t\tBButtonDown = function()\n\t\t\tPanels.creditsMenu:hide()\n\t\tend,\n\t\tcranked = function(change)\n\t\t\tcredits:cranked(change)\n\t\tend,\n\t}\n\t\n\tlocal menu = Panels.Menu.new(ScreenHeight, redrawCreditsMenu, inputHandlers)\n\tmenu.onWillShow = onCreditsMenuWillShow\n\tmenu.onDidShow = onCreditsMenuDidShow\n\treturn menu\nend\n\n\n-- -------------------------------------------------\n-- ALL MENUS\n\nfunction updateMenus()\t\n\tif Panels.mainMenu and Panels.mainMenu:isActive() then \n\t\tlocal val = Panels.mainMenu.animator:currentValue()\n\t\tdisplayMenuImage(val)\t\n\t\tif Panels.mainMenuDrawingCallBack ~= nil then Panels.mainMenuDrawingCallBack(val) end\n\t\tPanels.mainMenu:update() \n\tend\n\t\n\tif Panels.chapterMenu and Panels.chapterMenu:isActive() then\n\t\tPanels.chapterMenu:update()\n\tend\n\t\n\tif Panels.creditsMenu:isActive() then \n\t\tPanels.creditsMenu:update()\n\tend\nend\n\nfunction createMenus(sequences, gameDidFinish, gameDidStart)\n\tPanels.mainMenu = createMainMenu(gameDidFinish, gameDidStart)\n\n\tif Panels.Settings.useChapterMenu then \n\t\tPanels.chapterMenu = createChapterMenu(sequences)\n\tend\n\n\tPanels.creditsMenu = createCreditsMenu()\nend\n\n\nfunction updateMenuData(sequences, gameDidFinish, gameDidStart)\n\t-- updateMainMenu(gameDidFinish, gameDidStart)\n\t-- just recreate the damn thing so the inputHandlers have the right state\n\tPanels.mainMenu = createMainMenu(gameDidFinish, gameDidStart) \n\tupdateChapterMenu(sequences)\nend"
  },
  {
    "path": "modules/Panel.lua",
    "content": "Panels.Panel = {}\n\nlocal gfx <const> = playdate.graphics\nlocal ScreenHeight <const> = playdate.display.getHeight()\nlocal ScreenWidth <const> = playdate.display.getWidth()\n\nlocal reduceFlashing = playdate.getReduceFlashing()\nlocal pdButtonJustPressed = playdate.buttonJustPressed\n\nlocal AxisHorizontal = Panels.ScrollAxis.HORIZONTAL\n\n\nlocal function createFrameFromPartialFrame(frame)\n\tif frame.margin == nil then frame.margin = Panels.Settings.defaultFrame.margin end\n\n\tif frame.width == nil then\n\t\tframe.width = ScreenWidth - frame.margin * 2\n\tend\n\n\tif frame.height == nil then\n\t\tframe.height = ScreenHeight - frame.margin * 2\n\tend\n\n\tif frame.x == nil then\n\t\tframe.x = frame.margin\n\tend\n\n\tif frame.y == nil then\n\t\tframe.y = frame.margin\n\tend\n\n\tif frame.gap == nil then\n\t\tframe.gap = Panels.Settings.defaultFrame.gap\n\tend\n\n\treturn frame\nend\n\nfunction getScrollPercentages(frame, offset, axis)\n\tif offset == nil then return {x = 0.5, y - 0.5} end\n\n\tlocal xPct = 1 - (frame.x - frame.margin + frame.width + offset.x) / (ScreenWidth + frame.width)\n\tlocal yPct = 1 - (frame.y - frame.margin + frame.height + offset.y) / (ScreenHeight + frame.height)\n\n\tlocal pct = { x = xPct, y = yPct }\n\tif axis == AxisHorizontal then pct.y = 0.5 else pct.x = 0.5 end\n\treturn pct\nend\n\nlocal function calculateShake(strength)\n\treturn {\n\t\tx = math.random(-strength, strength),\n\t\ty = math.random(-strength, strength)\n\t}\nend\n\nfunction doLayerEffect(layer)\n\tif layer.effect.type == Panels.Effect.BLINK then\n\t\tif layer.timer == nil then\n\t\t\tif layer.effect.delay then\n\t\t\t\tlayer.visible = false\n\t\t\t\tlayer.timer = playdate.timer.new(layer.effect.delay)\n\t\t\t\tlayer.timer.repeats = false\n\t\t\telse\n\t\t\t\tlayer.timer = playdate.timer.new(layer.effect.durations.on + layer.effect.durations.off)\n\t\t\t\tlayer.timer.repeats = true\n\t\t\tend\n\n\t\telse\n\t\t\tif layer.effect.delay then\n\t\t\t\tif layer.timer.currentTime >= layer.effect.delay then\n\t\t\t\t\tlayer.effect.delay = false\n\t\t\t\t\tlayer.timer = playdate.timer.new(layer.effect.durations.on + layer.effect.durations.off)\n\t\t\t\t\tlayer.timer.repeats = true\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tif layer.timer.currentTime < layer.effect.durations.on then\n\t\t\t\t\tif layer.visible == false then\n\t\t\t\t\t\tlayer.visible = true\n\t\t\t\t\t\tif layer.sfxPlayer then\n\t\t\t\t\t\t\tlayer.sfxPlayer:play()\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\tlayer.visible = false\n\t\t\t\tend\n\t\t\tend\n\n\t\tend\n\n\n\tend\nend\n\nfunction Panels.Panel.new(data)\n\tlocal panel = table.shallowcopy(data)\n\tpanel.prevPct = 0\n\tpanel.frame = createFrameFromPartialFrame(panel.frame)\n\tpanel.buttonsPressed = {}\n\n\tpanel.willEnableInput = false\n\tpanel.inputEnabled = false\n\n\tif not panel.parallaxDistance then\n\t\tif panel.axis == Panels.ScrollAxis.HORIZONTAL then\n\t\t\tpanel.parallaxDistance = panel.frame.width * 1.2\n\t\telse\n\t\t\tpanel.parallaxDistance = panel.frame.height * 1.2\n\t\tend\n\tend\n\n\tif panel.panels then\n\t\tfor i, p in ipairs(panel.panels) do\n\t\t\tpanel.panels[i] = Panels.Panel.new(p)\n\t\tend\n\tend\n\n\tif panel.advanceControlPositions then\n\t\tpanel.advanceControlPosition = panel.advanceControlPositions[1]\n\tend\n\n\tlocal imageFolder = Panels.Settings.imageFolder\n\n\tif panel.showAdvanceControl then\n\t\tpanel.advanceButton = Panels.ButtonIndicator.new(panel.advanceControlSize)\n\t\tpanel.advanceButton:setButton(panel.advanceControl)\n\t\tif panel.advanceControlPosition then\n\t\t\tpanel.advanceButton:setPosition(panel.advanceControlPosition.x, panel.advanceControlPosition.y)\n\t\telse\n\t\t\tpanel.advanceButton:setPositionForScrollDirection(panel.direction, panel.advanceControlSize)\n\t\tend\n\tend\n\n\tif panel.layers then\n\t\tfor i, layer in ipairs(panel.layers) do\n\t\t\tif layer.image then\n\t\t\t\tlayer.img, error = Panels.Image.get(imageFolder .. layer.image)\n\t\t\t\tprintError(error, \"Error loading image on layer\")\n\t\t\tend\n\n\t\t\tif layer.images then\n\t\t\t\tlayer.imgs = {}\n\t\t\t\tlayer.currentImage = 1\n\t\t\t\tfor j, image in ipairs(layer.images) do\n\t\t\t\t\tlayer.imgs[j], error = Panels.Image.get(imageFolder .. image)\n\t\t\t\t\tprintError(error, \"Error loading images[\" .. j .. \"] on layer\")\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tif layer.imageTable then\n\t\t\t\tlocal imgTable, error = gfx.imagetable.new(Panels.Settings.imageFolder .. layer.imageTable)\n\t\t\t\tprintError(error, \"Error loading imagetable on layer\")\n\n\t\t\t\tlocal delay = layer.delay or 200\n\t\t\t\tif layer.reduceFlashingDelay and reduceFlashing then\n\t\t\t\t\tdelay = layer.reduceFlashingDelay\n\t\t\t\tend\n\t\t\t\tlocal anim = gfx.animation.loop.new(delay, imgTable, layer.loop or false)\n\t\t\t\tanim.paused = true\n\t\t\t\tif layer.scrollTrigger == nil then layer.scrollTrigger = 0 end\n\t\t\t\tlayer.animationLoop = anim\n\t\t\t\tlayer.imgTable = imgTable\n\t\t\tend\n\n\t\t\tif layer.stencil then\n\t\t\t\tmask, error = Panels.Image.get(imageFolder .. layer.stencil)\n\t\t\t\tlayer.maskImg = mask\n\t\t\t\tprintError(error, \"Error loading stencil image on layer\")\n\t\t\tend\n\n\t\t\tif layer.x == nil then layer.x = -panel.frame.margin end\n\t\t\tif layer.y == nil then layer.y = -panel.frame.margin end\n\t\t\tif layer.visible == nil then layer.visible = true end\n\t\t\tlayer.alpha = layer.opacity or nil\n\n\t\t\tif layer.effect then\n\t\t\t\tif layer.effect.type == Panels.Effect.BLINK and layer.effect.audio then\n\t\t\t\t\tlayer.sfxPlayer = playdate.sound.sampleplayer.new(Panels.Settings.audioFolder .. layer.effect.audio.file)\n\t\t\t\tend\n\n\t\t\t\tif reduceFlashing\n\t\t\t\t\tand layer.effect.type == Panels.Effect.BLINK\n\t\t\t\t\tand layer.effect.reduceFlashingDurations ~= nil\n\t\t\t\tthen\n\t\t\t\t\tlayer.effect.durations.on = layer.effect.reduceFlashingDurations.on\n\t\t\t\t\tlayer.effect.durations.off = layer.effect.reduceFlashingDurations.off\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tif layer.animate then\n\t\t\t\tif layer.animate.delay == nil then layer.animate.delay = 0 end\n\t\t\t\tif layer.animate.duration then\n\t\t\t\t\tif layer.animate.duration < 1 then layer.animate.duration = 1 end\n\t\t\t\tend\n\t\t\t\tif layer.animate.autoStart then layer.animate.scrollTrigger = 0 end\n\t\t\t\tif layer.animate.scrollTrigger and layer.animate.duration == nil then\n\t\t\t\t\tlayer.animate.duration = 200\n\t\t\t\tend\n\t\t\t\tif layer.opacity == nil then layer.opacity = 1 end\n\n\t\t\t\tif layer.animate.trigger then\n\t\t\t\t\tlayer.animate.triggerSequence = { layer.animate.trigger }\n\t\t\t\tend\n\n\t\t\t\tif layer.animate.audio then\n\t\t\t\t\tlayer.sfxPlayer = playdate.sound.sampleplayer.new(Panels.Settings.audioFolder .. layer.animate.audio.file)\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tif panel.audio then\n\t\tpanel.sfxPlayer = playdate.sound.sampleplayer.new(Panels.Settings.audioFolder .. panel.audio.file)\n\t\tif panel.audio.pan then\n\t\t\tpanel.sfxPlayer:setVolume(1 - panel.audio.pan, panel.audio.pan)\n\t\tend\n\t\tpanel.sfxTrigger = panel.audio.scrollTrigger or 0\n\tend\n\n\tif panel.choiceList then \n\t\t-- Create a wrapper function that preserves the panel context\n\t\tlocal function selectionCallback(index, button)\n\t\t\tpanel.onChoiceListSelectionChange(index, button)\n\t\tend\n\t\tif panel.choiceList.fontFamily == nil then\n\t\t\tpanel.choiceList.fontFamily = panel.fontFamily\n\t\tend\n\n\t\tpanel.choices = Panels.ChoiceList.new(panel.choiceList, panel.frame, selectionCallback)\n\tend\n\n\tfunction panel:enableInput(isOn)\n\t\tself.willEnableInput = isOn\n\tend\n\n\tfunction panel:nextAdvanceControl(controlIndex, show)\n\t\tif not self.inputEnabled then return end\n\t\tlocal control = self.advanceControlSequence[controlIndex]\n\t\tif control and self.advanceButton then\n\t\t\tself.advanceButton:reset()\n\t\t\tself.advanceButton:setButton(control)\n\t\t\tself.advanceControl = control\n\n\t\t\tif self.advanceControlPositions then\n\t\t\t\tlocal pos = self.advanceControlPositions[controlIndex]\n\t\t\t\tif pos then\n\t\t\t\t\tself.advanceButton:setPosition(pos.x, pos.y)\n\t\t\t\tend\n\t\t\tend\n\t\t\t\n\t\t\tif show then \n\t\t\t\tself.advanceButton:show() \n\t\t\tend\n\t\tend\n\tend\n\n\tfunction panel:isOnScreen(offset)\n\t\tlocal isOn = false\n\t\tlocal f = self.frame\n\t\tif f.x + offset.x <= ScreenWidth and f.x + f.width + offset.x > 0 and\n\t\t\tf.y + offset.y <= ScreenHeight and f.y + f.height + offset.y > 0 then\n\t\t\tisOn = true\n\t\tend\n\n\t\treturn isOn\n\tend\n\n\tfunction panel:fadePanelVolume(pct)\n\t\tlocal vol = 1\n\t\tif pct < 0.25 then\n\t\t\tvol = pct / 0.25\n\t\telseif pct > 0.75 then\n\t\t\tvol = (1 - pct) / 0.25\n\t\tend\n\n\t\tlocal leftPan = self.audio.volume or 1\n\t\tlocal rightPan = self.audio.volume or 1\n\n\t\tif self.audio.pan then\n\t\t\tleftPan = 1 - self.audio.pan\n\t\t\trightPan = self.audio.pan\n\t\tend\n\n\t\tself.sfxPlayer:setVolume(vol * leftPan, vol * rightPan)\n\tend\n\n\tfunction panel:pauseSounds()\n\t\tif self.sfxPlayer then\n\t\t\tself.soundIsPaused = true\n\t\t\tself.sfxPlayer:setPaused(true)\n\t\tend\n\tend\n\n\tfunction panel:unPauseSounds()\n\t\tif self.sfxPlayer then\n\t\t\tself.soundIsPaused = false\n\t\t\tself.sfxPlayer:setPaused(false)\n\t\tend\n\tend\n\n\tfunction panel:updatePanelAudio(offset)\n\t\tlocal pct = getScrollPercentages(self.frame, offset, self.axis)\n\t\tlocal cntrlPct = calculateControlPercent(pct, self)\n\n\t\tlocal count = self.audio.repeatCount or 1\n\t\tif self.audio.loop then count = 0 end\n\t\tif self.audio.triggerSequence then\n\t\t\tif self.inputEnabled then \n\t\t\t\tif self.audioTriggersPressed == nil then self.audioTriggersPressed = {} end\n\t\t\t\tlocal triggerButton = self.audio.triggerSequence[#self.audioTriggersPressed + 1]\n\n\t\t\t\tif pdButtonJustPressed(triggerButton) then\n\t\t\t\t\tself.audioTriggersPressed[#self.audioTriggersPressed + 1] = triggerButton\n\t\t\t\t\tif #self.audioTriggersPressed == #self.audio.triggerSequence then\n\t\t\t\t\t\tplaydate.timer.performAfterDelay(self.audio.delay or 0, function()\n\t\t\t\t\t\t\tif self.sfxPlayer then self.sfxPlayer:play(count) end\n\t\t\t\t\t\tend)\n\n\t\t\t\t\t\tif self.audio.repeats ~= nil then\n\t\t\t\t\t\t\tif self.audioRepeats == nil then self.audioRepeats = 1 end\n\t\t\t\t\t\t\tif self.audio.repeats > self.audioRepeats then\n\t\t\t\t\t\t\t\tself.audioTriggersPressed = {}\n\t\t\t\t\t\t\t\tself.audioRepeats = self.audioRepeats + 1\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\n\t\telseif (cntrlPct < 1 and cntrlPct >= self.sfxTrigger) and (self.prevPct <= self.sfxTrigger or self.audio.loop) then\n\t\t\tif not self.sfxPlayer:isPlaying() and not self.soundIsPaused then\n\t\t\t\tplaydate.timer.performAfterDelay(self.audio.delay or 0, function()\n\t\t\t\t\tif self.sfxPlayer then self.sfxPlayer:play(count) end\n\t\t\t\tend)\n\t\t\tend\n\t\tend\n\n\t\tself:fadePanelVolume(cntrlPct)\n\tend\n\n\tfunction panel:layerShouldShake(layer)\n\t\tlocal result = false\n\t\tif self.effect and\n\t\t\t(self.effect.type == Panels.Effect.SHAKE_UNISON or self.effect.type == Panels.Effect.SHAKE_INDIVIDUAL) then\n\t\t\tresult = true\n\t\tend\n\n\t\tif layer.effect and layer.effect.type == Panels.Effect.SHAKE then\n\t\t\tresult = true\n\t\tend\n\n\t\treturn result\n\tend\n\n\tfunction panel:exit()\n\t\tif self.layers then\n\t\t\tfor i, layer in ipairs(self.layers) do\n\t\t\t\tif layer.exit then\n\t\t\t\t\tlayer.isExiting = true\n\t\t\t\t\tlayer.animator = nil\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\tend\n\n\tfunction calculateControlPercent(scrollPercentages, panel)\n\t\tlocal cntrlPct = 0\n\t\tif panel.axis == AxisHorizontal then cntrlPct = scrollPercentages.x else cntrlPct = scrollPercentages.y end\n\t\tif panel.scrollingIsReversed then cntrlPct = 1 - cntrlPct end\n\t\treturn cntrlPct\n\tend\n\n\tfunction layerShouldRender(layer)\n\t\tif layer.renderCondition then\n\t\t\tif Panels.vars[layer.renderCondition.var] ~= nil then\n\t\t\t\tif layer.renderCondition.value ~= nil then\n\t\t\t\t\tif Panels.vars[layer.renderCondition.var] == layer.renderCondition.value then\n\t\t\t\t\t\treturn true\n\t\t\t\t\telse\n\t\t\t\t\t\treturn false\n\t\t\t\t\tend\n\t\t\t\telseif layer.renderCondition.valueNot then\n\t\t\t\t\tif Panels.vars[layer.renderCondition.var] ~= layer.renderCondition.valueNot then\n\t\t\t\t\t\treturn true\n\t\t\t\t\telse\n\t\t\t\t\t\treturn false\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tif not layer.didWarnForInvalidRenderCondition then\n\t\t\t\t\t-- just print this once per layer\n\t\t\t\t\tprintError(\"No value for '\" .. layer.renderCondition.var .. \"' found in Panels.vars\", \"Invalid renderCondition\")\n\t\t\t\t\tlayer.didWarnForInvalidRenderCondition = true\n\t\t\t\tend\n\t\t\t\tif layer.renderCondition.value == false or layer.renderCondition.valueNot ~= nil then -- match nil value to false condition\n\t\t\t\t\treturn true\n\t\t\t\telse\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\t\treturn true\n\tend\n\n\tfunction panel:drawLayers(offset)\n\t\tlocal layers = self.layers\n\t\tlocal frame = self.frame\n\t\tlocal shake\n\t\tlocal pct = getScrollPercentages(frame, offset, self.axis)\n\t\tlocal cntrlPct = calculateControlPercent(pct, self)\n\n\t\tif self.effect then\n\t\t\tif self.effect.type == Panels.Effect.SHAKE_UNISON then\n\t\t\t\tshake = calculateShake(self.effect.strength)\n\t\t\tend\n\t\tend\n\n\t\tif layers then\n\t\t\tfor i, layer in ipairs(layers) do\n\t\t\t\tif not layerShouldRender(layer) then goto continue end\n\n\t\t\t\tlocal p = layer.parallax or 0\n\t\t\t\tlocal startValues = table.shallow_copy(layer)\n\t\t\t\tif layer.isExiting and layer.animate then\n\t\t\t\t\tfor k, v in pairs(layer.animate) do startValues[k] = v end\n\t\t\t\tend\n\n\t\t\t\tlocal xPos = math.floor(startValues.x + (self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p)\n\t\t\t\tlocal yPos = math.floor(startValues.y + (self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p)\n\t\t\t\tlocal rotation = 0\n\n\t\t\t\tif layer.animate or layer.isExiting then\n\t\t\t\t\tlocal anim = layer.animate\n\n\t\t\t\t\tif layer.isExiting then\n\t\t\t\t\t\tanim = layer.exit\n\t\t\t\t\t\tanim.scrollTrigger = 0\n\t\t\t\t\tend\n\n\t\t\t\t\tif (anim.triggerSequence or anim.scrollTrigger ~= nil) and not layer.animator then\n\n\t\t\t\t\t\tif layer.buttonsPressed == nil then layer.buttonsPressed = {} end\n\t\t\t\t\t\tlocal triggerButton = nil\n\t\t\t\t\t\tif not anim.scrollTrigger and self.inputEnabled then\n\t\t\t\t\t\t\ttriggerButton = anim.triggerSequence[#layer.buttonsPressed + 1]\n\t\t\t\t\t\tend\n\n\t\t\t\t\t\tif anim.scrollTrigger ~= nil or (pdButtonJustPressed(triggerButton) and self.inputEnabled) then\n\t\t\t\t\t\t\tlayer.buttonsPressed[#layer.buttonsPressed + 1] = triggerButton\n\t\t\t\t\t\t\tif (anim.scrollTrigger ~= nil and cntrlPct >= anim.scrollTrigger) or\n\t\t\t\t\t\t\t\t(anim.triggerSequence and #layer.buttonsPressed == #anim.triggerSequence) then\n\t\t\t\t\t\t\t\tlayer.animator = gfx.animator.new((anim.duration or 200), 0, 1, anim.ease, anim.delay)\n\t\t\t\t\t\t\t\tif layer.sfxPlayer then\n\t\t\t\t\t\t\t\t\tlocal count = anim.audio.repeatCount or 1\n\t\t\t\t\t\t\t\t\tif anim.audio.loop then count = 0 end\n\t\t\t\t\t\t\t\t\tplaydate.timer.performAfterDelay(anim.delay + (anim.audio.delay or 0), function()\n\t\t\t\t\t\t\t\t\t\tif layer.sfxPlayer then layer.sfxPlayer:play(count) end\n\t\t\t\t\t\t\t\t\tend)\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\tend\n\t\t\t\t\telse\n\t\t\t\t\t\tlocal layerPct = cntrlPct\n\t\t\t\t\t\tif layer.animator then\n\t\t\t\t\t\t\tlayerPct = layer.animator:currentValue()\n\t\t\t\t\t\tend\n\n\t\t\t\t\t\tif anim.x then xPos = math.floor(xPos + ((anim.x - startValues.x) * layerPct)) end\n\t\t\t\t\t\tif anim.y then yPos = math.floor(yPos + ((anim.y - startValues.y) * layerPct)) end\n\t\t\t\t\t\tif anim.rotation then rotation = anim.rotation * layerPct end\n\t\t\t\t\t\tif anim.opacity then\n\t\t\t\t\t\t\tlocal o = (anim.opacity - layer.opacity) * layerPct + layer.opacity\n\t\t\t\t\t\t\tlayer.alpha = o\n\t\t\t\t\t\t\tif o <= 0 then\n\t\t\t\t\t\t\t\tlayer.visible = false\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tlayer.visible = true\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\tend\n\n\n\n\t\t\t\tif self:layerShouldShake(layer) then\n\t\t\t\t\tif self.effect and self.effect.type == Panels.Effect.SHAKE_INDIVIDUAL then\n\t\t\t\t\t\tshake = calculateShake(self.effect.strength or 2)\n\t\t\t\t\telseif layer.effect and layer.effect.type == Panels.Effect.SHAKE then\n\t\t\t\t\t\tshake = calculateShake(layer.effect.strength or 2)\n\t\t\t\t\tend\n\n\t\t\t\t\txPos = xPos + shake.x * (1 - p * p)\n\t\t\t\t\tyPos = yPos + shake.y * (1 - p * p)\n\t\t\t\tend\n\n\t\t\t\tif layer.pixelLock then\n\t\t\t\t\t-- offset gets added here to ensure the layer position + offset gets rounded properly\n\t\t\t\t\t-- then subtract the offset because it's applied at the panel level\n\t\t\t\t\tlocal offX = math.floor(offset.x)\n\t\t\t\t\tlocal offY = math.floor(offset.y)\n\n\t\t\t\t\txPos = math.floor((xPos + offX) / layer.pixelLock) * layer.pixelLock - offX\n\t\t\t\t\tyPos = math.floor((yPos + offY) / layer.pixelLock) * layer.pixelLock - offY\n\n\t\t\t\tend\n\n\t\t\t\tif layer.effect then\n\t\t\t\t\tdoLayerEffect(layer, xPos, yPos)\n\t\t\t\tend\n\n\n\t\t\t\tlocal img\n\t\t\t\tif layer.img then\n\t\t\t\t\timg = layer.img\n\t\t\t\telseif layer.imgs then\n\t\t\t\t\tif layer.advanceControl then\n\t\t\t\t\t\tif pdButtonJustPressed(layer.advanceControl) and self.inputEnabled then\n\t\t\t\t\t\t\tif layer.currentImage < #layer.imgs then\n\t\t\t\t\t\t\t\tlayer.currentImage = layer.currentImage + 1\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\tend\n\t\t\t\t\t\timg = layer.imgs[layer.currentImage]\n\t\t\t\t\telseif layer.manuallySetImageIndex then\n\t\t\t\t\t\timg = layer.imgs[layer.currentImage]\n\t\t\t\t\telse\n\t\t\t\t\t\tlocal p = cntrlPct\n\t\t\t\t\t\tp = p - (self.transitionOffset or 0)\n\t\t\t\t\t\tp = p - (layer.transitionOffset or 0)\n\t\t\t\t\t\tlocal j = math.max(math.min(math.ceil(p * #layer.imgs), #layer.imgs), 1)\n\t\t\t\t\t\timg = layer.imgs[j]\n\t\t\t\t\tend\n\t\t\t\tend\n\n\t\t\t\tlocal globalX = xPos + offset.x + self.frame.x\n\t\t\t\tlocal globalY = yPos + offset.y + self.frame.y\n\n\t\t\t\tif img then\n\t\t\t\t\tif layer.visible then\n\n\t\t\t\t\t\tif globalX + img.width > 0 and globalX < ScreenWidth and globalY + img.height > 0 and globalY < ScreenHeight then\n\n\t\t\t\t\t\t\tif layer.alpha and layer.alpha < 1 then\n\t\t\t\t\t\t\t\timg:drawFaded(xPos, yPos, layer.alpha, playdate.graphics.image.kDitherTypeBayer8x8)\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif layer.maskImg then\n\t\t\t\t\t\t\t\t\tlocal maskX = math.floor((self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.x + panel.frame.x\n\t\t\t\t\t\t\t\t\tlocal maskY = math.floor((self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.y + panel.frame.y\n\n\t\t\t\t\t\t\t\t\tlocal maskImg = gfx.image.new(ScreenWidth, ScreenHeight)\n\t\t\t\t\t\t\t\t\tgfx.lockFocus(maskImg)\n\t\t\t\t\t\t\t\t\tlayer.maskImg:draw(maskX, maskY)\n\t\t\t\t\t\t\t\t\tgfx.unlockFocus()\n\n\t\t\t\t\t\t\t\t\tgfx.setStencilImage(maskImg)\n\t\t\t\t\t\t\t\t\timg:draw(xPos, yPos)\n\t\t\t\t\t\t\t\t\tgfx.clearStencil()\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\timg:draw(xPos, yPos)\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\n\t\t\t\telseif layer.text then\n\t\t\t\t\tif layer.visible then\n\t\t\t\t\t\tlocal widthLimit = ScreenWidth\n\t\t\t\t\t\tlocal heightLimit = ScreenHeight\n\t\t\t\t\t\tif layer.rect and layer.rect.width > ScreenWidth then widthLimit = layer.rect.width end\n\t\t\t\t\t\tif layer.rect and layer.rect.height > ScreenHeight then heightLimit = layer.rect.height end\n\n\t\t\t\t\t\tif globalX + widthLimit > 0 and globalX < widthLimit and globalY + heightLimit > 0 and globalY < heightLimit then\n\t\t\t\t\t\t\tself:drawTextLayer(layer, xPos, yPos, cntrlPct)\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\telseif layer.animationLoop then\n\t\t\t\t\tif layer.visible then\n\t\t\t\t\t\tif layer.trigger then\n\t\t\t\t\t\t\tif pdButtonJustPressed(layer.trigger) and self.inputEnabled then\n\t\t\t\t\t\t\t\tlayer.animationLoop.paused = false\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\telseif layer.startDelay then\n\t\t\t\t\t\t\tif layer.startDelayTriggered == nil then\n\t\t\t\t\t\t\t\tplaydate.timer.performAfterDelay(layer.startDelay, function()\n\t\t\t\t\t\t\t\t\tif layer.animationLoop then layer.animationLoop.paused = false end\n\t\t\t\t\t\t\t\tend)\n\t\t\t\t\t\t\t\tlayer.startDelayTriggered = true\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\telseif cntrlPct >= layer.scrollTrigger then\n\t\t\t\t\t\t\tlayer.animationLoop.paused = false\n\t\t\t\t\t\tend\n\t\t\t\t\t\tlayer.animationLoop:draw(xPos, yPos)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\t::continue::\n\t\t\tend\n\t\tend\n\t\tself.prevPct = cntrlPct\n\n\tend\n\n\tfunction panel:setup() \n\t\tif self.setupFunction then\n\t\t\tself:setupFunction()\n\t\tend\n\tend\n\n\tfunction panel:reset()\n\t\tif self.resetFunction then\n\t\t\tself:resetFunction()\n\t\tend\n\n\t\tself:killTypingEffects()\n\t\tif self.sfxPlayer then\n\t\t\tself.sfxPlayer:stop()\n\t\tend\n\t\tif self.layers then\n\t\t\tfor i, layer in ipairs(self.layers) do\n\n\t\t\t\tlayer.startDelayTriggered = nil\n\t\t\t\tif layer.animationLoop then\n\t\t\t\t\tif layer.animationLoop.frame ~= 1 then\n\t\t\t\t\t\tlayer.animationLoop.frame = 1\n\t\t\t\t\tend\n\t\t\t\t\tlayer.animationLoop.paused = true\n\t\t\t\tend\n\t\t\t\tlayer.isExiting = false\n\n\t\t\t\tif layer.animator then\n\t\t\t\t\tlayer.animator = nil\n\t\t\t\tend\n\t\t\t\tif layer.opacity then\n\t\t\t\t\tlayer.alpha = layer.opacity\n\t\t\t\telse\n\t\t\t\t\tlayer.alpha = nil\n\t\t\t\tend\n\t\t\t\tif layer.sfxPlayer then\n\t\t\t\t\tlayer.sfxPlayer:stop()\n\t\t\t\tend\n\t\t\t\tif layer.textAnimator then\n\t\t\t\t\tlayer.textAnimator = nil\n\t\t\t\tend\n\t\t\t\tif layer.cachedTextImg then\n\t\t\t\t\tif(self.prevPct < 0.5) then\n\t\t\t\t\t\tlayer.cachedTextImg = nil\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tif layer.images then\n\t\t\t\t\tlayer.currentImage = 1\n\t\t\t\tend\n\t\t\t\tlayer.buttonsPressed = nil\n\t\t\t\tlayer.visible = true\n\t\t\tend\n\t\tend\n\t\tself.buttonsPressed = {}\n\t\tself.audioTriggersPressed = {}\n\t\tself.audioRepeats = 1\n\t\tself.advanceControlTimerDidEnd = false\n\t\tself.advanceControlTimer = nil\n\t\tself.autoAdvanceDidComplete = false\n\t\tself.autoAdvanceTimerDidStart = false\n\n\t\tif self.autoAdvanceTimer then\n\t\t\tself.autoAdvanceTimer:remove()\n\t\t\tself.autoAdvanceTimer = nil\n\t\tend\n\n\t\tif self.advanceControlSequence and #self.advanceControlSequence > 1 then\n\t\t\tself:nextAdvanceControl(1, false)\n\t\tend\n\n\t\tif self.advanceButton then\n\t\t\tself.advanceButton:reset()\n\t\tend\n\n\t\tif self.choices then \n\t\t\tself.choices:reset()\n\t\t\t-- self.choices = nil\n\t\tend\n\n\t\tif self.prevPct > 0.5 then\n\t\t\tself.prevPct = 1\n\t\telse\n\t\t\tself.prevPct = 0\n\t\tend\n\tend\n\n\tlocal function startLayerTypingSound(layer)\n\t\tif layer.isTyping then\n\t\t\tPanels.Audio.startTypingSound()\n\t\tend\n\tend\n\n\n\tlocal textMarginHorizontal<const> = 4\n\tlocal textMarginVertical<const> = 1\n\tfunction panel:drawTextLayer(layer, xPos, yPos, cntrlPct)\n\t\tif(layer.cachedTextImg == nil) then\n\t\t\tlocal textW = layer.rect and layer.rect.width + layer.x or ScreenWidth\n\t\t\tlocal textH = layer.rect and layer.rect.height + layer.y or ScreenHeight\n\t\t\tlayer.cachedTextImg = gfx.image.new(textW, textH)\n\t\t\tlayer.needsRedraw = true\n\t\tend\n\n\t\tlocal textMarginLeft = layer.margin and (layer.margin.left or layer.margin.h) or textMarginHorizontal\n\t\tlocal textMarginRight = layer.margin and (layer.margin.right or layer.margin.h) or textMarginHorizontal\n\t\tlocal textMarginTop = layer.margin and (layer.margin.top or layer.margin.v) or textMarginVertical\n\t\tlocal textMarginBottom = layer.margin and (layer.margin.bottom or layer.margin.v) or textMarginVertical\n\n\t\tlocal lineHeight = layer.lineHeightAdjustment or self.lineHeightAdjustment or 0\n\n\t\tif(layer.isTyping or layer.needsRedraw) then\n\t\t\tlayer.needsRedraw = false\n\t\t\tgfx.pushContext(layer.cachedTextImg)\n\t\t\tgfx.clear(gfx.kColorClear)\n\n\t\t\tif layer.fontFamily then\n\t\t\t\tgfx.setFontFamily(Panels.Font.getFamily(layer.fontFamily))\n\t\t\telseif self.fontFamily then\n\t\t\t\tgfx.setFontFamily(Panels.Font.getFamily(self.fontFamily))\n\t\t\telseif layer.font then\n\t\t\t\tgfx.setFont(Panels.Font.get(layer.font))\n\t\t\telseif self.font then\n\t\t\t\tgfx.setFont(Panels.Font.get(self.font))\n\t\t\tend\n\n\t\t\tlocal txt = layer.text\n\t\t\tif layer.effect then\n\t\t\t\tif layer.effect.type == Panels.Effect.TYPE_ON then\n\n\t\t\t\t\tif layer.textAnimator == nil then\n\t\t\t\t\t\tif self.prevPct == 1 then\n\t\t\t\t\t\t\t-- don't replay text animation (and sound) when backing into a frame\n\t\t\t\t\t\t\ttxt = layer.text\n\t\t\t\t\t\t\tlayer.needsRedraw = false\n\t\t\t\t\t\t\tlayer.textAnimator = gfx.animator.new(1, string.len(layer.text), string.len(layer.text))\n\t\t\t\t\t\telseif layer.effect.scrollTrigger == nil or cntrlPct >= layer.effect.scrollTrigger then\n\t\t\t\t\t\t\tlayer.isTyping = true\n\t\t\t\t\t\t\tlayer.textAnimator = gfx.animator.new(layer.effect.duration or 500, 0, string.len(layer.text),\n\t\t\t\t\t\t\t\tplaydate.easingFunctions.linear, layer.effect.delay or 0)\n\t\t\t\t\t\t\tif layer.effect.playAudio ~= false then\n\t\t\t\t\t\t\t\tplaydate.timer.performAfterDelay(layer.effect.delay or 0, startLayerTypingSound, layer)\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tlayer.needsRedraw = true\n\t\t\t\t\t\t\ttxt = \"\"\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\n\t\t\t\t\tif layer.isTyping then\n\t\t\t\t\t\tlocal j = math.ceil(layer.textAnimator:currentValue())\n\t\t\t\t\t\ttxt = string.sub(layer.text, 1, j)\n\n\t\t\t\t\t\tif txt == layer.text then\n\t\t\t\t\t\t\tlayer.isTyping = false\n\t\t\t\t\t\t\tlayer.needsRedraw = false\n\t\t\t\t\t\t\tPanels.Audio.stopTypingSound()\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tif layer.background then\n\t\t\t\tlocal w, h = 0, 0\n\t\t\t\tif layer.rect then\n\t\t\t\t\tw, h = gfx.getTextSizeForMaxWidth(txt, layer.rect.width, lineHeight)\n\t\t\t\telse\n\t\t\t\t\tw, h = gfx.getTextSize(txt)\n\t\t\t\tend\n\t\t\t\tlocal borderColor = Panels.Color.BLACK\n\t\t\t\tgfx.setColor(layer.background)\n\t\t\t\tif layer.background == Panels.Color.BLACK then\n\t\t\t\t\tgfx.setImageDrawMode(gfx.kDrawModeFillWhite)\n\t\t\t\t\tborderColor = Panels.Color.WHITE\n\t\t\t\tend\n\t\t\t\tif w > 0 and h > 0 then\n\t\t\t\t\tif layer.borderRadius then\n\t\t\t\t\t\tgfx.fillRoundRect(0, 0, w + textMarginLeft + textMarginRight, h + textMarginTop + textMarginBottom, layer.borderRadius)\n\t\t\t\t\telse\n\t\t\t\t\t\tgfx.fillRect(0, 0, w + textMarginLeft + textMarginRight, h + textMarginTop + textMarginBottom)\n\t\t\t\t\tend\n\n\t\t\t\t\tif layer.border then\n\t\t\t\t\t\tlocal borderWidth = layer.border or 1\n\t\t\t\t\t\tgfx.setColor(borderColor)\n\t\t\t\t\t\tgfx.setLineWidth(borderWidth)\n\t\t\t\t\t\tif layer.borderRadius then\n\t\t\t\t\t\t\tgfx.drawRoundRect(borderWidth * 0.5, borderWidth * 0.5, w + textMarginLeft + textMarginRight, h + textMarginTop + textMarginBottom, layer.borderRadius)\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tgfx.drawRect(borderWidth * 0.5, borderWidth * 0.5, w + textMarginLeft + textMarginRight, h + textMarginTop + textMarginBottom)\n\t\t\t\t\t\tend\n\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tlocal fillWhite = self.color == Panels.Color.WHITE\n\t\t\tif layer.color then fillWhite = layer.color == Panels.Color.WHITE end\n\t\t\tif fillWhite then\n\t\t\t\tgfx.setImageDrawMode(gfx.kDrawModeFillWhite)\n\t\t\tend\n\n\t\t\tlocal invertTextColor = self.invertTextColor\n\t\t\tif layer.invertTextColor ~= nil then invertTextColor = layer.invertTextColor end\n\t\t\tif invertTextColor then\n\t\t\t\tgfx.setImageDrawMode(gfx.kDrawModeInverted)\n\t\t\tend\n\n\t\t\tif layer.rect then\n\t\t\t\tgfx.drawTextInRect(txt, textMarginLeft, textMarginTop, layer.rect.width, layer.rect.height, lineHeight, \"...\",\n\t\t\t\t\tlayer.alignment or Panels.TextAlignment.LEFT)\n\t\t\telse\n\t\t\t\tgfx.drawText(txt, textMarginLeft, textMarginTop)\n\t\t\tend\n\n\t\t\tgfx.popContext()\n\t\tend\n\t\tif layer.alpha and layer.alpha < 1 then\n\t\t\tlayer.cachedTextImg:drawFaded(xPos - textMarginLeft, yPos - textMarginTop, layer.alpha, playdate.graphics.image.kDitherTypeBayer8x8)\n\t\telse\n\t\t\tlayer.cachedTextImg:draw(xPos - textMarginLeft, yPos - textMarginTop)\n\t\tend\n\n\tend\n\n\tfunction panel:drawBorder(color, bgColor)\n\t\tlocal frameW = self.frame.width\n\t\tlocal frameH = self.frame.height\n\t\tlocal borderW = Panels.Settings.borderWidth\n\t\tlocal b = gfx.image.new(frameW, frameH)\n\t\tlocal matte = gfx.image.new(frameW, frameH)\n\t\tgfx.pushContext(matte)\n\t\t-- create the corner matte\n\t\tgfx.setColor(bgColor)\n\t\tgfx.setLineWidth(borderW)\n\t\tgfx.fillRect(0, 0, frameW, frameH)\n\t\tgfx.setColor(Panels.Color.invert(bgColor))\n\t\tgfx.fillRoundRect(0, 0, frameW, frameH, Panels.Settings.borderRadius)\n\t\tgfx.popContext()\n\n\t\tgfx.pushContext(b)\n\t\t-- draw corner matte with center transparency\n\t\tif bgColor == Panels.Color.WHITE then\n\t\t\tgfx.setImageDrawMode(gfx.kDrawModeBlackTransparent)\n\t\telse\n\t\t\tgfx.setImageDrawMode(gfx.kDrawModeWhiteTransparent)\n\t\tend\n\t\tmatte:draw(0, 0)\n\n\t\tgfx.setLineWidth(borderW)\n\t\tgfx.setColor(color)\n\t\tgfx.drawRoundRect(borderW / 2, borderW / 2, frameW - borderW, frameH - borderW, Panels.Settings.borderRadius)\n\t\tgfx.popContext()\n\t\treturn b\n\tend\n\n\tlocal shouldAutoAdvance = false\n\n\tfunction panel:shouldAutoAdvance()\n\t\tif self.advanceFunction then\n\t\t\treturn self:advanceFunction()\n\t\telse\n\t\t\treturn self.autoAdvanceDidComplete\n\t\tend\n\tend\n\n\tfunction panel:killTypingEffects()\n\t\tif self.layers then\n\t\t\tfor i, l in ipairs(self.layers) do\n\t\t\t\tif l.isTyping then\n\t\t\t\t\tl.isTyping = false\n\t\t\t\t\tPanels.Audio.stopTypingSound()\n\t\t\t\tend\n\n\t\t\t\tif l.textAnimator then\n\t\t\t\t\tl.textAnimator = nil\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tfunction panel:updateAdvanceButton()\n\t\tif self.advanceButton.state == \"hidden\" then\n\t\t\tif self.advanceControlPosition and self.advanceControlPosition.delay and self.advanceControlTimer == nil then\n\t\t\t\tself.advanceControlTimer = playdate.timer.new(self.advanceControlPosition.delay, nil)\t\n\t\t\telseif self.advanceControlPosition == nil or self.advanceControlPosition.delay == nil or\n\t\t\t\t(self.advanceControlTimer and self.advanceControlTimer.currentTime >= self.advanceControlTimer.duration) then\n\t\t\t\tif not self.advanceControlTimerDidEnd then\n\t\t\t\t\tself.advanceButton:show()\n\t\t\t\t\tself.advanceControlTimerDidEnd = true\n\t\t\t\tend\n\t\t\tend\n\n\t\telse\n\t\t\tif pdButtonJustPressed(self.advanceControl) then\n\t\t\t\tif(self.inputEnabled) then \n\t\t\t\t\tself.advanceButton:press()\n\t\t\t\tend\n\t\t\tend\n\t\t\tself.advanceButton:draw()\n\t\tend\n\tend\n\n\tfunction panel:autoAdvanceTimerComplete() \n\t\tif self.autoAdvanceTimerDidStart then \n\t\t\tself.autoAdvanceDidComplete = true \n\t\telse \n\t\t\tself.autoAdvanceTimer:remove()\n\t\tend\n\tend\n\n\tfunction panel:render(offset, borderColor, bgColor)\n\t\tlocal frame = self.frame\n\t\tself.wasOnScreen = true\n\n\t\tif self.updateFunction then\n\t\t\tself:updateFunction(offset)\n\t\tend\n\n\t\tif self.autoAdvance ~= nil and not self.autoAdvanceTimerDidStart then\n\t\t\tself.autoAdvanceTimerDidStart = true\n\t\t\tself.autoAdvanceTimer = playdate.timer.new(self.autoAdvance, function() self:autoAdvanceTimerComplete() end)\n\t\tend\n\n\t\tgfx.setDrawOffset(math.floor(offset.x + frame.x), math.floor(offset.y + frame.y))\n\t\tgfx.setClipRect(0, 0, frame.width, frame.height)\n\n\t\tif self.backgroundColor then gfx.clear(self.backgroundColor) end\n\t\t\n\t\tif self.sfxPlayer then\n\t\t\tself:updatePanelAudio(offset)\n\t\tend\n\n\t\tif self.renderFunction then\n\t\t\tself:renderFunction(offset)\n\t\telse\n\t\t\tself:drawLayers(offset)\n\t\tend\n\n\t\tif self.choices then \n\t\t\tself.choices:render()\n\t\tend\n\n\t\tif not self.borderless then\n\t\t\tif self.borderImage == nil then\n\t\t\t\tself.borderImage = self:drawBorder(borderColor, bgColor)\n\t\t\tend\n\t\t\tself.borderImage:draw(0, 0)\n\t\tend\n\n\t\tif self.advanceButton then\n\t\t\tself:updateAdvanceButton()\n\t\tend\n\n\t\tif self.panels then\n\t\t\tlocal o = { x = offset.x + self.frame.x, y = offset.y + self.frame.y }\n\t\t\tif offset.x == 0 then o.x = 0 end\n\t\t\tif offset.y == 0 then o.y = 0 end\n\n\t\t\tfor i, subPanel in ipairs(self.panels) do\n\t\t\t\tsubPanel:render(o, borderColor, bgColor)\n\t\t\tend\n\t\tend\n\n\t\t-- let the frame render before disabling input\n\t\t-- so the button presses get rendered\n\t\tself.inputEnabled = self.willEnableInput or false\n\tend\n\n\n\treturn panel\nend\n\nfunction table.shallow_copy(t)\n\tlocal t2 = {}\n\tfor k, v in pairs(t) do\n\t\tt2[k] = v\n\tend\n\treturn t2\nend\n"
  },
  {
    "path": "modules/ScrollConstants.lua",
    "content": "Panels.ScrollType = {\n\tAUTO = 1,\n\tMANUAL = 2,\n}\n\nPanels.ScrollAxis = {\n\tVERTICAL = 1,\n\tHORIZONTAL = 2,\n}\n\nPanels.ScrollDirection = {\n\tTOP_DOWN = 1,\n\tTOP_TO_BOTTOM = 1,\n\n\tBOTTOM_UP = 2,\n\tBOTTOM_TO_TOP = 2,\n\n\tL_TO_R = 3,\n\tLEFT_TO_RIGHT = 3,\n\t\n\tR_TO_L = 4,\n\tRIGHT_TO_LEFT = 4,\n\n\tNONE = 5,\n}"
  },
  {
    "path": "modules/Settings.lua",
    "content": "Panels.Settings = {\n\t-- path settings\n\tpath = \"libraries/panels/\",\n\timageFolder = \"images/\",\n\taudioFolder = \"audio/\",\n\t\n\t-- project settings\n\tdefaultFont = nil,\n\tdefaultFontFamily = nil,\n\tmenuFontFamily = nil,\n\tresetVarsOnGameOver = true,\n\t\n\t-- panel settings\n\tdefaultFrame = {gap = 50, margin = 8},\n\tsnapToPanels = false,\n\tsequenceTransitionDuration = 750,\n\tborderWidth = 2,\n\tborderRadius = 2,\n\ttypingSound = Panels.Audio.TypingSound.DEFAULT,\n\tmaxScrollSpeed = 8,\n\t\n\t-- menu settings\n\tmenuImage = \"menuImage.png\",\n\tlistLockedSequences = true,\n\tchapterMenuHeaderImage = nil,\n\tuseChapterMenu = true,\n\tshowMenuOnLaunch = false,\n\tskipMenuOnFirstLaunch = false,\n\tplayMenuSounds = true,\n\tshowMainMenuOption = false,\n\tmainMenuOptionLabel = \"Main Menu\",\n\t\n\t-- credits\n\tuseCreditsMenu = true,\n\tshowCreditsOnGameOver = false,\n\n\t-- debug\n\tdebugControlsEnabled = false,\n\tlistUnnamedSequences = false,\n\tshowFPS = false,\n}\n\nlocal function addSlashToFolderName(f)\n\tif string.sub(f, -1) ~= \"/\" then\n\t\tf = f .. \"/\"\n\tend\n\treturn f\nend\n\nfunction validateSettings() \n\tlocal s = Panels.Settings\n\ts.imageFolder = addSlashToFolderName(s.imageFolder)\n\ts.audioFolder = addSlashToFolderName(s.audioFolder)\n\ts.path = addSlashToFolderName(s.path)\nend\n\n"
  },
  {
    "path": "modules/TextAlignment.lua",
    "content": "Panels.TextAlignment = {\n\tLEFT = kTextAlignment.left,\n\tRIGHT = kTextAlignment.right,\n\tCENTER = kTextAlignment.center\n}"
  },
  {
    "path": "modules/Utils.lua",
    "content": "function round(num, numDecimalPlaces)\n\tlocal mult = 10^(numDecimalPlaces or 0)\n\tif num >= 0 then return math.floor(num * mult + 0.5) / mult\n\telse return math.ceil(num * mult - 0.5) / mult end\nend\n\nfunction printError(error, message)\n\tif error then\n\t\tprint(\"Panels: \"..message)\n\t\tprint(\"- \"..error)\n\tend\nend\n\nfunction reverseTable(t) \n\tfor i = 1, math.floor(#t/2) do\n\t   local j = #t - i + 1\n\t\tt[i], t[j] = t[j], t[i]\n\tend\nend\n\nfunction hasValue(tbl, value)\n    for k, v in ipairs(tbl) do -- iterate table (for sequential tables only)\n        if v == value or (type(v) == \"table\" and hasValue(v, value)) then -- Compare value from the table directly with the value we are looking for, otherwise if the value is table, check its content for this value.\n            return true -- Found in this or nested table\n        end\n    end\n    return false -- Not found\nend"
  }
]