├── codepad ├── rendering │ ├── custom.render │ └── custom.render_script ├── bundle_resources │ └── web │ │ └── static │ │ ├── icon-reload.svg │ │ ├── icon-share.svg │ │ ├── icon-script.svg │ │ ├── FileSaver.min.js │ │ ├── syntax-theme.css │ │ ├── icon-logo.svg │ │ ├── codepad.css │ │ ├── FileSaver.min.js.map │ │ ├── keymaster.js │ │ ├── codepad.js │ │ └── jszip.min.js ├── gui.gui_script ├── go.script ├── utils │ └── escape.lua ├── template.html └── codepad.lua ├── main ├── assets │ ├── images │ │ └── logo.png │ └── logo.atlas ├── codepads │ ├── factory │ │ ├── factory.lua │ │ ├── logo.go │ │ └── factory.collection │ ├── label │ │ ├── label.lua │ │ └── label.collection │ ├── sprite │ │ ├── sprite.lua │ │ └── sprite.collection │ ├── two_gos │ │ ├── two_gos.lua │ │ └── two_gos.collection │ └── gui_nodes │ │ ├── gui_nodes.lua │ │ ├── gui_nodes.collection │ │ └── gui.gui ├── scripts │ └── factory │ │ ├── logo.script │ │ └── factory.script ├── main.script └── main.collection ├── .gitignore ├── .github └── workflows │ └── trigger-site-rebuild.yml ├── embed_example.html ├── game.project ├── LICENSE ├── .gitattributes ├── README.md └── input └── game.input_binding /codepad/rendering/custom.render: -------------------------------------------------------------------------------- 1 | script: "/codepad/rendering/custom.render_script" 2 | -------------------------------------------------------------------------------- /main/assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/defold/codepad/HEAD/main/assets/images/logo.png -------------------------------------------------------------------------------- /main/assets/logo.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/main/assets/images/logo.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.internal 2 | /build 3 | .externalToolBuilders 4 | .DS_Store 5 | Thumbs.db 6 | .lock-wscript 7 | *.pyc 8 | .project 9 | .cproject 10 | builtins -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/icon-reload.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /main/codepads/factory/factory.lua: -------------------------------------------------------------------------------- 1 | return { 2 | name = "Factory", 3 | url = "#cp_factory", 4 | grid = true, 5 | scripts = { 6 | { 7 | url = "cp_factory:/go#go", 8 | name = "factory.script", 9 | code = sys.load_resource("/main/scripts/factory/factory.script") 10 | }, 11 | { 12 | id = "logo", 13 | name = "logo.script", 14 | code = sys.load_resource("/main/scripts/factory/logo.script") 15 | }, 16 | } 17 | } -------------------------------------------------------------------------------- /main/scripts/factory/logo.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 2) 3 | end 4 | 5 | function final(self) 6 | 7 | end 8 | 9 | function update(self, dt) 10 | 11 | end 12 | 13 | function on_message(self, message_id, message, sender) 14 | 15 | end 16 | 17 | function on_input(self, action_id, action) 18 | 19 | end 20 | 21 | function on_reload(self) 22 | 23 | end -------------------------------------------------------------------------------- /.github/workflows/trigger-site-rebuild.yml: -------------------------------------------------------------------------------- 1 | name: Trigger site rebuild 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: [{ 11 | name: 'Repository dispatch', 12 | uses: defold/repository-dispatch@1.2.1, 13 | with: { 14 | repo: 'defold/defold.github.io', 15 | token: '${{ secrets.SERVICES_GITHUB_TOKEN }}', 16 | user: 'services@defold.se', 17 | action: 'codepad' 18 | } 19 | }] 20 | -------------------------------------------------------------------------------- /embed_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Embed example 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /main/scripts/factory/factory.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | msg.post(".", "acquire_input_focus") 3 | end 4 | 5 | function final(self) 6 | 7 | end 8 | 9 | function update(self, dt) 10 | 11 | end 12 | 13 | function on_message(self, message_id, message, sender) 14 | 15 | end 16 | 17 | function on_input(self, action_id, action) 18 | if action_id == hash("mouse_button_left") and action.released then 19 | local id = factory.create("#factory", vmath.vector3(action.x, action.y, 0)) 20 | print(id) 21 | end 22 | end 23 | 24 | function on_reload(self) 25 | 26 | end -------------------------------------------------------------------------------- /game.project: -------------------------------------------------------------------------------- 1 | [project] 2 | title = DefoldCodePad 3 | version = 0.1 4 | bundle_resources = /codepad/bundle_resources/ 5 | bundle_exclude_resources = 6 | custom_resources = main/scripts 7 | 8 | [bootstrap] 9 | main_collection = /main/main.collectionc 10 | render = /codepad/rendering/custom.renderc 11 | 12 | [input] 13 | game_binding = /input/game.input_bindingc 14 | use_accelerometer = 0 15 | 16 | [library] 17 | include_dirs = codepad 18 | 19 | [display] 20 | width = 720 21 | height = 720 22 | 23 | [physics] 24 | scale = 0.02 25 | 26 | [script] 27 | shared_state = 1 28 | 29 | [html5] 30 | htmlfile = /codepad/template.html 31 | 32 | -------------------------------------------------------------------------------- /main/codepads/label/label.lua: -------------------------------------------------------------------------------- 1 | local go_script = [[function init(self) 2 | label.set_text("#label", "Hello World!") 3 | end 4 | 5 | function final(self) 6 | 7 | end 8 | 9 | function update(self, dt) 10 | 11 | end 12 | 13 | function on_message(self, message_id, message, sender) 14 | 15 | end 16 | 17 | function on_input(self, action_id, action) 18 | 19 | end 20 | 21 | function on_reload(self) 22 | 23 | end 24 | ]] 25 | 26 | return { 27 | name = "GO + Label", 28 | url = "#cp_label", 29 | grid = true, 30 | scripts = { 31 | { 32 | url = "cp_label:/go#go", 33 | name = "go.script", 34 | code = go_script 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /main/codepads/sprite/sprite.lua: -------------------------------------------------------------------------------- 1 | local go_script = [[function init(self) 2 | go.animate(".", "position.y", go.PLAYBACK_LOOP_PINGPONG, 100, go.EASING_LINEAR, 2) 3 | end 4 | 5 | function final(self) 6 | 7 | end 8 | 9 | function update(self, dt) 10 | 11 | end 12 | 13 | function on_message(self, message_id, message, sender) 14 | 15 | end 16 | 17 | function on_input(self, action_id, action) 18 | 19 | end 20 | 21 | function on_reload(self) 22 | 23 | end 24 | ]] 25 | 26 | return { 27 | name = "GO + Sprite", 28 | url = "#cp_sprite", 29 | grid = true, 30 | scripts = { 31 | { 32 | url = "cp_sprite:/go#go", 33 | name = "go.script", 34 | code = go_script 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /main/main.script: -------------------------------------------------------------------------------- 1 | local codepad = require("codepad.codepad") 2 | 3 | 4 | local scenes = { 5 | require("main.codepads.sprite.sprite"), 6 | require("main.codepads.two_gos.two_gos"), 7 | require("main.codepads.gui_nodes.gui_nodes"), 8 | require("main.codepads.factory.factory"), 9 | require("main.codepads.label.label"), 10 | } 11 | 12 | function init(self) 13 | msg.post("#", "acquire_input_focus") 14 | codepad.init(self, scenes) 15 | if not html5 then 16 | codepad.restart(scenes[1].url) 17 | end 18 | end 19 | 20 | function update(self, dt) 21 | codepad.update(self, dt) 22 | end 23 | 24 | function on_message(self, message_id, message, sender) 25 | codepad.on_message(self, message_id, message, sender) 26 | end 27 | -------------------------------------------------------------------------------- /main/codepads/factory/logo.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "go" 3 | component: "/codepad/go.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | properties { 16 | id: "script_id" 17 | value: "logo" 18 | type: PROPERTY_TYPE_HASH 19 | } 20 | } 21 | embedded_components { 22 | id: "sprite" 23 | type: "sprite" 24 | data: "tile_set: \"/main/assets/logo.atlas\"\n" 25 | "default_animation: \"logo\"\n" 26 | "material: \"/builtins/materials/sprite.material\"\n" 27 | "blend_mode: BLEND_MODE_ALPHA\n" 28 | "" 29 | position { 30 | x: 0.0 31 | y: 0.0 32 | z: 0.0 33 | } 34 | rotation { 35 | x: 0.0 36 | y: 0.0 37 | z: 0.0 38 | w: 1.0 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Defold 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/icon-share.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /main/codepads/factory/factory.collection: -------------------------------------------------------------------------------- 1 | name: "cp_factory" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"go\"\n" 7 | " component: \"/codepad/go.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | " property_decls {\n" 20 | " }\n" 21 | "}\n" 22 | "embedded_components {\n" 23 | " id: \"factory\"\n" 24 | " type: \"factory\"\n" 25 | " data: \"prototype: \\\"/main/codepads/factory/logo.go\\\"\\n" 26 | "load_dynamically: false\\n" 27 | "dynamic_prototype: false\\n" 28 | "\"\n" 29 | " position {\n" 30 | " x: 0.0\n" 31 | " y: 0.0\n" 32 | " z: 0.0\n" 33 | " }\n" 34 | " rotation {\n" 35 | " x: 0.0\n" 36 | " y: 0.0\n" 37 | " z: 0.0\n" 38 | " w: 1.0\n" 39 | " }\n" 40 | "}\n" 41 | "" 42 | position { 43 | x: 0.0 44 | y: 0.0 45 | z: 0.0 46 | } 47 | rotation { 48 | x: 0.0 49 | y: 0.0 50 | z: 0.0 51 | w: 1.0 52 | } 53 | scale3 { 54 | x: 1.0 55 | y: 1.0 56 | z: 1.0 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /main/codepads/two_gos/two_gos.lua: -------------------------------------------------------------------------------- 1 | local go1_script = [[function init(self) 2 | go.animate(".", "position.y", go.PLAYBACK_LOOP_PINGPONG, 100, go.EASING_LINEAR, 2) 3 | end 4 | 5 | function final(self) 6 | 7 | end 8 | 9 | function update(self, dt) 10 | 11 | end 12 | 13 | function on_message(self, message_id, message, sender) 14 | 15 | end 16 | 17 | function on_input(self, action_id, action) 18 | 19 | end 20 | 21 | function on_reload(self) 22 | 23 | end 24 | ]] 25 | 26 | local go2_script = [[function init(self) 27 | go.animate(".", "position.y", go.PLAYBACK_LOOP_PINGPONG, 150, go.EASING_LINEAR, 2) 28 | end 29 | 30 | function final(self) 31 | 32 | end 33 | 34 | function update(self, dt) 35 | 36 | end 37 | 38 | function on_message(self, message_id, message, sender) 39 | 40 | end 41 | 42 | function on_input(self, action_id, action) 43 | 44 | end 45 | 46 | function on_reload(self) 47 | 48 | end 49 | ]] 50 | 51 | return { 52 | name = "Two GOs", 53 | url = "#cp_two_gos", 54 | grid = true, 55 | scripts = { 56 | { 57 | url = "cp_two_gos:/go1#go", 58 | name = "go1.script", 59 | code = go1_script 60 | }, 61 | { 62 | url = "cp_two_gos:/go2#go", 63 | name = "go2.script", 64 | --code = go2_script 65 | }, 66 | } 67 | } -------------------------------------------------------------------------------- /main/codepads/sprite/sprite.collection: -------------------------------------------------------------------------------- 1 | name: "cp_sprite" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"go\"\n" 7 | " component: \"/codepad/go.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "embedded_components {\n" 21 | " id: \"sprite\"\n" 22 | " type: \"sprite\"\n" 23 | " data: \"tile_set: \\\"/main/assets/logo.atlas\\\"\\n" 24 | "default_animation: \\\"logo\\\"\\n" 25 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 26 | "blend_mode: BLEND_MODE_ALPHA\\n" 27 | "\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "" 41 | position { 42 | x: 0.0 43 | y: 0.0 44 | z: 0.0 45 | } 46 | rotation { 47 | x: 0.0 48 | y: 0.0 49 | z: 0.0 50 | w: 1.0 51 | } 52 | scale3 { 53 | x: 1.0 54 | y: 1.0 55 | z: 1.0 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /main/codepads/gui_nodes/gui_nodes.lua: -------------------------------------------------------------------------------- 1 | local gui_script = [[function init(self) 2 | gui.animate(gui.get_node("box"), gui.PROP_POSITION, vmath.vector3(0), gui.EASING_INOUTQUAD, 2, 0, nil, gui.PLAYBACK_LOOP_PINGPONG) 3 | end 4 | 5 | function final(self) 6 | 7 | end 8 | 9 | function update(self, dt) 10 | 11 | end 12 | 13 | function on_message(self, message_id, message, sender) 14 | 15 | end 16 | 17 | function on_input(self, action_id, action) 18 | 19 | end 20 | 21 | function on_reload(self) 22 | 23 | end 24 | ]] 25 | 26 | local go_script = [[function init(self) 27 | go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 359, go.EASING_LINEAR, 2) 28 | end 29 | 30 | function final(self) 31 | 32 | end 33 | 34 | function update(self, dt) 35 | 36 | end 37 | 38 | function on_message(self, message_id, message, sender) 39 | 40 | end 41 | 42 | function on_input(self, action_id, action) 43 | 44 | end 45 | 46 | function on_reload(self) 47 | 48 | end 49 | ]] 50 | 51 | return { 52 | name = "Gui Nodes", 53 | url = "#cp_gui_nodes", 54 | grid = false, 55 | scripts = { 56 | { 57 | url = "cp_gui_nodes:/go#gui", 58 | name = "gui.gui_script", 59 | code = gui_script 60 | }, 61 | { 62 | url = "cp_gui_nodes:/go#go", 63 | name = "go.script", 64 | code = go_script 65 | }, 66 | } 67 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091) 2 | *.animationset linguist-language=JSON5 3 | *.atlas linguist-language=JSON5 4 | *.camera linguist-language=JSON5 5 | *.collection linguist-language=JSON5 6 | *.collectionfactory linguist-language=JSON5 7 | *.collectionproxy linguist-language=JSON5 8 | *.collisionobject linguist-language=JSON5 9 | *.cubemap linguist-language=JSON5 10 | *.display_profiles linguist-language=JSON5 11 | *.factory linguist-language=JSON5 12 | *.font linguist-language=JSON5 13 | *.gamepads linguist-language=JSON5 14 | *.go linguist-language=JSON5 15 | *.gui linguist-language=JSON5 16 | *.input_binding linguist-language=JSON5 17 | *.label linguist-language=JSON5 18 | *.material linguist-language=JSON5 19 | *.mesh linguist-language=JSON5 20 | *.model linguist-language=JSON5 21 | *.particlefx linguist-language=JSON5 22 | *.render linguist-language=JSON5 23 | *.sound linguist-language=JSON5 24 | *.sprite linguist-language=JSON5 25 | *.spinemodel linguist-language=JSON5 26 | *.spinescene linguist-language=JSON5 27 | *.texture_profiles linguist-language=JSON5 28 | *.tilemap linguist-language=JSON5 29 | *.tilesource linguist-language=JSON5 30 | 31 | # Defold JSON Files 32 | *.buffer linguist-language=JSON 33 | 34 | # Defold GLSL Shaders 35 | *.fp linguist-language=GLSL 36 | *.vp linguist-language=GLSL 37 | 38 | # Defold Lua Files 39 | *.editor_script linguist-language=Lua 40 | *.render_script linguist-language=Lua 41 | *.script linguist-language=Lua 42 | *.gui_script linguist-language=Lua 43 | -------------------------------------------------------------------------------- /codepad/gui.gui_script: -------------------------------------------------------------------------------- 1 | local codepad = require("codepad.codepad") 2 | 3 | function init(self) 4 | self.script_index = codepad.register_script() 5 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].init then 6 | codepad.funcs[self.script_index].init(self) 7 | end 8 | end 9 | 10 | function final(self) 11 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].final then 12 | codepad.funcs[self.script_index].final(self) 13 | end 14 | end 15 | 16 | function update(self, dt) 17 | if codepad.call_reload then 18 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_reload then 19 | codepad.funcs[self.script_index].on_reload(self, dt) 20 | end 21 | end 22 | 23 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].update then 24 | codepad.funcs[self.script_index].update(self, dt) 25 | end 26 | end 27 | 28 | function on_message(self, message_id, message, sender) 29 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_message then 30 | codepad.funcs[self.script_index].on_message(self, message_id, message, sender) 31 | end 32 | end 33 | 34 | function on_input(self, action_id, action) 35 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_input then 36 | codepad.funcs[self.script_index].on_input(self, action_id, action) 37 | end 38 | end 39 | 40 | function on_reload(self) 41 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_reload then 42 | codepad.funcs[self.script_index].on_reload(self, dt) 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /main/codepads/gui_nodes/gui_nodes.collection: -------------------------------------------------------------------------------- 1 | name: "cp_gui_nodes" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"go\"\n" 7 | " component: \"/codepad/go.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "components {\n" 21 | " id: \"gui\"\n" 22 | " component: \"/main/codepads/gui_nodes/gui.gui\"\n" 23 | " position {\n" 24 | " x: 0.0\n" 25 | " y: 0.0\n" 26 | " z: 0.0\n" 27 | " }\n" 28 | " rotation {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " w: 1.0\n" 33 | " }\n" 34 | "}\n" 35 | "embedded_components {\n" 36 | " id: \"sprite\"\n" 37 | " type: \"sprite\"\n" 38 | " data: \"tile_set: \\\"/main/assets/logo.atlas\\\"\\n" 39 | "default_animation: \\\"logo\\\"\\n" 40 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 41 | "blend_mode: BLEND_MODE_ALPHA\\n" 42 | "\"\n" 43 | " position {\n" 44 | " x: 0.0\n" 45 | " y: 0.0\n" 46 | " z: 0.0\n" 47 | " }\n" 48 | " rotation {\n" 49 | " x: 0.0\n" 50 | " y: 0.0\n" 51 | " z: 0.0\n" 52 | " w: 1.0\n" 53 | " }\n" 54 | "}\n" 55 | "" 56 | position { 57 | x: 0.0 58 | y: 0.0 59 | z: 0.0 60 | } 61 | rotation { 62 | x: 0.0 63 | y: 0.0 64 | z: 0.0 65 | w: 1.0 66 | } 67 | scale3 { 68 | x: 1.0 69 | y: 1.0 70 | z: 1.0 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /codepad/go.script: -------------------------------------------------------------------------------- 1 | go.property("script_id", hash("")) 2 | 3 | local codepad = require("codepad.codepad") 4 | 5 | function init(self) 6 | self.script_index = codepad.register_script(self.script_id) 7 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].init then 8 | codepad.funcs[self.script_index].init(self) 9 | end 10 | end 11 | 12 | function final(self) 13 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].final then 14 | codepad.funcs[self.script_index].final(self) 15 | end 16 | end 17 | 18 | function update(self, dt) 19 | if codepad.call_reload then 20 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_reload then 21 | codepad.funcs[self.script_index].on_reload(self, dt) 22 | end 23 | end 24 | 25 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].update then 26 | codepad.funcs[self.script_index].update(self, dt) 27 | end 28 | end 29 | 30 | function on_message(self, message_id, message, sender) 31 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_message then 32 | codepad.funcs[self.script_index].on_message(self, message_id, message, sender) 33 | end 34 | end 35 | 36 | function on_input(self, action_id, action) 37 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_input then 38 | codepad.funcs[self.script_index].on_input(self, action_id, action) 39 | end 40 | end 41 | 42 | function on_reload(self) 43 | if codepad.funcs[self.script_index] and codepad.funcs[self.script_index].on_reload then 44 | codepad.funcs[self.script_index].on_reload(self, dt) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/icon-script.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /main/codepads/label/label.collection: -------------------------------------------------------------------------------- 1 | name: "cp_label" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"go\"\n" 7 | " component: \"/codepad/go.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | " property_decls {\n" 20 | " }\n" 21 | "}\n" 22 | "embedded_components {\n" 23 | " id: \"label\"\n" 24 | " type: \"label\"\n" 25 | " data: \"size {\\n" 26 | " x: 128.0\\n" 27 | " y: 32.0\\n" 28 | " z: 0.0\\n" 29 | " w: 0.0\\n" 30 | "}\\n" 31 | "color {\\n" 32 | " x: 1.0\\n" 33 | " y: 1.0\\n" 34 | " z: 1.0\\n" 35 | " w: 1.0\\n" 36 | "}\\n" 37 | "outline {\\n" 38 | " x: 0.0\\n" 39 | " y: 0.0\\n" 40 | " z: 0.0\\n" 41 | " w: 1.0\\n" 42 | "}\\n" 43 | "shadow {\\n" 44 | " x: 0.0\\n" 45 | " y: 0.0\\n" 46 | " z: 0.0\\n" 47 | " w: 1.0\\n" 48 | "}\\n" 49 | "leading: 1.0\\n" 50 | "tracking: 0.0\\n" 51 | "pivot: PIVOT_CENTER\\n" 52 | "blend_mode: BLEND_MODE_ALPHA\\n" 53 | "line_break: false\\n" 54 | "text: \\\"Label\\\"\\n" 55 | "font: \\\"/builtins/fonts/system_font.font\\\"\\n" 56 | "material: \\\"/builtins/fonts/label.material\\\"\\n" 57 | "\"\n" 58 | " position {\n" 59 | " x: 0.0\n" 60 | " y: 0.0\n" 61 | " z: 0.0\n" 62 | " }\n" 63 | " rotation {\n" 64 | " x: 0.0\n" 65 | " y: 0.0\n" 66 | " z: 0.0\n" 67 | " w: 1.0\n" 68 | " }\n" 69 | "}\n" 70 | "" 71 | position { 72 | x: 0.0 73 | y: 0.0 74 | z: 0.0 75 | } 76 | rotation { 77 | x: 0.0 78 | y: 0.0 79 | z: 0.0 80 | w: 1.0 81 | } 82 | scale3 { 83 | x: 1.0 84 | y: 1.0 85 | z: 1.0 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /codepad/rendering/custom.render_script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | self.tile_pred = render.predicate({"tile"}) 3 | self.gui_pred = render.predicate({"gui"}) 4 | self.text_pred = render.predicate({"text"}) 5 | self.particle_pred = render.predicate({"particle"}) 6 | 7 | self.clear_color = vmath.vector4(44/255, 46/255, 51/255, 1) 8 | 9 | self.view = vmath.matrix4() 10 | end 11 | 12 | function update(self) 13 | render.set_depth_mask(true) 14 | render.set_stencil_mask(0xff) 15 | render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0}) 16 | 17 | render.set_viewport(0, 0, render.get_window_width(), render.get_window_height()) 18 | 19 | -- draw game objects 20 | local hw = render.get_window_width() / 2 21 | local hh = render.get_window_height() / 2 22 | local projection = vmath.matrix4_orthographic(-hw, hw, -hh, hh, -1, 1) 23 | local frustum = projection * self.view 24 | render.set_view(self.view) 25 | render.set_projection(projection) 26 | 27 | render.set_depth_mask(false) 28 | render.disable_state(render.STATE_DEPTH_TEST) 29 | render.disable_state(render.STATE_STENCIL_TEST) 30 | render.disable_state(render.STATE_CULL_FACE) 31 | render.enable_state(render.STATE_BLEND) 32 | render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA) 33 | 34 | render.draw_debug3d() 35 | render.draw(self.tile_pred, { frustum = frustum }) 36 | render.draw(self.particle_pred, { frustum = frustum }) 37 | 38 | -- draw gui 39 | local view_gui = vmath.matrix4() 40 | local proj_gui = vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1) 41 | local frustum_gui = proj_gui * view_gui 42 | render.set_view(view_gui) 43 | render.set_projection(proj_gui) 44 | 45 | render.enable_state(render.STATE_STENCIL_TEST) 46 | render.draw(self.gui_pred, {frustum = frustum_gui}) 47 | render.draw(self.text_pred, {frustum = frustum_gui}) 48 | render.disable_state(render.STATE_STENCIL_TEST) 49 | end 50 | 51 | function on_message(self, message_id, message) 52 | if message_id == hash("clear_color") then 53 | self.clear_color = message.color 54 | elseif message_id == hash("set_view_projection") then 55 | self.view = message.view 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /main/codepads/two_gos/two_gos.collection: -------------------------------------------------------------------------------- 1 | name: "cp_two_gos" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go2" 5 | data: "components {\n" 6 | " id: \"go\"\n" 7 | " component: \"/codepad/go.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "embedded_components {\n" 21 | " id: \"sprite\"\n" 22 | " type: \"sprite\"\n" 23 | " data: \"tile_set: \\\"/main/assets/logo.atlas\\\"\\n" 24 | "default_animation: \\\"logo\\\"\\n" 25 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 26 | "blend_mode: BLEND_MODE_ALPHA\\n" 27 | "\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "" 41 | position { 42 | x: 100.0 43 | y: 0.0 44 | z: 0.0 45 | } 46 | rotation { 47 | x: 0.0 48 | y: 0.0 49 | z: 0.0 50 | w: 1.0 51 | } 52 | scale3 { 53 | x: 1.0 54 | y: 1.0 55 | z: 1.0 56 | } 57 | } 58 | embedded_instances { 59 | id: "go1" 60 | data: "components {\n" 61 | " id: \"go\"\n" 62 | " component: \"/codepad/go.script\"\n" 63 | " position {\n" 64 | " x: 0.0\n" 65 | " y: 0.0\n" 66 | " z: 0.0\n" 67 | " }\n" 68 | " rotation {\n" 69 | " x: 0.0\n" 70 | " y: 0.0\n" 71 | " z: 0.0\n" 72 | " w: 1.0\n" 73 | " }\n" 74 | "}\n" 75 | "embedded_components {\n" 76 | " id: \"sprite\"\n" 77 | " type: \"sprite\"\n" 78 | " data: \"tile_set: \\\"/main/assets/logo.atlas\\\"\\n" 79 | "default_animation: \\\"logo\\\"\\n" 80 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 81 | "blend_mode: BLEND_MODE_ALPHA\\n" 82 | "\"\n" 83 | " position {\n" 84 | " x: 0.0\n" 85 | " y: 0.0\n" 86 | " z: 0.0\n" 87 | " }\n" 88 | " rotation {\n" 89 | " x: 0.0\n" 90 | " y: 0.0\n" 91 | " z: 0.0\n" 92 | " w: 1.0\n" 93 | " }\n" 94 | "}\n" 95 | "" 96 | position { 97 | x: -100.0 98 | y: 0.0 99 | z: 0.0 100 | } 101 | rotation { 102 | x: 0.0 103 | y: 0.0 104 | z: 0.0 105 | w: 1.0 106 | } 107 | scale3 { 108 | x: 1.0 109 | y: 1.0 110 | z: 1.0 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/FileSaver.min.js: -------------------------------------------------------------------------------- 1 | (function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(b,c,d){var e=new XMLHttpRequest;e.open("GET",b),e.responseType="blob",e.onload=function(){a(e.response,c,d)},e.onerror=function(){console.error("could not download file")},e.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(a,b,d,e){if(e=e||open("","_blank"),e&&(e.document.title=e.document.body.innerText="downloading..."),"string"==typeof a)return c(a,b,d);var g="application/octet-stream"===a.type,h=/constructor/i.test(f.HTMLElement)||f.safari,i=/CriOS\/[\d]+/.test(navigator.userAgent);if((i||g&&h)&&"object"==typeof FileReader){var j=new FileReader;j.onloadend=function(){var a=j.result;a=i?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),e?e.location.href=a:location=a,e=null},j.readAsDataURL(a)}else{var k=f.URL||f.webkitURL,l=k.createObjectURL(a);e?e.location=l:location.href=l,e=null,setTimeout(function(){k.revokeObjectURL(l)},4E4)}});f.saveAs=a.saveAs=a,"undefined"!=typeof module&&(module.exports=a)}); 2 | 3 | //# sourceMappingURL=FileSaver.min.js.map -------------------------------------------------------------------------------- /codepad/utils/escape.lua: -------------------------------------------------------------------------------- 1 | --- Turbo.lua Escape module 2 | -- 3 | -- Copyright John Abrahamsen 2011, 2012, 2013 < JhnAbrhmsn@gmail.com > 4 | -- 5 | -- "Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | -- this software and associated documentation files (the "Software"), to deal in 7 | -- the Software without restriction, including without limitation the rights to 8 | -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | -- of the Software, and to permit persons to whom the Software is furnished to do 10 | -- so, subject to the following conditions: 11 | -- 12 | -- The above copyright notice and this permission notice shall be included in all 13 | -- copies or substantial portions of the Software. 14 | -- 15 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | -- SOFTWARE." 22 | 23 | local escape = {} -- escape namespace 24 | 25 | local function _unhex(hex) return string.char(tonumber(hex, 16)) end 26 | --- Unescape a escaped hexadecimal representation string. 27 | -- @param s (String) String to unescape. 28 | function escape.unescape(s) 29 | return string.gsub(s, "%%(%x%x)", _unhex) 30 | end 31 | 32 | local function _hex(c) 33 | return string.format("%%%02x", string.byte(c)) 34 | end 35 | --- Encodes a string into its escaped hexadecimal representation. 36 | -- @param s (String) String to escape. 37 | function escape.escape(s) 38 | return string.gsub(s, "([^A-Za-z0-9_])", _hex) 39 | end 40 | 41 | --- Encodes the HTML entities in a string. Helpfull to avoid XSS. 42 | -- @param s (String) String to escape. 43 | function escape.html_escape(s) 44 | assert("Expected string in argument #1.") 45 | return (string.gsub(s, "[}{\">/<'&]", { 46 | ["&"] = "&", 47 | ["<"] = "<", 48 | [">"] = ">", 49 | ['"'] = """, 50 | ["'"] = "'", 51 | ["/"] = "/" 52 | })) 53 | end 54 | 55 | -- Remove trailing and leading whitespace from string. 56 | -- @param s String 57 | function escape.trim(s) 58 | -- from PiL2 20.4 59 | return (s:gsub("^%s*(.-)%s*$", "%1")) 60 | end 61 | 62 | -- Remove leading whitespace from string. 63 | -- @param s String 64 | function escape.ltrim(s) 65 | return (s:gsub("^%s*", "")) 66 | end 67 | 68 | -- Remove trailing whitespace from string. 69 | -- @param s String 70 | function escape.rtrim(s) 71 | local n = #s 72 | while n > 0 and s:find("^%s", n) do n = n - 1 end 73 | return s:sub(1, n) 74 | end 75 | 76 | return escape -------------------------------------------------------------------------------- /main/main.collection: -------------------------------------------------------------------------------- 1 | name: "main" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "main" 5 | data: "components {\n" 6 | " id: \"main\"\n" 7 | " component: \"/main/main.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | " property_decls {\n" 20 | " }\n" 21 | "}\n" 22 | "embedded_components {\n" 23 | " id: \"cp_sprite\"\n" 24 | " type: \"collectionproxy\"\n" 25 | " data: \"collection: \\\"/main/codepads/sprite/sprite.collection\\\"\\n" 26 | "exclude: false\\n" 27 | "\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "embedded_components {\n" 41 | " id: \"cp_two_gos\"\n" 42 | " type: \"collectionproxy\"\n" 43 | " data: \"collection: \\\"/main/codepads/two_gos/two_gos.collection\\\"\\n" 44 | "exclude: false\\n" 45 | "\"\n" 46 | " position {\n" 47 | " x: 0.0\n" 48 | " y: 0.0\n" 49 | " z: 0.0\n" 50 | " }\n" 51 | " rotation {\n" 52 | " x: 0.0\n" 53 | " y: 0.0\n" 54 | " z: 0.0\n" 55 | " w: 1.0\n" 56 | " }\n" 57 | "}\n" 58 | "embedded_components {\n" 59 | " id: \"cp_gui_nodes\"\n" 60 | " type: \"collectionproxy\"\n" 61 | " data: \"collection: \\\"/main/codepads/gui_nodes/gui_nodes.collection\\\"\\n" 62 | "exclude: false\\n" 63 | "\"\n" 64 | " position {\n" 65 | " x: 0.0\n" 66 | " y: 0.0\n" 67 | " z: 0.0\n" 68 | " }\n" 69 | " rotation {\n" 70 | " x: 0.0\n" 71 | " y: 0.0\n" 72 | " z: 0.0\n" 73 | " w: 1.0\n" 74 | " }\n" 75 | "}\n" 76 | "embedded_components {\n" 77 | " id: \"cp_factory\"\n" 78 | " type: \"collectionproxy\"\n" 79 | " data: \"collection: \\\"/main/codepads/factory/factory.collection\\\"\\n" 80 | "exclude: false\\n" 81 | "\"\n" 82 | " position {\n" 83 | " x: 0.0\n" 84 | " y: 0.0\n" 85 | " z: 0.0\n" 86 | " }\n" 87 | " rotation {\n" 88 | " x: 0.0\n" 89 | " y: 0.0\n" 90 | " z: 0.0\n" 91 | " w: 1.0\n" 92 | " }\n" 93 | "}\n" 94 | "embedded_components {\n" 95 | " id: \"cp_label\"\n" 96 | " type: \"collectionproxy\"\n" 97 | " data: \"collection: \\\"/main/codepads/label/label.collection\\\"\\n" 98 | "exclude: false\\n" 99 | "\"\n" 100 | " position {\n" 101 | " x: 0.0\n" 102 | " y: 0.0\n" 103 | " z: 0.0\n" 104 | " }\n" 105 | " rotation {\n" 106 | " x: 0.0\n" 107 | " y: 0.0\n" 108 | " z: 0.0\n" 109 | " w: 1.0\n" 110 | " }\n" 111 | "}\n" 112 | "" 113 | position { 114 | x: 0.0 115 | y: 0.0 116 | z: 0.0 117 | } 118 | rotation { 119 | x: 0.0 120 | y: 0.0 121 | z: 0.0 122 | w: 1.0 123 | } 124 | scale3 { 125 | x: 1.0 126 | y: 1.0 127 | z: 1.0 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /main/codepads/gui_nodes/gui.gui: -------------------------------------------------------------------------------- 1 | script: "/codepad/gui.gui_script" 2 | fonts { 3 | name: "system_font" 4 | font: "/builtins/fonts/system_font.font" 5 | } 6 | background_color { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | w: 0.0 11 | } 12 | nodes { 13 | position { 14 | x: 100.0 15 | y: 620.0 16 | z: 0.0 17 | w: 1.0 18 | } 19 | rotation { 20 | x: 0.0 21 | y: 0.0 22 | z: 0.0 23 | w: 1.0 24 | } 25 | scale { 26 | x: 1.0 27 | y: 1.0 28 | z: 1.0 29 | w: 1.0 30 | } 31 | size { 32 | x: 100.0 33 | y: 100.0 34 | z: 0.0 35 | w: 1.0 36 | } 37 | color { 38 | x: 1.0 39 | y: 1.0 40 | z: 1.0 41 | w: 1.0 42 | } 43 | type: TYPE_BOX 44 | blend_mode: BLEND_MODE_ALPHA 45 | texture: "" 46 | id: "box" 47 | xanchor: XANCHOR_NONE 48 | yanchor: YANCHOR_NONE 49 | pivot: PIVOT_CENTER 50 | adjust_mode: ADJUST_MODE_FIT 51 | layer: "" 52 | inherit_alpha: true 53 | slice9 { 54 | x: 0.0 55 | y: 0.0 56 | z: 0.0 57 | w: 0.0 58 | } 59 | clipping_mode: CLIPPING_MODE_NONE 60 | clipping_visible: true 61 | clipping_inverted: false 62 | alpha: 1.0 63 | template_node_child: false 64 | size_mode: SIZE_MODE_MANUAL 65 | } 66 | nodes { 67 | position { 68 | x: 100.0 69 | y: 535.0 70 | z: 0.0 71 | w: 1.0 72 | } 73 | rotation { 74 | x: 0.0 75 | y: 0.0 76 | z: 0.0 77 | w: 1.0 78 | } 79 | scale { 80 | x: 1.0 81 | y: 1.0 82 | z: 1.0 83 | w: 1.0 84 | } 85 | size { 86 | x: 200.0 87 | y: 100.0 88 | z: 0.0 89 | w: 1.0 90 | } 91 | color { 92 | x: 1.0 93 | y: 1.0 94 | z: 1.0 95 | w: 1.0 96 | } 97 | type: TYPE_TEXT 98 | blend_mode: BLEND_MODE_ALPHA 99 | text: "" 100 | font: "system_font" 101 | id: "text" 102 | xanchor: XANCHOR_NONE 103 | yanchor: YANCHOR_NONE 104 | pivot: PIVOT_CENTER 105 | outline { 106 | x: 1.0 107 | y: 1.0 108 | z: 1.0 109 | w: 1.0 110 | } 111 | shadow { 112 | x: 1.0 113 | y: 1.0 114 | z: 1.0 115 | w: 1.0 116 | } 117 | adjust_mode: ADJUST_MODE_FIT 118 | line_break: true 119 | layer: "" 120 | inherit_alpha: true 121 | alpha: 1.0 122 | outline_alpha: 1.0 123 | shadow_alpha: 1.0 124 | template_node_child: false 125 | text_leading: 1.0 126 | text_tracking: 0.0 127 | } 128 | nodes { 129 | position { 130 | x: 100.0 131 | y: 450.0 132 | z: 0.0 133 | w: 1.0 134 | } 135 | rotation { 136 | x: 0.0 137 | y: 0.0 138 | z: 0.0 139 | w: 1.0 140 | } 141 | scale { 142 | x: 1.0 143 | y: 1.0 144 | z: 1.0 145 | w: 1.0 146 | } 147 | size { 148 | x: 100.0 149 | y: 100.0 150 | z: 0.0 151 | w: 1.0 152 | } 153 | color { 154 | x: 1.0 155 | y: 1.0 156 | z: 1.0 157 | w: 1.0 158 | } 159 | type: TYPE_PIE 160 | blend_mode: BLEND_MODE_ALPHA 161 | texture: "" 162 | id: "pie" 163 | xanchor: XANCHOR_NONE 164 | yanchor: YANCHOR_NONE 165 | pivot: PIVOT_CENTER 166 | adjust_mode: ADJUST_MODE_FIT 167 | layer: "" 168 | inherit_alpha: true 169 | outerBounds: PIEBOUNDS_ELLIPSE 170 | innerRadius: 0.0 171 | perimeterVertices: 32 172 | pieFillAngle: 270.0 173 | clipping_mode: CLIPPING_MODE_NONE 174 | clipping_visible: true 175 | clipping_inverted: false 176 | alpha: 1.0 177 | template_node_child: false 178 | size_mode: SIZE_MODE_MANUAL 179 | } 180 | material: "/builtins/materials/gui.material" 181 | adjust_reference: ADJUST_REFERENCE_PARENT 182 | max_nodes: 512 183 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codepad 2 | Online Defold compiler/interpreter. [Try it here](https://defold.com/codepad/) or host your own custom version. 3 | 4 | # Installation 5 | You can use the Codepad in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add: 6 | 7 | https://github.com/defold/codepad/archive/master.zip 8 | 9 | Or point to the ZIP file of a [specific release](https://github.com/defold/codepad/releases). 10 | 11 | # Usage 12 | The Codepad can be used in two ways: 13 | 14 | 1. As a stand-alone webpage with a code editor, live preview and console 15 | 2. As an embedded example on another webpage where the source code is provided 16 | 17 | When you use the Codepad on a stand-alone webpage you need to define one or more scenes to chose from. Each scene should be contained within a collection and expose one or more scripts that the user should be able to modify. The scene collections should be available to the Codepad via collection proxies. 18 | 19 | When you use the Codepad embedded on a webpage you define a single scene and expose one or more scripts that should accept source code from the embedding page. 20 | 21 | ## game.project setup 22 | In both the stand-alone and embedded version of the Code pad you need to use the Codepad HTML template (located in `codepad/template.html`) as HTML file in `game.project` in the `HTML5` section. 23 | 24 | You also need to make sure to include the static HTML5 content (css, javascript and images) from the `codepad/bundle_resources/` folder. You do this by adding `/codepad/bundle_resources/` in the Bundle Resources field of `game.project` in the `Project` section. 25 | 26 | ## Expose modifiable scripts 27 | The scripts that are modifiable from the Codepad can be both game object scripts and GUI scripts. A game object or GUI scene that wants to have a modifiable script must add the `codepad/go.script` or `codepad/gui.gui_script` respectively. 28 | 29 | ## Initialise and update the codepad 30 | Before the Codepad is used it must be initialised with available scenes and modifiable scripts per scene. 31 | 32 | local codepad = require "codepad.codepad" 33 | 34 | local scenes = { 35 | { 36 | name = "My Scene", 37 | url = "#scene_proxy", 38 | scripts = { 39 | { 40 | url = "myscene:/go#go", 41 | name = "go.script", 42 | code = nil, -- string with default script 43 | } 44 | } 45 | } 46 | } 47 | 48 | function init(self) 49 | codepad.init(self, scenes) 50 | end 51 | 52 | function update(self, dt) 53 | codepad.update(self, dt) 54 | end 55 | 56 | function on_message(self, message_id, message, sender) 57 | codepad.on_message(self, message_id, message, sender) 58 | end 59 | 60 | In the above example we define a single scene named "My Scene" with a proxy URL of "#scene_proxy" (relative to the running script). The scene has a single script named "go.script" and the script URL is "myscene:/go#go". The names should be descriptive and help the user of the Codepad to chose the right scene and script to edit. 61 | 62 | You can also provide an additional property `code` per script to provide a string containing any code you wish to use as default for the script. If no `code` is provided then the Codepad will use a default script containing empty Defold lifecycle functions. 63 | 64 | 65 | ## Libraries 66 | Codepad uses the following libraries: 67 | 68 | * [FileSaver.js](https://github.com/eligrey/FileSaver.js) 69 | * [JSZip](https://github.com/Stuk/jszip) 70 | * [Keymaster](https://github.com/madrobby/keymaster) 71 | * [LZ-String](https://github.com/pieroxy/lz-string) 72 | * [Ace](https://github.com/ajaxorg/ace/) 73 | * [split.js](https://github.com/nathancahill/split/) 74 | 75 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/syntax-theme.css: -------------------------------------------------------------------------------- 1 | .ace-tomorrow-night-eighties .ace_gutter { 2 | background: #27292d; 3 | color: #CCC 4 | } 5 | 6 | .ace-tomorrow-night-eighties .ace_print-margin { 7 | width: 1px; 8 | background: #27292d 9 | } 10 | 11 | .ace-tomorrow-night-eighties { 12 | background-color: #27292d; 13 | color: #CCCCCC 14 | } 15 | 16 | .ace-tomorrow-night-eighties .ace_constant.ace_other, 17 | .ace-tomorrow-night-eighties .ace_cursor { 18 | color: #CCCCCC 19 | } 20 | 21 | .ace-tomorrow-night-eighties .ace_marker-layer .ace_selection { 22 | background: #4e4a46 23 | } 24 | 25 | .ace-tomorrow-night-eighties.ace_multiselect .ace_selection.ace_start { 26 | box-shadow: 0 0 3px 0px #2D2D2D; 27 | } 28 | 29 | .ace-tomorrow-night-eighties .ace_marker-layer .ace_step { 30 | background: rgb(102, 82, 0) 31 | } 32 | 33 | .ace-tomorrow-night-eighties .ace_marker-layer .ace_bracket { 34 | margin: -1px 0 0 -1px; 35 | border: 1px solid #6A6A6A 36 | } 37 | 38 | .ace-tomorrow-night-bright .ace_stack { 39 | background: rgb(66, 90, 44) 40 | } 41 | 42 | .ace-tomorrow-night-eighties .ace_marker-layer .ace_active-line { 43 | background: #393939 44 | } 45 | 46 | .ace-tomorrow-night-eighties .ace_gutter-active-line { 47 | background-color: #393939 48 | } 49 | 50 | .ace-tomorrow-night-eighties .ace_marker-layer .ace_selected-word { 51 | border: 1px solid #515151 52 | } 53 | 54 | .ace-tomorrow-night-eighties .ace_invisible { 55 | color: #6A6A6A 56 | } 57 | 58 | .ace-tomorrow-night-eighties .ace_keyword, 59 | .ace-tomorrow-night-eighties .ace_meta, 60 | .ace-tomorrow-night-eighties .ace_storage, 61 | .ace-tomorrow-night-eighties .ace_storage.ace_type, 62 | .ace-tomorrow-night-eighties .ace_support.ace_type { 63 | color: #ff6506 64 | } 65 | 66 | .ace-tomorrow-night-eighties .ace_keyword.ace_operator { 67 | color: #66CCCC 68 | } 69 | 70 | .ace-tomorrow-night-eighties .ace_constant.ace_character, 71 | .ace-tomorrow-night-eighties .ace_constant.ace_language, 72 | .ace-tomorrow-night-eighties .ace_constant.ace_numeric, 73 | .ace-tomorrow-night-eighties .ace_keyword.ace_other.ace_unit, 74 | .ace-tomorrow-night-eighties .ace_support.ace_constant, 75 | .ace-tomorrow-night-eighties .ace_variable.ace_parameter { 76 | color: #aba7ff 77 | } 78 | 79 | .ace-tomorrow-night-eighties .ace_invalid { 80 | color: #CDCDCD; 81 | background-color: #F2777A 82 | } 83 | 84 | .ace-tomorrow-night-eighties .ace_invalid.ace_deprecated { 85 | color: #CDCDCD; 86 | background-color: #ff6506 87 | } 88 | 89 | .ace-tomorrow-night-eighties .ace_fold { 90 | background-color: #6699CC; 91 | border-color: #CCCCCC 92 | } 93 | 94 | .ace-tomorrow-night-eighties .ace_entity.ace_name.ace_function, 95 | .ace-tomorrow-night-eighties .ace_support.ace_function, 96 | .ace-tomorrow-night-eighties .ace_variable { 97 | color: #6699CC 98 | } 99 | 100 | .ace-tomorrow-night-eighties .ace_support.ace_class, 101 | .ace-tomorrow-night-eighties .ace_support.ace_type { 102 | color: #FFCC66 103 | } 104 | 105 | .ace-tomorrow-night-eighties .ace_heading, 106 | .ace-tomorrow-night-eighties .ace_markup.ace_heading, 107 | .ace-tomorrow-night-eighties .ace_string { 108 | color: #fccf00 109 | } 110 | 111 | .ace-tomorrow-night-eighties .ace_comment { 112 | color: #b0b0b0 113 | } 114 | 115 | .ace-tomorrow-night-eighties .ace_entity.ace_name.ace_tag, 116 | .ace-tomorrow-night-eighties .ace_entity.ace_other.ace_attribute-name, 117 | .ace-tomorrow-night-eighties .ace_meta.ace_tag, 118 | .ace-tomorrow-night-eighties .ace_variable { 119 | color: #e5a863 120 | } 121 | 122 | .ace-tomorrow-night-eighties .ace_indent-guide { 123 | background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWPQ09NrYAgMjP4PAAtGAwchHMyAAAAAAElFTkSuQmCC) right repeat-y 124 | } 125 | -------------------------------------------------------------------------------- /codepad/template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | {{project.title}} {{project.version}} 12 | 13 | 14 | 15 |
LOADING
16 | 21 |
Collection: 22 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
32 |
33 | 34 |
35 |
36 |
37 |
38 |
39 |
40 | 41 |
42 |
43 |
44 |
45 |
46 |
47 | 48 |
49 |
50 |
51 | 52 |
53 |
54 | 55 |
56 | 57 | 58 |
59 |
60 | 61 | 62 | 63 | 64 | 65 | 89 | 90 | 91 | 92 | 93 | 94 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/icon-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/codepad.css: -------------------------------------------------------------------------------- 1 | 2 | html, body { 3 | padding: 0px; 4 | margin: 0px; 5 | overflow: hidden; 6 | height: 100%; 7 | } 8 | 9 | body { 10 | color: #cccfd4; 11 | background-color: #212428; 12 | height: 100%; 13 | overflow: auto; 14 | font-size: 13px; 15 | font-family: 'Source Sans Pro', sans-serif; 16 | -webkit-font-smoothing: antialiased; 17 | -moz-osx-font-smoothing: grayscale; 18 | } 19 | 20 | body.embedded { 21 | overflow: hidden; 22 | } 23 | 24 | *:focus { 25 | outline: none; 26 | } 27 | 28 | button, input, select { 29 | -webkit-appearance: none; 30 | -webkit-border-radius: 0px; 31 | background: #434448; 32 | border-radius: 2px; 33 | border: none; 34 | color: #b3b4b5; 35 | height: 28px; 36 | padding: 0px 14px 0px 14px; 37 | margin: 0px 4px 0px 4px; 38 | text-transform: uppercase; 39 | font-weight: bold; 40 | font-size: 14px; 41 | font-family: 'Source Sans Pro', sans-serif; 42 | transition: background 0.6s ease 0s; 43 | } 44 | 45 | button:active, input:active, select:active { 46 | background: #5c5d61; 47 | transition: background 0.0s ease 0s; 48 | } 49 | 50 | #splash { 51 | display: block; 52 | background-color: #434448; 53 | position: fixed; 54 | top: 0px; 55 | left: 0px; 56 | bottom: 0px; 57 | right: 0px; 58 | z-index: 999999; 59 | 60 | 61 | color: #b3b4b5; 62 | text-transform: uppercase; 63 | font-weight: bold; 64 | font-size: 18px; 65 | font-family: 'Source Sans Pro', sans-serif; 66 | 67 | cursor: pointer; 68 | } 69 | 70 | #splash>div { 71 | position: absolute; 72 | top: 0; 73 | bottom: 0; 74 | left: 0; 75 | right: 0; 76 | width: 200px; 77 | height: 0px; 78 | margin: auto; 79 | text-align: center; 80 | } 81 | 82 | #toolbar { 83 | position: absolute; 84 | left: 20px; 85 | right: 20px; 86 | top: 0px; 87 | height: 60px; 88 | line-height: 60px; 89 | color: #737679; 90 | } 91 | 92 | #share-wrap { 93 | position: absolute; 94 | top: 0px; 95 | right: 0px; 96 | } 97 | 98 | #layout { 99 | position: absolute; 100 | top: 60px; 101 | bottom: 8px; 102 | left: 8px; 103 | right: 8px; 104 | } 105 | 106 | .pane-content { 107 | background-color: #2c2e33; 108 | border-radius: 3px; 109 | overflow: hidden; 110 | } 111 | 112 | body.embedded .pane-content { 113 | border-radius: 0px; 114 | } 115 | 116 | .tabs-wrap { 117 | position: absolute; 118 | top: 0px; 119 | height: 38px; 120 | width: 100%; 121 | padding: 0px 0px 0px 0px; 122 | margin: 0px; 123 | border: 0px; 124 | font-size: 13px; 125 | } 126 | 127 | .tabs-wrap label { 128 | opacity: 0.4; 129 | color: #eff2f6; 130 | margin: 0px; 131 | padding: 0px; 132 | height: 38px; 133 | line-height: 38px; 134 | padding: 0px 12px 0px 12px; 135 | border: none; 136 | border-bottom: 2px solid #212428; 137 | display: inline-block; 138 | transition: all 0.2s ease 0s; 139 | } 140 | 141 | .tabs-wrap input { 142 | margin: 0px; 143 | padding: 0px; 144 | display: none; 145 | } 146 | 147 | .tabs-wrap [type=radio]:checked + label 148 | { 149 | opacity: 1; 150 | color: #eff2f6; 151 | border-bottom: 2px solid #fd6623; 152 | } 153 | 154 | svg, .svg-image { 155 | display: inline-block; 156 | vertical-align: middle; 157 | margin-right: 6px; 158 | } 159 | 160 | #pane-editor, #pane-console { 161 | position: relative; 162 | } 163 | 164 | #editor-wrap { 165 | width: 100%; 166 | position: absolute; 167 | top: 40px; 168 | bottom: 0px; 169 | } 170 | 171 | #editor-wrap > button { 172 | position: absolute; 173 | bottom: 10px; 174 | right: 10px; 175 | z-index: 999998; 176 | } 177 | 178 | #editor { 179 | position: absolute; 180 | top: 0px; 181 | bottom: 0px; 182 | left: 0px; 183 | right: 0px; 184 | } 185 | 186 | #canvas { 187 | width: 100%; 188 | height: 100%; 189 | max-width: 100%; 190 | max-height: 100%; 191 | } 192 | 193 | #console-wrap { 194 | position: absolute; 195 | top: 40px; 196 | bottom: 0px; 197 | left: 0px; 198 | right: 0px; 199 | } 200 | 201 | #console-wrap > button { 202 | position: absolute; 203 | bottom: 10px; 204 | right: 10px; 205 | z-index: 999998; 206 | } 207 | 208 | #console { 209 | position: absolute; 210 | top: 8px; 211 | bottom: 8px; 212 | left: 8px; 213 | right: 8px; 214 | padding: 0px; 215 | margin: 0px; 216 | border: 0px; 217 | overflow: auto; 218 | font-size: 12px; 219 | font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace; 220 | } 221 | 222 | .gutter { 223 | } 224 | 225 | .gutter.gutter-horizontal { 226 | cursor: ew-resize; 227 | } 228 | 229 | .gutter.gutter-vertical { 230 | cursor: ns-resize; 231 | } 232 | 233 | .split.split-horizontal, .gutter.gutter-horizontal { 234 | height: 100%; 235 | float: left; 236 | } 237 | 238 | .canvas-app-container { 239 | background: #000; 240 | position: relative; 241 | width: 100%; 242 | height: 100%; 243 | } 244 | 245 | .canvas-app-container:-webkit-full-screen { 246 | width: auto; 247 | height: auto; 248 | } 249 | 250 | .canvas-app-canvas { 251 | width: 100%; 252 | height: 100%; 253 | } 254 | 255 | #defold-progress-label { 256 | width: 200px; 257 | } 258 | 259 | #defold-progress { 260 | width: 200px; 261 | height: 2px; 262 | /*background: #0f0;*/ 263 | margin-top: 10px; 264 | display: inline-block; 265 | } 266 | 267 | #defold-progress-bar { 268 | height: 100%; 269 | background-color: #fff; 270 | } 271 | 272 | body.embedded #toolbar { 273 | display: none; 274 | height: 0px; 275 | } 276 | 277 | body.embedded #layout { 278 | position: static; 279 | top: auto; 280 | right: auto; 281 | bottom: auto; 282 | left: auto; 283 | height: 0px; 284 | } 285 | 286 | #view_source, #reload_page { 287 | display: none; 288 | } 289 | 290 | body.embedded #view_source, body.embedded #reload_page { 291 | display: inline-block; 292 | position: fixed; 293 | } 294 | 295 | body.embedded #view_source { 296 | right: 20px; 297 | bottom: 20px; 298 | } 299 | 300 | body.embedded #reload_page { 301 | right: 20px; 302 | top: 20px; 303 | } 304 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/FileSaver.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../src/FileSaver.js"],"names":[],"mappings":"uLAkBA,QAAS,CAAA,CAAT,CAAc,CAAd,CAAoB,CAApB,CAA0B,OACJ,WAAhB,QAAO,CAAA,CADa,CACS,CAAI,CAAG,CAAE,OAAO,GAAT,CADhB,CAEC,QAAhB,QAAO,CAAA,CAFQ,GAGtB,OAAO,CAAC,IAAR,CAAa,oDAAb,CAHsB,CAItB,CAAI,CAAG,CAAE,OAAO,CAAE,CAAC,CAAZ,CAJe,EASpB,CAAI,CAAC,OAAL,EAAgB,6EAA6E,IAA7E,CAAkF,CAAI,CAAC,IAAvF,CATI,CAUf,GAAI,CAAA,IAAJ,CAAS,UAA8B,CAA9B,CAAT,CAA8C,CAAE,IAAI,CAAE,CAAI,CAAC,IAAb,CAA9C,CAVe,CAYjB,CACR,CAED,QAAS,CAAA,CAAT,CAAmB,CAAnB,CAAwB,CAAxB,CAA8B,CAA9B,CAAoC,CAClC,GAAI,CAAA,CAAG,CAAG,GAAI,CAAA,cAAd,CACA,CAAG,CAAC,IAAJ,CAAS,KAAT,CAAgB,CAAhB,CAFkC,CAGlC,CAAG,CAAC,YAAJ,CAAmB,MAHe,CAIlC,CAAG,CAAC,MAAJ,CAAa,UAAY,CACvB,CAAM,CAAC,CAAG,CAAC,QAAL,CAAe,CAAf,CAAqB,CAArB,CACP,CANiC,CAOlC,CAAG,CAAC,OAAJ,CAAc,UAAY,CACxB,OAAO,CAAC,KAAR,CAAc,yBAAd,CACD,CATiC,CAUlC,CAAG,CAAC,IAAJ,EACD,CAED,QAAS,CAAA,CAAT,CAAsB,CAAtB,CAA2B,CACzB,GAAI,CAAA,CAAG,CAAG,GAAI,CAAA,cAAd,CAEA,CAAG,CAAC,IAAJ,CAAS,MAAT,CAAiB,CAAjB,IAHyB,CAIzB,GAAI,CACF,CAAG,CAAC,IAAJ,EACD,CAAC,MAAO,CAAP,CAAU,CAAE,CACd,MAAqB,IAAd,EAAA,CAAG,CAAC,MAAJ,EAAmC,GAAd,EAAA,CAAG,CAAC,MACjC,CAGD,QAAS,CAAA,CAAT,CAAgB,CAAhB,CAAsB,CACpB,GAAI,CACF,CAAI,CAAC,aAAL,CAAmB,GAAI,CAAA,UAAJ,CAAe,OAAf,CAAnB,CACD,CAAC,MAAO,CAAP,CAAU,CACV,GAAI,CAAA,CAAG,CAAG,QAAQ,CAAC,WAAT,CAAqB,aAArB,CAAV,CACA,CAAG,CAAC,cAAJ,CAAmB,OAAnB,OAAwC,MAAxC,CAAgD,CAAhD,CAAmD,CAAnD,CAAsD,CAAtD,CAAyD,EAAzD,CACsB,EADtB,aACsD,CADtD,CACyD,IADzD,CAFU,CAIV,CAAI,CAAC,aAAL,CAAmB,CAAnB,CACD,CACF,C,GAtDG,CAAA,CAAO,CAAqB,QAAlB,QAAO,CAAA,MAAP,EAA8B,MAAM,CAAC,MAAP,GAAkB,MAAhD,CACV,MADU,CACe,QAAhB,QAAO,CAAA,IAAP,EAA4B,IAAI,CAAC,IAAL,GAAc,IAA1C,CACT,IADS,CACgB,QAAlB,QAAO,CAAA,MAAP,EAA8B,MAAM,CAAC,MAAP,GAAkB,MAAhD,CACP,MADO,O,CAuDP,CAAQ,CAAG,cAAc,IAAd,CAAmB,SAAS,CAAC,SAA7B,C,CAEX,CAAM,CAAG,CAAO,CAAC,MAAR,GAEQ,QAAlB,QAAO,CAAA,MAAP,EAA8B,MAAM,GAAK,CAA1C,CACI,UAAmB,CAAc,CADrC,CAIG,YAAc,CAAA,iBAAiB,CAAC,SAAhC,EAA6C,CAAC,CAA/C,CACA,SAAiB,CAAjB,CAAuB,CAAvB,CAA6B,CAA7B,CAAmC,IAC/B,CAAA,CAAG,CAAG,CAAO,CAAC,GAAR,EAAe,CAAO,CAAC,SADE,CAE/B,CAAC,CAAG,QAAQ,CAAC,aAAT,CAAuB,GAAvB,CAF2B,CAGnC,CAAI,CAAG,CAAI,EAAI,CAAI,CAAC,IAAb,EAAqB,UAHO,CAKnC,CAAC,CAAC,QAAF,CAAa,CALsB,CAMnC,CAAC,CAAC,GAAF,CAAQ,UAN2B,CAWf,QAAhB,QAAO,CAAA,CAXwB,EAajC,CAAC,CAAC,IAAF,CAAS,CAbwB,CAc7B,CAAC,CAAC,MAAF,GAAa,QAAQ,CAAC,MAdO,CAmB/B,CAAK,CAAC,CAAD,CAnB0B,CAe/B,CAAW,CAAC,CAAC,CAAC,IAAH,CAAX,CACI,CAAQ,CAAC,CAAD,CAAO,CAAP,CAAa,CAAb,CADZ,CAEI,CAAK,CAAC,CAAD,CAAI,CAAC,CAAC,MAAF,CAAW,QAAf,CAjBsB,GAuBjC,CAAC,CAAC,IAAF,CAAS,CAAG,CAAC,eAAJ,CAAoB,CAApB,CAvBwB,CAwBjC,UAAU,CAAC,UAAY,CAAE,CAAG,CAAC,eAAJ,CAAoB,CAAC,CAAC,IAAtB,CAA6B,CAA5C,CAA8C,GAA9C,CAxBuB,CAyBjC,UAAU,CAAC,UAAY,CAAE,CAAK,CAAC,CAAD,CAAK,CAAzB,CAA2B,CAA3B,CAzBuB,CA2BpC,CA5BC,CA+BA,oBAAsB,CAAA,SAAtB,CACA,SAAiB,CAAjB,CAAuB,CAAvB,CAA6B,CAA7B,CAAmC,CAGnC,GAFA,CAAI,CAAG,CAAI,EAAI,CAAI,CAAC,IAAb,EAAqB,UAE5B,CAAoB,QAAhB,QAAO,CAAA,CAAX,CAUE,SAAS,CAAC,gBAAV,CAA2B,CAAG,CAAC,CAAD,CAAO,CAAP,CAA9B,CAA4C,CAA5C,CAVF,KACE,IAAI,CAAW,CAAC,CAAD,CAAf,CACE,CAAQ,CAAC,CAAD,CAAO,CAAP,CAAa,CAAb,CADV,KAEO,CACL,GAAI,CAAA,CAAC,CAAG,QAAQ,CAAC,aAAT,CAAuB,GAAvB,CAAR,CACA,CAAC,CAAC,IAAF,CAAS,CAFJ,CAGL,CAAC,CAAC,MAAF,CAAW,QAHN,CAIL,UAAU,CAAC,UAAY,CAAE,CAAK,CAAC,CAAD,CAAK,CAAzB,CACX,CAIJ,CAhBC,CAmBA,SAAiB,CAAjB,CAAuB,CAAvB,CAA6B,CAA7B,CAAmC,CAAnC,CAA0C,CAS1C,GANA,CAAK,CAAG,CAAK,EAAI,IAAI,CAAC,EAAD,CAAK,QAAL,CAMrB,CALI,CAKJ,GAJE,CAAK,CAAC,QAAN,CAAe,KAAf,CACA,CAAK,CAAC,QAAN,CAAe,IAAf,CAAoB,SAApB,CAAgC,gBAGlC,EAAoB,QAAhB,QAAO,CAAA,CAAX,CAA8B,MAAO,CAAA,CAAQ,CAAC,CAAD,CAAO,CAAP,CAAa,CAAb,CAAf,CATY,GAWtC,CAAA,CAAK,CAAiB,0BAAd,GAAA,CAAI,CAAC,IAXyB,CAYtC,CAAQ,CAAG,eAAe,IAAf,CAAoB,CAAO,CAAC,WAA5B,GAA4C,CAAO,CAAC,MAZzB,CAatC,CAAW,CAAG,eAAe,IAAf,CAAoB,SAAS,CAAC,SAA9B,CAbwB,CAe1C,GAAI,CAAC,CAAW,EAAK,CAAK,EAAI,CAAzB,EAAsC,CAAvC,GAA0E,WAAtB,QAAO,CAAA,UAA/D,CAA2F,CAEzF,GAAI,CAAA,CAAM,CAAG,GAAI,CAAA,UAAjB,CACA,CAAM,CAAC,SAAP,CAAmB,UAAY,CAC7B,GAAI,CAAA,CAAG,CAAG,CAAM,CAAC,MAAjB,CACA,CAAG,CAAG,CAAW,CAAG,CAAH,CAAS,CAAG,CAAC,OAAJ,CAAY,cAAZ,CAA4B,uBAA5B,CAFG,CAGzB,CAHyB,CAGlB,CAAK,CAAC,QAAN,CAAe,IAAf,CAAsB,CAHJ,CAIxB,QAAQ,CAAG,CAJa,CAK7B,CAAK,CAAG,IACT,CATwF,CAUzF,CAAM,CAAC,aAAP,CAAqB,CAArB,CACD,CAXD,IAWO,IACD,CAAA,CAAG,CAAG,CAAO,CAAC,GAAR,EAAe,CAAO,CAAC,SAD5B,CAED,CAAG,CAAG,CAAG,CAAC,eAAJ,CAAoB,CAApB,CAFL,CAGD,CAHC,CAGM,CAAK,CAAC,QAAN,CAAiB,CAHvB,CAIA,QAAQ,CAAC,IAAT,CAAgB,CAJhB,CAKL,CAAK,CAAG,IALH,CAML,UAAU,CAAC,UAAY,CAAE,CAAG,CAAC,eAAJ,CAAoB,CAApB,CAA0B,CAAzC,CAA2C,GAA3C,CACX,CACF,CA1FU,C,CA6Fb,CAAO,CAAC,MAAR,CAAiB,CAAM,CAAC,MAAP,CAAgB,C,CAEX,WAAlB,QAAO,CAAA,M,GACT,MAAM,CAAC,OAAP,CAAiB,C","file":"FileSaver.min.js","sourcesContent":["/*\n* FileSaver.js\n* A saveAs() FileSaver implementation.\n*\n* By Eli Grey, http://eligrey.com\n*\n* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)\n* source : http://purl.eligrey.com/github/FileSaver.js\n*/\n\n// The one and only way of getting global scope in all environments\n// https://stackoverflow.com/q/3277182/1008999\nvar _global = typeof window === 'object' && window.window === window\n ? window : typeof self === 'object' && self.self === self\n ? self : typeof global === 'object' && global.global === global\n ? global\n : this\n\nfunction bom (blob, opts) {\n if (typeof opts === 'undefined') opts = { autoBom: false }\n else if (typeof opts !== 'object') {\n console.warn('Deprecated: Expected third argument to be a object')\n opts = { autoBom: !opts }\n }\n\n // prepend BOM for UTF-8 XML and text/* types (including HTML)\n // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF\n if (opts.autoBom && /^\\s*(?:text\\/\\S*|application\\/xml|\\S*\\/\\S*\\+xml)\\s*;.*charset\\s*=\\s*utf-8/i.test(blob.type)) {\n return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type })\n }\n return blob\n}\n\nfunction download (url, name, opts) {\n var xhr = new XMLHttpRequest()\n xhr.open('GET', url)\n xhr.responseType = 'blob'\n xhr.onload = function () {\n saveAs(xhr.response, name, opts)\n }\n xhr.onerror = function () {\n console.error('could not download file')\n }\n xhr.send()\n}\n\nfunction corsEnabled (url) {\n var xhr = new XMLHttpRequest()\n // use sync to avoid popup blocker\n xhr.open('HEAD', url, false)\n try {\n xhr.send()\n } catch (e) {}\n return xhr.status >= 200 && xhr.status <= 299\n}\n\n// `a.click()` doesn't work for all browsers (#465)\nfunction click (node) {\n try {\n node.dispatchEvent(new MouseEvent('click'))\n } catch (e) {\n var evt = document.createEvent('MouseEvents')\n evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80,\n 20, false, false, false, false, 0, null)\n node.dispatchEvent(evt)\n }\n}\n\n// Detect WebKit inside a native macOS app\nvar isWebKit = /AppleWebKit/.test(navigator.userAgent)\n\nvar saveAs = _global.saveAs || (\n // probably in some web worker\n (typeof window !== 'object' || window !== _global)\n ? function saveAs () { /* noop */ }\n\n // Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app\n : ('download' in HTMLAnchorElement.prototype && !isWebKit)\n ? function saveAs (blob, name, opts) {\n var URL = _global.URL || _global.webkitURL\n var a = document.createElement('a')\n name = name || blob.name || 'download'\n\n a.download = name\n a.rel = 'noopener' // tabnabbing\n\n // TODO: detect chrome extensions & packaged apps\n // a.target = '_blank'\n\n if (typeof blob === 'string') {\n // Support regular links\n a.href = blob\n if (a.origin !== location.origin) {\n corsEnabled(a.href)\n ? download(blob, name, opts)\n : click(a, a.target = '_blank')\n } else {\n click(a)\n }\n } else {\n // Support blobs\n a.href = URL.createObjectURL(blob)\n setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s\n setTimeout(function () { click(a) }, 0)\n }\n }\n\n // Use msSaveOrOpenBlob as a second approach\n : 'msSaveOrOpenBlob' in navigator\n ? function saveAs (blob, name, opts) {\n name = name || blob.name || 'download'\n\n if (typeof blob === 'string') {\n if (corsEnabled(blob)) {\n download(blob, name, opts)\n } else {\n var a = document.createElement('a')\n a.href = blob\n a.target = '_blank'\n setTimeout(function () { click(a) })\n }\n } else {\n navigator.msSaveOrOpenBlob(bom(blob, opts), name)\n }\n }\n\n // Fallback to using FileReader and a popup\n : function saveAs (blob, name, opts, popup) {\n // Open a popup immediately do go around popup blocker\n // Mostly only available on user interaction and the fileReader is async so...\n popup = popup || open('', '_blank')\n if (popup) {\n popup.document.title =\n popup.document.body.innerText = 'downloading...'\n }\n\n if (typeof blob === 'string') return download(blob, name, opts)\n\n var force = blob.type === 'application/octet-stream'\n var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari\n var isChromeIOS = /CriOS\\/[\\d]+/.test(navigator.userAgent)\n\n if ((isChromeIOS || (force && isSafari) || isWebKit) && typeof FileReader !== 'undefined') {\n // Safari doesn't allow downloading of blob URLs\n var reader = new FileReader()\n reader.onloadend = function () {\n var url = reader.result\n url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;')\n if (popup) popup.location.href = url\n else location = url\n popup = null // reverse-tabnabbing #460\n }\n reader.readAsDataURL(blob)\n } else {\n var URL = _global.URL || _global.webkitURL\n var url = URL.createObjectURL(blob)\n if (popup) popup.location = url\n else location.href = url\n popup = null // reverse-tabnabbing #460\n setTimeout(function () { URL.revokeObjectURL(url) }, 4E4) // 40s\n }\n }\n)\n\n_global.saveAs = saveAs.saveAs = saveAs\n\nif (typeof module !== 'undefined') {\n module.exports = saveAs;\n}\n"]} -------------------------------------------------------------------------------- /codepad/codepad.lua: -------------------------------------------------------------------------------- 1 | local escape = require "codepad.utils.escape" 2 | 3 | local codepad = {} 4 | 5 | local is_error = false 6 | local luastrsanitize = function (str) 7 | str=str:gsub("\\","\\\\") 8 | str=str:gsub("&","&") 9 | str=str:gsub("'","'") 10 | str=str:gsub("/","/") 11 | str=str:gsub("<","<") 12 | str=str:gsub(">",">") 13 | str=str:gsub('"','"') 14 | str=str:gsub("\n","
") 15 | return str 16 | end 17 | 18 | local console_lines = {} 19 | local console_max = 80 20 | 21 | codepad.funcs = {} 22 | codepad.scenes = {} 23 | codepad.current_cp = nil 24 | 25 | function codepad.url_to_hex(url) 26 | url = url or msg.url() 27 | return hash_to_hex(url.socket) .. hash_to_hex(url.path) .. hash_to_hex(url.fragment) 28 | end 29 | 30 | function codepad.register_script(id) 31 | local scene = codepad.scenes[codepad.current_cp] 32 | assert(scene) 33 | local original_id = id 34 | if not id or id == hash("") then 35 | id = codepad.url_to_hex() 36 | else 37 | id = hash_to_hex(id) 38 | end 39 | for i,script in ipairs(scene.scripts) do 40 | if script.id == id then 41 | return i 42 | end 43 | end 44 | error("Unknown script! Did you forget to define it? " .. tostring(original_id)) 45 | end 46 | 47 | -- initialise the codepad 48 | -- @param scene List of scenes to chose from 49 | function codepad.init(self, scenes) 50 | sys.set_error_handler(codepad.error_handler) 51 | 52 | -- validate scenes and store them (keyed on url) 53 | for i, scene in ipairs(scenes) do 54 | assert(scene.url, ("Scene #%d doesn't define a proxy url"):format(i)) 55 | assert(scene.scripts, ("The scene %s doesn't define any scripts"):format(scene.url)) 56 | scene.id = scene.url 57 | codepad.scenes[scene.url] = scene 58 | for i,script in pairs(scene.scripts) do 59 | assert(script.name, ("Script #%d doesn't have a name"):format(i)) 60 | assert(script.url or script.id, ("Script %s doesn't define a url or id"):format(script.name)) 61 | -- make a copy to ensure that if two scenes refers to the same script instance they 62 | -- get correct ids 63 | script = { 64 | code = script.code, 65 | name = script.name, 66 | url = script.url, 67 | id = script.id, 68 | } 69 | scene.scripts[i] = script 70 | if script.url then 71 | script.id = codepad.url_to_hex(msg.url(script.url)) 72 | else 73 | script.id = hash_to_hex(hash(script.id)) 74 | end 75 | end 76 | end 77 | 78 | if not html5 then 79 | print("You must run this from a browser") 80 | return 81 | end 82 | 83 | -- send scenes and configs to html 84 | local project_info = { 85 | title = sys.get_config_string("project.title"), 86 | version = sys.get_config_string("project.version"), 87 | } 88 | local engine_info = sys.get_engine_info() 89 | local scenes_json = escape.escape(json.encode(scenes)) 90 | local project_json = escape.escape(json.encode(project_info)) 91 | local engine_json = escape.escape(json.encode(engine_info)) 92 | html5.run(("codepad_ready('%s', '%s', '%s')"):format(scenes_json, project_json, engine_json)) 93 | 94 | end 95 | 96 | 97 | -- update codepad with any changes from the html5 page 98 | function codepad.update(self, dt) 99 | if codepad.call_reload then 100 | codepad.call_reload = false 101 | end 102 | -- poll if we should reload 103 | if html5 then 104 | codepad.check_change_scene() 105 | codepad.check_should_reload() 106 | codepad.check_should_restart() 107 | codepad.check_should_clear_console() 108 | end 109 | -- draw grid if enabled for the current scene 110 | if codepad.scenes[codepad.current_cp].grid then 111 | local grid_line_count = 100 112 | local grid_step = 50 113 | local color = vmath.vector4(0.3) 114 | local origo = vmath.vector4(0.5) 115 | for i=-grid_line_count,grid_line_count do 116 | -- x 117 | local cur_color = color 118 | if i == 0 then 119 | cur_color = origo 120 | end 121 | msg.post("@render:", "draw_line", { start_point = vmath.vector3(i*grid_step, -grid_line_count*grid_step, 0), 122 | end_point = vmath.vector3(i*grid_step, grid_line_count*grid_step, 0), 123 | color = cur_color 124 | }) 125 | msg.post("@render:", "draw_line", { start_point = vmath.vector3(-grid_line_count*grid_step, i*grid_step, 0), 126 | end_point = vmath.vector3(grid_line_count*grid_step, i*grid_step, 0), 127 | color = cur_color 128 | }) 129 | end 130 | end 131 | end 132 | 133 | 134 | function codepad.on_message(self, message_id, message, sender) 135 | if message_id == hash("proxy_loaded") then 136 | msg.post(sender, "enable") 137 | end 138 | end 139 | 140 | function codepad.change_scene(scene_id) 141 | assert(scene_id, 'You must specify scene_id when you change scene manually') 142 | html5.run('codepad_change_scene("' .. scene_id .. '")') 143 | end 144 | 145 | function codepad.check_change_scene() 146 | local should_change_scene = html5.run('codepad_should_change_scene') 147 | if should_change_scene == "true" then 148 | local scene = html5.run('codepad_get_scene()') 149 | codepad.restart(scene) 150 | html5.run('codepad_should_change_scene = false;') 151 | end 152 | end 153 | 154 | function codepad.check_should_reload() 155 | local should_reload = html5.run('codepad_should_reload') 156 | if should_reload == "true" then 157 | codepad.reload() 158 | html5.run('codepad_should_reload = false;') 159 | end 160 | end 161 | 162 | function codepad.check_should_restart() 163 | local should_restart = html5.run('codepad_should_restart') 164 | if should_restart == "true" then 165 | codepad.restart(codepad.current_cp) 166 | html5.run('codepad_should_restart = false;') 167 | end 168 | end 169 | 170 | function codepad.check_should_clear_console() 171 | local should_clear = html5.run('codepad_should_clear_console') 172 | if should_clear == "true" then 173 | console_lines = {} 174 | html5.run('codepad_should_clear_console = false;') 175 | html5.run('codepad_update_console("")') 176 | end 177 | end 178 | 179 | function codepad.reload() 180 | print("Reloading...") 181 | codepad.get_external_code() 182 | codepad.call_reload = true 183 | end 184 | 185 | function codepad.restart(scene) 186 | print("Restarting...") 187 | -- unload current pad and async load the cp again 188 | if codepad.current_cp then 189 | msg.post(codepad.current_cp, "unload") 190 | end 191 | codepad.current_cp = scene 192 | codepad.get_external_code() 193 | msg.post(codepad.current_cp, "async_load") 194 | end 195 | 196 | function codepad.get_external_code() 197 | if not html5 then 198 | print("Ignoring request to get external code. Not running in a browser") 199 | return 200 | end 201 | 202 | -- clear old code 203 | codepad.funcs = {} 204 | 205 | local code_snippet_count = #codepad.scenes[codepad.current_cp].scripts 206 | 207 | for i=1,code_snippet_count do 208 | 209 | codepad.funcs[i] = { 210 | init = nil, 211 | final = nil, 212 | update = nil, 213 | on_message = nil, 214 | on_input = nil, 215 | on_reload = nil 216 | } 217 | 218 | local new_code = html5.run("codepad_get_code(" .. i .. ")") 219 | new_code, err = loadstring(new_code, "=" .. tostring(codepad.scenes[codepad.current_cp].scripts[i].name)) 220 | 221 | if not new_code then 222 | error("Error while loading new code: " .. tostring(err)) 223 | else 224 | 225 | local temp_G = {} 226 | for k,v in pairs(_G) do 227 | temp_G[k] = v 228 | end 229 | setfenv(new_code, temp_G) 230 | new_code() 231 | codepad.funcs[i].init = temp_G.init 232 | temp_G.init = nil 233 | codepad.funcs[i].final = temp_G.final 234 | temp_G.final = nil 235 | codepad.funcs[i].update = temp_G.update 236 | temp_G.update = nil 237 | codepad.funcs[i].on_message = temp_G.on_message 238 | temp_G.on_message = nil 239 | codepad.funcs[i].on_input = temp_G.on_input 240 | temp_G.on_input = nil 241 | codepad.funcs[i].on_reload = temp_G.on_reload 242 | temp_G.on_reload = nil 243 | 244 | -- apply env to global env 245 | for k,v in pairs(temp_G) do 246 | _G[k] = v 247 | end 248 | 249 | if codepad.funcs[i].init then setfenv(codepad.funcs[i].init, _G) end 250 | if codepad.funcs[i].final then setfenv(codepad.funcs[i].final, _G) end 251 | if codepad.funcs[i].update then setfenv(codepad.funcs[i].update, _G) end 252 | if codepad.funcs[i].on_message then setfenv(codepad.funcs[i].on_message, _G) end 253 | if codepad.funcs[i].on_input then setfenv(codepad.funcs[i].on_input, _G) end 254 | if codepad.funcs[i].on_reload then setfenv(codepad.funcs[i].on_reload, _G) end 255 | end 256 | end 257 | end 258 | 259 | -- hack print 260 | local ___print = print 261 | print = function(...) 262 | ___print(...) 263 | 264 | if html5 then 265 | local input = {...} 266 | local line = "" 267 | --for _,v in pairs(input) do 268 | for i=1,#input do 269 | local v = input[i] 270 | local d = tostring(v) 271 | if v == nil then 272 | d = "nil" 273 | end 274 | line = line .. d .. " " 275 | end 276 | if #input == 0 then 277 | line = "nil" 278 | end 279 | 280 | table.insert(console_lines, luastrsanitize(line)) 281 | 282 | if is_error then 283 | console_lines[#console_lines] = '' .. console_lines[#console_lines] .. "" 284 | end 285 | 286 | if #console_lines > console_max then 287 | local rem_lines = #console_lines - console_max 288 | for i=1,rem_lines do 289 | table.remove(console_lines, 1) 290 | end 291 | end 292 | 293 | local out = "" 294 | for _,v in ipairs(console_lines) do 295 | out = out .. v .. "
" 296 | end 297 | 298 | if html5 then 299 | html5.run('codepad_update_console("' .. out .. '")') 300 | end 301 | end 302 | end 303 | 304 | function codepad.error_handler(source, message, traceback) 305 | is_error = true 306 | print(message) 307 | print(traceback) 308 | is_error = false 309 | end 310 | 311 | return codepad 312 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/keymaster.js: -------------------------------------------------------------------------------- 1 | 2 | // keymaster.js 3 | // (c) 2011-2013 Thomas Fuchs 4 | // keymaster.js may be freely distributed under the MIT license. 5 | 6 | ;(function(global){ 7 | var k, 8 | _handlers = {}, 9 | _mods = { 16: false, 18: false, 17: false, 91: false }, 10 | _scope = 'all', 11 | // modifier keys 12 | _MODIFIERS = { 13 | '⇧': 16, shift: 16, 14 | '⌥': 18, alt: 18, option: 18, 15 | '⌃': 17, ctrl: 17, control: 17, 16 | '⌘': 91, command: 91 17 | }, 18 | // special keys 19 | _MAP = { 20 | backspace: 8, tab: 9, clear: 12, 21 | enter: 13, 'return': 13, 22 | esc: 27, escape: 27, space: 32, 23 | left: 37, up: 38, 24 | right: 39, down: 40, 25 | del: 46, 'delete': 46, 26 | home: 36, end: 35, 27 | pageup: 33, pagedown: 34, 28 | ',': 188, '.': 190, '/': 191, 29 | '`': 192, '-': 189, '=': 187, 30 | ';': 186, '\'': 222, 31 | '[': 219, ']': 221, '\\': 220 32 | }, 33 | code = function(x){ 34 | return _MAP[x] || x.toUpperCase().charCodeAt(0); 35 | }, 36 | _downKeys = []; 37 | 38 | for(k=1;k<20;k++) _MAP['f'+k] = 111+k; 39 | 40 | // IE doesn't support Array#indexOf, so have a simple replacement 41 | function index(array, item){ 42 | var i = array.length; 43 | while(i--) if(array[i]===item) return i; 44 | return -1; 45 | } 46 | 47 | // for comparing mods before unassignment 48 | function compareArray(a1, a2) { 49 | if (a1.length != a2.length) return false; 50 | for (var i = 0; i < a1.length; i++) { 51 | if (a1[i] !== a2[i]) return false; 52 | } 53 | return true; 54 | } 55 | 56 | var modifierMap = { 57 | 16:'shiftKey', 58 | 18:'altKey', 59 | 17:'ctrlKey', 60 | 91:'metaKey' 61 | }; 62 | function updateModifierKey(event) { 63 | for(k in _mods) _mods[k] = event[modifierMap[k]]; 64 | }; 65 | 66 | // handle keydown event 67 | function dispatch(event) { 68 | var key, handler, k, i, modifiersMatch, scope; 69 | key = event.keyCode; 70 | 71 | if (index(_downKeys, key) == -1) { 72 | _downKeys.push(key); 73 | } 74 | 75 | // if a modifier key, set the key. property to true and return 76 | if(key == 93 || key == 224) key = 91; // right command on webkit, command on Gecko 77 | if(key in _mods) { 78 | _mods[key] = true; 79 | // 'assignKey' from inside this closure is exported to window.key 80 | for(k in _MODIFIERS) if(_MODIFIERS[k] == key) assignKey[k] = true; 81 | return; 82 | } 83 | updateModifierKey(event); 84 | 85 | // see if we need to ignore the keypress (filter() can can be overridden) 86 | // by default ignore key presses if a select, textarea, or input is focused 87 | if(!assignKey.filter.call(this, event)) return; 88 | 89 | // abort if no potentially matching shortcuts found 90 | if (!(key in _handlers)) return; 91 | 92 | scope = getScope(); 93 | 94 | // for each potential shortcut 95 | for (i = 0; i < _handlers[key].length; i++) { 96 | handler = _handlers[key][i]; 97 | 98 | // see if it's in the current scope 99 | if(handler.scope == scope || handler.scope == 'all'){ 100 | // check if modifiers match if any 101 | modifiersMatch = handler.mods.length > 0; 102 | for(k in _mods) 103 | if((!_mods[k] && index(handler.mods, +k) > -1) || 104 | (_mods[k] && index(handler.mods, +k) == -1)) modifiersMatch = false; 105 | // call the handler and stop the event if neccessary 106 | if((handler.mods.length == 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91]) || modifiersMatch){ 107 | if(handler.method(event, handler)===false){ 108 | if(event.preventDefault) event.preventDefault(); 109 | else event.returnValue = false; 110 | if(event.stopPropagation) event.stopPropagation(); 111 | if(event.cancelBubble) event.cancelBubble = true; 112 | } 113 | } 114 | } 115 | } 116 | }; 117 | 118 | // unset modifier keys on keyup 119 | function clearModifier(event){ 120 | var key = event.keyCode, k, 121 | i = index(_downKeys, key); 122 | 123 | // remove key from _downKeys 124 | if (i >= 0) { 125 | _downKeys.splice(i, 1); 126 | } 127 | 128 | if(key == 93 || key == 224) key = 91; 129 | if(key in _mods) { 130 | _mods[key] = false; 131 | for(k in _MODIFIERS) if(_MODIFIERS[k] == key) assignKey[k] = false; 132 | } 133 | }; 134 | 135 | function resetModifiers() { 136 | for(k in _mods) _mods[k] = false; 137 | for(k in _MODIFIERS) assignKey[k] = false; 138 | }; 139 | 140 | // parse and assign shortcut 141 | function assignKey(key, scope, method){ 142 | var keys, mods; 143 | keys = getKeys(key); 144 | if (method === undefined) { 145 | method = scope; 146 | scope = 'all'; 147 | } 148 | 149 | // for each shortcut 150 | for (var i = 0; i < keys.length; i++) { 151 | // set modifier keys if any 152 | mods = []; 153 | key = keys[i].split('+'); 154 | if (key.length > 1){ 155 | mods = getMods(key); 156 | key = [key[key.length-1]]; 157 | } 158 | // convert to keycode and... 159 | key = key[0] 160 | key = code(key); 161 | // ...store handler 162 | if (!(key in _handlers)) _handlers[key] = []; 163 | _handlers[key].push({ shortcut: keys[i], scope: scope, method: method, key: keys[i], mods: mods }); 164 | } 165 | }; 166 | 167 | // unbind all handlers for given key in current scope 168 | function unbindKey(key, scope) { 169 | var multipleKeys, keys, 170 | mods = [], 171 | i, j, obj; 172 | 173 | multipleKeys = getKeys(key); 174 | 175 | for (j = 0; j < multipleKeys.length; j++) { 176 | keys = multipleKeys[j].split('+'); 177 | 178 | if (keys.length > 1) { 179 | mods = getMods(keys); 180 | } 181 | 182 | key = keys[keys.length - 1]; 183 | key = code(key); 184 | 185 | if (scope === undefined) { 186 | scope = getScope(); 187 | } 188 | if (!_handlers[key]) { 189 | return; 190 | } 191 | for (i = 0; i < _handlers[key].length; i++) { 192 | obj = _handlers[key][i]; 193 | // only clear handlers if correct scope and mods match 194 | if (obj.scope === scope && compareArray(obj.mods, mods)) { 195 | _handlers[key][i] = {}; 196 | } 197 | } 198 | } 199 | }; 200 | 201 | // Returns true if the key with code 'keyCode' is currently down 202 | // Converts strings into key codes. 203 | function isPressed(keyCode) { 204 | if (typeof(keyCode)=='string') { 205 | keyCode = code(keyCode); 206 | } 207 | return index(_downKeys, keyCode) != -1; 208 | } 209 | 210 | function getPressedKeyCodes() { 211 | return _downKeys.slice(0); 212 | } 213 | 214 | function filter(event){ 215 | var tagName = (event.target || event.srcElement).tagName; 216 | // ignore keypressed in any elements that support keyboard data input 217 | return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA'); 218 | } 219 | 220 | // initialize key. to false 221 | for(k in _MODIFIERS) assignKey[k] = false; 222 | 223 | // set current scope (default 'all') 224 | function setScope(scope){ _scope = scope || 'all' }; 225 | function getScope(){ return _scope || 'all' }; 226 | 227 | // delete all handlers for a given scope 228 | function deleteScope(scope){ 229 | var key, handlers, i; 230 | 231 | for (key in _handlers) { 232 | handlers = _handlers[key]; 233 | for (i = 0; i < handlers.length; ) { 234 | if (handlers[i].scope === scope) handlers.splice(i, 1); 235 | else i++; 236 | } 237 | } 238 | }; 239 | 240 | // abstract key logic for assign and unassign 241 | function getKeys(key) { 242 | var keys; 243 | key = key.replace(/\s/g, ''); 244 | keys = key.split(','); 245 | if ((keys[keys.length - 1]) == '') { 246 | keys[keys.length - 2] += ','; 247 | } 248 | return keys; 249 | } 250 | 251 | // abstract mods logic for assign and unassign 252 | function getMods(key) { 253 | var mods = key.slice(0, key.length - 1); 254 | for (var mi = 0; mi < mods.length; mi++) 255 | mods[mi] = _MODIFIERS[mods[mi]]; 256 | return mods; 257 | } 258 | 259 | // cross-browser events 260 | function addEvent(object, event, method) { 261 | if (object.addEventListener) 262 | object.addEventListener(event, method, false); 263 | else if(object.attachEvent) 264 | object.attachEvent('on'+event, function(){ method(window.event) }); 265 | }; 266 | 267 | // set the handlers globally on document 268 | addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 269 | addEvent(document, 'keyup', clearModifier); 270 | 271 | // reset modifiers to false whenever the window is (re)focused. 272 | addEvent(window, 'focus', resetModifiers); 273 | 274 | // store previously defined key 275 | var previousKey = global.key; 276 | 277 | // restore previously defined key and return reference to our key object 278 | function noConflict() { 279 | var k = global.key; 280 | global.key = previousKey; 281 | return k; 282 | } 283 | 284 | // set window.key and window.key.set/get/deleteScope, and the default filter 285 | global.key = assignKey; 286 | global.key.setScope = setScope; 287 | global.key.getScope = getScope; 288 | global.key.deleteScope = deleteScope; 289 | global.key.filter = filter; 290 | global.key.isPressed = isPressed; 291 | global.key.getPressedKeyCodes = getPressedKeyCodes; 292 | global.key.noConflict = noConflict; 293 | global.key.unbind = unbindKey; 294 | 295 | if(typeof module !== 'undefined') module.exports = assignKey; 296 | 297 | })(this); 298 | 299 | /* 300 | key('ctrl+r, ⌘+r', function(){ codepad_reload(); return false }); 301 | key('ctrl+shift+r, ⌘+shift+r', function(){ codepad_restart(); return false }); 302 | editor.commands.addCommand({ 303 | name: 'reloadCommand', 304 | bindKey: {win: 'Ctrl-R', mac: 'Ctrl-R'}, 305 | exec: function() { 306 | codepad_reload(); 307 | return false 308 | }, 309 | passEvent: false, 310 | readOnly: false // false if this command should not apply in readOnly mode 311 | }); 312 | editor.commands.addCommand({ 313 | name: 'restartCommand', 314 | bindKey: {win: 'Ctrl-Shift-R', mac: 'Ctrl-Shift-R'}, 315 | exec: function() { 316 | codepad_restart(); 317 | return false 318 | }, 319 | passEvent: false, 320 | readOnly: false // false if this command should not apply in readOnly mode 321 | }); 322 | */ 323 | -------------------------------------------------------------------------------- /input/game.input_binding: -------------------------------------------------------------------------------- 1 | key_trigger { 2 | input: KEY_SPACE 3 | action: "key_space" 4 | } 5 | key_trigger { 6 | input: KEY_EXCLAIM 7 | action: "key_exclamationmark" 8 | } 9 | key_trigger { 10 | input: KEY_QUOTEDBL 11 | action: "key_doublequote" 12 | } 13 | key_trigger { 14 | input: KEY_HASH 15 | action: "key_hash" 16 | } 17 | key_trigger { 18 | input: KEY_DOLLAR 19 | action: "key_dollarsign" 20 | } 21 | key_trigger { 22 | input: KEY_AMPERSAND 23 | action: "key_ampersand" 24 | } 25 | key_trigger { 26 | input: KEY_QUOTE 27 | action: "key_singlequote" 28 | } 29 | key_trigger { 30 | input: KEY_LPAREN 31 | action: "key_lparen" 32 | } 33 | key_trigger { 34 | input: KEY_RPAREN 35 | action: "key_rparen" 36 | } 37 | key_trigger { 38 | input: KEY_ASTERISK 39 | action: "key_asterisk" 40 | } 41 | key_trigger { 42 | input: KEY_PLUS 43 | action: "key_plus" 44 | } 45 | key_trigger { 46 | input: KEY_COMMA 47 | action: "key_comma" 48 | } 49 | key_trigger { 50 | input: KEY_MINUS 51 | action: "key_minus" 52 | } 53 | key_trigger { 54 | input: KEY_PERIOD 55 | action: "key_period" 56 | } 57 | key_trigger { 58 | input: KEY_SLASH 59 | action: "key_slash" 60 | } 61 | key_trigger { 62 | input: KEY_0 63 | action: "key_0" 64 | } 65 | key_trigger { 66 | input: KEY_1 67 | action: "key_1" 68 | } 69 | key_trigger { 70 | input: KEY_2 71 | action: "key_2" 72 | } 73 | key_trigger { 74 | input: KEY_3 75 | action: "key_3" 76 | } 77 | key_trigger { 78 | input: KEY_4 79 | action: "key_4" 80 | } 81 | key_trigger { 82 | input: KEY_5 83 | action: "key_5" 84 | } 85 | key_trigger { 86 | input: KEY_6 87 | action: "key_6" 88 | } 89 | key_trigger { 90 | input: KEY_7 91 | action: "key_7" 92 | } 93 | key_trigger { 94 | input: KEY_8 95 | action: "key_8" 96 | } 97 | key_trigger { 98 | input: KEY_9 99 | action: "key_9" 100 | } 101 | key_trigger { 102 | input: KEY_COLON 103 | action: "key_colon" 104 | } 105 | key_trigger { 106 | input: KEY_SEMICOLON 107 | action: "key_semicolon" 108 | } 109 | key_trigger { 110 | input: KEY_LESS 111 | action: "key_lessthan" 112 | } 113 | key_trigger { 114 | input: KEY_EQUALS 115 | action: "key_equals" 116 | } 117 | key_trigger { 118 | input: KEY_GREATER 119 | action: "key_greaterthan" 120 | } 121 | key_trigger { 122 | input: KEY_QUESTION 123 | action: "key_questionmark" 124 | } 125 | key_trigger { 126 | input: KEY_AT 127 | action: "key_at" 128 | } 129 | key_trigger { 130 | input: KEY_A 131 | action: "key_a" 132 | } 133 | key_trigger { 134 | input: KEY_B 135 | action: "key_b" 136 | } 137 | key_trigger { 138 | input: KEY_C 139 | action: "key_c" 140 | } 141 | key_trigger { 142 | input: KEY_D 143 | action: "key_d" 144 | } 145 | key_trigger { 146 | input: KEY_E 147 | action: "key_e" 148 | } 149 | key_trigger { 150 | input: KEY_F 151 | action: "key_f" 152 | } 153 | key_trigger { 154 | input: KEY_G 155 | action: "key_g" 156 | } 157 | key_trigger { 158 | input: KEY_H 159 | action: "key_h" 160 | } 161 | key_trigger { 162 | input: KEY_I 163 | action: "key_i" 164 | } 165 | key_trigger { 166 | input: KEY_J 167 | action: "key_j" 168 | } 169 | key_trigger { 170 | input: KEY_K 171 | action: "key_k" 172 | } 173 | key_trigger { 174 | input: KEY_L 175 | action: "key_l" 176 | } 177 | key_trigger { 178 | input: KEY_M 179 | action: "key_m" 180 | } 181 | key_trigger { 182 | input: KEY_N 183 | action: "key_n" 184 | } 185 | key_trigger { 186 | input: KEY_O 187 | action: "key_o" 188 | } 189 | key_trigger { 190 | input: KEY_P 191 | action: "key_p" 192 | } 193 | key_trigger { 194 | input: KEY_Q 195 | action: "key_q" 196 | } 197 | key_trigger { 198 | input: KEY_R 199 | action: "key_r" 200 | } 201 | key_trigger { 202 | input: KEY_S 203 | action: "key_s" 204 | } 205 | key_trigger { 206 | input: KEY_T 207 | action: "key_t" 208 | } 209 | key_trigger { 210 | input: KEY_U 211 | action: "key_u" 212 | } 213 | key_trigger { 214 | input: KEY_V 215 | action: "key_v" 216 | } 217 | key_trigger { 218 | input: KEY_W 219 | action: "key_w" 220 | } 221 | key_trigger { 222 | input: KEY_X 223 | action: "key_x" 224 | } 225 | key_trigger { 226 | input: KEY_Y 227 | action: "key_y" 228 | } 229 | key_trigger { 230 | input: KEY_Z 231 | action: "key_z" 232 | } 233 | key_trigger { 234 | input: KEY_LBRACKET 235 | action: "key_lbracket" 236 | } 237 | key_trigger { 238 | input: KEY_RBRACKET 239 | action: "key_rbracket" 240 | } 241 | key_trigger { 242 | input: KEY_BACKSLASH 243 | action: "key_backslash" 244 | } 245 | key_trigger { 246 | input: KEY_CARET 247 | action: "key_caret" 248 | } 249 | key_trigger { 250 | input: KEY_UNDERSCORE 251 | action: "key_underscore" 252 | } 253 | key_trigger { 254 | input: KEY_BACKQUOTE 255 | action: "key_grave" 256 | } 257 | key_trigger { 258 | input: KEY_LBRACE 259 | action: "key_lbrace" 260 | } 261 | key_trigger { 262 | input: KEY_RBRACE 263 | action: "key_rbrace" 264 | } 265 | key_trigger { 266 | input: KEY_PIPE 267 | action: "key_pipe" 268 | } 269 | key_trigger { 270 | input: KEY_TILDE 271 | action: "this does not work do not use it (use key_grave + shift) leave this comment here though" 272 | } 273 | key_trigger { 274 | input: KEY_ESC 275 | action: "key_esc" 276 | } 277 | key_trigger { 278 | input: KEY_F1 279 | action: "key_f1" 280 | } 281 | key_trigger { 282 | input: KEY_F2 283 | action: "key_f2" 284 | } 285 | key_trigger { 286 | input: KEY_F3 287 | action: "key_f3" 288 | } 289 | key_trigger { 290 | input: KEY_F4 291 | action: "key_f4" 292 | } 293 | key_trigger { 294 | input: KEY_F5 295 | action: "key_f5" 296 | } 297 | key_trigger { 298 | input: KEY_F6 299 | action: "key_f6" 300 | } 301 | key_trigger { 302 | input: KEY_F7 303 | action: "key_f7" 304 | } 305 | key_trigger { 306 | input: KEY_F8 307 | action: "key_f8" 308 | } 309 | key_trigger { 310 | input: KEY_F9 311 | action: "key_f9" 312 | } 313 | key_trigger { 314 | input: KEY_F10 315 | action: "key_f10" 316 | } 317 | key_trigger { 318 | input: KEY_F11 319 | action: "key_f11" 320 | } 321 | key_trigger { 322 | input: KEY_F12 323 | action: "key_f12" 324 | } 325 | key_trigger { 326 | input: KEY_UP 327 | action: "key_up" 328 | } 329 | key_trigger { 330 | input: KEY_DOWN 331 | action: "key_down" 332 | } 333 | key_trigger { 334 | input: KEY_LEFT 335 | action: "key_left" 336 | } 337 | key_trigger { 338 | input: KEY_RIGHT 339 | action: "key_right" 340 | } 341 | key_trigger { 342 | input: KEY_LSHIFT 343 | action: "key_lshift" 344 | } 345 | key_trigger { 346 | input: KEY_RSHIFT 347 | action: "key_rshift" 348 | } 349 | key_trigger { 350 | input: KEY_LCTRL 351 | action: "key_lctrl" 352 | } 353 | key_trigger { 354 | input: KEY_RCTRL 355 | action: "key_rctrl" 356 | } 357 | key_trigger { 358 | input: KEY_LALT 359 | action: "key_lalt" 360 | } 361 | key_trigger { 362 | input: KEY_RALT 363 | action: "key_ralt" 364 | } 365 | key_trigger { 366 | input: KEY_TAB 367 | action: "key_tab" 368 | } 369 | key_trigger { 370 | input: KEY_ENTER 371 | action: "key_enter" 372 | } 373 | key_trigger { 374 | input: KEY_BACKSPACE 375 | action: "key_backspace" 376 | } 377 | key_trigger { 378 | input: KEY_INSERT 379 | action: "key_insert" 380 | } 381 | key_trigger { 382 | input: KEY_DEL 383 | action: "key_del" 384 | } 385 | key_trigger { 386 | input: KEY_PAGEUP 387 | action: "key_pageup" 388 | } 389 | key_trigger { 390 | input: KEY_PAGEDOWN 391 | action: "key_pagedown" 392 | } 393 | key_trigger { 394 | input: KEY_HOME 395 | action: "key_home" 396 | } 397 | key_trigger { 398 | input: KEY_END 399 | action: "key_end" 400 | } 401 | key_trigger { 402 | input: KEY_KP_0 403 | action: "key_numpad_0" 404 | } 405 | key_trigger { 406 | input: KEY_KP_1 407 | action: "key_numpad_1" 408 | } 409 | key_trigger { 410 | input: KEY_KP_2 411 | action: "key_numpad_2" 412 | } 413 | key_trigger { 414 | input: KEY_KP_3 415 | action: "key_numpad_3" 416 | } 417 | key_trigger { 418 | input: KEY_KP_4 419 | action: "key_numpad_4" 420 | } 421 | key_trigger { 422 | input: KEY_KP_5 423 | action: "key_numpad_5" 424 | } 425 | key_trigger { 426 | input: KEY_KP_6 427 | action: "key_numpad_6" 428 | } 429 | key_trigger { 430 | input: KEY_KP_7 431 | action: "key_numpad_7" 432 | } 433 | key_trigger { 434 | input: KEY_KP_8 435 | action: "key_numpad_8" 436 | } 437 | key_trigger { 438 | input: KEY_KP_9 439 | action: "key_numpad_9" 440 | } 441 | key_trigger { 442 | input: KEY_KP_DIVIDE 443 | action: "key_numpad_divide" 444 | } 445 | key_trigger { 446 | input: KEY_KP_MULTIPLY 447 | action: "key_numpad_multiply" 448 | } 449 | key_trigger { 450 | input: KEY_KP_SUBTRACT 451 | action: "key_numpad_subtract" 452 | } 453 | key_trigger { 454 | input: KEY_KP_ADD 455 | action: "key_numpad_add" 456 | } 457 | key_trigger { 458 | input: KEY_KP_DECIMAL 459 | action: "key_numpad_decimal" 460 | } 461 | key_trigger { 462 | input: KEY_KP_EQUAL 463 | action: "key_numpad_equal" 464 | } 465 | key_trigger { 466 | input: KEY_KP_ENTER 467 | action: "key_numpad_enter" 468 | } 469 | key_trigger { 470 | input: KEY_KP_NUM_LOCK 471 | action: "key_numpad_numlock" 472 | } 473 | key_trigger { 474 | input: KEY_CAPS_LOCK 475 | action: "key_capslock" 476 | } 477 | key_trigger { 478 | input: KEY_SCROLL_LOCK 479 | action: "key_scrolllock" 480 | } 481 | key_trigger { 482 | input: KEY_PAUSE 483 | action: "key_pause" 484 | } 485 | key_trigger { 486 | input: KEY_LSUPER 487 | action: "key_lsuper" 488 | } 489 | key_trigger { 490 | input: KEY_RSUPER 491 | action: "key_rsuper" 492 | } 493 | key_trigger { 494 | input: KEY_MENU 495 | action: "key_menu" 496 | } 497 | key_trigger { 498 | input: KEY_BACK 499 | action: "key_back" 500 | } 501 | mouse_trigger { 502 | input: MOUSE_WHEEL_UP 503 | action: "mouse_wheel_up" 504 | } 505 | mouse_trigger { 506 | input: MOUSE_WHEEL_DOWN 507 | action: "mouse_wheel_down" 508 | } 509 | mouse_trigger { 510 | input: MOUSE_BUTTON_LEFT 511 | action: "mouse_button_left" 512 | } 513 | mouse_trigger { 514 | input: MOUSE_BUTTON_MIDDLE 515 | action: "mouse_button_middle" 516 | } 517 | mouse_trigger { 518 | input: MOUSE_BUTTON_RIGHT 519 | action: "mouse_button_right" 520 | } 521 | mouse_trigger { 522 | input: MOUSE_BUTTON_1 523 | action: "mouse_button_1" 524 | } 525 | mouse_trigger { 526 | input: MOUSE_BUTTON_2 527 | action: "mouse_button_2" 528 | } 529 | mouse_trigger { 530 | input: MOUSE_BUTTON_3 531 | action: "mouse_button_3" 532 | } 533 | mouse_trigger { 534 | input: MOUSE_BUTTON_4 535 | action: "mouse_button_4" 536 | } 537 | mouse_trigger { 538 | input: MOUSE_BUTTON_5 539 | action: "mouse_button_5" 540 | } 541 | mouse_trigger { 542 | input: MOUSE_BUTTON_6 543 | action: "mouse_button_6" 544 | } 545 | mouse_trigger { 546 | input: MOUSE_BUTTON_7 547 | action: "mouse_button_7" 548 | } 549 | mouse_trigger { 550 | input: MOUSE_BUTTON_8 551 | action: "mouse_button_8" 552 | } 553 | mouse_trigger { 554 | input: MOUSE_BUTTON_1 555 | action: "touch" 556 | } 557 | gamepad_trigger { 558 | input: GAMEPAD_LSTICK_LEFT 559 | action: "gamepad_lstick_left" 560 | } 561 | gamepad_trigger { 562 | input: GAMEPAD_LSTICK_RIGHT 563 | action: "gamepad_lstick_right" 564 | } 565 | gamepad_trigger { 566 | input: GAMEPAD_LSTICK_DOWN 567 | action: "gamepad_lstick_down" 568 | } 569 | gamepad_trigger { 570 | input: GAMEPAD_LSTICK_UP 571 | action: "gamepad_lstick_up" 572 | } 573 | gamepad_trigger { 574 | input: GAMEPAD_LSTICK_CLICK 575 | action: "gamepad_lstick_click" 576 | } 577 | gamepad_trigger { 578 | input: GAMEPAD_LTRIGGER 579 | action: "gamepad_ltrigger" 580 | } 581 | gamepad_trigger { 582 | input: GAMEPAD_LSHOULDER 583 | action: "gamepad_lshoulder" 584 | } 585 | gamepad_trigger { 586 | input: GAMEPAD_LPAD_LEFT 587 | action: "gamepad_lpad_left" 588 | } 589 | gamepad_trigger { 590 | input: GAMEPAD_LPAD_RIGHT 591 | action: "gamepad_lpad_right" 592 | } 593 | gamepad_trigger { 594 | input: GAMEPAD_LPAD_DOWN 595 | action: "gamepad_lpad_down" 596 | } 597 | gamepad_trigger { 598 | input: GAMEPAD_LPAD_UP 599 | action: "gamepad_lpad_up" 600 | } 601 | gamepad_trigger { 602 | input: GAMEPAD_RSTICK_LEFT 603 | action: "gamepad_rstick_left" 604 | } 605 | gamepad_trigger { 606 | input: GAMEPAD_RSTICK_RIGHT 607 | action: "gamepad_rstick_right" 608 | } 609 | gamepad_trigger { 610 | input: GAMEPAD_RSTICK_DOWN 611 | action: "gamepad_rstick_down" 612 | } 613 | gamepad_trigger { 614 | input: GAMEPAD_RSTICK_UP 615 | action: "gamepad_rstick_up" 616 | } 617 | gamepad_trigger { 618 | input: GAMEPAD_RSTICK_CLICK 619 | action: "gamepad_rstick_click" 620 | } 621 | gamepad_trigger { 622 | input: GAMEPAD_RTRIGGER 623 | action: "gamepad_rtrigger" 624 | } 625 | gamepad_trigger { 626 | input: GAMEPAD_RSHOULDER 627 | action: "gamepad_rshoulder" 628 | } 629 | gamepad_trigger { 630 | input: GAMEPAD_RPAD_LEFT 631 | action: "gamepad_rpad_left" 632 | } 633 | gamepad_trigger { 634 | input: GAMEPAD_RPAD_RIGHT 635 | action: "gamepad_rpad_right" 636 | } 637 | gamepad_trigger { 638 | input: GAMEPAD_RPAD_DOWN 639 | action: "gamepad_rpad_down" 640 | } 641 | gamepad_trigger { 642 | input: GAMEPAD_RPAD_UP 643 | action: "gamepad_rpad_up" 644 | } 645 | gamepad_trigger { 646 | input: GAMEPAD_START 647 | action: "gamepad_start" 648 | } 649 | gamepad_trigger { 650 | input: GAMEPAD_BACK 651 | action: "gamepad_back" 652 | } 653 | gamepad_trigger { 654 | input: GAMEPAD_GUIDE 655 | action: "gamepad_guide" 656 | } 657 | touch_trigger { 658 | input: TOUCH_MULTI 659 | action: "touch_multi" 660 | } 661 | text_trigger { 662 | input: TEXT 663 | action: "text" 664 | } 665 | text_trigger { 666 | input: MARKED_TEXT 667 | action: "marked_text" 668 | } 669 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/codepad.js: -------------------------------------------------------------------------------- 1 | /*jshint esversion: 6 */ 2 | 3 | var EditSession = undefined; 4 | var editor = undefined; 5 | 6 | // EditSessions per file 7 | var codepad_sessions = []; 8 | 9 | // file sources provided in URL 10 | var codepad_shared_sources = []; 11 | 12 | // all available scenes 13 | var scenes = []; 14 | 15 | var project_info = {}; 16 | var engine_info = {}; 17 | 18 | var default_script = `function init(self) 19 | 20 | end 21 | 22 | function final(self) 23 | 24 | end 25 | 26 | function update(self, dt) 27 | 28 | end 29 | 30 | function on_message(self, message_id, message, sender) 31 | 32 | end 33 | 34 | function on_input(self, action_id, action) 35 | 36 | end 37 | 38 | function on_reload(self) 39 | 40 | end`; 41 | 42 | function dynload(src, callback) { 43 | var script = document.createElement('script'), loaded; 44 | script.setAttribute('src', src); 45 | if (callback) { 46 | script.onreadystatechange = script.onload = function () { 47 | if (!loaded) { 48 | callback(); 49 | } 50 | loaded = true; 51 | }; 52 | } 53 | document.getElementsByTagName('head')[0].appendChild(script); 54 | } 55 | 56 | function dynload_multiple(sources, final_callback) { 57 | var src = sources.pop(); 58 | if (src !== undefined) { 59 | console.log("loading: " + src); 60 | dynload(src, function () { 61 | dynload_multiple(sources, final_callback); 62 | }); 63 | } else { 64 | if (final_callback) { 65 | final_callback(); 66 | } 67 | } 68 | } 69 | 70 | /** 71 | * Load the code editor from CDN and set up editor panes 72 | */ 73 | function codepad_load_editor(callback) { 74 | console.log("loading editor..."); 75 | var js_libs = [ 76 | "https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.7/ace.js", 77 | "https://cdnjs.cloudflare.com/ajax/libs/split.js/1.5.11/split.min.js"]; 78 | 79 | dynload_multiple(js_libs, function () { 80 | console.log("editor loaded"); 81 | 82 | EditSession = require("ace/edit_session").EditSession; 83 | editor = ace.edit("editor"); 84 | editor.setTheme("ace/theme/tomorrow_night_eighties"); 85 | //editor.session.setMode("ace/mode/lua"); 86 | 87 | // Setup panel splitters 88 | Split(['#pane-editors', '#pane-canvas'], { 89 | direction: 'vertical', 90 | onDrag: function () { fix_canvas_size(); } 91 | }); 92 | 93 | Split(['#pane-console', '#pane-editor'], { 94 | sizes: [30, 70] 95 | }); 96 | 97 | if (callback) { 98 | callback(); 99 | } 100 | }); 101 | } 102 | 103 | 104 | /** 105 | * Get the currently selected scene from the scene drop-down 106 | */ 107 | function codepad_get_scene() { 108 | var scenes_elem = document.getElementById("scene"); 109 | return scenes_elem.options[scenes_elem.selectedIndex].value; 110 | } 111 | 112 | function codepad_get_scene_object(scene_id) { 113 | for (var i = 0; i < scenes.length; i++) { 114 | var scene = scenes[i]; 115 | if (scene.id == scene_id) { 116 | return scene 117 | } 118 | } 119 | } 120 | 121 | function codepad_get_scene_name(scene_id) { 122 | return codepad_get_scene_object(scene_id).name; 123 | } 124 | 125 | function codepad_get_scripts(scene_id) { 126 | return codepad_get_scene_object(scene_id).scripts; 127 | } 128 | 129 | /** 130 | * Create the editor session for a scene. This will create the file tabs. 131 | * This is called when changing scene. 132 | */ 133 | function codepad_create_edit_sessions(scene) { 134 | var files_div = document.getElementById("files"); 135 | files_div.innerHTML = ""; 136 | 137 | var script_icon = document.getElementById("icon-script"); 138 | script_icon = script_icon.innerHTML; 139 | 140 | var new_buttons = ""; 141 | for (var i = 0; i < scene.scripts.length; i++) { 142 | var radio_id = "file_" + (i + 1); 143 | var src_data = scene.scripts[i].code; 144 | if (!src_data) { 145 | src_data = default_script; 146 | } 147 | if (codepad_shared_sources[i] !== undefined) { 148 | src_data = codepad_shared_sources[i]; 149 | } 150 | var file_session = new EditSession(src_data); 151 | file_session.setMode("ace/mode/lua"); 152 | codepad_sessions[i] = file_session; 153 | var checked = ""; 154 | if (i == 0) { 155 | checked = " checked"; 156 | editor.setSession(file_session); 157 | } 158 | var new_file_button = ''; 159 | new_buttons = new_buttons + new_file_button; 160 | } 161 | files_div.innerHTML = new_buttons; 162 | } 163 | 164 | function codepad_create_edit_sessions_from_shared_sources(scene) { 165 | for (var i = 0; i < scene.scripts.length; i++) { 166 | codepad_sessions[i] = codepad_shared_sources[i]; 167 | } 168 | } 169 | 170 | /** 171 | * Call this when the codepad should change scene. This usually gets triggered 172 | * by a change in the scene selection drop-down menu. 173 | * The function will do two main things: 174 | * 1. It will set the codepad_should_change_scene flag. This will be read by Defold 175 | * 2. Update the edit session with the code for the scene 176 | */ 177 | function codepad_change_scene() { 178 | codepad_should_change_scene = true; 179 | var scene_id = codepad_get_scene(); 180 | for (var i = 0; i < scenes.length; i++) { 181 | var scene = scenes[i]; 182 | if (scene.id == scene_id) { 183 | codepad_sessions = []; 184 | if (EditSession !== undefined) { 185 | codepad_create_edit_sessions(scene); 186 | } else { 187 | codepad_create_edit_sessions_from_shared_sources(scene); 188 | } 189 | break; 190 | } 191 | } 192 | } 193 | 194 | 195 | // Set selected scene in the html drop down 196 | function codepad_set_selected_scene(scene_id) { 197 | var scenes_elem = document.getElementById("scene"); 198 | var scene_options = scenes_elem.options; 199 | for (var option, i = 0; option = scene_options[i]; i++) { 200 | if (option.value == scene_id) { 201 | scenes_elem.selectedIndex = i; 202 | break; 203 | } 204 | } 205 | } 206 | 207 | /** 208 | * Called by Defold when the codepad is ready for use. This will do two things: 209 | * 1. Check if this codepad was started from a link containing code or from scratch 210 | * 2. Show the initial/default scene 211 | */ 212 | function codepad_ready(scenes_json, project_json, engine_json) { 213 | scenes = JSON.parse(unescape(scenes_json)); 214 | 215 | // create scene dropdown 216 | var scenes_elem = document.getElementById("scene"); 217 | for (var i = 0; i < scenes.length; i++) { 218 | var option = document.createElement("option"); 219 | option.value = scenes[i].id; 220 | option.text = scenes[i].name; 221 | scenes_elem.appendChild(option); 222 | } 223 | 224 | engine_info = JSON.parse(unescape(engine_json)); 225 | project_info = JSON.parse(unescape(project_json)); 226 | 227 | var version_string = "Defold " + engine_info.version + " (" + engine_info.version_sha1 + ")"; 228 | document.getElementById("defold_version").innerHTML = version_string; 229 | 230 | codepad_trigger_url_check(); 231 | codepad_change_scene(); 232 | } 233 | 234 | /** 235 | * Called when the user changed file tab. This will update the editor session with 236 | * new code. 237 | */ 238 | function codepad_change_file() { 239 | var file_tabs = document.getElementsByName('current_file'); 240 | 241 | for (var i = 0, length = file_tabs.length; i < length; i++) { 242 | if (file_tabs[i].checked) { 243 | editor.setSession(codepad_sessions[i]); 244 | break; 245 | } 246 | } 247 | } 248 | 249 | function codepad_clear_console() { 250 | codepad_should_clear_console = true; 251 | } 252 | 253 | function codepad_update_console(text) { 254 | var console_elem = document.getElementById("console"); 255 | if (console_elem) { 256 | console_elem.innerHTML = text; 257 | console_elem.scrollTop = console_elem.scrollHeight; 258 | } 259 | } 260 | 261 | function codepad_reload() { 262 | codepad_should_reload = true; 263 | } 264 | 265 | function codepad_restart() { 266 | codepad_should_restart = true; 267 | } 268 | 269 | function codepad_get_code(i) { 270 | if (codepad_sessions[i - 1]) { 271 | if (EditSession !== undefined) { 272 | return codepad_sessions[i - 1].getDocument().getValue(); 273 | } else { 274 | return codepad_sessions[i - 1]; 275 | } 276 | } 277 | return ""; 278 | } 279 | 280 | function deparam(querystring) { 281 | // remove any preceding url and split 282 | querystring = querystring.substring(querystring.indexOf('?') + 1).split('&'); 283 | var params = {}, pair, d = decodeURIComponent; 284 | // march and parse 285 | for (var i = querystring.length - 1; i >= 0; i--) { 286 | pair = querystring[i].split('='); 287 | params[d(pair[0])] = d(pair[1] || ''); 288 | } 289 | 290 | return params; 291 | }; 292 | 293 | // handle url and shared data 294 | function codepad_trigger_url_check() { 295 | var codepad_params = deparam(window.location.hash); 296 | if (codepad_params.c !== undefined) { 297 | 298 | // Change scene 299 | var scenes_elem = document.getElementById("scene"); 300 | for (var i = 0; i < scenes_elem.options.length; i++) { 301 | if (scenes_elem.options[i].value == codepad_params.c) { 302 | scenes_elem.selectedIndex = i; 303 | break; 304 | } 305 | } 306 | 307 | for (var key in codepad_params) { 308 | if (codepad_params.hasOwnProperty(key)) { 309 | if (key.charAt(0) == 's') { 310 | var src_index = key.substr(1); 311 | src_index = parseInt(src_index); 312 | codepad_shared_sources[src_index - 1] = LZString.decompressFromBase64(codepad_params[key]); 313 | } 314 | } 315 | } 316 | } 317 | } 318 | 319 | /** 320 | * Called when the user has chosen to share the current codepad contents. This 321 | * will update the browser URL to contain the full contents of the codepad for 322 | * easy sharing. 323 | */ 324 | function codepad_share() { 325 | var share_url = "?c=" + codepad_get_scene(); 326 | for (var i = 0; i < codepad_sessions.length; i++) { 327 | var compressed_code = LZString.compressToBase64(codepad_get_code(i + 1)); 328 | compressed_code = "&s" + (i + 1) + "=" + compressed_code; 329 | share_url = share_url + compressed_code; 330 | } 331 | 332 | window.location.hash = share_url; 333 | } 334 | 335 | /** 336 | * Called when the user has chosen to save the current codepad contents. This 337 | * will create a zip and start a download. 338 | */ 339 | function codepad_save() { 340 | var scene_id = codepad_get_scene(); 341 | var scene_name = codepad_get_scene_name(scene_id); 342 | var scripts = codepad_get_scripts(scene_id); 343 | 344 | var zip_filename = scene_name.replace(/[^a-z0-9]/gi, '_').toLowerCase(); 345 | 346 | var zip = new JSZip(); 347 | var dir = zip.folder(zip_filename); 348 | for (var i = 0; i < scripts.length; i++) { 349 | var filename = scripts[i].name; 350 | var code = codepad_get_code(i + 1); 351 | dir.file(filename, code); 352 | } 353 | 354 | zip.generateAsync({ type: "blob" }) 355 | .then(function (content) { 356 | saveAs(content, zip_filename); 357 | }); 358 | } 359 | 360 | // read by Defold runtime 361 | codepad_should_reload = false; 362 | codepad_should_restart = false; 363 | codepad_should_change_scene = true; 364 | codepad_should_clear_console = false; 365 | 366 | 367 | function codepad_is_embedded() { 368 | try { 369 | return window.self !== window.top; 370 | } catch (e) { 371 | return true; 372 | } 373 | } 374 | 375 | function fix_canvas_size(event) { 376 | var canvas = document.getElementById('canvas'); 377 | if (codepad_is_embedded()) { 378 | canvas.width = document.body.offsetWidth; 379 | canvas.height = document.body.offsetHeight; 380 | } else { 381 | canvas.width = canvas.offsetWidth; 382 | canvas.height = canvas.offsetHeight; 383 | } 384 | } 385 | 386 | function codepad_loaded(callback) { 387 | var splash = document.getElementById("splash"); 388 | splash.onclick = undefined; 389 | splash.remove(); 390 | callback(); 391 | fix_canvas_size(); 392 | } 393 | 394 | function codepad_show_play_embed(callback) { 395 | var splash = document.getElementById("splash"); 396 | splash.onclick = function () { 397 | codepad_loaded(callback); 398 | }; 399 | splash.innerHTML = "
Run code
"; 400 | document.body.classList += "embedded"; 401 | var pane_editors = document.getElementById("pane-editors"); 402 | pane_editors.remove(); 403 | } 404 | 405 | function codepad_start(callback) { 406 | window.onresize = fix_canvas_size; 407 | if (codepad_is_embedded()) { 408 | codepad_show_play_embed(callback); 409 | } else { 410 | codepad_load_editor(function () { 411 | codepad_loaded(callback); 412 | }); 413 | } 414 | } 415 | -------------------------------------------------------------------------------- /codepad/bundle_resources/web/static/jszip.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | 3 | JSZip v3.10.1 - A JavaScript class for generating and reading zip files 4 | 5 | 6 | (c) 2009-2016 Stuart Knightley 7 | Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/main/LICENSE.markdown. 8 | 9 | JSZip uses the library pako released under the MIT license : 10 | https://github.com/nodeca/pako/blob/main/LICENSE 11 | */ 12 | 13 | !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JSZip=e()}}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=o[r]={exports:{}};a[r][0].call(i.exports,function(e){var t=a[r][1][e];return u(t||e)},i,i.exports,s,a,o,h)}return o[r].exports}for(var l="function"==typeof require&&require,e=0;e>2,s=(3&t)<<4|r>>4,a=1>6:64,o=2>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l}},{"./support":30,"./utils":32}],2:[function(e,t,r){"use strict";var n=e("./external"),i=e("./stream/DataWorker"),s=e("./stream/Crc32Probe"),a=e("./stream/DataLengthProbe");function o(e,t,r,n,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=r,this.compression=n,this.compressedContent=i}o.prototype={getContentWorker:function(){var e=new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),t=this;return e.on("end",function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),e},getCompressedWorker:function(){return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(e,t,r){return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression",t)},t.exports=o},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,r){"use strict";var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},r.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,r){"use strict";var n=e("./utils");var o=function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}();t.exports=function(e,t){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return-1^e}(0|t,e,e.length,0):function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t.charCodeAt(a))];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,r){"use strict";r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(e,t,r){"use strict";var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n}},{lie:37}],7:[function(e,t,r){"use strict";var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=e("pako"),s=e("./utils"),a=e("./stream/GenericWorker"),o=n?"uint8array":"array";function h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1)},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null},h.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta})}},r.compressWorker=function(e){return new h("Deflate",e)},r.uncompressWorker=function(){return new h("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,r){"use strict";function A(e,t){var r,n="";for(r=0;r>>=8;return n}function n(e,t,r,n,i,s){var a,o,h=e.file,u=e.compression,l=s!==O.utf8encode,f=I.transformTo("string",s(h.name)),c=I.transformTo("string",O.utf8encode(h.name)),d=h.comment,p=I.transformTo("string",s(d)),m=I.transformTo("string",O.utf8encode(d)),_=c.length!==h.name.length,g=m.length!==d.length,b="",v="",y="",w=h.dir,k=h.date,x={crc32:0,compressedSize:0,uncompressedSize:0};t&&!r||(x.crc32=e.crc32,x.compressedSize=e.compressedSize,x.uncompressedSize=e.uncompressedSize);var S=0;t&&(S|=8),l||!_&&!g||(S|=2048);var z=0,C=0;w&&(z|=16),"UNIX"===i?(C=798,z|=function(e,t){var r=e;return e||(r=t?16893:33204),(65535&r)<<16}(h.unixPermissions,w)):(C=20,z|=function(e){return 63&(e||0)}(h.dosPermissions)),a=k.getUTCHours(),a<<=6,a|=k.getUTCMinutes(),a<<=5,a|=k.getUTCSeconds()/2,o=k.getUTCFullYear()-1980,o<<=4,o|=k.getUTCMonth()+1,o<<=5,o|=k.getUTCDate(),_&&(v=A(1,1)+A(B(f),4)+c,b+="up"+A(v.length,2)+v),g&&(y=A(1,1)+A(B(p),4)+m,b+="uc"+A(y.length,2)+y);var E="";return E+="\n\0",E+=A(S,2),E+=u.magic,E+=A(a,2),E+=A(o,2),E+=A(x.crc32,4),E+=A(x.compressedSize,4),E+=A(x.uncompressedSize,4),E+=A(f.length,2),E+=A(b.length,2),{fileRecord:R.LOCAL_FILE_HEADER+E+f+b,dirRecord:R.CENTRAL_FILE_HEADER+A(C,2)+E+A(p.length,2)+"\0\0\0\0"+A(z,4)+A(n,4)+f+b+p}}var I=e("../utils"),i=e("../stream/GenericWorker"),O=e("../utf8"),B=e("../crc32"),R=e("../signature");function s(e,t,r,n){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=r,this.encodeFileName=n,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}I.inherits(s,i),s.prototype.push=function(e){var t=e.meta.percent||0,r=this.entriesCount,n=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,i.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:r?(t+100*(r-n-1))/r:100}}))},s.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var r=n(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:r.fileRecord,meta:{percent:0}})}else this.accumulate=!0},s.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,r=n(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),t)this.push({data:function(e){return R.DATA_DESCRIPTOR+A(e.crc32,4)+A(e.compressedSize,4)+A(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},s.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)r=(r<<8)+this.byteAt(t);return this.index+=e,r},readString:function(e){return n.transformTo("string",this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i},{"../utils":32}],19:[function(e,t,r){"use strict";var n=e("./Uint8ArrayReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,r){"use strict";var n=e("./DataReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./DataReader":18}],21:[function(e,t,r){"use strict";var n=e("./ArrayReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.readData=function(e){if(this.checkOffset(e),0===e)return new Uint8Array(0);var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,r){"use strict";var n=e("../utils"),i=e("../support"),s=e("./ArrayReader"),a=e("./StringReader"),o=e("./NodeBufferReader"),h=e("./Uint8ArrayReader");t.exports=function(e){var t=n.getTypeOf(e);return n.checkSupport(t),"string"!==t||i.uint8array?"nodebuffer"===t?new o(e):i.uint8array?new h(n.transformTo("uint8array",e)):new s(n.transformTo("array",e)):new a(e)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,r){"use strict";r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\b"},{}],24:[function(e,t,r){"use strict";var n=e("./GenericWorker"),i=e("../utils");function s(e){n.call(this,"ConvertWorker to "+e),this.destType=e}i.inherits(s,n),s.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta})},t.exports=s},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,r){"use strict";var n=e("./GenericWorker"),i=e("../crc32");function s(){n.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}e("../utils").inherits(s,n),s.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e)},t.exports=s},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,r){"use strict";var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataLengthProbe for "+e),this.propName=e,this.withStreamInfo(e,0)}n.inherits(s,i),s.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length}i.prototype.processChunk.call(this,e)},t.exports=s},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,r){"use strict";var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataWorker");var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=n.getTypeOf(e),t.isPaused||t._tickAndRepeat()},function(e){t.error(e)})}n.inherits(s,i),s.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null},s.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,n.delay(this._tickAndRepeat,[],this)),!0)},s.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(n.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},s.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":e=this.data.substring(this.index,t);break;case"uint8array":e=this.data.subarray(this.index,t);break;case"array":case"nodebuffer":e=this.data.slice(this.index,t)}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=s},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,r){"use strict";function n(e){this.name=e||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}n.prototype={push:function(e){this.emit("data",e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(e){this.emit("error",e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit("error",e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var r=0;r "+e:e}},t.exports=n},{}],29:[function(e,t,r){"use strict";var h=e("../utils"),i=e("./ConvertWorker"),s=e("./GenericWorker"),u=e("../base64"),n=e("../support"),a=e("../external"),o=null;if(n.nodestream)try{o=e("../nodejs/NodejsStreamOutputAdapter")}catch(e){}function l(e,o){return new a.Promise(function(t,r){var n=[],i=e._internalType,s=e._outputType,a=e._mimeType;e.on("data",function(e,t){n.push(e),o&&o(t)}).on("error",function(e){n=[],r(e)}).on("end",function(){try{var e=function(e,t,r){switch(e){case"blob":return h.newBlob(h.transformTo("arraybuffer",t),r);case"base64":return u.encode(t);default:return h.transformTo(e,t)}}(s,function(e,t){var r,n=0,i=null,s=0;for(r=0;r>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t}(e)},s.utf8decode=function(e){return h.nodebuffer?o.transformTo("nodebuffer",e).toString("utf-8"):function(e){var t,r,n,i,s=e.length,a=new Array(2*s);for(t=r=0;t>10&1023,a[r++]=56320|1023&n)}return a.length!==r&&(a.subarray?a=a.subarray(0,r):a.length=r),o.applyFromCharCode(a)}(e=o.transformTo(h.uint8array?"uint8array":"array",e))},o.inherits(a,n),a.prototype.processChunk=function(e){var t=o.transformTo(h.uint8array?"uint8array":"array",e.data);if(this.leftOver&&this.leftOver.length){if(h.uint8array){var r=t;(t=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),t.set(r,this.leftOver.length)}else t=this.leftOver.concat(t);this.leftOver=null}var n=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}(t),i=t;n!==t.length&&(h.uint8array?(i=t.subarray(0,n),this.leftOver=t.subarray(n,t.length)):(i=t.slice(0,n),this.leftOver=t.slice(n,t.length))),this.push({data:s.utf8decode(i),meta:e.meta})},a.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:s.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},s.Utf8DecodeWorker=a,o.inherits(l,n),l.prototype.processChunk=function(e){this.push({data:s.utf8encode(e.data),meta:e.meta})},s.Utf8EncodeWorker=l},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,a){"use strict";var o=e("./support"),h=e("./base64"),r=e("./nodejsUtils"),u=e("./external");function n(e){return e}function l(e,t){for(var r=0;r>8;this.dir=!!(16&this.externalFileAttributes),0==e&&(this.dosPermissions=63&this.externalFileAttributes),3==e&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4))}},readExtraFields:function(e){var t,r,n,i=e.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});e.index+4>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t},r.buf2binstring=function(e){return l(e,e.length)},r.binstring2buf=function(e){for(var t=new h.Buf8(e.length),r=0,n=t.length;r>10&1023,o[n++]=56320|1023&i)}return l(o,n)},r.utf8border=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}},{"./common":41}],43:[function(e,t,r){"use strict";t.exports=function(e,t,r,n){for(var i=65535&e|0,s=e>>>16&65535|0,a=0;0!==r;){for(r-=a=2e3>>1:e>>>1;t[r]=e}return t}();t.exports=function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return-1^e}},{}],46:[function(e,t,r){"use strict";var h,c=e("../utils/common"),u=e("./trees"),d=e("./adler32"),p=e("./crc32"),n=e("./messages"),l=0,f=4,m=0,_=-2,g=-1,b=4,i=2,v=8,y=9,s=286,a=30,o=19,w=2*s+1,k=15,x=3,S=258,z=S+x+1,C=42,E=113,A=1,I=2,O=3,B=4;function R(e,t){return e.msg=n[t],t}function T(e){return(e<<1)-(4e.avail_out&&(r=e.avail_out),0!==r&&(c.arraySet(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0))}function N(e,t){u._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm)}function U(e,t){e.pending_buf[e.pending++]=t}function P(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t}function L(e,t){var r,n,i=e.max_chain_length,s=e.strstart,a=e.prev_length,o=e.nice_match,h=e.strstart>e.w_size-z?e.strstart-(e.w_size-z):0,u=e.window,l=e.w_mask,f=e.prev,c=e.strstart+S,d=u[s+a-1],p=u[s+a];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(u[(r=t)+a]===p&&u[r+a-1]===d&&u[r]===u[s]&&u[++r]===u[s+1]){s+=2,r++;do{}while(u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&sh&&0!=--i);return a<=e.lookahead?a:e.lookahead}function j(e){var t,r,n,i,s,a,o,h,u,l,f=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=f+(f-z)){for(c.arraySet(e.window,e.window,f,f,0),e.match_start-=f,e.strstart-=f,e.block_start-=f,t=r=e.hash_size;n=e.head[--t],e.head[t]=f<=n?n-f:0,--r;);for(t=r=f;n=e.prev[--t],e.prev[t]=f<=n?n-f:0,--r;);i+=f}if(0===e.strm.avail_in)break;if(a=e.strm,o=e.window,h=e.strstart+e.lookahead,u=i,l=void 0,l=a.avail_in,u=x)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x)if(n=u._tr_tally(e,e.strstart-e.match_start,e.match_length-x),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=x){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-x,n=u._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-x),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(j(e),0===e.lookahead&&t===l)return A;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((0===e.strstart||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,N(e,!1),0===e.strm.avail_out))return A;if(e.strstart-e.block_start>=e.w_size-z&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):(e.strstart>e.block_start&&(N(e,!1),e.strm.avail_out),A)}),new M(4,4,8,4,Z),new M(4,5,16,8,Z),new M(4,6,32,32,Z),new M(4,4,16,16,W),new M(8,16,32,32,W),new M(8,16,128,128,W),new M(8,32,128,256,W),new M(32,128,258,1024,W),new M(32,258,258,4096,W)],r.deflateInit=function(e,t){return Y(e,t,v,15,8,0)},r.deflateInit2=Y,r.deflateReset=K,r.deflateResetKeep=G,r.deflateSetHeader=function(e,t){return e&&e.state?2!==e.state.wrap?_:(e.state.gzhead=t,m):_},r.deflate=function(e,t){var r,n,i,s;if(!e||!e.state||5>8&255),U(n,n.gzhead.time>>16&255),U(n,n.gzhead.time>>24&255),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(U(n,255&n.gzhead.extra.length),U(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=p(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(U(n,0),U(n,0),U(n,0),U(n,0),U(n,0),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,3),n.status=E);else{var a=v+(n.w_bits-8<<4)<<8;a|=(2<=n.strategy||n.level<2?0:n.level<6?1:6===n.level?2:3)<<6,0!==n.strstart&&(a|=32),a+=31-a%31,n.status=E,P(n,a),0!==n.strstart&&(P(n,e.adler>>>16),P(n,65535&e.adler)),e.adler=1}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending!==n.pending_buf_size));)U(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.status=103)}else n.status=103;if(103===n.status&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&F(e),n.pending+2<=n.pending_buf_size&&(U(n,255&e.adler),U(n,e.adler>>8&255),e.adler=0,n.status=E)):n.status=E),0!==n.pending){if(F(e),0===e.avail_out)return n.last_flush=-1,m}else if(0===e.avail_in&&T(t)<=T(r)&&t!==f)return R(e,-5);if(666===n.status&&0!==e.avail_in)return R(e,-5);if(0!==e.avail_in||0!==n.lookahead||t!==l&&666!==n.status){var o=2===n.strategy?function(e,t){for(var r;;){if(0===e.lookahead&&(j(e),0===e.lookahead)){if(t===l)return A;break}if(e.match_length=0,r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):3===n.strategy?function(e,t){for(var r,n,i,s,a=e.window;;){if(e.lookahead<=S){if(j(e),e.lookahead<=S&&t===l)return A;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=x&&0e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=x?(r=u._tr_tally(e,1,e.match_length-x),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):h[n.level].func(n,t);if(o!==O&&o!==B||(n.status=666),o===A||o===O)return 0===e.avail_out&&(n.last_flush=-1),m;if(o===I&&(1===t?u._tr_align(n):5!==t&&(u._tr_stored_block(n,0,0,!1),3===t&&(D(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),F(e),0===e.avail_out))return n.last_flush=-1,m}return t!==f?m:n.wrap<=0?1:(2===n.wrap?(U(n,255&e.adler),U(n,e.adler>>8&255),U(n,e.adler>>16&255),U(n,e.adler>>24&255),U(n,255&e.total_in),U(n,e.total_in>>8&255),U(n,e.total_in>>16&255),U(n,e.total_in>>24&255)):(P(n,e.adler>>>16),P(n,65535&e.adler)),F(e),0=r.w_size&&(0===s&&(D(r.head),r.strstart=0,r.block_start=0,r.insert=0),u=new c.Buf8(r.w_size),c.arraySet(u,t,l-r.w_size,r.w_size,0),t=u,l=r.w_size),a=e.avail_in,o=e.next_in,h=e.input,e.avail_in=l,e.next_in=0,e.input=t,j(r);r.lookahead>=x;){for(n=r.strstart,i=r.lookahead-(x-1);r.ins_h=(r.ins_h<>>=y=v>>>24,p-=y,0===(y=v>>>16&255))C[s++]=65535&v;else{if(!(16&y)){if(0==(64&y)){v=m[(65535&v)+(d&(1<>>=y,p-=y),p<15&&(d+=z[n++]<>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<>>=y,p-=y,(y=s-a)>3,d&=(1<<(p-=w<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function s(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new I.Buf16(320),this.work=new I.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function a(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=P,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new I.Buf32(n),t.distcode=t.distdyn=new I.Buf32(i),t.sane=1,t.back=-1,N):U}function o(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,a(e)):U}function h(e,t){var r,n;return e&&e.state?(n=e.state,t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=s.wsize?(I.arraySet(s.window,t,r-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(n<(i=s.wsize-s.wnext)&&(i=n),I.arraySet(s.window,t,r-n,i,s.wnext),(n-=i)?(I.arraySet(s.window,t,r-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,r.check=B(r.check,E,2,0),l=u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",r.mode=30;break}if(8!=(15&u)){e.msg="unknown compression method",r.mode=30;break}if(l-=4,k=8+(15&(u>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=3;case 3:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>8&255,E[2]=u>>>16&255,E[3]=u>>>24&255,r.check=B(r.check,E,4,0)),l=u=0,r.mode=4;case 4:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>8),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=5;case 5:if(1024&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>>8&255,r.check=B(r.check,E,2,0)),l=u=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(o<(d=r.length)&&(d=o),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),I.arraySet(r.head.extra,n,s,d,k)),512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286>>=3,l-=3}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=_,l-=_,r.lens[r.have++]=b;else{if(16===b){for(z=_+2;l>>=_,l-=_,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2}else if(17===b){for(z=_+3;l>>=_)),u>>>=3,l-=3}else{for(z=_+7;l>>=_)),u>>>=7,l-=7}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=k}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},x=T(D,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},x=T(F,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,x){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,6===t)break e;case 20:r.mode=21;case 21:if(6<=o&&258<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=12;break}if(64&g){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg="invalid distance code",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p=d>r.wnext?(d-=r.wnext,r.wsize-d):r.wnext-d,d>r.length&&(d=r.length),m=r.window}else m=i,p=a-r.offset,d=r.length;for(hd?(m=R[T+a[v]],A[I+a[v]]):(m=96,0),h=1<>S)+(u-=h)]=p<<24|m<<16|_|0,0!==u;);for(h=1<>=1;if(0!==h?(E&=h-1,E+=h):E=0,v++,0==--O[b]){if(b===w)break;b=t[r+a[v]]}if(k>>7)]}function U(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255}function P(e,t,r){e.bi_valid>d-r?(e.bi_buf|=t<>d-e.bi_valid,e.bi_valid+=r-d):(e.bi_buf|=t<>>=1,r<<=1,0<--t;);return r>>>1}function Z(e,t,r){var n,i,s=new Array(g+1),a=0;for(n=1;n<=g;n++)s[n]=a=a+r[n-1]<<1;for(i=0;i<=t;i++){var o=e[2*i+1];0!==o&&(e[2*i]=j(s[o]++,o))}}function W(e){var t;for(t=0;t>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u>=7;n>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=i&&(i=s)):i=s=r+5,r+4<=i&&-1!==t?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]++),e.last_lit===e.lit_bufsize-1},r._tr_align=function(e){P(e,2,3),L(e,m,z),function(e){16===e.bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)}},{"../utils/common":41}],53:[function(e,t,r){"use strict";t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,r){(function(e){!function(r,n){"use strict";if(!r.setImmediate){var i,s,t,a,o=1,h={},u=!1,l=r.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(r);e=e&&e.setTimeout?e:r,i="[object process]"==={}.toString.call(r.process)?function(e){process.nextTick(function(){c(e)})}:function(){if(r.postMessage&&!r.importScripts){var e=!0,t=r.onmessage;return r.onmessage=function(){e=!1},r.postMessage("","*"),r.onmessage=t,e}}()?(a="setImmediate$"+Math.random()+"$",r.addEventListener?r.addEventListener("message",d,!1):r.attachEvent("onmessage",d),function(e){r.postMessage(a+e,"*")}):r.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){c(e.data)},function(e){t.port2.postMessage(e)}):l&&"onreadystatechange"in l.createElement("script")?(s=l.documentElement,function(e){var t=l.createElement("script");t.onreadystatechange=function(){c(e),t.onreadystatechange=null,s.removeChild(t),t=null},s.appendChild(t)}):function(e){setTimeout(c,0,e)},e.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r