commit de89e4cdf5248fc6bcccd78a9c6e4abe2d6e4799 Author: HF Date: Thu Jan 2 17:58:06 2020 +0100 Mirror repository for github diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..f38d98a --- /dev/null +++ b/.babelrc @@ -0,0 +1,21 @@ +{ + "presets": [ + [ + "@babel/env", + { + "targets": { + "node": "current" + } + } + ], + ], + "plugins": [ + "@babel/transform-flow-strip-types", + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", + ["@babel/plugin-proposal-class-properties", { "loose": true }], + ] +} diff --git a/.env_back b/.env_back new file mode 100644 index 0000000..995fca4 --- /dev/null +++ b/.env_back @@ -0,0 +1 @@ +NODE_ENV=production \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..cd58dab --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "extends": [ + "plugin:flowtype/recommended", + "airbnb" + ], + "plugins": [ + "flowtype", + "react", + "jsx-a11y", + "import" + ], + "globals": { + "__DEV__": false + }, + "env": { + "browser": true + }, + "rules": { + "max-len": [1, 80, 2, {"ignoreComments": true}], + "no-bitwise": 0, + "no-plusplus" : "off", + "no-param-reassign": "off", + "no-mixed-operators":"off" + } +} diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..4a58bdc --- /dev/null +++ b/.flowconfig @@ -0,0 +1,7 @@ +[ignore] + +[include] + +[libs] + +[options] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a76ea0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +build +chunks +players.json +.digitalocean +database.sqlite +.ftpquota + + +# Created by https://www.gitignore.io/api/node,webstorm + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### WebStorm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### WebStorm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# End of https://www.gitignore.io/api/node,webstorm + +package-lock.json +yarn.lock + +osm.tar.xz +backup +backup/* +ips +pixelplanetmap.zip diff --git a/API.md b/API.md new file mode 100644 index 0000000..a303b0a --- /dev/null +++ b/API.md @@ -0,0 +1,95 @@ +# API Websocket + +This websocket provides unlimited access to many functions of the site, it is used for Discord Chat Bridge and Minecraft Bridge. + +Websocket url: +`https://[old.]pixelplanet.fun/mcws` + +Connection just possible with header: + +``` +Authorization: "Bearer APISOCKETKEY" +``` + +All requests are made as JSON encoded array. +### Subscribe to chat messages +```["sub", "chat"]``` + +All chat messages, except the once you send with `chat` or `mcchat`, will be sent to you in the form: + +```["msg", name, message]``` +### Subscribe to online user counter +```["sub", "online"]``` + +Online counter will be sent to you as typical binary packages all 15s +### Subscribe to pixel packages +```["sub", "pxl"]``` + +All pixels (including your own) will be sent to you as typical binary packages +### Set Pixel + +```[ "setpxl", minecraftid, ip, x, y, clr ]``` + +(x, y, clr are integers, rest strings) + +Sets a pixel with the according cooldown to minecraftid, ip. Minecraftid is optional, but ip is required if it is given. If both minecraftid and ip are null/None, the pixel will get set without cooldown check. No race condition checks are performed. + +You will get a reply with: + +```["retpxl", id, error, success, waitSeconds, coolDownSeconds]``` + +(id and error as strings, success as boolean, waitSeconds and coolDownSeconds as float) + +ID is minecraftid, if given, else ip. +error is a message on error, else null. +success... self explanatory +waitSeconds is the current cooldown. +coolDownSeconds is the added cooldown (negative if pixel couldn't be set because max cooldown got reached) +### Minecraft Login notification +```["login", minecraftid, minecraftname, ip]``` + +You will get an answer back like: + +```["mcme", minecraftid, waitSeconds, pixelplanetname]``` + +with pixelplanetname being null/None if there is no pixelplanet account linked to this minecraftid. +wait Seconds is the cooldown like in `retpixel` above. +### Minecraft LogOut notification +```["logout", minecraftid]``` +### Send Chat Message from Minecraft +```["mcchat", minecraftname, message]``` + +(got an extra command because minecraftname gets resolved to linked pixelplanet user if possible) +### Send Chat Message +```["chat", name, message]``` + +(messages with the name "info" will be displayed as red notifications in the chat window) +### Link Minecraft Account to pixelplanet Account +```["linkacc", minecraftid, minecraftname, pixelplanetname]``` + +Immediate answer: + +```["linkret", minecraftid, error]``` + +Error will be null/None if link request can get sent, else it will be a string with the reason why not, examples: + +- "You are already verified to [name]" +- "Can not find user [name] on pixelplanet" +- "You already linked to other account [name]" + +User will then be asked if he wants to link the account on pixelplanet. + +Answer after accept/deny by user: + +```["linkver", minecraftid, pixelplanetname, accepted]``` + +With accepted being either true or false. This will be sent to every client connected to the API websocket. +### Report online minecraft users +Send list of all online users in minecraft periodically (all 10 to 15min) to avoid getting out of sync. + +```["userlst", [["minecraftid1", "minecraftname1"], ["minecraftid2", "minecraftname2"], ...]]``` +### Minecraft TP request + +If a user requests a tp in minecraft you get a message + +```["mctp", "minecraftid", x, y]``` diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3fd1df0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + PixelCanvas Copyright (C) 2017 Rafael Arquero + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2d8447 --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ +# PixelPlanet.fun + +Official repository of [pixelplanet.fun](http://www.pixelplanet.fun). + +![videothumb](promotion/videothumb.gif) + +Just to the 2nd anniversary of r/space, pixelplanet takes pixelgames to a new level. Place pixels, create pixelart and fight faction wars on pixelplanet.fun. +Pixelplanet is a 65k x 65k large canvas that is a map of the world and can also be seen as 3d globe, you can place pixels where ever you want, build an island, take over another country with a flag or just create pixelart. +24 well chosen colors (decided by polls within the community) are available and you can place a pixel every 3s on an empty space, and 5s on an already set pixel. But pixels can be stacked up to a min, so you don't have to wait every time. + +Pixelplanet receives regular updates and launches events, like a zero second cooldown day on r/place anniversary. We are driven by our community, because placing pixels is more fun together. + +Controls: +W, A, S, D, click and drag or pan: Move +Q, E or scroll or pinch: Zoom +Click or tab: Place Pixel +![screenshot](promotion/screenshot.png) + + +## Build +### Requriements +- [nodejs environment](https://nodejs.org/en/) +- [yarn](https://yarnpkg.com/lang/en/docs/install/#debian-stable) +- (optional) [babel-cli](https://www.npmjs.com/package/babel-cli) (`sudo npm install --global babel-cli`) + +### Building +Make sure that you have rights to g++ (if not, run as root and then `chown username:username -R .` after build) + +``` +yarn install +yarn run build --release +``` +All needed files to run it got created in `./build` +#### Note: +If yarn install fails with "unable to connect to github.com" set: +``` +git config --global url.https://github.com/.insteadOf git://github.com/ +``` + +## Run +### Requriements +- nodejs environment with [npm](https://www.npmjs.com/get-npm) +- (optional)[babel-cli](https://www.npmjs.com/package/babel-cli) (`npm install -g babel-cli`) +- [pm2](https://github.com/Unitech/pm2) (`npm install -g pm2`) as process manager and for logging +- [redis](https://redis.io/) as database for storgìng the canvas +- mysql or mariadb ([setup own user](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql) and [create database](https://www.w3schools.com/SQl/sql_create_db.asp) for pixelplanet) for storing additional data like IP blacklist + +### Configuration +Configuration takes place in the environment variables that are defined in ecosystem.yml + +#### Neccessary Configuration + +| Variable | Description | Example | +|----------------|:-------------------------|------------------------:| +| HOSTURL | URL of the canvas | "http://localhost" | +| ASSET_SERVER | URL for assets | "http://localhost" | +| PORT | Port | 80 | +| REDIS_URL | URL:PORT of redis server | "http://localhost:6379" | +| MYSQL_HOST | MySql Host | "localhost" | +| MYSQL_USER | MySql User | "user" | +| MYSQL_PW | MySql Password | "password" | +| MYSQL_DATABASE | MySql Database | "pixelpladb" | + +#### Optional Configuration + +| Variable | Description | Example | +|-------------------|:--------------------------------------|-------------| +| USE_PROXYCHECK | Check users for Proxies | 0 | +| APISOCKET_KEY | Key for API Socket for SpecialAccess™ | "SDfasife3" | +| ADMIN_IDS | Ids of users with Admin rights | "1,12,3" | +| RECAPTCHA_SECRET | reCaptcha secret key | "asdieewff" | +| RECAPTCHA_SITEKEY | reCaptcha site key | "23ksdfssd" | +| RECAPTCHA_TIME | time in minutes between captchas | 30 | +| SESSION_SECRET | random sting for expression sessions | "ayylmao" | + +Notes: + +- to be able to use USE_PROXYCHECK, you have to have an account on proxycheck.io or getipintel or another checker setup and you might set some proxies in `src/proxies.json` (before building) that get used for making proxycheck requests. Look into `src/isProxy.js` to see how things work, but keep in mind that this isn't neccessarily how pixelplanet.fun uses it. +- Admins are users with 0cd and access to `./admintools` for image-upload and whatever +- You can find out the id of a user by looking into the logs (i.e. `info: {ip} / {id} wants to place 2 in (1701, -8315)`) when he places a pixel or by checking the MySql Users database + +#### Social Media + +| Variable | Description | +|-----------------------|:-------------------------| +| DISCORD_INVITE | Invite to discord server | +| DISCORD_CLIENT_ID | All | +| DISCORD_CLIENT_SECRET | those | +| GOOGLE_CLIENT_ID | values | +| GOOGLE_CLIENT_SECRET | are | +| FACEBOOK_APP_ID | for | +| FACEBOOK_APP_SECRET | login | +| VK_CLIENT_ID | with | +| VK_CLIENT_SECRET | Social | +| REDDIT_CLIENT_ID | Media | +| REDDIT_CLIENT_SECRET | Accounts | + +Note: + +- The HTML for SocialMedia logins is in src/componets/UserAreaModal.js , delete stuff from there if you don't need it +- The HTML for the Help Screen is in src/components/HelpModal.js + +Canvas specific configuartion like colors and cooldown is in `src/canvases.json` for all canvases. +The CanvasSize is expected to be a power of 4 (4096, 16384, 65536,...) and not smaller than 256. +bcd is base cooldown for unset pixels, pcd is cooldown for placing on top of others, cds is stacktime, req is the requirement to be allowed to set on canvas in total pixels placed. All the cooldown values are in ms. +The default configuration values can be seen in `src/core/config.js` and for the canvases in `src/core/constats.js` + +### Running + +1. Make sure that mysql and redis are running +3. Start with +``` +pm2 start ecosystem.yml +``` +Note: It might be neccessary to change the charset and collate of the sql colum names of table Users to support special character names, which can be done with the SQL command: +``` +ALTER TABLE Users CONVERT TO CHARACTER SET utf8mb4 COLLATE 'utf8mb4_unicode_ci'; +``` + +### Logging +logs are in ~/pm2/log/, you can view them with +``` +pm2 log web +``` +you can flush the logs with +``` +pm2 log flush +``` + +### Stopping +``` +pm2 stop web +``` + +### If using Cloudflare +In order to get the real IP and not use the cloudflare Proxy IP for placing pixels, we filter those out. The cloudflare IPs are in src/utils/cloudflareip.js and used in src/utils/ip.js. If for some reason cloudflare ads more IPs to it, you can see them at https://www.cloudflare.com/ips/ and add them. +If you use any other Reverse Proxy, you can define it's IPs there too. + +### Auto-Start +To have the canvas with all it's components autostart at systemstart, +enable mysql, redis (and probably nginx if you use it) according to your system (`systemctl enable ...`) +And then setup pm2 startup with: +``` +pm2 startup +``` +(execute as the user that is running pixelplanet) +And follow the printed steps if needed. This will generate a systemctl service file `/etc/systemd/system/pm2-pixelplanet.service` and enable it. You will have to run `pm2 save` while the canvas is running to let pm2 know what to start. +To make sure that mysql and redis are up when pixelplanet starts, edit this service file and modify the lines: +``` +Wants=network-online.target +After=network.target mysql.service redis.service +``` + +#### nginx auto-start issues +If nginx fails to auto start because the network is not propably up yet, add the line: +``` +After=network-online.target +``` +in `systemctl edit nginx.service`, which will create the file `/etc/systemd/system/nginx.service.d/override.conf` + +### Development + +Install packages that are just required for building with `yarn add --dev` others with `yarn add` diff --git a/deployment/README.md b/deployment/README.md new file mode 100644 index 0000000..f8b1fd1 --- /dev/null +++ b/deployment/README.md @@ -0,0 +1,12 @@ +# Utils and informations of current deployment +Files here might be very specific to the setup of pixelplanet.fun and might not be relevant for everyone + +##updtmsg +Basic nodejs script to print a message and a youtube video, used as a message while updating + +##post-receive +Pixelplanet has its own git repository for deployment on the live system, if an commit get pushed to it, it will automatically build the canvas and deploy it and post update messages to discord. This hook is managing that on the server. + +##Some notes: +Cloudflare Caching Setting `Broser Cache Expiration` should be set to `Respect Existing Headers` or it would default to 4h, which is unreasonable for chunks. +Additinally make sure that cachebreakers get blocked by setting Cloudflare Firewall rules to block empty query strings at least for chunks diff --git a/deployment/post-receive b/deployment/post-receive new file mode 100755 index 0000000..6cf8527 --- /dev/null +++ b/deployment/post-receive @@ -0,0 +1,67 @@ +#!/bin/bash +# This hook builds pixelplanet after a push, and deploys it +# If it is the production branch, it will deploy it on the life system, and other branch will get deployed to the dev-canvas (a second canvas that is running on the server) +# Update messages will get sent via the Webhooks to Discord +# +# To set up a server to use this, you have to go through the building steps manually first. +# This hook just builds the canvas, it does not install new yarn/npm packages if needed. So this has to be done manually first +# Also keep in mind that running a dev-canvas and a life canvas independently together on one server needs two redis installations. +# tl;dr: Don't just copy that script, try to know how that setup works first +# +#discord webhook for dev canvas +WEBHOOK='https://discordapp.com/api/webhooks/' +#discord webhook for production canvas +PWEBHOOK='https://discordapp.com/api/webhooks/' +#folder for building the canvas (the git repository will get checkout there and the canvas will get buil thtere) +BUILDDIR="pixelplanet-build" +#folder for dev canvas +DEVFOLDER="pixelplanet-dev" +#folder for production canvas +PFOLDER="pixelplanet" +#proxies.json path +PROXYFILE="/proxies.json" + +while read oldrev newrev refname +do + branch=$(git rev-parse --symbolic --abbrev-ref $refname) + if [ "production" == "$branch" ]; then + echo "---UPDATING REPO ON PRODUCTION SERVER---" + GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git fetch --all + GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git reset --hard origin/production + curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "Restarting canvas for Updates..." }' "$PWEBHOOK" + COMMITS=`git log --pretty=format:'- %s%b' $newrev ^$oldrev` + COMMITS=`echo "$COMMITS" | sed ':a;N;$!ba;s/\n/\\\n/g'` + echo "---BUILDING pixelplanet---" + cd "$BUILDDIR" + cp "$PROXYFILE" ./ + yarn run build --release + echo "---RESTARTING CANVAS---" + cp -r build/* "${PFOLDER}/" + #cp ecosystem-production.yml "${PFOLDER}/ecosystem.yml" + cd "$PFOLDER" + pm2 stop web + pm2 start ecosystem.yml + #make backup + tar -cvJf /backup/pixelplanet-src/pixelplanet-src-`date +%Y%m%d`.tar.xz --exclude=node_modules --exclude=.git -C "${BUILDDIR}/.." "pixelplanet-build" + #send update message to discord + curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "...Done", "embeds": [{"title": "New Commits", "url": "https://pixelplanet.fun", "description": "'"$COMMITS"'", "color": 15258703}] }' "$PWEBHOOK" + else + echo "---UPDATING REPO ON DEV SERVER---" + pm2 stop web-dev + GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git fetch --all + GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git reset --hard "origin/$branch" + curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "Restarting pixelplanet development canvas for update..." }' "$WEBHOOK" + COMMITS=`git log --pretty=format:'- %s%b' $newrev ^$oldrev` + COMMITS=`echo "$COMMITS" | sed ':a;N;$!ba;s/\n/\\\n/g'` + echo "---BUILDING pixelplanet---" + cd "$BUILDDIR" + cp "$PROXYFILE" ./ + nice -n 19 yarn run build --release + echo "---RESTARTING CANVAS---" + cp -r build/* "${DEVFOLDER}/" + #cp ecosystem-dev.yml "${DEVFOLDER}/ecosystem.yml" + cd "$DEVFOLDER" + pm2 start ecosystem.yml + curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "...Done\nhttp://dev.pixelplanet.fun is now on branch '"$branch"'", "embeds": [{"title": "New Commits", "url": "https://pixelplanet.fun", "description": "'"$COMMITS"'", "color": 15258703}] }' "$WEBHOOK" + fi +done diff --git a/deployment/updatemsg/README.md b/deployment/updatemsg/README.md new file mode 100644 index 0000000..db25cc7 --- /dev/null +++ b/deployment/updatemsg/README.md @@ -0,0 +1,3 @@ +# update.js +This is just a basic nodejs app that shows a html with a youtube video. +Can show it during downtimes when updating. diff --git a/deployment/updatemsg/update.html b/deployment/updatemsg/update.html new file mode 100644 index 0000000..c2ae6c5 --- /dev/null +++ b/deployment/updatemsg/update.html @@ -0,0 +1,34 @@ + + + + + + + +

We are updating...

+

will be back soon

+
+ +
+ + diff --git a/deployment/updatemsg/update.js b/deployment/updatemsg/update.js new file mode 100644 index 0000000..74f2930 --- /dev/null +++ b/deployment/updatemsg/update.js @@ -0,0 +1,21 @@ +const http = require('http'); +const path = require('path'); +const fileSystem = require('fs'); + +const hostname = '127.0.0.1'; +const port = 3000; + +const file = 'update.html'; + +const server = http.createServer((req, res) => { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/html; charset=UTF-8'); + res.setHeader('Cache-Control', 'public, max-age=90'); + var filePath = path.join(__dirname, file); + var readStream = fileSystem.createReadStream(filePath); + readStream.pipe(res); +}); + +server.listen(port, hostname, () => { + console.log(`Server running at http://${hostname}:${port}/`); +}); diff --git a/ecosystem.yml b/ecosystem.yml new file mode 100644 index 0000000..37988f5 --- /dev/null +++ b/ecosystem.yml @@ -0,0 +1,14 @@ +apps: + - script : ./build/web.js + name : 'web' + node_args: --nouse-idle-notification --expose-gc + env: + HOSTURL: "http://localhost" + ASSET_SERVER: "http://localhost" + PORT: 80 + REDIS_URL: 'redis://localhost:6379' + MYSQL_HOST: "localhost" + MYSQL_USER: "pixelplanet" + MYSQL_DATABASE: "pixelplanet" + MYSQL_PW: "sqlpassword" + SESSION_SECRET: "ayyylmao" diff --git a/package.json b/package.json new file mode 100644 index 0000000..408c0df --- /dev/null +++ b/package.json @@ -0,0 +1,142 @@ +{ + "name": "PixelPlanet", + "version": "1.0.0", + "private": true, + "engines": { + "node": ">=10.18.0", + "npm": ">=6.13.4" + }, + "description": "Unlimited planet canvas for placing pixels", + "main": "server.js", + "scripts": { + "build": "babel-node tools/run build", + "clean": "babel-node tools/run clean", + "lint:js": "eslint src", + "lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"", + "lint:staged": "lint-staged", + "lint": "yarn run lint:js && yarn run lint:css" + }, + "author": "HF ", + "browserslist": [ + ">1%", + "last 2 versions", + "Firefox ESR", + "not ie <= 11" + ], + "dependencies": { + "bcrypt": "^3.0.6", + "bluebird": "^3.5.0", + "body-parser": "^1.17.2", + "bufferutil": "^3.0.0", + "compression": "^1.7.3", + "connect-redis": "^3.3.0", + "cookie-parser": "^1.4.3", + "core-js": "^3.6.1", + "cors": "^2.8.4", + "etag": "^1.8.1", + "express": "^4.15.3", + "express-limiter": "^1.6.0", + "express-session": "^1.15.2", + "express-validator": "^3.2.0", + "global": "^4.3.2", + "hammerjs": "^2.0.8", + "http-proxy-agent": "^2.1.0", + "ip": "^1.1.5", + "ip-address": "^5.8.9", + "isomorphic-fetch": "^2.2.1", + "keycode": "^2.1.9", + "localforage": "^1.5.0", + "lumber-cli": "^1.3.1", + "morgan": "^1.8.2", + "multer": "^1.4.1", + "mysql2": "^1.3.6", + "node-sass": "^4.11.0", + "passport": "^0.4.0", + "passport-discord": "^0.1.2", + "passport-facebook": "^2.1.1", + "passport-google-oauth": "^1.0.0", + "passport-json": "^1.2.0", + "passport-reddit": "^0.2.4", + "passport-vkontakte": "^0.3.2", + "push.js": "1.0.9", + "react": "^16.9.0", + "react-dom": "^16.9.0", + "react-file-download": "^0.3.4", + "react-icons": "^3.7.0", + "react-modal": "^3.10.1", + "react-redux": "^7.1.1", + "react-responsive": "^8.0.1", + "react-stay-scrolled": "^7.0.0", + "react-toggle-button": "^2.1.0", + "redis": "^2.7.1", + "redlock": "^4.0.0", + "redux": "^4.0.4", + "redux-logger": "^3.0.6", + "redux-persist": "^6.0.0", + "redux-thunk": "^2.2.0", + "rimraf": "^2.6.1", + "sendmail": "^1.6.1", + "sequelize": "^5.19.2", + "sharp": "^0.21.3", + "startaudiocontext": "^1.2.1", + "sweetalert2": "^6.6.6", + "url-search-params-polyfill": "^7.0.0", + "validator": "^7.0.0", + "visibilityjs": "^1.2.4", + "winston": "^2.3.1", + "ws": "^7.1.2" + }, + "devDependencies": { + "@babel/core": "^7.0.0", + "@babel/node": "^7.0.0", + "@babel/plugin-proposal-class-properties": "^7.0.0", + "@babel/plugin-proposal-decorators": "^7.0.0", + "@babel/plugin-proposal-do-expressions": "^7.0.0", + "@babel/plugin-proposal-export-default-from": "^7.0.0", + "@babel/plugin-proposal-export-namespace-from": "^7.0.0", + "@babel/plugin-proposal-function-bind": "^7.0.0", + "@babel/plugin-proposal-function-sent": "^7.0.0", + "@babel/plugin-proposal-json-strings": "^7.0.0", + "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0", + "@babel/plugin-proposal-numeric-separator": "^7.0.0", + "@babel/plugin-proposal-optional-chaining": "^7.0.0", + "@babel/plugin-proposal-pipeline-operator": "^7.0.0", + "@babel/plugin-proposal-throw-expressions": "^7.0.0", + "@babel/plugin-syntax-dynamic-import": "^7.0.0", + "@babel/plugin-syntax-import-meta": "^7.0.0", + "@babel/plugin-transform-flow-strip-types": "^7.0.0", + "@babel/plugin-transform-react-constant-elements": "^7.6.3", + "@babel/plugin-transform-react-inline-elements": "^7.2.0", + "@babel/polyfill": "^7.7.0", + "@babel/preset-env": "^7.0.0", + "@babel/preset-flow": "^7.0.0", + "@babel/preset-react": "^7.0.0", + "assets-webpack-plugin": "^3.5.1", + "babel-eslint": "^10.0.3", + "babel-loader": "^8.0.6", + "babel-plugin-transform-react-pure-class-to-function": "^1.0.1", + "babel-plugin-transform-react-remove-prop-types": "^0.4.24", + "css-loader": "^0.28.4", + "eslint": "^4.11.0", + "eslint-config-airbnb": "^15.0.1", + "eslint-config-airbnb-base": "^11.2.0", + "eslint-plugin-flowtype": "^2.33.0", + "eslint-plugin-import": "^2.2.0", + "eslint-plugin-jsx-a11y": "^5.0.3", + "eslint-plugin-react": "^7.0.1", + "flow-bin": "^0.59.0", + "http-proxy": "^1.16.2", + "json-loader": "^0.5.4", + "react-hot-loader": "^4.12.14", + "react-svg-loader": "^3.0.3", + "sass-loader": "^7.1.0", + "style-loader": "^0.23.1", + "webpack": "^4.41.0", + "webpack-bundle-analyzer": "^2.8.2", + "webpack-dev-middleware": "^3.7.1", + "webpack-hot-middleware": "^2.18.0", + "write-file-webpack-plugin": "^4.0.2", + "yarn": "^1.17.3" + } +} diff --git a/promotion/README.md b/promotion/README.md new file mode 100644 index 0000000..33f3d18 --- /dev/null +++ b/promotion/README.md @@ -0,0 +1 @@ +Folder for videos, screenshots and thumbnails used to promote pixelplanet diff --git a/promotion/screenshot.png b/promotion/screenshot.png new file mode 100644 index 0000000..e90651c Binary files /dev/null and b/promotion/screenshot.png differ diff --git a/promotion/thumbnail.png b/promotion/thumbnail.png new file mode 100644 index 0000000..5fc2ccd Binary files /dev/null and b/promotion/thumbnail.png differ diff --git a/promotion/videothumb-uncropped.mp4 b/promotion/videothumb-uncropped.mp4 new file mode 100644 index 0000000..4e0244f Binary files /dev/null and b/promotion/videothumb-uncropped.mp4 differ diff --git a/promotion/videothumb.gif b/promotion/videothumb.gif new file mode 100644 index 0000000..00477a3 Binary files /dev/null and b/promotion/videothumb.gif differ diff --git a/promotion/videothumb.mp4 b/promotion/videothumb.mp4 new file mode 100644 index 0000000..9f98990 Binary files /dev/null and b/promotion/videothumb.mp4 differ diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000..f6c58db Binary files /dev/null and b/public/apple-touch-icon.png differ diff --git a/public/browserconfig.xml b/public/browserconfig.xml new file mode 100644 index 0000000..57f30ff --- /dev/null +++ b/public/browserconfig.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/public/bundle.js b/public/bundle.js new file mode 100644 index 0000000..0e2687f --- /dev/null +++ b/public/bundle.js @@ -0,0 +1 @@ +var _0x170fd8=function(){var _0x3e23c3=!![];return function(_0x52ce06,_0x107754){var _0x235c55=_0x3e23c3?function(){if(_0x107754){var _0x311191=_0x107754['apply'](_0x52ce06,arguments);_0x107754=null;return _0x311191;}}:function(){};_0x3e23c3=![];return _0x235c55;};}();var _0x1cd806=_0x170fd8(this,function(){var _0x4b69fd=function(){return'\x64\x65\x76';},_0x44fa8c=function(){return'\x77\x69\x6e\x64\x6f\x77';};var _0x484b77=function(){var _0x406519=new RegExp('\x5c\x77\x2b\x20\x2a\x5c\x28\x5c\x29\x20\x2a\x7b\x5c\x77\x2b\x20\x2a\x5b\x27\x7c\x22\x5d\x2e\x2b\x5b\x27\x7c\x22\x5d\x3b\x3f\x20\x2a\x7d');return!_0x406519['\x74\x65\x73\x74'](_0x4b69fd['\x74\x6f\x53\x74\x72\x69\x6e\x67']());};var _0x417cdd=function(){var _0x2d58cd=new RegExp('\x28\x5c\x5c\x5b\x78\x7c\x75\x5d\x28\x5c\x77\x29\x7b\x32\x2c\x34\x7d\x29\x2b');return _0x2d58cd['\x74\x65\x73\x74'](_0x44fa8c['\x74\x6f\x53\x74\x72\x69\x6e\x67']());};var _0x56d344=function(_0x595838){var _0x29782d=~-0x1>>0x1+0xff%0x0;if(_0x595838['\x69\x6e\x64\x65\x78\x4f\x66']('\x69'===_0x29782d)){_0x5506d4(_0x595838);}};var _0x5506d4=function(_0x5257ab){var _0x37accc=~-0x4>>0x1+0xff%0x0;if(_0x5257ab['\x69\x6e\x64\x65\x78\x4f\x66']((!![]+'')[0x3])!==_0x37accc){_0x56d344(_0x5257ab);}};if(!_0x484b77()){if(!_0x417cdd()){_0x56d344('\x69\x6e\x64\u0435\x78\x4f\x66');}else{_0x56d344('\x69\x6e\x64\x65\x78\x4f\x66');}}else{_0x56d344('\x69\x6e\x64\u0435\x78\x4f\x66');}});_0x1cd806();(function(){function _0x4db3ff(_0x9cc5b5){_0x9cc5b5=_0x9cc5b5||{};this['\x6d\x65\x74\x68\x6f\x64']=_0x9cc5b5['\x6d\x65\x74\x68\x6f\x64']||0x2;this['\x63\x6f\x6c\x6f\x72\x73']=_0x9cc5b5['\x63\x6f\x6c\x6f\x72\x73']||0x100;this['\x69\x6e\x69\x74\x43\x6f\x6c\x6f\x72\x73']=_0x9cc5b5['\x69\x6e\x69\x74\x43\x6f\x6c\x6f\x72\x73']||0x1000;this['\x69\x6e\x69\x74\x44\x69\x73\x74']=_0x9cc5b5['\x69\x6e\x69\x74\x44\x69\x73\x74']||0.05;this['\x64\x69\x73\x74\x49\x6e\x63\x72']=_0x9cc5b5['\x64\x69\x73\x74\x49\x6e\x63\x72']||0.02;this['\x68\x75\x65\x47\x72\x6f\x75\x70\x73']=_0x9cc5b5['\x68\x75\x65\x47\x72\x6f\x75\x70\x73']||0xa;this['\x73\x61\x74\x47\x72\x6f\x75\x70\x73']=_0x9cc5b5['\x73\x61\x74\x47\x72\x6f\x75\x70\x73']||0xa;this['\x6c\x75\x6d\x47\x72\x6f\x75\x70\x73']=_0x9cc5b5['\x6c\x75\x6d\x47\x72\x6f\x75\x70\x73']||0xa;this['\x6d\x69\x6e\x48\x75\x65\x43\x6f\x6c\x73']=_0x9cc5b5['\x6d\x69\x6e\x48\x75\x65\x43\x6f\x6c\x73']||0x0;this['\x68\x75\x65\x53\x74\x61\x74\x73']=this['\x6d\x69\x6e\x48\x75\x65\x43\x6f\x6c\x73']?new _0x57203b(this['\x68\x75\x65\x47\x72\x6f\x75\x70\x73'],this['\x6d\x69\x6e\x48\x75\x65\x43\x6f\x6c\x73']):null;this['\x62\x6f\x78\x53\x69\x7a\x65']=_0x9cc5b5['\x62\x6f\x78\x53\x69\x7a\x65']||[0x40,0x40];this['\x62\x6f\x78\x50\x78\x6c\x73']=_0x9cc5b5['\x62\x6f\x78\x50\x78\x6c\x73']||0x2;this['\x70\x61\x6c\x4c\x6f\x63\x6b\x65\x64']=![];this['\x68\x69\x73\x74\x6f\x67\x72\x61\x6d']={};this['\x69\x64\x78\x72\x67\x62']=[];this['\x69\x64\x78\x69\x33\x32']=[];this['\x69\x33\x32\x69\x64\x78']={};this['\x69\x33\x32\x69\x33\x32']={};this['\x69\x33\x32\x72\x67\x62']={};}_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x73\x61\x6d\x70\x6c\x65']=function sample(_0x437be4,_0x231ae8){if(this['\x70\x61\x6c\x4c\x6f\x63\x6b\x65\x64'])throw'\x43\x61\x6e\x6e\x6f\x74\x20\x73\x61\x6d\x70\x6c\x65\x20\x61\x64\x64\x69\x74\x69\x6f\x6e\x61\x6c\x20\x69\x6d\x61\x67\x65\x73\x2c\x20\x70\x61\x6c\x65\x74\x74\x65\x20\x61\x6c\x72\x65\x61\x64\x79\x20\x61\x73\x73\x65\x6d\x62\x6c\x65\x64\x2e';var _0x5e507e=_0x54bd78(_0x437be4,_0x231ae8);switch(this['\x6d\x65\x74\x68\x6f\x64']){case 0x1:this['\x63\x6f\x6c\x6f\x72\x53\x74\x61\x74\x73\x31\x44'](_0x5e507e['\x62\x75\x66\x33\x32']);break;case 0x2:this['\x63\x6f\x6c\x6f\x72\x53\x74\x61\x74\x73\x32\x44'](_0x5e507e['\x62\x75\x66\x33\x32'],_0x5e507e['\x77\x69\x64\x74\x68']);break;}};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x72\x65\x64\x75\x63\x65']=function reduce(_0x218eee,_0x3c8c79){if(!this['\x70\x61\x6c\x4c\x6f\x63\x6b\x65\x64'])this['\x62\x75\x69\x6c\x64\x50\x61\x6c']();_0x3c8c79=_0x3c8c79||0x1;var _0x244bcd=_0x54bd78(_0x218eee),_0x407d9a=_0x244bcd['\x62\x75\x66\x33\x32'],_0x337ccb=_0x407d9a['\x6c\x65\x6e\x67\x74\x68'],_0x2f4684=_0x3c8c79==0x1?new Uint32Array(_0x337ccb):_0x3c8c79==0x2?new Array(_0x337ccb):null;for(var _0x4fe4f2=0x0;_0x4fe4f2<_0x337ccb;_0x4fe4f2++){var _0x5dec03=_0x407d9a[_0x4fe4f2];_0x2f4684[_0x4fe4f2]=_0x3c8c79==0x1?this['\x6e\x65\x61\x72\x65\x73\x74\x43\x6f\x6c\x6f\x72'](_0x5dec03):_0x3c8c79==0x2?this['\x6e\x65\x61\x72\x65\x73\x74\x49\x6e\x64\x65\x78'](_0x5dec03):null;}return _0x3c8c79==0x1?new Uint8Array(_0x2f4684['\x62\x75\x66\x66\x65\x72']):_0x3c8c79==0x2?_0x2f4684:null;};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x62\x75\x69\x6c\x64\x50\x61\x6c']=function buildPal(){if(this['\x70\x61\x6c\x4c\x6f\x63\x6b\x65\x64'])return;var _0x79beed=this['\x68\x69\x73\x74\x6f\x67\x72\x61\x6d'],_0x393b92=_0x578574(_0x79beed,!![]);if(_0x393b92['\x6c\x65\x6e\x67\x74\x68']==0x0)throw'\x4e\x6f\x74\x68\x69\x6e\x67\x20\x68\x61\x73\x20\x62\x65\x65\x6e\x20\x73\x61\x6d\x70\x6c\x65\x64\x2c\x20\x70\x61\x6c\x65\x74\x74\x65\x20\x63\x61\x6e\x6e\x6f\x74\x20\x62\x65\x20\x62\x75\x69\x6c\x74\x2e';switch(this['\x6d\x65\x74\x68\x6f\x64']){case 0x1:var _0x2f9334=this['\x69\x6e\x69\x74\x43\x6f\x6c\x6f\x72\x73'],_0x1fb00d=_0x393b92[_0x2f9334-0x1],_0x177a9d=_0x79beed[_0x1fb00d];var _0x115a96=_0x393b92['\x73\x6c\x69\x63\x65'](0x0,_0x2f9334);var _0x5a5557=_0x2f9334,_0x40da8f=_0x393b92['\x6c\x65\x6e\x67\x74\x68'];while(_0x5a5557<_0x40da8f&&_0x79beed[_0x393b92[_0x5a5557]]==_0x177a9d)_0x115a96['\x70\x75\x73\x68'](_0x393b92[_0x5a5557++]);if(this['\x68\x75\x65\x53\x74\x61\x74\x73'])this['\x68\x75\x65\x53\x74\x61\x74\x73']['\x69\x6e\x6a\x65\x63\x74'](_0x115a96);break;case 0x2:var _0x115a96=_0x393b92;break;}_0x115a96=_0x115a96['\x6d\x61\x70'](function(_0x411071){return+_0x411071;});this['\x72\x65\x64\x75\x63\x65\x50\x61\x6c'](_0x115a96);this['\x73\x6f\x72\x74\x50\x61\x6c']();this['\x70\x61\x6c\x4c\x6f\x63\x6b\x65\x64']=!![];};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x70\x61\x6c\x65\x74\x74\x65']=function palette(_0x5d1205){this['\x62\x75\x69\x6c\x64\x50\x61\x6c']();return _0x5d1205?this['\x69\x64\x78\x72\x67\x62']:new Uint8Array(new Uint32Array(this['\x69\x64\x78\x69\x33\x32'])['\x62\x75\x66\x66\x65\x72']);};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x72\x65\x64\x75\x63\x65\x50\x61\x6c']=function reducePal(_0x1e9063){var _0x527fd9=_0x1e9063['\x6d\x61\x70'](function(_0x230cfa){return[_0x230cfa&0xff,(_0x230cfa&0xff00)>>0x8,(_0x230cfa&0xff0000)>>0x10];});var _0x55eb75=_0x527fd9['\x6c\x65\x6e\x67\x74\x68'],_0x4f6472=_0x55eb75,_0x418c33={};thold=this['\x69\x6e\x69\x74\x44\x69\x73\x74'];if(_0x4f6472>this['\x63\x6f\x6c\x6f\x72\x73']){while(_0x4f6472>this['\x63\x6f\x6c\x6f\x72\x73']){var _0x2517b4=[];for(var _0x1cd043=0x0;_0x1cd043<_0x55eb75;_0x1cd043++){var _0x490b9d=_0x527fd9[_0x1cd043],_0x7ac611=_0x1e9063[_0x1cd043];if(!_0x490b9d)continue;for(var _0x424529=_0x1cd043+0x1;_0x424529<_0x55eb75;_0x424529++){var _0x35f5d3=_0x527fd9[_0x424529],_0x2309a0=_0x1e9063[_0x424529];if(!_0x35f5d3)continue;var _0x21b271=_0x5b551f(_0x490b9d,_0x35f5d3)*0x64;if(_0x21b271>0x18==0x0)continue;if(this['\x68\x75\x65\x53\x74\x61\x74\x73'])this['\x68\x75\x65\x53\x74\x61\x74\x73']['\x63\x68\x65\x63\x6b'](_0x1b7f79);if(_0x1b7f79 in _0x5eb595)_0x5eb595[_0x1b7f79]++;else _0x5eb595[_0x1b7f79]=0x1;}};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x63\x6f\x6c\x6f\x72\x53\x74\x61\x74\x73\x32\x44']=function colorStats2D(_0x833914,_0x552a3b){var _0x2d16e3=this['\x62\x6f\x78\x53\x69\x7a\x65'][0x0],_0x400952=this['\x62\x6f\x78\x53\x69\x7a\x65'][0x1],_0x641d95=_0x2d16e3*_0x400952,_0x4887ce=_0x405a7b(_0x552a3b,_0x833914['\x6c\x65\x6e\x67\x74\x68']/_0x552a3b,_0x2d16e3,_0x400952),_0x371bc7=this['\x68\x69\x73\x74\x6f\x67\x72\x61\x6d'],_0x44c6ce=this;_0x4887ce['\x66\x6f\x72\x45\x61\x63\x68'](function(_0x5c4a84){var _0x29082f=Math['\x6d\x61\x78'](Math['\x72\x6f\x75\x6e\x64'](_0x5c4a84['\x77']*_0x5c4a84['\x68']/_0x641d95)*_0x44c6ce['\x62\x6f\x78\x50\x78\x6c\x73'],0x2),_0x3f3f1c={},_0x41a5ec;_0x7afce0(_0x5c4a84,_0x552a3b,function(_0x32332b){_0x41a5ec=_0x833914[_0x32332b];if((_0x41a5ec&0xff000000)>>0x18==0x0)return;if(_0x44c6ce['\x68\x75\x65\x53\x74\x61\x74\x73'])_0x44c6ce['\x68\x75\x65\x53\x74\x61\x74\x73']['\x63\x68\x65\x63\x6b'](_0x41a5ec);if(_0x41a5ec in _0x371bc7)_0x371bc7[_0x41a5ec]++;else if(_0x41a5ec in _0x3f3f1c){if(++_0x3f3f1c[_0x41a5ec]>=_0x29082f)_0x371bc7[_0x41a5ec]=_0x3f3f1c[_0x41a5ec];}else _0x3f3f1c[_0x41a5ec]=0x1;});});if(this['\x68\x75\x65\x53\x74\x61\x74\x73'])this['\x68\x75\x65\x53\x74\x61\x74\x73']['\x69\x6e\x6a\x65\x63\x74'](_0x371bc7);};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x73\x6f\x72\x74\x50\x61\x6c']=function sortPal(){var _0x1a875b=this;this['\x69\x64\x78\x69\x33\x32']['\x73\x6f\x72\x74'](function(_0x207b21,_0x24f641){var _0x3ba669=_0x1a875b['\x69\x33\x32\x69\x64\x78'][_0x207b21],_0x392967=_0x1a875b['\x69\x33\x32\x69\x64\x78'][_0x24f641],_0x56b6c9=_0x1a875b['\x69\x64\x78\x72\x67\x62'][_0x3ba669],_0x4d4318=_0x1a875b['\x69\x64\x78\x72\x67\x62'][_0x392967];var _0x1e7476=_0x3ffe90(_0x56b6c9[0x0],_0x56b6c9[0x1],_0x56b6c9[0x2]),_0x36f595=_0x3ffe90(_0x4d4318[0x0],_0x4d4318[0x1],_0x4d4318[0x2]);var _0x33f104=_0x56b6c9[0x0]==_0x56b6c9[0x1]&&_0x56b6c9[0x1]==_0x56b6c9[0x2]?-0x1:_0x2e8671(_0x1e7476['\x68'],_0x1a875b['\x68\x75\x65\x47\x72\x6f\x75\x70\x73']);var _0x1279fc=_0x4d4318[0x0]==_0x4d4318[0x1]&&_0x4d4318[0x1]==_0x4d4318[0x2]?-0x1:_0x2e8671(_0x36f595['\x68'],_0x1a875b['\x68\x75\x65\x47\x72\x6f\x75\x70\x73']);var _0x2947f4=_0x1279fc-_0x33f104;if(_0x2947f4)return-_0x2947f4;var _0x298a02=_0x4266c4(+_0x36f595['\x6c']['\x74\x6f\x46\x69\x78\x65\x64'](0x2))-_0x4266c4(+_0x1e7476['\x6c']['\x74\x6f\x46\x69\x78\x65\x64'](0x2));if(_0x298a02)return-_0x298a02;var _0x1fce61=_0x326408(+_0x36f595['\x73']['\x74\x6f\x46\x69\x78\x65\x64'](0x2))-_0x326408(+_0x1e7476['\x73']['\x74\x6f\x46\x69\x78\x65\x64'](0x2));if(_0x1fce61)return-_0x1fce61;});this['\x69\x64\x78\x69\x33\x32']['\x66\x6f\x72\x45\x61\x63\x68'](function(_0x474a95,_0x44c5c3){_0x1a875b['\x69\x64\x78\x72\x67\x62'][_0x44c5c3]=_0x1a875b['\x69\x33\x32\x72\x67\x62'][_0x474a95];_0x1a875b['\x69\x33\x32\x69\x64\x78'][_0x474a95]=_0x44c5c3;});};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x6e\x65\x61\x72\x65\x73\x74\x43\x6f\x6c\x6f\x72']=function nearestColor(_0x17d140){var _0x5d6498=this['\x6e\x65\x61\x72\x65\x73\x74\x49\x6e\x64\x65\x78'](_0x17d140);return _0x5d6498===null?0x0:this['\x69\x64\x78\x69\x33\x32'][_0x5d6498];};_0x4db3ff['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x6e\x65\x61\x72\x65\x73\x74\x49\x6e\x64\x65\x78']=function nearestIndex(_0xb4dddc){if((_0xb4dddc&0xff000000)>>0x18==0x0)return null;var _0x4f471b=this['\x69\x33\x32\x69\x33\x32'][_0xb4dddc];if(_0x4f471b)return this['\x69\x33\x32\x69\x64\x78'][_0x4f471b];var _0x42580f=0x3e8,_0x540576,_0x33e966=[_0xb4dddc&0xff,(_0xb4dddc&0xff00)>>0x8,(_0xb4dddc&0xff0000)>>0x10],_0x4e6991=this['\x69\x64\x78\x72\x67\x62']['\x6c\x65\x6e\x67\x74\x68'];for(var _0x13251e=0x0;_0x13251e<_0x4e6991;_0x13251e++){var _0x9e245f=_0x5b551f(_0x33e966,this['\x69\x64\x78\x72\x67\x62'][_0x13251e]);if(_0x9e245f<_0x42580f){_0x42580f=_0x9e245f;_0x540576=_0x13251e;}}return _0x540576;};function _0x57203b(_0x288981,_0x61071a){this['\x6e\x75\x6d\x47\x72\x6f\x75\x70\x73']=_0x288981;this['\x6d\x69\x6e\x43\x6f\x6c\x73']=_0x61071a;this['\x73\x74\x61\x74\x73']={};for(var _0x4696e0=-0x1;_0x4696e0<_0x288981;_0x4696e0++)this['\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x33\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x34\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x36\x5c\x78\x33\x31\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x34\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x33'][_0x4696e0]={};this['\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x33\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x34\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x36\x5c\x78\x33\x31\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x34\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x33'][_0x4696e0]['\x6e\x75\x6d']=0x0;this['\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x33\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x34\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x36\x5c\x78\x33\x31\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x34\x5c\x78\x35\x63\x5c\x78\x37\x38\x5c\x78\x33\x37\x5c\x78\x33\x33'][_0x4696e0]['\x63\x6f\x6c\x73']=[];this['\x67\x72\x6f\x75\x70\x73\x46\x75\x6c\x6c']=0x0;}_0x57203b['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x63\x68\x65\x63\x6b']=function checkHue(_0x3adcba){if(this['\x67\x72\x6f\x75\x70\x73\x46\x75\x6c\x6c']==this['\x6e\x75\x6d\x47\x72\x6f\x75\x70\x73']+0x1)this['\x63\x68\x65\x63\x6b']=function(){return;};var _0x5021cc=_0x3adcba&0xff,_0xcee686=(_0x3adcba&0xff00)>>0x8,_0x3e07b1=(_0x3adcba&0xff0000)>>0x10,_0x5ab897=_0x5021cc==_0xcee686&&_0xcee686==_0x3e07b1?-0x1:_0x2e8671(_0x3ffe90(_0x5021cc,_0xcee686,_0x3e07b1)['\x68'],this['\x6e\x75\x6d\x47\x72\x6f\x75\x70\x73']),_0x3547cf=this['\x73\x74\x61\x74\x73'][_0x5ab897],_0x50965d=this['\x6d\x69\x6e\x43\x6f\x6c\x73'];_0x3547cf['\x6e\x75\x6d']++;if(_0x3547cf['\x6e\x75\x6d']>_0x50965d)return;if(_0x3547cf['\x6e\x75\x6d']==_0x50965d)this['\x67\x72\x6f\x75\x70\x73\x46\x75\x6c\x6c']++;if(_0x3547cf['\x6e\x75\x6d']<=_0x50965d)this['\x73\x74\x61\x74\x73'][_0x5ab897]['\x63\x6f\x6c\x73']['\x70\x75\x73\x68'](_0x3adcba);};_0x57203b['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x69\x6e\x6a\x65\x63\x74']=function injectHues(_0x28a858){for(var _0xedeeec=-0x1;_0xedeeec0.5?_0x53f1b6/(0x2-_0x11cf9e-_0x10cef3):_0x53f1b6/(_0x11cf9e+_0x10cef3);switch(_0x11cf9e){case _0x3c09c4:_0x2e53f4=(_0x10dccc-_0x4393c0)/_0x53f1b6+(_0x10dccc<_0x4393c0?0x6:0x0);break;case _0x10dccc:_0x2e53f4=(_0x4393c0-_0x3c09c4)/_0x53f1b6+0x2;break;case _0x4393c0:_0x2e53f4=(_0x3c09c4-_0x10dccc)/_0x53f1b6+0x4;break;}_0x2e53f4/=0x6;}return{'\x68':_0x2e53f4,'\x73':_0x22745e,'\x6c':_0x252a05(_0x3c09c4,_0x10dccc,_0x4393c0)};}function _0x2e8671(_0x56a8c6,_0x2cf08b){var _0x1a317b=0x1/_0x2cf08b,_0x55be05=_0x1a317b/0x2;if(_0x56a8c6>=0x1-_0x55be05||_0x56a8c6<=_0x55be05)return 0x0;for(var _0x3181e4=0x1;_0x3181e4<_0x2cf08b;_0x3181e4++){var _0x352b80=_0x3181e4*_0x1a317b;if(_0x56a8c6>=_0x352b80-_0x55be05&&_0x56a8c6<=_0x352b80+_0x55be05)return _0x3181e4;}}function _0x326408(_0x10d287){return _0x10d287;}function _0x4266c4(_0x4700e9){return _0x4700e9;}function _0x4e9995(_0x2bf5c7){return Object['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x74\x6f\x53\x74\x72\x69\x6e\x67']['\x63\x61\x6c\x6c'](_0x2bf5c7)['\x73\x6c\x69\x63\x65'](0x8,-0x1);}var _0x23a0e7=_0x1e2e31()?Array['\x70\x72\x6f\x74\x6f\x74\x79\x70\x65']['\x73\x6f\x72\x74']:_0x2aa31f;function _0x2aa31f(_0x338e77){var _0x1adbaa=_0x4e9995(this[0x0]);if(_0x1adbaa=='\x4e\x75\x6d\x62\x65\x72'||_0x1adbaa=='\x53\x74\x72\x69\x6e\x67'){var _0x405e1e={},_0x12d561=this['\x6c\x65\x6e\x67\x74\x68'],_0x3b908a;for(var _0x13cfc8=0x0;_0x13cfc8<_0x12d561;_0x13cfc8++){_0x3b908a=this[_0x13cfc8];if(_0x405e1e[_0x3b908a]||_0x405e1e[_0x3b908a]===0x0)continue;_0x405e1e[_0x3b908a]=_0x13cfc8;}return this['\x73\x6f\x72\x74'](function(_0xa9d1f5,_0x13eaf6){return _0x338e77(_0xa9d1f5,_0x13eaf6)||_0x405e1e[_0xa9d1f5]-_0x405e1e[_0x13eaf6];});}else{var _0x405e1e=this['\x6d\x61\x70'](function(_0x406225){return _0x406225;});return this['\x73\x6f\x72\x74'](function(_0x1e9342,_0x506bae){return _0x338e77(_0x1e9342,_0x506bae)||_0x405e1e['\x69\x6e\x64\x65\x78\x4f\x66'](_0x1e9342)-_0x405e1e['\x69\x6e\x64\x65\x78\x4f\x66'](_0x506bae);});}}function _0x1e2e31(){var _0x551a35='\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a';return'\x78\x79\x7a\x76\x77\x74\x75\x72\x73\x6f\x70\x71\x6d\x6e\x6b\x6c\x68\x69\x6a\x66\x67\x64\x65\x61\x62\x63'==_0x551a35['\x73\x70\x6c\x69\x74']('')['\x73\x6f\x72\x74'](function(_0x176d7a,_0x18f158){return~~(_0x551a35['\x69\x6e\x64\x65\x78\x4f\x66'](_0x18f158)/2.3)-~~(_0x551a35['\x69\x6e\x64\x65\x78\x4f\x66'](_0x176d7a)/2.3);})['\x6a\x6f\x69\x6e']('');}function _0x54bd78(_0x2b5918,_0x43c1cf){var _0x1961b8,_0x52c2e2,_0x2d90c1,_0x42133d,_0x1dd272,_0x4687ea;switch(_0x4e9995(_0x2b5918)){case'\x48\x54\x4d\x4c\x49\x6d\x61\x67\x65\x45\x6c\x65\x6d\x65\x6e\x74':_0x1961b8=document['\x63\x72\x65\x61\x74\x65\x45\x6c\x65\x6d\x65\x6e\x74']('\x63\x61\x6e\x76\x61\x73');_0x1961b8['\x77\x69\x64\x74\x68']=_0x2b5918['\x6e\x61\x74\x75\x72\x61\x6c\x57\x69\x64\x74\x68'];_0x1961b8['\x68\x65\x69\x67\x68\x74']=_0x2b5918['\x6e\x61\x74\x75\x72\x61\x6c\x48\x65\x69\x67\x68\x74'];_0x52c2e2=_0x1961b8['\x67\x65\x74\x43\x6f\x6e\x74\x65\x78\x74']('\x32\x64');_0x52c2e2['\x64\x72\x61\x77\x49\x6d\x61\x67\x65'](_0x2b5918,0x0,0x0);case'\x48\x54\x4d\x4c\x43\x61\x6e\x76\x61\x73\x45\x6c\x65\x6d\x65\x6e\x74':_0x1961b8=_0x1961b8||_0x2b5918;_0x52c2e2=_0x52c2e2||_0x1961b8['\x67\x65\x74\x43\x6f\x6e\x74\x65\x78\x74']('\x32\x64');case'\x43\x61\x6e\x76\x61\x73\x52\x65\x6e\x64\x65\x72\x69\x6e\x67\x43\x6f\x6e\x74\x65\x78\x74\x32\x44':_0x52c2e2=_0x52c2e2||_0x2b5918;_0x1961b8=_0x1961b8||_0x52c2e2['\x63\x61\x6e\x76\x61\x73'];_0x2d90c1=_0x52c2e2['\x67\x65\x74\x49\x6d\x61\x67\x65\x44\x61\x74\x61'](0x0,0x0,_0x1961b8['\x77\x69\x64\x74\x68'],_0x1961b8['\x68\x65\x69\x67\x68\x74']);case'\x49\x6d\x61\x67\x65\x44\x61\x74\x61':_0x2d90c1=_0x2d90c1||_0x2b5918;_0x42133d=_0x2d90c1['\x64\x61\x74\x61'];_0x43c1cf=_0x2d90c1['\x77\x69\x64\x74\x68'];case'\x41\x72\x72\x61\x79':_0x42133d=_0x42133d||new Uint8Array(_0x2b5918);case'\x55\x69\x6e\x74\x38\x41\x72\x72\x61\x79':case'\x55\x69\x6e\x74\x38\x43\x6c\x61\x6d\x70\x65\x64\x41\x72\x72\x61\x79':_0x42133d=_0x42133d||_0x2b5918;_0x1dd272=new Uint32Array(_0x42133d['\x62\x75\x66\x66\x65\x72']);case'\x55\x69\x6e\x74\x33\x32\x41\x72\x72\x61\x79':_0x1dd272=_0x1dd272||_0x2b5918;_0x42133d=_0x42133d||new Uint8Array(_0x1dd272['\x62\x75\x66\x66\x65\x72']);_0x43c1cf=_0x43c1cf||_0x1dd272['\x6c\x65\x6e\x67\x74\x68'];_0x4687ea=_0x1dd272['\x6c\x65\x6e\x67\x74\x68']/_0x43c1cf;}return{'\x63\x61\x6e':_0x1961b8,'\x63\x74\x78':_0x52c2e2,'\x69\x6d\x67\x64':_0x2d90c1,'\x62\x75\x66\x38':_0x42133d,'\x62\x75\x66\x33\x32':_0x1dd272,'\x77\x69\x64\x74\x68':_0x43c1cf,'\x68\x65\x69\x67\x68\x74':_0x4687ea};}function _0x405a7b(_0x533f08,_0x1f6e4d,_0x347e61,_0x565984){var _0x1ff064=~~(_0x533f08/_0x347e61),_0x54f466=_0x533f08%_0x347e61,_0x447bce=~~(_0x1f6e4d/_0x565984),_0x5285f2=_0x1f6e4d%_0x565984,_0x544229=_0x533f08-_0x54f466,_0x3ce3a5=_0x1f6e4d-_0x5285f2;var _0x156971=[];for(var _0x2f93d9=0x0;_0x2f93d9<_0x1f6e4d;_0x2f93d9+=_0x565984)for(var _0x47c024=0x0;_0x47c024<_0x533f08;_0x47c024+=_0x347e61)_0x156971['\x70\x75\x73\x68']({'\x78':_0x47c024,'\x79':_0x2f93d9,'\x77':_0x47c024==_0x544229?_0x54f466:_0x347e61,'\x68':_0x2f93d9==_0x3ce3a5?_0x5285f2:_0x565984});return _0x156971;}function _0x7afce0(_0x5f16c7,_0x51c213,_0x2770a6){var _0x2a0003=_0x5f16c7,_0x31b9f8=_0x2a0003['\x79']*_0x51c213+_0x2a0003['\x78'],_0x3222b6=(_0x2a0003['\x79']+_0x2a0003['\x68']-0x1)*_0x51c213+(_0x2a0003['\x78']+_0x2a0003['\x77']-0x1),_0xcfcc49=0x0,_0x345337=_0x51c213-_0x2a0003['\x77']+0x1,_0x34c4cb=_0x31b9f8;do{_0x2770a6['\x63\x61\x6c\x6c'](this,_0x34c4cb);_0x34c4cb+=++_0xcfcc49%_0x2a0003['\x77']==0x0?_0x345337:0x1;}while(_0x34c4cb<=_0x3222b6);}function _0x578574(_0x5c678d,_0x1a4a9b){var _0x42c95f=[];for(var _0x9425f6 in _0x5c678d)_0x42c95f['\x70\x75\x73\x68'](_0x9425f6);return _0x23a0e7['\x63\x61\x6c\x6c'](_0x42c95f,function(_0x525135,_0x962967){return _0x1a4a9b?_0x5c678d[_0x962967]-_0x5c678d[_0x525135]:_0x5c678d[_0x525135]-_0x5c678d[_0x962967];});}this['\x52\x67\x62\x51\x75\x61\x6e\x74']=_0x4db3ff;}['\x63\x61\x6c\x6c'](this)); \ No newline at end of file diff --git a/public/convert.html b/public/convert.html new file mode 100644 index 0000000..261e40a --- /dev/null +++ b/public/convert.html @@ -0,0 +1,41 @@ + + + + + + PixelPlace.fun - Image Converter + + + + + + + + + Select your image:
+ Conversion Strategy: +
+ Github Reference!
+
+ Converted image
+ + diff --git a/public/convert2.html b/public/convert2.html new file mode 100644 index 0000000..87da279 --- /dev/null +++ b/public/convert2.html @@ -0,0 +1,41 @@ + + + + + + PixelPlace.fun - Image Converter + + + + + + + + + Select your image:
+ Conversion Strategy: +
+ Github Reference!
+
+ Converted image
+ + diff --git a/public/discordlogo.svg b/public/discordlogo.svg new file mode 100644 index 0000000..65c9fcc --- /dev/null +++ b/public/discordlogo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/facebooklogo.svg b/public/facebooklogo.svg new file mode 100644 index 0000000..e19a18f --- /dev/null +++ b/public/facebooklogo.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e1e57db Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/go/Detector.js b/public/go/Detector.js new file mode 100644 index 0000000..315f8ed --- /dev/null +++ b/public/go/Detector.js @@ -0,0 +1,40 @@ +/** + * @author alteredq / http://alteredqualia.com/ + * @author mr.doob / http://mrdoob.com/ + */ + +var Detector = { + + canvas: !! window.CanvasRenderingContext2D, + webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(), + workers: !! window.Worker, + fileapi: window.File && window.FileReader && window.FileList && window.Blob, + + getWebGLErrorMessage: function () { + + var element = document.createElement( 'div' ); + element.className = 'webgl-error'; + + if ( !this.webgl ) { + + element.innerHTML = window.WebGLRenderingContext ? [ + 'Your graphics card does not seem to support WebGL.
', + 'Find out how to get it here.' + ].join( '\n' ) : [ + 'Your browser does not seem to support WebGL.
', + 'Find out how to get it here.' + ].join( '\n' ); + + } + + return element; + + }, + + addGetWebGLMessage: function (parent ) { + + parent.appendChild( Detector.getWebGLErrorMessage() ); + + } + +}; \ No newline at end of file diff --git a/public/go/TrackballControls.js b/public/go/TrackballControls.js new file mode 100644 index 0000000..c1fa60d --- /dev/null +++ b/public/go/TrackballControls.js @@ -0,0 +1,537 @@ +/** + * @author Eberhard Graether / http://egraether.com/ + */ + +THREE.TrackballControls = function ( object, domElement ) { + + var _this = this; + var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM: 4, TOUCH_PAN: 5 }; + + this.object = object; + this.domElement = ( domElement !== undefined ) ? domElement : document; + + // API + + this.enabled = true; + + this.screen = { width: 0, height: 0, offsetLeft: 0, offsetTop: 0 }; + this.radius = ( this.screen.width + this.screen.height ) / 4; + + this.rotateSpeed = 1.0; + this.zoomSpeed = 1.2; + this.panSpeed = 0.3; + + this.noRotate = false; + this.noZoom = false; + this.noPan = false; + + this.staticMoving = false; + this.dynamicDampingFactor = 0.2; + + this.minDistance = 1.6; + this.maxDistance = 118.32; + + this.keys = [ 65 /*A*/, 83 /*S*/, 68 /*D*/ ]; + + // internals + + this.target = new THREE.Vector3(); + + var lastPosition = new THREE.Vector3(); + + var _state = STATE.NONE, + _prevState = STATE.NONE, + + _eye = new THREE.Vector3(), + + _rotateStart = new THREE.Vector3(), + _rotateEnd = new THREE.Vector3(), + + _zoomStart = new THREE.Vector2(), + _zoomEnd = new THREE.Vector2(), + + _touchZoomDistanceStart = 0, + _touchZoomDistanceEnd = 0, + + _panStart = new THREE.Vector2(), + _panEnd = new THREE.Vector2(); + + // for reset + + this.target0 = this.target.clone(); + this.position0 = this.object.position.clone(); + this.up0 = this.object.up.clone(); + + // events + + var changeEvent = { type: 'change' }; + + + // methods + + this.handleResize = function () { + + this.screen.width = window.innerWidth; + this.screen.height = window.innerHeight; + + this.screen.offsetLeft = 0; + this.screen.offsetTop = 0; + + this.radius = ( this.screen.width + this.screen.height ) / 4; + + }; + + this.handleEvent = function ( event ) { + + if ( typeof this[ event.type ] == 'function' ) { + + this[ event.type ]( event ); + + } + + }; + + this.getMouseOnScreen = function ( clientX, clientY ) { + + return new THREE.Vector2( + ( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5, + ( clientY - _this.screen.offsetTop ) / _this.radius * 0.5 + ); + + }; + + this.getMouseProjectionOnBall = function ( clientX, clientY ) { + + var mouseOnBall = new THREE.Vector3( + ( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius, + ( _this.screen.height * 0.5 + _this.screen.offsetTop - clientY ) / _this.radius, + 0.0 + ); + + var length = mouseOnBall.length(); + + if ( length > 1.0 ) { + + mouseOnBall.normalize(); + + } else { + + mouseOnBall.z = Math.sqrt( 1.0 - length * length ); + + } + + _eye.copy( _this.object.position ).sub( _this.target ); + + var projection = _this.object.up.clone().setLength( mouseOnBall.y ); + projection.add( _this.object.up.clone().cross( _eye ).setLength( mouseOnBall.x ) ); + projection.add( _eye.setLength( mouseOnBall.z ) ); + + return projection; + + }; + + this.rotateCamera = function () { + + var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() ); + + if ( angle ) { + + var axis = ( new THREE.Vector3() ).crossVectors( _rotateStart, _rotateEnd ).normalize(); + quaternion = new THREE.Quaternion(); + + angle *= _this.rotateSpeed; + + quaternion.setFromAxisAngle( axis, -angle ); + + _eye.applyQuaternion( quaternion ); + _this.object.up.applyQuaternion( quaternion ); + + _rotateEnd.applyQuaternion( quaternion ); + + if ( _this.staticMoving ) { + + _rotateStart.copy( _rotateEnd ); + + } else { + + quaternion.setFromAxisAngle( axis, angle * ( _this.dynamicDampingFactor - 1.0 ) ); + _rotateStart.applyQuaternion( quaternion ); + + } + + } + + }; + + this.zoomCamera = function () { + + if ( _state === STATE.TOUCH_ZOOM ) { + + var factor = _touchZoomDistanceStart / _touchZoomDistanceEnd; + _touchZoomDistanceStart = _touchZoomDistanceEnd; + _eye.multiplyScalar( factor ); + + } else { + + var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed; + + if ( factor !== 1.0 && factor > 0.0 ) { + + _eye.multiplyScalar( factor ); + + if ( _this.staticMoving ) { + + _zoomStart.copy( _zoomEnd ); + + } else { + + _zoomStart.y += ( _zoomEnd.y - _zoomStart.y ) * this.dynamicDampingFactor; + + } + + } + + } + + }; + + this.panCamera = function () { + + var mouseChange = _panEnd.clone().sub( _panStart ); + + if ( mouseChange.lengthSq() ) { + + mouseChange.multiplyScalar( _eye.length() * _this.panSpeed ); + + var pan = _eye.clone().cross( _this.object.up ).setLength( mouseChange.x ); + pan.add( _this.object.up.clone().setLength( mouseChange.y ) ); + + _this.object.position.add( pan ); + _this.target.add( pan ); + + if ( _this.staticMoving ) { + + _panStart = _panEnd; + + } else { + + _panStart.add( mouseChange.subVectors( _panEnd, _panStart ).multiplyScalar( _this.dynamicDampingFactor ) ); + + } + + } + + }; + + this.checkDistances = function () { + + if ( !_this.noZoom || !_this.noPan ) { + + if ( _this.object.position.lengthSq() > _this.maxDistance * _this.maxDistance ) { + + _this.object.position.setLength( _this.maxDistance ); + + } + + if ( _eye.lengthSq() < _this.minDistance * _this.minDistance ) { + + _this.object.position.addVectors( _this.target, _eye.setLength( _this.minDistance ) ); + + } + + } + + }; + + this.update = function () { + + _eye.subVectors( _this.object.position, _this.target ); + + if ( !_this.noRotate ) { + + _this.rotateCamera(); + + } + + if ( !_this.noZoom ) { + + _this.zoomCamera(); + + } + + if ( !_this.noPan ) { + + _this.panCamera(); + + } + + _this.object.position.addVectors( _this.target, _eye ); + + _this.checkDistances(); + + _this.object.lookAt( _this.target ); + + if ( lastPosition.distanceToSquared( _this.object.position ) > 0 ) { + + _this.dispatchEvent( changeEvent ); + + lastPosition.copy( _this.object.position ); + + } + + }; + + this.reset = function () { + + _state = STATE.NONE; + _prevState = STATE.NONE; + + _this.target.copy( _this.target0 ); + _this.object.position.copy( _this.position0 ); + _this.object.up.copy( _this.up0 ); + + _eye.subVectors( _this.object.position, _this.target ); + + _this.object.lookAt( _this.target ); + + _this.dispatchEvent( changeEvent ); + + lastPosition.copy( _this.object.position ); + + }; + + // listeners + + function keydown( event ) { + + if ( _this.enabled === false ) return; + + window.removeEventListener( 'keydown', keydown ); + + _prevState = _state; + + if ( _state !== STATE.NONE ) { + + return; + + } else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) { + + _state = STATE.ROTATE; + + } else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) { + + _state = STATE.ZOOM; + + } else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) { + + _state = STATE.PAN; + + } + + } + + function keyup( event ) { + + if ( _this.enabled === false ) return; + + _state = _prevState; + + window.addEventListener( 'keydown', keydown, false ); + + } + + function mousedown( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + if ( _state === STATE.NONE ) { + + _state = event.button; + + } + + if ( _state === STATE.ROTATE && !_this.noRotate ) { + + _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY ); + + } else if ( _state === STATE.ZOOM && !_this.noZoom ) { + + _zoomStart = _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } else if ( _state === STATE.PAN && !_this.noPan ) { + + _panStart = _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } + + document.addEventListener( 'mousemove', mousemove, false ); + document.addEventListener( 'mouseup', mouseup, false ); + + } + + function mousemove( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + if ( _state === STATE.ROTATE && !_this.noRotate ) { + + _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY ); + + } else if ( _state === STATE.ZOOM && !_this.noZoom ) { + + _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } else if ( _state === STATE.PAN && !_this.noPan ) { + + _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } + + } + + function mouseup( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + _state = STATE.NONE; + + document.removeEventListener( 'mousemove', mousemove ); + document.removeEventListener( 'mouseup', mouseup ); + + } + + function mousewheel( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + var delta = 0; + + if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9 + + delta = event.wheelDelta / 40; + + } else if ( event.detail ) { // Firefox + + delta = - event.detail / 3; + + } + + _zoomStart.y += delta * 0.01; + + } + + function touchstart( event ) { + + if ( _this.enabled === false ) return; + + switch ( event.touches.length ) { + + case 1: + _state = STATE.TOUCH_ROTATE; + _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: + _state = STATE.TOUCH_ZOOM; + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + _touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt( dx * dx + dy * dy ); + break; + + case 3: + _state = STATE.TOUCH_PAN; + _panStart = _panEnd = _this.getMouseOnScreen( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + default: + _state = STATE.NONE; + + } + + } + + function touchmove( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + switch ( event.touches.length ) { + + case 1: + _rotateEnd = _this.getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + _touchZoomDistanceEnd = Math.sqrt( dx * dx + dy * dy ) + break; + + case 3: + _panEnd = _this.getMouseOnScreen( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + default: + _state = STATE.NONE; + + } + + } + + function touchend( event ) { + + if ( _this.enabled === false ) return; + + switch ( event.touches.length ) { + + case 1: + _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: + _touchZoomDistanceStart = _touchZoomDistanceEnd = 0; + break; + + case 3: + _panStart = _panEnd = _this.getMouseOnScreen( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + } + + _state = STATE.NONE; + + } + + this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false ); + + this.domElement.addEventListener( 'mousedown', mousedown, false ); + + this.domElement.addEventListener( 'mousewheel', mousewheel, false ); + this.domElement.addEventListener( 'DOMMouseScroll', mousewheel, false ); // firefox + + this.domElement.addEventListener( 'touchstart', touchstart, false ); + this.domElement.addEventListener( 'touchend', touchend, false ); + this.domElement.addEventListener( 'touchmove', touchmove, false ); + + window.addEventListener( 'keydown', keydown, false ); + window.addEventListener( 'keyup', keyup, false ); + + this.handleResize(); + +}; + +THREE.TrackballControls.prototype = Object.create( THREE.EventDispatcher.prototype ); diff --git a/public/go/clouds.png b/public/go/clouds.png new file mode 100644 index 0000000..528ca99 Binary files /dev/null and b/public/go/clouds.png differ diff --git a/public/go/globe.glb b/public/go/globe.glb new file mode 100644 index 0000000..d86553c Binary files /dev/null and b/public/go/globe.glb differ diff --git a/public/go/index.html b/public/go/index.html new file mode 100644 index 0000000..e22852f --- /dev/null +++ b/public/go/index.html @@ -0,0 +1,26 @@ + + + + + + PixelPlanet.fun + + + +
+
(0, 0)
+
Double click on globe to go back.
+ + + + + + + diff --git a/public/go/normal.jpg b/public/go/normal.jpg new file mode 100644 index 0000000..f049bc5 Binary files /dev/null and b/public/go/normal.jpg differ diff --git a/public/go/normalm.jpg b/public/go/normalm.jpg new file mode 100644 index 0000000..70e14c4 Binary files /dev/null and b/public/go/normalm.jpg differ diff --git a/public/go/space.js b/public/go/space.js new file mode 100644 index 0000000..2ebde19 --- /dev/null +++ b/public/go/space.js @@ -0,0 +1,178 @@ +(function () { + function checkMaterial(object) { + if (object.material) { + const materialName = object.material.name; + if (materialName == "canvas") { + console.log("Found material"); + object.material = canvasTexture; + return true; + } + } + return false; + } + + function parseHashCoords() { + try { + const hash = window.location.hash; + const array = hash.substring(1).split(','); + const ident = array.shift(); + const [id, size, x, y] = array.map((z) => parseInt(z)); + if (!ident || isNaN(x) || isNaN(y) || isNaN(id) || isNaN(size)) { + throw "NaN"; + } + return [ident, id, size, x, y]; + } catch (error) { + return ['d', 0, 65536, 0, 0]; + }; + } + + function rotateToCoords(canvasSize, object, coords) { + console.log("Rotate to", coords); + const [x, y] = coords; + const rotOffsetX = 0; + const rotOffsetY = 3 * Math.PI / 2; + const rotX = -y * Math.PI / canvasSize; + const rotY = -x * 2 * Math.PI / canvasSize; + object.rotation.x += rotOffsetX + rotX; + object.rotation.y += rotOffsetY + rotY; + } + + var webglEl = document.getElementById('webgl'); + + if (!Detector.webgl) { + Detector.addGetWebGLMessage(webglEl); + return; + } + + const [canvasIdent, canvasId, canvasSize, x, y] = parseHashCoords(); + + const canvasTexture = new THREE.MeshPhongMaterial({ + map: new THREE.TextureLoader().load(`../tiles/${canvasId}/texture.png`), + bumpMap: new THREE.TextureLoader().load((canvasId == 0) ? 'normal.jpg' : 'normalm.jpg'), + bumpScale: 0.02, + specularMap: new THREE.TextureLoader().load((canvasId == 0) ? 'specular.jpg' : 'specularm.jpg'), + specular: new THREE.Color('grey') + }); + + var width = window.innerWidth, + height = window.innerHeight; + + var scene = new THREE.Scene(); + + var camera = new THREE.PerspectiveCamera(45, width / height, 0.01, 1000); + camera.position.z = 4.0; + + var renderer = new THREE.WebGLRenderer(); + renderer.setSize(width, height); + + scene.add(new THREE.AmbientLight(0x333333)); + + var light = new THREE.DirectionalLight(0xffffff, 0.7); + light.position.set(10,6,10); + scene.add(light); + + var object = null; + var loader = new THREE.GLTFLoader(); + loader.load('globe.glb', function (glb) { + scene.add(glb.scene); + const children = glb.scene.children; + for (let cnt = 0; cnt < children.length; cnt++) { + //children[cnt].scale.x *= -1; + //children[cnt].scale.y *= -1; + if (checkMaterial(children[cnt])) + object = children[cnt]; + const grandchildren = children[cnt].children; + for (let xnt = 0; xnt < grandchildren.length; xnt++) { + if (checkMaterial(grandchildren[xnt])) + object = children[cnt]; + //children[cnt].material.side = THREE.DoubleSide; + } + } + rotateToCoords(canvasSize, object, [x, y]); + }, function (xhr) {console.log((xhr.loaded / xhr.total * 100) + '% loaded'); + }, function (error) {console.log('An error happened', error); + }); + + + // Earth params + var radius = 0.5, + segments = 32, + rotation = 6; + + + var stars = createStars(90, 64); + scene.add(stars); + + var controls = new THREE.TrackballControls(camera); + + webglEl.appendChild(renderer.domElement); + + render(); + + function render() { + controls.update(); + if (object) object.rotation.y += 0.0005; + requestAnimationFrame(render); + renderer.render(scene, camera); + } + + function createStars(radius, segments) { + return new THREE.Mesh( + new THREE.SphereGeometry(radius, segments, segments), + new THREE.MeshBasicMaterial({ + map: THREE.ImageUtils.loadTexture('starfield.png'), + side: THREE.BackSide + }) + ); + } + + setInterval(onDocumentMouseMove, 1000); + + var raycaster = new THREE.Raycaster(); + var mouse = new THREE.Vector2(); + var lastView = [0, 0]; + const coorbox = document.getElementById("coorbox"); + function onDocumentMouseMove(event) { + if (event) { + mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; + mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; + } else { + mouse.x = 0.0; + mouse.y = 0.0; + } + + raycaster.setFromCamera( mouse, camera ); + var intersects = raycaster.intersectObject( object ); + + const elem = document.getElementsByTagName("BODY")[0]; + if(intersects.length > 0) { + const { x, y } = intersects[0].uv; + const xabs = Math.floor((x - 0.5) * canvasSize); + const yabs = Math.floor((0.5 - y) * canvasSize); + //console.log(`On ${xabs} / ${yabs} cam: ${camera.position.z}`); + coorbox.innerHTML = `(${xabs}, ${yabs})`; + elem.style.cursor = 'move'; + } else { + elem.style.cursor = 'default'; + } + } + + function onDocumentDblClick(event) { + mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; + mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; + + raycaster.setFromCamera( mouse, camera ); + var intersects = raycaster.intersectObject( object ); + + if(intersects.length > 0) { + const { x, y } = intersects[0].uv; + const xabs = Math.round((x - 0.5) * canvasSize); + const yabs = Math.round((0.5 - y) * canvasSize); + window.location.href = `../#${canvasIdent},${xabs},${yabs},0`; + } + } + + document.addEventListener('mousemove', onDocumentMouseMove, false); + document.addEventListener('dblclick', onDocumentDblClick, false); + +}()); diff --git a/public/go/specular.jpg b/public/go/specular.jpg new file mode 100644 index 0000000..db881ef Binary files /dev/null and b/public/go/specular.jpg differ diff --git a/public/go/specularm.jpg b/public/go/specularm.jpg new file mode 100644 index 0000000..cc779dc Binary files /dev/null and b/public/go/specularm.jpg differ diff --git a/public/go/starfield.png b/public/go/starfield.png new file mode 100644 index 0000000..67d808a Binary files /dev/null and b/public/go/starfield.png differ diff --git a/public/go/texture.png b/public/go/texture.png new file mode 100644 index 0000000..e604fff Binary files /dev/null and b/public/go/texture.png differ diff --git a/public/googlelogo.svg b/public/googlelogo.svg new file mode 100644 index 0000000..b518c52 --- /dev/null +++ b/public/googlelogo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/loading.png b/public/loading.png new file mode 100644 index 0000000..d9b8332 Binary files /dev/null and b/public/loading.png differ diff --git a/public/palette0.gpl b/public/palette0.gpl new file mode 100644 index 0000000..b5f2d6a --- /dev/null +++ b/public/palette0.gpl @@ -0,0 +1,34 @@ +GIMP Palette +Name: Pixelplanet +Columns: 0 +# +255 255 255 White +228 228 228 Light Gray +136 136 136 Dark Gray + 78 78 78 Darker Gray + 0 0 0 Black +244 179 174 Skin +255 167 209 Light Pink +255 84 178 Pink +255 101 101 Peach +229 0 0 Red +154 0 0 Dark Red +254 164 96 Light Brown +229 149 0 Orange +160 106 66 Unbenannt +245 223 176 Unbenannt +229 217 0 Unbenannt +148 224 68 Unbenannt + 2 190 1 Unbenannt + 0 101 19 Unbenannt +202 227 255 Unbenannt + 0 211 221 Unbenannt + 0 131 199 Unbenannt + 0 0 234 Unbenannt + 25 25 115 Unbenannt +207 110 228 Unbenannt +130 0 128 Unbenannt +196 196 196 Silver +96 64 40 Dark Brown +255 248 137 Khaki +104 131 56 Olive diff --git a/public/palette1.gpl b/public/palette1.gpl new file mode 100644 index 0000000..bdbe8b6 --- /dev/null +++ b/public/palette1.gpl @@ -0,0 +1,34 @@ +GIMP Palette +Name: Greenstar30 +#Description: Created by starhouse for their game CrescentWhole. Based off MortMort's SoftMilk32 palette. Used on pixelplanet with 2 colors removed +#Colors: 32 +49 46 47 #312e2f +99 92 90 #635c5a +129 119 107 #81776b +198 181 165 #c6b5a5 +255 237 212 #ffedd4 +150 86 122 #96567a +202 112 145 #ca7091 +96 67 79 #60434f +136 79 94 #884f5e +175 101 103 #af6567 +195 124 107 #c37c6b +221 153 126 #dd997e +233 181 140 #e9b58c +198 139 91 #c68b5b +140 89 74 #8c594a +94 68 63 #5e443f +225 173 86 #e1ad56 +248 207 142 #f8cf8e +239 220 118 #efdc76 +206 190 85 #cebe55 +157 159 55 #9d9f37 +114 121 43 #72792b +81 94 46 #515e2e +69 100 79 #45644f +80 134 87 #508657 +187 209 138 #bbd18a +91 84 108 #5b546c +106 113 137 #6a7189 +122 148 156 #7a949c +174 215 185 #aed7b9 diff --git a/public/redditlogo.svg b/public/redditlogo.svg new file mode 100644 index 0000000..d250320 --- /dev/null +++ b/public/redditlogo.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/tile-wide.png b/public/tile-wide.png new file mode 100644 index 0000000..828e75c Binary files /dev/null and b/public/tile-wide.png differ diff --git a/public/tile.png b/public/tile.png new file mode 100644 index 0000000..06c4c83 Binary files /dev/null and b/public/tile.png differ diff --git a/public/turtle/Detector.js b/public/turtle/Detector.js new file mode 100644 index 0000000..315f8ed --- /dev/null +++ b/public/turtle/Detector.js @@ -0,0 +1,40 @@ +/** + * @author alteredq / http://alteredqualia.com/ + * @author mr.doob / http://mrdoob.com/ + */ + +var Detector = { + + canvas: !! window.CanvasRenderingContext2D, + webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(), + workers: !! window.Worker, + fileapi: window.File && window.FileReader && window.FileList && window.Blob, + + getWebGLErrorMessage: function () { + + var element = document.createElement( 'div' ); + element.className = 'webgl-error'; + + if ( !this.webgl ) { + + element.innerHTML = window.WebGLRenderingContext ? [ + 'Your graphics card does not seem to support WebGL.
', + 'Find out how to get it here.' + ].join( '\n' ) : [ + 'Your browser does not seem to support WebGL.
', + 'Find out how to get it here.' + ].join( '\n' ); + + } + + return element; + + }, + + addGetWebGLMessage: function (parent ) { + + parent.appendChild( Detector.getWebGLErrorMessage() ); + + } + +}; \ No newline at end of file diff --git a/public/turtle/TrackballControls.js b/public/turtle/TrackballControls.js new file mode 100644 index 0000000..103b4a5 --- /dev/null +++ b/public/turtle/TrackballControls.js @@ -0,0 +1,537 @@ +/** + * @author Eberhard Graether / http://egraether.com/ + */ + +THREE.TrackballControls = function ( object, domElement ) { + + var _this = this; + var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM: 4, TOUCH_PAN: 5 }; + + this.object = object; + this.domElement = ( domElement !== undefined ) ? domElement : document; + + // API + + this.enabled = true; + + this.screen = { width: 0, height: 0, offsetLeft: 0, offsetTop: 0 }; + this.radius = ( this.screen.width + this.screen.height ) / 4; + + this.rotateSpeed = 1.0; + this.zoomSpeed = 1.2; + this.panSpeed = 0.3; + + this.noRotate = false; + this.noZoom = false; + this.noPan = false; + + this.staticMoving = false; + this.dynamicDampingFactor = 0.2; + + this.minDistance = 0; + this.maxDistance = Infinity; + + this.keys = [ 65 /*A*/, 83 /*S*/, 68 /*D*/ ]; + + // internals + + this.target = new THREE.Vector3(); + + var lastPosition = new THREE.Vector3(); + + var _state = STATE.NONE, + _prevState = STATE.NONE, + + _eye = new THREE.Vector3(), + + _rotateStart = new THREE.Vector3(), + _rotateEnd = new THREE.Vector3(), + + _zoomStart = new THREE.Vector2(), + _zoomEnd = new THREE.Vector2(), + + _touchZoomDistanceStart = 0, + _touchZoomDistanceEnd = 0, + + _panStart = new THREE.Vector2(), + _panEnd = new THREE.Vector2(); + + // for reset + + this.target0 = this.target.clone(); + this.position0 = this.object.position.clone(); + this.up0 = this.object.up.clone(); + + // events + + var changeEvent = { type: 'change' }; + + + // methods + + this.handleResize = function () { + + this.screen.width = window.innerWidth; + this.screen.height = window.innerHeight; + + this.screen.offsetLeft = 0; + this.screen.offsetTop = 0; + + this.radius = ( this.screen.width + this.screen.height ) / 4; + + }; + + this.handleEvent = function ( event ) { + + if ( typeof this[ event.type ] == 'function' ) { + + this[ event.type ]( event ); + + } + + }; + + this.getMouseOnScreen = function ( clientX, clientY ) { + + return new THREE.Vector2( + ( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5, + ( clientY - _this.screen.offsetTop ) / _this.radius * 0.5 + ); + + }; + + this.getMouseProjectionOnBall = function ( clientX, clientY ) { + + var mouseOnBall = new THREE.Vector3( + ( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius, + ( _this.screen.height * 0.5 + _this.screen.offsetTop - clientY ) / _this.radius, + 0.0 + ); + + var length = mouseOnBall.length(); + + if ( length > 1.0 ) { + + mouseOnBall.normalize(); + + } else { + + mouseOnBall.z = Math.sqrt( 1.0 - length * length ); + + } + + _eye.copy( _this.object.position ).sub( _this.target ); + + var projection = _this.object.up.clone().setLength( mouseOnBall.y ); + projection.add( _this.object.up.clone().cross( _eye ).setLength( mouseOnBall.x ) ); + projection.add( _eye.setLength( mouseOnBall.z ) ); + + return projection; + + }; + + this.rotateCamera = function () { + + var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() ); + + if ( angle ) { + + var axis = ( new THREE.Vector3() ).crossVectors( _rotateStart, _rotateEnd ).normalize(); + quaternion = new THREE.Quaternion(); + + angle *= _this.rotateSpeed; + + quaternion.setFromAxisAngle( axis, -angle ); + + _eye.applyQuaternion( quaternion ); + _this.object.up.applyQuaternion( quaternion ); + + _rotateEnd.applyQuaternion( quaternion ); + + if ( _this.staticMoving ) { + + _rotateStart.copy( _rotateEnd ); + + } else { + + quaternion.setFromAxisAngle( axis, angle * ( _this.dynamicDampingFactor - 1.0 ) ); + _rotateStart.applyQuaternion( quaternion ); + + } + + } + + }; + + this.zoomCamera = function () { + + if ( _state === STATE.TOUCH_ZOOM ) { + + var factor = _touchZoomDistanceStart / _touchZoomDistanceEnd; + _touchZoomDistanceStart = _touchZoomDistanceEnd; + _eye.multiplyScalar( factor ); + + } else { + + var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed; + + if ( factor !== 1.0 && factor > 0.0 ) { + + _eye.multiplyScalar( factor ); + + if ( _this.staticMoving ) { + + _zoomStart.copy( _zoomEnd ); + + } else { + + _zoomStart.y += ( _zoomEnd.y - _zoomStart.y ) * this.dynamicDampingFactor; + + } + + } + + } + + }; + + this.panCamera = function () { + + var mouseChange = _panEnd.clone().sub( _panStart ); + + if ( mouseChange.lengthSq() ) { + + mouseChange.multiplyScalar( _eye.length() * _this.panSpeed ); + + var pan = _eye.clone().cross( _this.object.up ).setLength( mouseChange.x ); + pan.add( _this.object.up.clone().setLength( mouseChange.y ) ); + + _this.object.position.add( pan ); + _this.target.add( pan ); + + if ( _this.staticMoving ) { + + _panStart = _panEnd; + + } else { + + _panStart.add( mouseChange.subVectors( _panEnd, _panStart ).multiplyScalar( _this.dynamicDampingFactor ) ); + + } + + } + + }; + + this.checkDistances = function () { + + if ( !_this.noZoom || !_this.noPan ) { + + if ( _this.object.position.lengthSq() > _this.maxDistance * _this.maxDistance ) { + + _this.object.position.setLength( _this.maxDistance ); + + } + + if ( _eye.lengthSq() < _this.minDistance * _this.minDistance ) { + + _this.object.position.addVectors( _this.target, _eye.setLength( _this.minDistance ) ); + + } + + } + + }; + + this.update = function () { + + _eye.subVectors( _this.object.position, _this.target ); + + if ( !_this.noRotate ) { + + _this.rotateCamera(); + + } + + if ( !_this.noZoom ) { + + _this.zoomCamera(); + + } + + if ( !_this.noPan ) { + + _this.panCamera(); + + } + + _this.object.position.addVectors( _this.target, _eye ); + + _this.checkDistances(); + + _this.object.lookAt( _this.target ); + + if ( lastPosition.distanceToSquared( _this.object.position ) > 0 ) { + + _this.dispatchEvent( changeEvent ); + + lastPosition.copy( _this.object.position ); + + } + + }; + + this.reset = function () { + + _state = STATE.NONE; + _prevState = STATE.NONE; + + _this.target.copy( _this.target0 ); + _this.object.position.copy( _this.position0 ); + _this.object.up.copy( _this.up0 ); + + _eye.subVectors( _this.object.position, _this.target ); + + _this.object.lookAt( _this.target ); + + _this.dispatchEvent( changeEvent ); + + lastPosition.copy( _this.object.position ); + + }; + + // listeners + + function keydown( event ) { + + if ( _this.enabled === false ) return; + + window.removeEventListener( 'keydown', keydown ); + + _prevState = _state; + + if ( _state !== STATE.NONE ) { + + return; + + } else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) { + + _state = STATE.ROTATE; + + } else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) { + + _state = STATE.ZOOM; + + } else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) { + + _state = STATE.PAN; + + } + + } + + function keyup( event ) { + + if ( _this.enabled === false ) return; + + _state = _prevState; + + window.addEventListener( 'keydown', keydown, false ); + + } + + function mousedown( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + if ( _state === STATE.NONE ) { + + _state = event.button; + + } + + if ( _state === STATE.ROTATE && !_this.noRotate ) { + + _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY ); + + } else if ( _state === STATE.ZOOM && !_this.noZoom ) { + + _zoomStart = _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } else if ( _state === STATE.PAN && !_this.noPan ) { + + _panStart = _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } + + document.addEventListener( 'mousemove', mousemove, false ); + document.addEventListener( 'mouseup', mouseup, false ); + + } + + function mousemove( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + if ( _state === STATE.ROTATE && !_this.noRotate ) { + + _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY ); + + } else if ( _state === STATE.ZOOM && !_this.noZoom ) { + + _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } else if ( _state === STATE.PAN && !_this.noPan ) { + + _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY ); + + } + + } + + function mouseup( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + _state = STATE.NONE; + + document.removeEventListener( 'mousemove', mousemove ); + document.removeEventListener( 'mouseup', mouseup ); + + } + + function mousewheel( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + var delta = 0; + + if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9 + + delta = event.wheelDelta / 40; + + } else if ( event.detail ) { // Firefox + + delta = - event.detail / 3; + + } + + _zoomStart.y += delta * 0.01; + + } + + function touchstart( event ) { + + if ( _this.enabled === false ) return; + + switch ( event.touches.length ) { + + case 1: + _state = STATE.TOUCH_ROTATE; + _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: + _state = STATE.TOUCH_ZOOM; + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + _touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt( dx * dx + dy * dy ); + break; + + case 3: + _state = STATE.TOUCH_PAN; + _panStart = _panEnd = _this.getMouseOnScreen( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + default: + _state = STATE.NONE; + + } + + } + + function touchmove( event ) { + + if ( _this.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + switch ( event.touches.length ) { + + case 1: + _rotateEnd = _this.getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + _touchZoomDistanceEnd = Math.sqrt( dx * dx + dy * dy ) + break; + + case 3: + _panEnd = _this.getMouseOnScreen( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + default: + _state = STATE.NONE; + + } + + } + + function touchend( event ) { + + if ( _this.enabled === false ) return; + + switch ( event.touches.length ) { + + case 1: + _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: + _touchZoomDistanceStart = _touchZoomDistanceEnd = 0; + break; + + case 3: + _panStart = _panEnd = _this.getMouseOnScreen( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + } + + _state = STATE.NONE; + + } + + this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false ); + + this.domElement.addEventListener( 'mousedown', mousedown, false ); + + this.domElement.addEventListener( 'mousewheel', mousewheel, false ); + this.domElement.addEventListener( 'DOMMouseScroll', mousewheel, false ); // firefox + + this.domElement.addEventListener( 'touchstart', touchstart, false ); + this.domElement.addEventListener( 'touchend', touchend, false ); + this.domElement.addEventListener( 'touchmove', touchmove, false ); + + window.addEventListener( 'keydown', keydown, false ); + window.addEventListener( 'keyup', keyup, false ); + + this.handleResize(); + +}; + +THREE.TrackballControls.prototype = Object.create( THREE.EventDispatcher.prototype ); \ No newline at end of file diff --git a/public/turtle/index.html b/public/turtle/index.html new file mode 100644 index 0000000..f82b5f9 --- /dev/null +++ b/public/turtle/index.html @@ -0,0 +1,22 @@ + + + + + + WebGL PixelPlace TechDemo Globe + + + +
+ + + + + + + diff --git a/public/turtle/space.js b/public/turtle/space.js new file mode 100644 index 0000000..bfa2aad --- /dev/null +++ b/public/turtle/space.js @@ -0,0 +1,137 @@ +// Created by Bjorn Sandvik - thematicmapping.org +(function () { + + var webglEl = document.getElementById('webgl'); + + if (!Detector.webgl) { + Detector.addGetWebGLMessage(webglEl); + return; + } + + var width = window.innerWidth, + height = window.innerHeight; + + // Earth params + var radius = 0.5, + segments = 32, + rotation = 6; + + var scene = new THREE.Scene(); + + var camera = new THREE.PerspectiveCamera(45, width / height, 0.01, 1000); + camera.position.z = 20.0; + + var renderer = new THREE.WebGLRenderer(); + renderer.setSize(width, height); + + scene.add(new THREE.AmbientLight(0x333333)); + + var light = new THREE.DirectionalLight(0xffffff, 1); + light.position.set(5,3,5); + scene.add(light); + + var loader = new THREE.GLTFLoader(); + loader.load('turtle.glb', function (glb) { + window.test2 = glb.scene; + scene.add(glb.scene); + window.test = scene; + const children = glb.scene.children; + for (let cnt = 0; cnt < children.length; cnt++) { + //children[cnt].scale.x *= -1; + //children[cnt].scale.y *= -1; + const child = children[cnt].children; + if (children[cnt].material) { + const material = children[cnt].material.name; + console.log(material); + if (material == "canvas") { + console.log("Found material"); + children[cnt].material = new THREE.MeshPhongMaterial({ + map: new THREE.TextureLoader().load('../tiles/texture.png?a=b'), + bumpMap: new THREE.TextureLoader().load('../images/elev_bump_4k2.jpg'), + bumpScale: 0.04, + }); + //children[cnt].material.side = THREE.DoubleSide; + } + } + for (let xnt = 0; xnt < child.length; xnt++) { + const material = child[xnt].material.name; + console.log(material); + if (material == "canvas") { + console.log("Found material"); + child[xnt].material = new THREE.MeshPhongMaterial({ + map: new THREE.TextureLoader().load('../tiles/texture.png?a=b'), + bumpMap: new THREE.TextureLoader().load('../images/elev_bump_4k2.jpg'), + bumpScale: 0.04, + }); + //children[cnt].material.side = THREE.DoubleSide; + } + } + } + //glb.animations; + //glb.scene; + //glb.scenes; + //glb.cameras; + //glb.asset; + }, function (xhr) {console.log((xhr.loaded / xhr.total * 100) + '% loaded'); + }, function (error) {console.log('An error happened', error); + }); + + //var sphere = createSphere(radius, segments); + //sphere.rotation.y = rotation; + //scene.add(sphere) + + //var clouds = createClouds(radius, segments); + //clouds.rotation.y = rotation * 10; + //scene.add(clouds) + + var stars = createStars(90, 64); + scene.add(stars); + + var controls = new THREE.TrackballControls(camera); + + webglEl.appendChild(renderer.domElement); + + render(); + + function render() { + controls.update(); + //sphere.rotation.y += 0.0005; + //clouds.rotation.y += 0.005; + requestAnimationFrame(render); + renderer.render(scene, camera); + } + + function createSphere(radius, segments) { + return new THREE.Mesh( + new THREE.SphereGeometry(radius, segments, segments), + new THREE.MeshPhongMaterial({ + map: THREE.ImageUtils.loadTexture('../tiles/texture.png'), + bumpMap: THREE.ImageUtils.loadTexture('../images/elev_bump_4k.jpg'), + bumpScale: 0.004, + //specularMap: THREE.ImageUtils.loadTexture('images/water_4k.png'), + //specular: new THREE.Color('grey') + }) + ); + } + + function createClouds(radius, segments) { + return new THREE.Mesh( + new THREE.SphereGeometry(radius + 0.005, segments, segments), + new THREE.MeshPhongMaterial({ + map: THREE.ImageUtils.loadTexture('../images/fair_clouds_dark_4k.png'), + transparent: true + }) + ); + } + + function createStars(radius, segments) { + return new THREE.Mesh( + new THREE.SphereGeometry(radius, segments, segments), + new THREE.MeshBasicMaterial({ + map: THREE.ImageUtils.loadTexture('../images/galaxy_starfield.png'), + side: THREE.BackSide + }) + ); + } + +}()); diff --git a/public/turtle/turtle.glb b/public/turtle/turtle.glb new file mode 100644 index 0000000..0c9f2b0 Binary files /dev/null and b/public/turtle/turtle.glb differ diff --git a/public/vklogo.svg b/public/vklogo.svg new file mode 100644 index 0000000..e679e79 --- /dev/null +++ b/public/vklogo.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/public/vpPlace.png b/public/vpPlace.png new file mode 100644 index 0000000..60f172d Binary files /dev/null and b/public/vpPlace.png differ diff --git a/src/actions/index.js b/src/actions/index.js new file mode 100644 index 0000000..87d50d1 --- /dev/null +++ b/src/actions/index.js @@ -0,0 +1,674 @@ +/* @flow */ + +import swal from 'sweetalert2'; +import 'sweetalert2/src/sweetalert2.scss'; + +import type { + Action, + ThunkAction, + PromiseAction, +} from './types'; +import type { Cell } from '../core/Cell'; +import type { ColorIndex } from '../core/Palette'; + +import ProtocolClient from '../socket/ProtocolClient'; +import loadImage from '../ui/loadImage'; +import { + getColorIndexOfPixel, +} from '../core/utils'; + + +export function toggleChatBox(): Action { + return { + type: 'TOGGLE_CHAT_BOX', + }; +} + +export function toggleGrid(): Action { + return { + type: 'TOGGLE_GRID', + }; +} + +export function togglePixelNotify(): Action { + return { + type: 'TOGGLE_PIXEL_NOTIFY', + }; +} + +export function toggleAutoZoomIn(): Action { + return { + type: 'TOGGLE_AUTO_ZOOM_IN', + }; +} + +export function toggleMute(): Action { + return { + type: 'TOGGLE_MUTE', + }; +} + +export function toggleCompactPalette(): Action { + return { + type: 'TOGGLE_COMPACT_PALETTE', + }; +} + +export function toggleChatNotify(): Action { + return { + type: 'TOGGLE_CHAT_NOTIFY', + }; +} + +export function togglePotatoMode(): Action { + return { + type: 'TOGGLE_POTATO_MODE', + }; +} + +export function toggleOpenPalette(): Action { + return { + type: 'TOGGLE_OPEN_PALETTE', + }; +} + +export function toggleOpenMenu(): Action { + return { + type: 'TOGGLE_OPEN_MENU', + }; +} + +export function setPlaceAllowed(placeAllowed: boolean): Action { + return { + type: 'SET_PLACE_ALLOWED', + placeAllowed, + }; +} + +export function setNotification(notification: string): Action { + return { + type: 'SET_NOTIFICATION', + notification, + }; +} + +export function unsetNotification(): Action { + return { + type: 'UNSET_NOTIFICATION', + }; +} + +export function setHover(hover: Cell): Action { + return { + type: 'SET_HOVER', + hover, + }; +} + +export function unsetHover(): Action { + return { + type: 'UNSET_HOVER', + }; +} + +export function setWait(wait: ?number): Action { + return { + type: 'SET_WAIT', + wait, + }; +} + +export function selectColor(color: ColorIndex): Action { + return { + type: 'SELECT_COLOR', + color, + }; +} + +export function selectCanvas(canvasId: number): Action { + return { + type: 'SELECT_CANVAS', + canvasId, + }; +} + +export function placePixel(coordinates: Cell, color: ColorIndex): Action { + return { + type: 'PLACE_PIXEL', + coordinates, + color, + }; +} + +export function pixelWait(coordinates: Cell, color: ColorIndex): Action { + return { + type: 'PIXEL_WAIT', + coordinates, + color, + }; +} + +export function pixelFailure(): Action { + return { + type: 'PIXEL_FAILURE', + }; +} + +export function receiveOnline(online: number): Action { + return { + type: 'RECEIVE_ONLINE', + online, + }; +} + +export function receiveChatMessage(name: string, text: string): Action { + return { + type: 'RECEIVE_CHAT_MESSAGE', + name, + text, + }; +} + +export function receiveChatHistory(data: Array): Action { + return { + type: 'RECEIVE_CHAT_HISTORY', + data, + }; +} + +let lastNotify = null; +export function notify(notification: string) { + return async (dispatch) => { + dispatch(setNotification(notification)); + if (lastNotify) { + clearTimeout(lastNotify); + lastNotify = null; + } + lastNotify = setTimeout(() => { + dispatch(unsetNotification()); + }, 1500); + }; +} + +export function requestPlacePixel( + canvasId: number, + coordinates: Cell, + color: ColorIndex, + token: ?string = null, +): ThunkAction { + const [x, y] = coordinates; + + return async (dispatch) => { + const body = JSON.stringify({ + cn: canvasId, + x, + y, + clr: color, + token, + a: x + y + 8, + }); + + dispatch(setPlaceAllowed(false)); + try { + const response = await fetch('/api/pixel', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body, + // https://github.com/github/fetch/issues/349 + credentials: 'include', + }); + const { + success, + waitSeconds, + coolDownSeconds, + errors, + errorTitle, + } = await response.json(); + + if (waitSeconds) { + dispatch(setWait(waitSeconds * 1000)); + } + if (coolDownSeconds) { + dispatch(notify(Math.round(coolDownSeconds))); + } + if (response.ok) { + if (success) { + dispatch(placePixel(coordinates, color)); + } else { + dispatch(pixelWait(coordinates, color)); + } + return; + } + + if (response.status === 422) { + window.pixel = { canvasId, coordinates, color }; + grecaptcha.execute(); + return; + } + + dispatch(pixelFailure()); + swal({ + title: (errorTitle || `Error ${response.status}`), + text: errors[0].msg, + type: 'error', + confirmButtonText: 'OK', + }); + } catch (e) { + throw e; + } finally { + dispatch(setPlaceAllowed(true)); + } + }; +} + +export function tryPlacePixel( + coordinates: Cell, + color: ?ColorIndex = null, +): ThunkAction { + return (dispatch, getState) => { + const state = getState(); + const { canvasId } = state.canvas; + const selectedColor = (color === undefined || color === null) + ? state.gui.selectedColor + : color; + + if (getColorIndexOfPixel(getState(), coordinates) !== selectedColor) { + dispatch(requestPlacePixel(canvasId, coordinates, selectedColor)); + } + }; +} + +export function setViewCoordinates(view: Cell): Action { + return { + type: 'SET_VIEW_COORDINATES', + view, + }; +} + +export function move([dx, dy]: Cell): ThunkAction { + return (dispatch, getState) => { + const { view } = getState().canvas; + + const [x, y] = view; + dispatch(setViewCoordinates([x + dx, y + dy])); + }; +} + +export function moveDirection([vx, vy]: Cell): ThunkAction { + // TODO check direction is unitary vector + return (dispatch, getState) => { + const { viewscale } = getState().canvas; + + const speed = 100.0 / viewscale; + dispatch(move([speed * vx, speed * vy])); + }; +} + +export function moveNorth(): ThunkAction { + return (dispatch) => { + dispatch(moveDirection([0, -1])); + }; +} + +export function moveWest(): ThunkAction { + return (dispatch) => { + dispatch(moveDirection([-1, 0])); + }; +} + +export function moveSouth(): ThunkAction { + return (dispatch) => { + dispatch(moveDirection([0, 1])); + }; +} + +export function moveEast(): ThunkAction { + return (dispatch) => { + dispatch(moveDirection([1, 0])); + }; +} + + +export function setScale(scale: number, zoompoint: Cell): Action { + return { + type: 'SET_SCALE', + scale, + zoompoint, + }; +} + +export function zoomIn(zoompoint): ThunkAction { + return (dispatch, getState) => { + const { scale } = getState().canvas; + const zoomscale = scale >= 1.0 ? scale * 1.1 : scale * 1.04; + dispatch(setScale(zoomscale, zoompoint)); + }; +} + +export function zoomOut(zoompoint): ThunkAction { + return (dispatch, getState) => { + const { scale } = getState().canvas; + const zoomscale = scale >= 1.0 ? scale / 1.1 : scale / 1.04; + dispatch(setScale(zoomscale, zoompoint)); + }; +} + +function requestBigChunk(center: Cell): Action { + return { + type: 'REQUEST_BIG_CHUNK', + center, + }; +} + +function receiveBigChunk( + center: Cell, + arrayBuffer: ArrayBuffer, +): Action { + return { + type: 'RECEIVE_BIG_CHUNK', + center, + arrayBuffer, + }; +} + +function receiveImageTile( + center: Cell, + tile: Image, +): Action { + return { + type: 'RECEIVE_IMAGE_TILE', + center, + tile, + }; +} + + +function receiveBigChunkFailure(center: Cell, error: Error): Action { + return { + type: 'RECEIVE_BIG_CHUNK_FAILURE', + center, + error, + }; +} + +export function fetchTile(canvasId, center: Cell): PromiseAction { + const [cz, cx, cy] = center; + + return async (dispatch) => { + dispatch(requestBigChunk(center)); + try { + const url = `/tiles/${canvasId}/${cz}/${cx}/${cy}.png`; + const img = await loadImage(url); + dispatch(receiveImageTile(center, img)); + } catch (error) { + dispatch(receiveBigChunkFailure(center, error)); + } + }; +} + +export function fetchChunk(canvasId, center: Cell): PromiseAction { + const [, cx, cy] = center; + + return async (dispatch) => { + dispatch(requestBigChunk(center)); + try { + ProtocolClient.registerChunk([cx, cy]); + const url = `/chunks/${canvasId}/${cx}/${cy}.bmp`; + const response = await fetch(url); + if (response.ok) { + const arrayBuffer = await response.arrayBuffer(); + dispatch(receiveBigChunk(center, arrayBuffer)); + } else { + const error = new Error('Network response was not ok.'); + dispatch(receiveBigChunkFailure(center, error)); + } + } catch (error) { + console.log(`Error at requesting chunk ${cx}/${cy}`); + dispatch(receiveBigChunkFailure(center, error)); + } + }; +} + + +export function receiveCoolDown( + waitSeconds: number, +): Action { + return { + type: 'RECEIVE_COOLDOWN', + waitSeconds, + }; +} + + +export function receivePixelUpdate( + i: number, + j: number, + offset: number, + color: ColorIndex, +): Action { + return { + type: 'RECEIVE_PIXEL_UPDATE', + i, + j, + offset, + color, + }; +} + +export function receiveMe( + me: Object, +): Action { + const { + name, + messages, + mailreg, + totalPixels, + dailyTotalPixels, + ranking, + dailyRanking, + minecraftname, + canvases, + } = me; + ProtocolClient.setName(name); + return { + type: 'RECEIVE_ME', + name: (name) || null, + messages: (messages) || [], + mailreg: (mailreg) || false, + totalPixels, + dailyTotalPixels, + ranking, + dailyRanking, + minecraftname, + canvases, + }; +} + +export function receiveStats( + rankings: Object, +): Action { + const { ranking: totalRanking, dailyRanking: totalDailyRanking } = rankings; + return { + type: 'RECEIVE_STATS', + totalRanking, + totalDailyRanking, + }; +} + +export function setName( + name: string, +): Action { + ProtocolClient.setName(name); + return { + type: 'SET_NAME', + name, + }; +} + +export function setMinecraftName( + minecraftname: string, +): Action { + return { + type: 'SET_MINECRAFT_NAME', + minecraftname, + }; +} + +export function setMailreg( + mailreg: boolean, +): Action { + return { + type: 'SET_MAILREG', + mailreg, + }; +} + +export function remFromMessages( + message: string, +): Action { + return { + type: 'REM_FROM_MESSAGES', + message, + }; +} + +export function fetchStats(): PromiseAction { + return async (dispatch) => { + const response = await fetch('api/ranking', { credentials: 'include' }); + if (response.ok) { + const rankings = await response.json(); + + dispatch(receiveStats(rankings)); + } + }; +} + +export function fetchMe(): PromiseAction { + return async (dispatch, getState) => { + const response = await fetch('/api/me', { + credentials: 'include', + }); + + if (response.ok) { + const me = await response.json(); + await dispatch(receiveMe(me)); + const state = getState(); + ProtocolClient.setCanvas(state.canvas.canvasId); + } + }; +} + +function setCoolDown(coolDown): Action { + return { + type: 'COOLDOWN_SET', + coolDown, + }; +} + +function endCoolDown(): Action { + return { + type: 'COOLDOWN_END', + }; +} + +function getPendingActions(state): Array { + const actions = []; + + const { wait } = state.user; + if (wait === null || wait === undefined) return actions; + + const coolDown = wait - Date.now(); + + if (coolDown > 0) actions.push(setCoolDown(coolDown)); + else actions.push(endCoolDown()); + + return actions; +} + +export function initTimer(): ThunkAction { + return (dispatch, getState) => { + function tick() { + const state = getState(); + const actions = getPendingActions(state); + dispatch(actions); + } + + // something shorter than 1000 ms + setInterval(tick, 333); + }; +} + +export function showModal(modalType: string, modalProps: Object = {}): Action { + return { + type: 'SHOW_MODAL', + modalType, + modalProps, + }; +} + +export function showSettingsModal(): Action { + return showModal('SETTINGS'); +} + +export function showUserAreaModal(): Action { + return showModal('USERAREA'); +} + +export function showMinecraftModal(): Action { + return showModal('MINECRAFT'); +} + +export function showRegisterModal(): Action { + return showModal('REGISTER'); +} + +export function showForgotPasswordModal(): Action { + return showModal('FORGOT_PASSWORD'); +} + +export function showHelpModal(): Action { + return showModal('HELP'); +} + +export function showChatModal(): Action { + if (window.innerWidth > 604) { return toggleChatBox(); } + return showModal('CHAT'); +} + +export function hideModal(): Action { + return { + type: 'HIDE_MODAL', + }; +} + +export function reloadUrl(): Action { + return { + type: 'RELOAD_URL', + }; +} + +export function onViewFinishChange(): Action { + return { + type: 'ON_VIEW_FINISH_CHANGE', + }; +} + +export function urlChange(): PromiseAction { + return async (dispatch, getState) => { + await dispatch(reloadUrl()); + const state = getState(); + ProtocolClient.setCanvas(state.canvas.canvasId); + }; +} + +export function switchCanvas(canvasId: number): PromiseAction { + return async (dispatch, getState) => { + await dispatch(selectCanvas(canvasId)); + const state = getState(); + ProtocolClient.setCanvas(state.canvas.canvasId); + dispatch(onViewFinishChange()); + }; +} + diff --git a/src/actions/types.js b/src/actions/types.js new file mode 100644 index 0000000..36ba568 --- /dev/null +++ b/src/actions/types.js @@ -0,0 +1,62 @@ +/* @flow */ + +import type { Cell } from '../core/Cell'; +import type { ColorIndex } from '../core/Palette'; +import type { State } from '../reducers'; + + +export type Action = + { type: 'LOGGED_OUT' } + // my actions + | { type: 'TOGGLE_GRID' } + | { type: 'TOGGLE_PIXEL_NOTIFY' } + | { type: 'TOGGLE_AUTO_ZOOM_IN' } + | { type: 'TOGGLE_MUTE' } + | { type: 'TOGGLE_OPEN_PALETTE' } + | { type: 'TOGGLE_COMPACT_PALETTE' } + | { type: 'TOGGLE_CHAT_NOTIFY' } + | { type: 'TOGGLE_POTATO_MODE' } + | { type: 'TOGGLE_OPEN_MENU' } + | { type: 'SET_NOTIFICATION', notification: string } + | { type: 'UNSET_NOTIFICATION' } + | { type: 'SET_PLACE_ALLOWED', placeAllowed: boolean } + | { type: 'SET_HOVER', hover: Cell } + | { type: 'UNSET_HOVER' } + | { type: 'SET_WAIT', wait: ?number } + | { type: 'COOLDOWN_END' } + | { type: 'COOLDOWN_SET', coolDown: number } + | { type: 'SELECT_COLOR', color: ColorIndex } + | { type: 'SELECT_CANVAS', canvasId: number } + | { type: 'PLACE_PIXEL', coordinates: Cell, color: ColorIndex, wait: string } + | { type: 'PIXEL_WAIT', coordinates: Cell, color: ColorIndex, wait: string } + | { type: 'PIXEL_FAILURE' } + | { type: 'SET_VIEW_COORDINATES', view: Cell } + | { type: 'SET_SCALE', scale: number, zoompoint: Cell } + | { type: 'REQUEST_BIG_CHUNK', center: Cell } + | { type: 'RECEIVE_BIG_CHUNK', center: Cell, arrayBuffer: ArrayBuffer } + | { type: 'RECEIVE_IMAGE_TILE', center: Cell, tile: Image } + | { type: 'RECEIVE_BIG_CHUNK_FAILURE', center: Cell, error: Error } + | { type: 'RECEIVE_COOLDOWN', waitSeconds: number } + | { type: 'RECEIVE_PIXEL_UPDATE', i: number, j: number, offset: number, color: ColorIndex } + | { type: 'RECEIVE_ONLINE', online: number } + | { type: 'RECEIVE_CHAT_MESSAGE', name: string, text: string } + | { type: 'RECEIVE_CHAT_HISTORY', data: Array } + | { type: 'RECEIVE_ME', name: string, waitSeconds: number, messages: Array, + mailreg: boolean, totalPixels: number, dailyTotalPixels: number, + ranking: number, dailyRanking: number, minecraftname: string, canvases: Object} + | { type: 'RECEIVE_STATS', totalRanking: Object, totalDailyRanking: Object } + | { type: 'SET_NAME', name: string } + | { type: 'SET_MINECRAFT_NAME', minecraftname: string } + | { type: 'SET_MAILREG', mailreg: boolean } + | { type: 'REM_FROM_MESSAGES', message: string } + | { type: 'SHOW_MODAL', modalType: string, modalProps: obj } + | { type: 'HIDE_MODAL' } + | { type: 'RELOAD_URL' } + | { type: 'ON_VIEW_FINISH_CHANGE' } + ; + + +export type PromiseAction = Promise; +export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array) => any; +export type GetState = () => State; +export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any; diff --git a/src/canvases.json b/src/canvases.json new file mode 100644 index 0000000..bdbe1f1 --- /dev/null +++ b/src/canvases.json @@ -0,0 +1,88 @@ +{ + "0": { + "ident":"d", + "colors": [ + [ 202, 227, 255 ], + [ 255, 255, 255 ], + [ 255, 255, 255 ], + [ 228, 228, 228 ], + [ 196, 196, 196 ], + [ 136, 136, 136 ], + [ 78, 78, 78 ], + [ 0, 0, 0 ], + [ 244, 179, 174 ], + [ 255, 167, 209 ], + [ 255, 84, 178 ], + [ 255, 101, 101 ], + [ 229, 0, 0 ], + [ 154, 0, 0 ], + [ 254, 164, 96 ], + [ 229, 149, 0 ], + [ 160, 106, 66 ], + [ 96, 64, 40 ], + [ 245, 223, 176 ], + [ 255, 248, 137 ], + [ 229, 217, 0 ], + [ 148, 224, 68 ], + [ 2, 190, 1 ], + [ 104, 131, 56 ], + [ 0, 101, 19 ], + [ 202, 227, 255 ], + [ 0, 211, 221 ], + [ 0, 131, 199 ], + [ 0, 0, 234 ], + [ 25, 25, 115 ], + [ 207, 110, 228 ], + [ 130, 0, 128 ] + ], + "alpha": 0, + "size": 65536, + "bcd": 4000, + "pcd" : 7000, + "cds": 60000, + "req": 0 + }, + "1": { + "ident": "m", + "colors" : [ + [ 49, 46, 47 ], + [ 99, 92, 90 ], + [ 49, 46, 47 ], + [ 99, 92, 90 ], + [ 129, 119, 107 ], + [ 198, 181, 165 ], + [ 255, 237, 212 ], + [ 150, 86, 122 ], + [ 202, 112, 145 ], + [ 96, 67, 79 ], + [ 136, 79, 94 ], + [ 175, 101, 103 ], + [ 195, 124, 107 ], + [ 221, 153, 126 ], + [ 233, 181, 140 ], + [ 198, 139, 91 ], + [ 140, 89, 74 ], + [ 94, 68, 63 ], + [ 225, 173, 86 ], + [ 248, 207, 142 ], + [ 239, 220, 118 ], + [ 206, 190, 85 ], + [ 157, 159, 55 ], + [ 114, 121, 43 ], + [ 81, 94, 46 ], + [ 69, 100, 79 ], + [ 80, 134, 87 ], + [ 187, 209, 138 ], + [ 91, 84, 108 ], + [ 106, 113, 137 ], + [ 122, 148, 156 ], + [ 174, 215, 185 ] + ], + "alpha": 0, + "size" : 1024, + "bcd": 15000, + "pcd": 15000, + "cds": 900000, + "req": 8000 + } +} diff --git a/src/client.js b/src/client.js new file mode 100644 index 0000000..029cfa0 --- /dev/null +++ b/src/client.js @@ -0,0 +1,269 @@ +/* @flow */ + +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Provider } from 'react-redux'; +import fetch from 'isomorphic-fetch'; // TODO put in the beggining with webpack! +import Hammer from 'hammerjs'; + +import './components/font.css'; + +import { + screenToWorld, + getColorIndexOfPixel, +} from './core/utils'; + +import type { State } from './reducers'; +import initAds, { requestAds } from './ui/ads'; +import { + tryPlacePixel, + setHover, + unsetHover, + setViewCoordinates, + setScale, + zoomIn, + zoomOut, + receivePixelUpdate, + receiveCoolDown, + fetchMe, + fetchStats, + initTimer, + urlChange, + onViewFinishChange, + receiveOnline, + receiveChatMessage, + receiveChatHistory, + selectColor, +} from './actions'; +import store from './ui/store'; + +import onKeyPress from './ui/keypress'; + +import App from './components/App'; + +import Renderer from './ui/Renderer'; +import ProtocolClient from './socket/ProtocolClient'; + +window.addEventListener('keydown', onKeyPress, false); + + +function initViewport() { + const canvas = document.getElementById('gameWindow'); + + const viewport = canvas; + viewport.width = window.innerWidth; + viewport.height = window.innerHeight; + + // track hover + viewport.onmousemove = ({ clientX, clientY }: MouseEvent) => { + store.dispatch(setHover([clientX, clientY])); + }; + viewport.onmouseout = () => { + store.dispatch(unsetHover()); + }; + viewport.onwheel = ({ deltaY }: WheelEvent) => { + const state = store.getState(); + const { hover } = state.gui; + let zoompoint = null; + if (hover) { + zoompoint = screenToWorld(state, viewport, hover); + } + if (deltaY < 0) { + store.dispatch(zoomIn(zoompoint)); + } + if (deltaY > 0) { + store.dispatch(zoomOut(zoompoint)); + } + store.dispatch(onViewFinishChange()); + }; + viewport.onauxclick = ({ which, clientX, clientY }: MouseEvent) => { + // middle mouse button + if (which !== 2) { + return; + } + const state = store.getState(); + if (state.canvas.scale < 3) { + return; + } + const coords = screenToWorld(state, viewport, [clientX, clientY]); + const clrIndex = getColorIndexOfPixel(state, coords); + if (clrIndex === null) { + return; + } + store.dispatch(selectColor(clrIndex)); + }; + + // fingers controls on touch + const hammertime = new Hammer(viewport); + hammertime.get('pan').set({ direction: Hammer.DIRECTION_ALL }); + hammertime.get('swipe').set({ direction: Hammer.DIRECTION_ALL }); + // Zoom-in Zoom-out in touch devices + hammertime.get('pinch').set({ enable: true }); + + hammertime.on('tap', ({ center }) => { + const state = store.getState(); + const { autoZoomIn } = state.gui; + const { placeAllowed } = state.user; + + const { scale } = state.canvas; + const { x, y } = center; + const cell = screenToWorld(state, viewport, [x, y]); + + if (autoZoomIn && scale < 8) { + store.dispatch(setViewCoordinates(cell)); + store.dispatch(setScale(12)); + return; + } + + // don't allow placing of pixel just on low zoomlevels + if (scale < 3) return; + + if (!placeAllowed) return; + + // dirty trick: to fetch only before multiple 3 AND on user action + // if (pixelsPlaced % 3 === 0) requestAds(); + + // TODO assert only one finger + store.dispatch(tryPlacePixel(cell)); + }); + + const initialState: State = store.getState(); + [window.lastPosX, window.lastPosY] = initialState.canvas.view; + let lastScale = initialState.canvas.scale; + hammertime.on( + 'panstart pinchstart pan pinch panend pinchend', + ({ type, deltaX, deltaY, scale }, + ) => { + viewport.style.cursor = 'move'; // like google maps + const { scale: viewportScale } = store.getState().canvas; + + // pinch start + if (type === 'pinchstart') { + store.dispatch(unsetHover()); + lastScale = viewportScale; + } + + // panstart + if (type === 'panstart') { + store.dispatch(unsetHover()); + const { view: initView } = store.getState().canvas; + [window.lastPosX, window.lastPosY] = initView; + } + + // pinch + if (type === 'pinch') { + store.dispatch(setScale(lastScale * scale)); + } + + // pan + store.dispatch(setViewCoordinates([ + window.lastPosX - (deltaX / viewportScale), + window.lastPosY - (deltaY / viewportScale), + ])); + + // pinch end + if (type === 'pinchend') { + lastScale = viewportScale; + } + + // panend + if (type === 'panend') { + store.dispatch(onViewFinishChange()); + const { view } = store.getState().canvas; + [window.lastPosX, window.lastPosY] = view; + viewport.style.cursor = 'auto'; + } + }, + ); + + return viewport; +} + + +document.addEventListener('DOMContentLoaded', () => { + ReactDOM.render( + + + , + document.getElementById('app'), + ); + + const viewport = initViewport(); + const renderer = new Renderer(); + renderer.setViewport(viewport); + + ProtocolClient.on('pixelUpdate', ({ i, j, offset, color }) => { + store.dispatch(receivePixelUpdate(i, j, offset, color)); + // render updated pixel + renderer.renderPixel(i, j, offset, color); + }); + ProtocolClient.on('cooldownPacket', (waitSeconds) => { + console.log(`Received CoolDown ${waitSeconds}`); + store.dispatch(receiveCoolDown(waitSeconds)); + }); + ProtocolClient.on('onlineCounter', ({ online }) => { + store.dispatch(receiveOnline(online)); + }); + ProtocolClient.on('chatMessage', (name, text) => { + store.dispatch(receiveChatMessage(name, text)); + }); + ProtocolClient.on('chatHistory', (data) => { + store.dispatch(receiveChatHistory(data)); + }); + ProtocolClient.on('changedMe', () => { + store.dispatch(fetchMe()); + }); + + window.addEventListener('resize', () => { + viewport.width = window.innerWidth; + viewport.height = window.innerHeight; + renderer.forceNextRender = true; + }); + window.addEventListener('hashchange', () => { + store.dispatch(urlChange()); + }); + + store.subscribe(() => { + // const state: State = store.getState(); + // this gets executed when store changes + }); + + store.dispatch(initTimer()); + + function animationLoop() { + renderer.render(viewport); + window.requestAnimationFrame(animationLoop); + } + animationLoop(); + + store.dispatch(fetchMe()); + ProtocolClient.connect(); + + store.dispatch(fetchStats()); + setInterval(() => { store.dispatch(fetchStats()); }, 300000); + + // garbage collection + function runGC() { + const state: State = store.getState(); + const { chunks } = state.canvas; + + const curTime = Date.now(); + let cnt = 0; + chunks.forEach((value, key) => { + if (curTime > value.timestamp + 300000) { + cnt++; + const [z, i, j] = value.cell; + if (!renderer.isChunkInView(z, i, j)) { + console.log(value.cell); + if (value.isBasechunk) { + console.log(`deregister chunk ${i},${j}`); + ProtocolClient.deRegisterChunk([i, j]); + } + chunks.delete(key); + } + } + }); + console.log('Garbage collection cleaned', cnt, 'chunks'); + } + setInterval(runGC, 300000); +}); diff --git a/src/components/Admin.js b/src/components/Admin.js new file mode 100644 index 0000000..a6fb6ec --- /dev/null +++ b/src/components/Admin.js @@ -0,0 +1,37 @@ +/* + * react html for adminpage + */ + +import React from 'react'; + +const Admin = () => ( +
+

------Image Upload------

+

file:

+ +
+

canvasId (d: default, m: moon): +

+ x: +
+ y: +
+
+

---------IP actions---------

+ +
+

-----------------------

+ +
+); + +export default Admin; diff --git a/src/components/App.js b/src/components/App.js new file mode 100644 index 0000000..d0bda9d --- /dev/null +++ b/src/components/App.js @@ -0,0 +1,54 @@ +/** + * + * @flow + */ + +import React from 'react'; +import { IconContext } from 'react-icons'; + +import CoolDownBox from './CoolDownBox'; +import NotifyBox from './NotifyBox.js'; +import CoordinatesBox from './CoordinatesBox'; +import GlobeButton from './GlobeButton'; +import CanvasSwitchButton from './CanvasSwitchButton'; +import OnlineBox from './OnlineBox'; +import PalselButton from './PalselButton.js'; +import ChatButton from './ChatButton'; +import Palette from './Palette'; +import ChatBox from './ChatBox'; +import Menu from './Menu'; +import ReCaptcha from './ReCaptcha'; +import ExpandMenuButton from './ExpandMenuButton'; +import ModalRoot from './ModalRoot'; + +import baseCss from './base.tcss'; + +const position = 'absolute'; +const left = '1em'; +const right = left; + +const App = () => ( +
+