Mirror repository for github
21
.babelrc
Normal file
|
@ -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 }],
|
||||
]
|
||||
}
|
25
.eslintrc.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
7
.flowconfig
Normal file
|
@ -0,0 +1,7 @@
|
|||
[ignore]
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
|
||||
[options]
|
133
.gitignore
vendored
Normal file
|
@ -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
|
95
API.md
Normal file
|
@ -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]```
|
674
LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
163
README.md
Normal file
|
@ -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`
|
12
deployment/README.md
Normal file
|
@ -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
|
67
deployment/post-receive
Executable file
|
@ -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
|
3
deployment/updatemsg/README.md
Normal file
|
@ -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.
|
34
deployment/updatemsg/update.html
Normal file
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
.videoWrapper {
|
||||
position: relative;
|
||||
padding-bottom: 56.25%; /* 16:9 */
|
||||
padding-top: 25px;
|
||||
height: 0;
|
||||
}
|
||||
.videoWrapper iframe {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>We are updating...</h1>
|
||||
<p>will be back soon</p>
|
||||
<div class="videoWrapper">
|
||||
<iframe width="560" height="349" src="https://www.youtube.com/embed/pNfTK39k55U" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
21
deployment/updatemsg/update.js
Normal file
|
@ -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}/`);
|
||||
});
|
14
ecosystem.yml
Normal file
|
@ -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"
|
142
package.json
Normal file
|
@ -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 <hf@example.com>",
|
||||
"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"
|
||||
}
|
||||
}
|
1
promotion/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
Folder for videos, screenshots and thumbnails used to promote pixelplanet
|
BIN
promotion/screenshot.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
promotion/thumbnail.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
promotion/videothumb-uncropped.mp4
Normal file
BIN
promotion/videothumb.gif
Normal file
After Width: | Height: | Size: 798 KiB |
BIN
promotion/videothumb.mp4
Normal file
BIN
public/apple-touch-icon.png
Normal file
After Width: | Height: | Size: 24 KiB |
12
public/browserconfig.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Please read: http://msdn.microsoft.com/en-us/library/ie/dn455106.aspx -->
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square70x70logo src="tile.png"/>
|
||||
<square150x150logo src="tile.png"/>
|
||||
<wide310x150logo src="tile-wide.png"/>
|
||||
<square310x310logo src="tile.png"/>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
1
public/bundle.js
Normal file
41
public/convert.html
Normal file
41
public/convert2.html
Normal file
1
public/discordlogo.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 245 240"><style>.st0{fill:#7289DA;}</style><path class="st0" d="M104.4 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1.1-6.1-4.5-11.1-10.2-11.1zM140.9 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1s-4.5-11.1-10.2-11.1z"/><path class="st0" d="M189.5 20h-134C44.2 20 35 29.2 35 40.6v135.2c0 11.4 9.2 20.6 20.5 20.6h113.4l-5.3-18.5 12.8 11.9 12.1 11.2 21.5 19V40.6c0-11.4-9.2-20.6-20.5-20.6zm-38.6 130.6s-3.6-4.3-6.6-8.1c13.1-3.7 18.1-11.9 18.1-11.9-4.1 2.7-8 4.6-11.5 5.9-5 2.1-9.8 3.5-14.5 4.3-9.6 1.8-18.4 1.3-25.9-.1-5.7-1.1-10.6-2.7-14.7-4.3-2.3-.9-4.8-2-7.3-3.4-.3-.2-.6-.3-.9-.5-.2-.1-.3-.2-.4-.3-1.8-1-2.8-1.7-2.8-1.7s4.8 8 17.5 11.8c-3 3.8-6.7 8.3-6.7 8.3-22.1-.7-30.5-15.2-30.5-15.2 0-32.2 14.4-58.3 14.4-58.3 14.4-10.8 28.1-10.5 28.1-10.5l1 1.2c-18 5.2-26.3 13.1-26.3 13.1s2.2-1.2 5.9-2.9c10.7-4.7 19.2-6 22.7-6.3.6-.1 1.1-.2 1.7-.2 6.1-.8 13-1 20.2-.2 9.5 1.1 19.7 3.9 30.1 9.6 0 0-7.9-7.5-24.9-12.7l1.4-1.6s13.7-.3 28.1 10.5c0 0 14.4 26.1 14.4 58.3 0 0-8.5 14.5-30.6 15.2z"/></svg>
|
After Width: | Height: | Size: 1.1 KiB |
20
public/facebooklogo.svg
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Creator: CorelDRAW X6 -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="14.2222in" height="14.2222in" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
|
||||
viewBox="0 0 14222 14222"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<defs>
|
||||
<style type="text/css">
|
||||
<![CDATA[
|
||||
.fil0 {fill:#1977F3;fill-rule:nonzero}
|
||||
.fil1 {fill:#FEFEFE;fill-rule:nonzero}
|
||||
]]>
|
||||
</style>
|
||||
</defs>
|
||||
<g id="Layer_x0020_1">
|
||||
<metadata id="CorelCorpID_0Corel-Layer"/>
|
||||
<path class="fil0" d="M14222 7111c0,-3927 -3184,-7111 -7111,-7111 -3927,0 -7111,3184 -7111,7111 0,3549 2600,6491 6000,7025l0 -4969 -1806 0 0 -2056 1806 0 0 -1567c0,-1782 1062,-2767 2686,-2767 778,0 1592,139 1592,139l0 1750 -897 0c-883,0 -1159,548 -1159,1111l0 1334 1972 0 -315 2056 -1657 0 0 4969c3400,-533 6000,-3475 6000,-7025z"/>
|
||||
<path class="fil1" d="M9879 9167l315 -2056 -1972 0 0 -1334c0,-562 275,-1111 1159,-1111l897 0 0 -1750c0,0 -814,-139 -1592,-139 -1624,0 -2686,984 -2686,2767l0 1567 -1806 0 0 2056 1806 0 0 4969c362,57 733,86 1111,86 378,0 749,-30 1111,-86l0 -4969 1657 0z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
BIN
public/favicon.ico
Normal file
After Width: | Height: | Size: 23 KiB |
40
public/go/Detector.js
Normal file
|
@ -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 <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br />',
|
||||
'Find out how to get it <a href="http://get.webgl.org/">here</a>.'
|
||||
].join( '\n' ) : [
|
||||
'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br/>',
|
||||
'Find out how to get it <a href="http://get.webgl.org/">here</a>.'
|
||||
].join( '\n' );
|
||||
|
||||
}
|
||||
|
||||
return element;
|
||||
|
||||
},
|
||||
|
||||
addGetWebGLMessage: function (parent ) {
|
||||
|
||||
parent.appendChild( Detector.getWebGLErrorMessage() );
|
||||
|
||||
}
|
||||
|
||||
};
|
537
public/go/TrackballControls.js
Normal file
|
@ -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 );
|
BIN
public/go/clouds.png
Normal file
After Width: | Height: | Size: 4.8 MiB |
BIN
public/go/globe.glb
Normal file
26
public/go/index.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PixelPlanet.fun</title>
|
||||
<style>
|
||||
body { margin: 0; overflow: hidden; background-color: #000; font-size: 16px; font-family: Montserrat,sans-serif; }
|
||||
.tm { position: absolute; top: 10px; right: 10px; }
|
||||
.webgl-error { font: 15px/30px monospace; text-align: center; color: #fff; margin: 50px; }
|
||||
.webgl-error a { color: #fff; }
|
||||
#coorbox { position: absolute; background-color: hsla(0,0%,89%,.8); color: #000; text-align: center; vertical-align: middle; line-height: 36px; width: auto; height: 36px; padding: 0 24px; border: solid #000; border-width: thin; left: 16px; bottom: 16px}
|
||||
#info { font-size: 13px; position: absolute; background-color: hsla(0,0%,89%,.8); color: #000; text-align: center; vertical-align: middle; line-height: 36px; width: auto; height: 36px; padding: 0 24px; border: solid #000; border-width: thin; left: 16px; top: 16px}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="webgl"></div>
|
||||
<div id="coorbox">(0, 0)</div>
|
||||
<div id="info">Double click on globe to go back.</div>
|
||||
<script src="https://unpkg.com/three@0.91.0/build/three.min.js"></script>
|
||||
<script src="https://unpkg.com/three@0.91.0/examples/js/loaders/GLTFLoader.js"></script>
|
||||
<script src="Detector.js"></script>
|
||||
<script src="TrackballControls.js"></script>
|
||||
<script src="space.js"></script>
|
||||
</body>
|
||||
</html>
|
BIN
public/go/normal.jpg
Normal file
After Width: | Height: | Size: 778 KiB |
BIN
public/go/normalm.jpg
Normal file
After Width: | Height: | Size: 195 KiB |
178
public/go/space.js
Normal file
|
@ -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);
|
||||
|
||||
}());
|
BIN
public/go/specular.jpg
Normal file
After Width: | Height: | Size: 958 KiB |
BIN
public/go/specularm.jpg
Normal file
After Width: | Height: | Size: 172 KiB |
BIN
public/go/starfield.png
Normal file
After Width: | Height: | Size: 658 KiB |
BIN
public/go/texture.png
Normal file
After Width: | Height: | Size: 610 KiB |
1
public/googlelogo.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48"><defs><path id="a" d="M44.5 20H24v8.5h11.8C34.7 33.9 30.1 37 24 37c-7.2 0-13-5.8-13-13s5.8-13 13-13c3.1 0 5.9 1.1 8.1 2.9l6.4-6.4C34.6 4.1 29.6 2 24 2 11.8 2 2 11.8 2 24s9.8 22 22 22c11 0 21-8 21-22 0-1.3-.2-2.7-.5-4z"/></defs><clipPath id="b"><use xlink:href="#a" overflow="visible"/></clipPath><path clip-path="url(#b)" fill="#FBBC05" d="M0 37V11l17 13z"/><path clip-path="url(#b)" fill="#EA4335" d="M0 11l17 13 7-6.1L48 14V0H0z"/><path clip-path="url(#b)" fill="#34A853" d="M0 37l30-23 7.9 1L48 0v48H0z"/><path clip-path="url(#b)" fill="#4285F4" d="M48 48L17 24l-4-3 35-10z"/></svg>
|
After Width: | Height: | Size: 688 B |
BIN
public/loading.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
34
public/palette0.gpl
Normal file
|
@ -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
|
34
public/palette1.gpl
Normal file
|
@ -0,0 +1,34 @@
|
|||
GIMP Palette
|
||||
Name: Greenstar30
|
||||
#Description: Created by <a target="_blank" href="https://twitter.com/starhousedev">starhouse</a> 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
|
57
public/redditlogo.svg
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 429.709 429.709" style="enable-background:new 0 0 429.709 429.709;" xml:space="preserve">
|
||||
<path style="fill:#181A1C;" d="M429.709,196.618c0-29.803-24.16-53.962-53.963-53.962c-14.926,0-28.41,6.085-38.176,15.881
|
||||
c-30.177-19.463-68.73-31.866-111.072-33.801c0.026-17.978,8.078-34.737,22.104-45.989c14.051-11.271,32.198-15.492,49.775-11.588
|
||||
l2.414,0.536c-0.024,0.605-0.091,1.198-0.091,1.809c0,24.878,20.168,45.046,45.046,45.046s45.046-20.168,45.046-45.046
|
||||
c0-24.879-20.168-45.046-45.046-45.046c-15.997,0-30.01,8.362-38.002,20.929l-4.317-0.959c-24.51-5.446-49.807,0.442-69.395,16.156
|
||||
c-19.564,15.695-30.792,39.074-30.818,64.152c-42.332,1.934-80.878,14.331-111.052,33.785c-9.767-9.798-23.271-15.866-38.2-15.866
|
||||
C24.16,142.656,0,166.815,0,196.618c0,20.765,11.75,38.755,28.946,47.776c-1.306,6.68-1.993,13.51-1.993,20.462
|
||||
c0,77.538,84.126,140.395,187.901,140.395s187.901-62.857,187.901-140.395c0-6.948-0.687-13.775-1.991-20.452
|
||||
C417.961,235.381,429.709,217.385,429.709,196.618z M345.746,47.743c12,0,21.762,9.762,21.762,21.762
|
||||
c0,11.999-9.762,21.761-21.762,21.761s-21.762-9.762-21.762-21.761C323.984,57.505,333.747,47.743,345.746,47.743z M23.284,196.618
|
||||
c0-16.916,13.762-30.678,30.678-30.678c7.245,0,13.895,2.538,19.142,6.758c-16.412,14.08-29.118,30.631-37.007,48.804
|
||||
C28.349,215.937,23.284,206.868,23.284,196.618z M333.784,345.477c-31.492,23.53-73.729,36.489-118.929,36.489
|
||||
s-87.437-12.959-118.929-36.489c-29.462-22.013-45.688-50.645-45.688-80.621c0-29.977,16.226-58.609,45.688-80.622
|
||||
c31.492-23.53,73.729-36.489,118.929-36.489s87.437,12.959,118.929,36.489c29.462,22.013,45.688,50.645,45.688,80.622
|
||||
C379.471,294.832,363.246,323.464,333.784,345.477z M393.605,221.488c-7.891-18.17-20.596-34.716-37.005-48.794
|
||||
c5.247-4.22,11.901-6.754,19.147-6.754c16.916,0,30.678,13.762,30.678,30.678C406.424,206.867,401.353,215.925,393.605,221.488z"/>
|
||||
<g>
|
||||
<circle style="fill:#D80000;" cx="146.22" cy="232.07" r="24.57"/>
|
||||
<circle style="fill:#D80000;" cx="283.48" cy="232.07" r="24.57"/>
|
||||
</g>
|
||||
<path style="fill:#181A1C;" d="M273.079,291.773c-17.32,15.78-39.773,24.47-63.224,24.47c-26.332,0-50.729-10.612-68.696-29.881
|
||||
c-4.384-4.704-11.751-4.96-16.454-0.575c-4.703,4.384-4.96,11.752-0.575,16.454c22.095,23.695,53.341,37.285,85.726,37.285
|
||||
c29.266,0,57.288-10.847,78.905-30.543c4.752-4.33,5.096-11.694,0.765-16.446C285.197,287.788,277.838,287.44,273.079,291.773z"/>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
BIN
public/tile-wide.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
public/tile.png
Normal file
After Width: | Height: | Size: 24 KiB |
40
public/turtle/Detector.js
Normal file
|
@ -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 <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br />',
|
||||
'Find out how to get it <a href="http://get.webgl.org/">here</a>.'
|
||||
].join( '\n' ) : [
|
||||
'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>.<br/>',
|
||||
'Find out how to get it <a href="http://get.webgl.org/">here</a>.'
|
||||
].join( '\n' );
|
||||
|
||||
}
|
||||
|
||||
return element;
|
||||
|
||||
},
|
||||
|
||||
addGetWebGLMessage: function (parent ) {
|
||||
|
||||
parent.appendChild( Detector.getWebGLErrorMessage() );
|
||||
|
||||
}
|
||||
|
||||
};
|
537
public/turtle/TrackballControls.js
Normal file
|
@ -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 );
|
22
public/turtle/index.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WebGL PixelPlace TechDemo Globe</title>
|
||||
<style>
|
||||
body { margin: 0; overflow: hidden; background-color: #000; }
|
||||
.tm { position: absolute; top: 10px; right: 10px; }
|
||||
.webgl-error { font: 15px/30px monospace; text-align: center; color: #fff; margin: 50px; }
|
||||
.webgl-error a { color: #fff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="webgl"></div>
|
||||
<script src="https://unpkg.com/three@0.91.0/build/three.min.js"></script>
|
||||
<script src="https://unpkg.com/three@0.91.0/examples/js/loaders/GLTFLoader.js"></script>
|
||||
<script src="Detector.js"></script>
|
||||
<script src="TrackballControls.js"></script>
|
||||
<script src="space.js"></script>
|
||||
</body>
|
||||
</html>
|
137
public/turtle/space.js
Normal file
|
@ -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
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}());
|
BIN
public/turtle/turtle.glb
Normal file
6
public/vklogo.svg
Normal file
|
@ -0,0 +1,6 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" viewBox="0 0 192 192">
|
||||
<g fill="none" fill-rule="evenodd">
|
||||
<path fill="#5181B8" d="M66.56,0 C120.32,0 71.68,0 125.44,0 C179.2,0 192,12.8 192,66.56 C192,120.32 192,71.68 192,125.44 C192,179.2 179.2,192 125.44,192 C71.68,192 120.32,192 66.56,192 C12.8,192 0,179.2 0,125.44 C0,71.68 0,96.580329 0,66.56 C0,12.8 12.8,0 66.56,0 Z"/>
|
||||
<path fill="#FFFFFF" d="M157.233993,66.1462211 C158.123557,63.1797719 157.233994,61 153.000244,61 L139.000244,61 C135.440505,61 133.799415,62.8830035 132.909356,64.9593945 C132.909356,64.9593945 125.789878,82.3129373 115.704198,93.5851974 C112.441227,96.8481681 110.957879,97.8863636 109.178009,97.8863636 C108.288198,97.8863636 107,96.8481681 107,93.8819658 L107,66.1462211 C107,62.586482 105.96694,61 103.000244,61 L81.0002441,61 C78.7757158,61 77.4378669,62.6521562 77.4378669,64.2179674 C77.4378669,67.5925348 82.4804603,68.3707494 83.0002441,77.8633869 L83.0002441,98.4799003 C83.0002441,103 82.1839388,103.819509 80.4040693,103.819509 C75.6579974,103.819509 64.1131647,86.388441 57.2660122,66.4427426 C55.9241353,62.5659897 54.5782535,61 51.0002441,61 L37.0002441,61 C33.0002441,61 32.2001953,62.8830035 32.2001953,64.9593945 C32.2001953,68.6675178 36.9465141,87.059256 54.2998099,111.383646 C65.8685915,127.995268 82.1682449,137 97.0002441,137 C105.899345,137 107.000244,135 107.000244,131.555007 L107.000244,119 C107.000244,115 107.843292,114.201711 110.661357,114.201711 C112.737749,114.201711 116.297488,115.239906 124.603545,123.249196 C134.095936,132.741586 135.660882,137 141.000244,137 L155.000244,137 C159.000244,137 161.000244,135 159.846475,131.053112 C158.583906,127.119411 154.051802,121.412135 148.038124,114.646617 C144.774906,110.790356 139.88045,106.637574 138.397102,104.560689 C136.320711,101.891255 136.914001,100.704429 138.397102,98.3315162 C138.397102,98.3315162 155.454123,74.3036478 157.233993,66.1462211 Z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
BIN
public/vpPlace.png
Normal file
After Width: | Height: | Size: 230 KiB |
674
src/actions/index.js
Normal file
|
@ -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<Action> {
|
||||
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());
|
||||
};
|
||||
}
|
||||
|
62
src/actions/types.js
Normal file
|
@ -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<Action>;
|
||||
export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
|
||||
export type GetState = () => State;
|
||||
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
|
88
src/canvases.json
Normal file
|
@ -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
|
||||
}
|
||||
}
|
269
src/client.js
Normal file
|
@ -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(
|
||||
<Provider store={store}>
|
||||
<App />
|
||||
</Provider>,
|
||||
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);
|
||||
});
|
37
src/components/Admin.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* react html for adminpage
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
const Admin = () => (
|
||||
<form method="post" action="admintools" encType="multipart/form-data">
|
||||
<p>------Image Upload------</p>
|
||||
<p>file:</p>
|
||||
<select name="imageaction">
|
||||
<option value="build">build</option>
|
||||
<option value="protect">protect</option>
|
||||
<option value="wipe">wipe</option>
|
||||
</select>
|
||||
<input type="file" name="image" /><br />
|
||||
<p><span>canvasId (d: default, m: moon):</span>
|
||||
<input type="text" name="canvasident" /></p>
|
||||
<span>x:</span>
|
||||
<input type="number" name="x" min="-40000" max="40000" /><br />
|
||||
<span>y:</span>
|
||||
<input type="number" name="y" min="-40000" max="40000" /><br />
|
||||
<br />
|
||||
<p>---------IP actions---------</p>
|
||||
<select name="action">
|
||||
<option value="ban">ban</option>
|
||||
<option value="unban">unban</option>
|
||||
<option value="whitelist">whitelist</option>
|
||||
<option value="unwhitelist">unwhitelist</option>
|
||||
</select>
|
||||
<input type="text" name="ip" /><br />
|
||||
<p>-----------------------</p>
|
||||
<button type="submit" name="upload">Submit</button>
|
||||
</form>
|
||||
);
|
||||
|
||||
export default Admin;
|
54
src/components/App.js
Normal file
|
@ -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 = () => (
|
||||
<div>
|
||||
<style dangerouslySetInnerHTML={{ __html: baseCss }} />
|
||||
<canvas id="gameWindow" />
|
||||
<div id="outstreamContainer" />
|
||||
<ReCaptcha />
|
||||
<IconContext.Provider value={{ style: { verticalAlign: 'middle' } }}>
|
||||
<CoolDownBox />
|
||||
<NotifyBox />
|
||||
<Menu />
|
||||
<GlobeButton />
|
||||
<CanvasSwitchButton />
|
||||
<PalselButton />
|
||||
<ChatButton />
|
||||
<Palette />
|
||||
<ChatBox />
|
||||
<OnlineBox />
|
||||
<CoordinatesBox />
|
||||
<ExpandMenuButton />
|
||||
<ModalRoot />
|
||||
</IconContext.Provider>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default App;
|
42
src/components/CanvasSwitchButton.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { FaGlobe, FaGlobeAfrica } from 'react-icons/fa';
|
||||
|
||||
import { switchCanvas } from '../actions';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
function globe(canvasId, canvasIdent, canvasSize, view) {
|
||||
const [x, y] = view.map(Math.round);
|
||||
window.location.href = `globe/#${canvasIdent},${canvasId},${canvasSize},${x},${y}`;
|
||||
}
|
||||
|
||||
|
||||
const CanvasSwitchButton = ({ canvasId, switchCanvas }) => (
|
||||
<div id="canvasbutton" className="actionbuttons" onClick={() => switchCanvas(canvasId)}>
|
||||
{(canvasId == 0) ? <FaGlobe /> : <FaGlobeAfrica />}
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { canvasId } = state.canvas;
|
||||
return { canvasId };
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
switchCanvas(canvasId) {
|
||||
const newCanvasId = (canvasId == 0) ? 1 : 0;
|
||||
dispatch(switchCanvas(newCanvasId));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps,
|
||||
mapDispatchToProps)(CanvasSwitchButton);
|
115
src/components/ChangeMail.js
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Change Mail Form
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { validateName, validateEMail, validatePassword, parseAPIresponse } from '../utils/validation';
|
||||
|
||||
function validate(email, password) {
|
||||
const errors = [];
|
||||
|
||||
const passerror = validatePassword(password);
|
||||
if (passerror) errors.push(passerror);
|
||||
const mailerror = validateEMail(email);
|
||||
if (mailerror) errors.push(mailerror);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
async function submit_mailchange(email, password) {
|
||||
const body = JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
const response = await fetch('./api/auth/change_mail', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body,
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
return parseAPIresponse(response);
|
||||
}
|
||||
|
||||
class ChangeMail extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
password: '',
|
||||
email: '',
|
||||
submitting: false,
|
||||
success: false,
|
||||
|
||||
errors: [],
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { email, password, submitting } = this.state;
|
||||
if (submitting) return;
|
||||
|
||||
const errors = validate(email, password);
|
||||
|
||||
this.setState({ errors });
|
||||
if (errors.length > 0) return;
|
||||
this.setState({ submitting: true });
|
||||
|
||||
const { errors: resperrors } = await submit_mailchange(email, password);
|
||||
if (resperrors) {
|
||||
this.setState({
|
||||
errors: resperrors,
|
||||
submitting: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
success: true,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.success) {
|
||||
return (
|
||||
<div className="inarea">
|
||||
<p className="modalmessage">Changed Mail successfully. We sent you a verification mail, please verify your new mail adress.</p>
|
||||
<button type="button" onClick={this.props.done}>Close</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<div className="inarea">
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
{errors.map(error => (
|
||||
<p key={error} className="errormessage">Error: {error}</p>
|
||||
))}
|
||||
<input
|
||||
value={this.state.password}
|
||||
onChange={evt => this.setState({ password: evt.target.value })}
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
/>
|
||||
<br />
|
||||
<input
|
||||
value={this.state.email}
|
||||
onChange={evt => this.setState({ email: evt.target.value })}
|
||||
type="text"
|
||||
placeholder="New Mail"
|
||||
/>
|
||||
<br />
|
||||
<button type="submit">{(this.state.submitting) ? '...' : 'Save'}</button>
|
||||
<button type="button" onClick={this.props.done}>Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ChangeMail;
|
95
src/components/ChangeName.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Change Name Form
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { validateName, parseAPIresponse } from '../utils/validation';
|
||||
|
||||
|
||||
function validate(name) {
|
||||
const errors = [];
|
||||
|
||||
const nameerror = validateName(name);
|
||||
if (nameerror) errors.push(nameerror);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
async function submit_namechange(name) {
|
||||
const body = JSON.stringify({
|
||||
name,
|
||||
});
|
||||
const response = await fetch('./api/auth/change_name', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body,
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
return parseAPIresponse(response);
|
||||
}
|
||||
|
||||
class ChangeName extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
name: '',
|
||||
submitting: false,
|
||||
|
||||
errors: [],
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { name, submitting } = this.state;
|
||||
if (submitting) return;
|
||||
|
||||
const errors = validate(name);
|
||||
|
||||
this.setState({ errors });
|
||||
if (errors.length > 0) return;
|
||||
this.setState({ submitting: true });
|
||||
|
||||
const { errors: resperrors } = await submit_namechange(name);
|
||||
if (resperrors) {
|
||||
this.setState({
|
||||
errors: resperrors,
|
||||
submitting: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.props.set_name(name);
|
||||
this.props.done();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<div className="inarea">
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
{errors.map(error => (
|
||||
<p key={error} className="errormessage">Error: {error}</p>
|
||||
))}
|
||||
<input
|
||||
value={this.state.name}
|
||||
onChange={evt => this.setState({ name: evt.target.value })}
|
||||
type="text"
|
||||
placeholder="New Username"
|
||||
/>
|
||||
<br />
|
||||
<button type="submit">{(this.state.submitting) ? '...' : 'Save'}</button>
|
||||
<button type="button" onClick={this.props.done}>Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ChangeName;
|
132
src/components/ChangePassword.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Change Password Form
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { validatePassword, parseAPIresponse } from '../utils/validation';
|
||||
|
||||
function validate(mailreg, password, new_password, confirm_password) {
|
||||
const errors = [];
|
||||
|
||||
if (mailreg) {
|
||||
const oldpasserror = validatePassword(password);
|
||||
if (oldpasserror) errors.push(oldpasserror);
|
||||
}
|
||||
if (new_password != confirm_password) {
|
||||
errors.push('Passwords do not match.');
|
||||
return errors;
|
||||
}
|
||||
const passerror = validatePassword(new_password);
|
||||
if (passerror) errors.push(passerror);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
async function submit_passwordchange(new_password, password) {
|
||||
const body = JSON.stringify({
|
||||
password,
|
||||
new_password,
|
||||
});
|
||||
const response = await fetch('./api/auth/change_passwd', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body,
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
return parseAPIresponse(response);
|
||||
}
|
||||
|
||||
|
||||
class ChangePassword extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
password: '',
|
||||
new_password: '',
|
||||
confirm_password: '',
|
||||
success: false,
|
||||
submitting: false,
|
||||
|
||||
errors: [],
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { password, new_password, confirm_password, submitting } = this.state;
|
||||
if (submitting) return;
|
||||
|
||||
const errors = validate(this.props.mailreg, password, new_password, confirm_password);
|
||||
|
||||
this.setState({ errors });
|
||||
if (errors.length > 0) return;
|
||||
this.setState({ submitting: true });
|
||||
|
||||
const { errors: resperrors } = await submit_passwordchange(new_password, password);
|
||||
if (resperrors) {
|
||||
this.setState({
|
||||
errors: resperrors,
|
||||
submitting: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
success: true,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.success) {
|
||||
return (
|
||||
<div className="inarea">
|
||||
<p className="modalmessage">Changed Password successfully.</p>
|
||||
<button type="button" onClick={this.props.done}>Close</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<div className="inarea">
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
{errors.map(error => (
|
||||
<p key={error} className="errormessage">Error: {error}</p>
|
||||
))}
|
||||
{(this.props.mailreg) &&
|
||||
<input
|
||||
value={this.state.password}
|
||||
onChange={evt => this.setState({ password: evt.target.value })}
|
||||
type="password"
|
||||
placeholder="Old Password"
|
||||
/>
|
||||
}
|
||||
<br />
|
||||
<input
|
||||
value={this.state.new_password}
|
||||
onChange={evt => this.setState({ new_password: evt.target.value })}
|
||||
type="password"
|
||||
placeholder="New Password"
|
||||
/>
|
||||
<br />
|
||||
<input
|
||||
value={this.state.confirm_password}
|
||||
onChange={evt => this.setState({ confirm_password: evt.target.value })}
|
||||
type="password"
|
||||
placeholder="Confirm New Password"
|
||||
/>
|
||||
<br />
|
||||
<button type="submit">{(this.state.submitting) ? '...' : 'Save'}</button>
|
||||
<button type="button" onClick={this.props.cancel}>Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ChangePassword;
|
57
src/components/Chat.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React, { useRef, useLayoutEffect } from 'react';
|
||||
import useStayScrolled from 'react-stay-scrolled';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
import ChatInput from './ChatInput';
|
||||
import { colorFromText, splitCoordsInString } from '../core/utils';
|
||||
|
||||
|
||||
const Chat = ({ chatMessages }) => {
|
||||
const listRef = useRef();
|
||||
const { stayScrolled } = useStayScrolled(listRef, {
|
||||
initialScroll: Infinity,
|
||||
});
|
||||
|
||||
useLayoutEffect(() => {
|
||||
stayScrolled();
|
||||
}, [chatMessages.length]);
|
||||
|
||||
return (
|
||||
<div style={{ height: '100%' }}>
|
||||
<ul className="chatarea" ref={listRef}>
|
||||
{
|
||||
chatMessages.map(message => (
|
||||
<p className="chatmsg">
|
||||
{(message[0] == 'info') ?
|
||||
<span style={{ color: '#cc0000' }}>{message[1]}</span> :
|
||||
<div>
|
||||
<span className="chatname" style={{ color: colorFromText(message[0]) }}>{`${message[0]}: `}</span>
|
||||
{
|
||||
splitCoordsInString(message[1]).map((text, i) => {
|
||||
if (i % 2 == 0) { return (<span className="msg">{text}</span>); }
|
||||
return (<a href={`./${text}`}>{text}</a>);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</p>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
<ChatInput />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { chatMessages } = state.user;
|
||||
return { chatMessages };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(Chat);
|
29
src/components/ChatBox.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
import Chat from './Chat';
|
||||
|
||||
|
||||
const ChatBox = ({ chatOpen }) => (
|
||||
<div>
|
||||
{(chatOpen) ?
|
||||
<div className="chatbox">
|
||||
<Chat />
|
||||
</div> : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
// TODO optimize
|
||||
function mapStateToProps(state: State) {
|
||||
const { chatOpen } = state.modal;
|
||||
return { chatOpen };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(ChatBox);
|
27
src/components/ChatButton.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdForum } from 'react-icons/md';
|
||||
|
||||
import { showChatModal } from '../actions';
|
||||
|
||||
|
||||
const ChatButton = ({ name, open }) => (
|
||||
<div id="chatbutton" className="actionbuttons" onClick={open}>
|
||||
<MdForum />
|
||||
</div>: null
|
||||
);
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
open() {
|
||||
dispatch(showChatModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(ChatButton);
|
71
src/components/ChatInput.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Chat input field
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
import ProtocolClient from '../socket/ProtocolClient';
|
||||
|
||||
import { showUserAreaModal } from '../actions';
|
||||
|
||||
class ChatInput extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
message: '',
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { message } = this.state;
|
||||
if (!message) return;
|
||||
// send message via websocket
|
||||
ProtocolClient.sendMessage(message);
|
||||
this.setState({
|
||||
message: '',
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.props.name) {
|
||||
return (
|
||||
<div className="chatinput">
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<input
|
||||
style={{ maxWidth: '80%', width: '240px' }}
|
||||
value={this.state.message}
|
||||
onChange={evt => this.setState({ message: evt.target.value })}
|
||||
type="text"
|
||||
placeholder="Chat here"
|
||||
/>
|
||||
<button id="chatmsginput" type="submit">Send</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="modallink" onClick={this.props.open} style={{ textAlign: 'center', fontSize: 13 }}>You must be logged in to chat</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { name } = state.user;
|
||||
return { name };
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
open() {
|
||||
dispatch(showUserAreaModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ChatInput);
|
44
src/components/ChatModal.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Modal from './Modal';
|
||||
import Chat from './Chat';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const textStyle = {
|
||||
color: 'hsla(218, 5%, 47%, .6)',
|
||||
fontSize: 14,
|
||||
fontWeight: 500,
|
||||
position: 'relative',
|
||||
textAlign: 'inherit',
|
||||
float: 'none',
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
lineHeight: 'normal',
|
||||
};
|
||||
|
||||
|
||||
const ChatModal = ({ center }) => (
|
||||
<Modal title="Chat">
|
||||
<p style={{ textAlign: 'center' }}>
|
||||
<p style={textStyle}>Chat with other people here</p>
|
||||
</p>
|
||||
<div className="inarea" style={{ height: '65%' }}>
|
||||
<Chat />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { center } = state.user;
|
||||
return { center };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(ChatModal);
|
31
src/components/CoolDownBox.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import {
|
||||
durationToString,
|
||||
} from '../core/utils';
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const CoolDownBox = ({ coolDown }) => (
|
||||
<div
|
||||
className="cooldownbox"
|
||||
style={{
|
||||
display: (coolDown) ? 'block' : 'none',
|
||||
}}
|
||||
>
|
||||
{coolDown && durationToString(coolDown, true)}
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { coolDown } = state.user;
|
||||
return { coolDown };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(CoolDownBox);
|
31
src/components/CoordinatesBox.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { screenToWorld } from '../core/utils';
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
function renderCoordinates([x, y]: Cell): string {
|
||||
return `(${x}, ${y})`;
|
||||
}
|
||||
|
||||
// TODO vaya chapuza, arreglalo un poco...
|
||||
// TODO create viewport state
|
||||
const CoordinatesBox = ({ state, view, hover }) => (
|
||||
<div className="coorbox">{renderCoordinates(hover
|
||||
? screenToWorld(state, document.getElementById('gameWindow'), hover)
|
||||
: view.map(Math.round))}</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { view } = state.canvas;
|
||||
const { hover } = state.gui;
|
||||
return { view, state, hover };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(CoordinatesBox);
|
56
src/components/Creeper.svg
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
x="0px"
|
||||
y="0px"
|
||||
width="864px"
|
||||
height="864px"
|
||||
viewBox="0 0 864 864"
|
||||
enable-background="new 0 0 864 864"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="Creeper.svg"
|
||||
inkscape:version="0.92.4 (unknown)"><metadata
|
||||
id="metadata13"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs11" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="2416"
|
||||
inkscape:window-height="1621"
|
||||
id="namedview9"
|
||||
showgrid="false"
|
||||
inkscape:zoom="0.77257965"
|
||||
inkscape:cx="13.722139"
|
||||
inkscape:cy="191.30415"
|
||||
inkscape:window-x="423"
|
||||
inkscape:window-y="239"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="g6" />
|
||||
<g
|
||||
id="g6">
|
||||
|
||||
<path
|
||||
d="m 169.92806,224.8757 c 12.96191,0 174.83965,2.84395 174.83965,2.84395 1.031,45.06702 -0.18501,97.37311 -0.18501,144.3008 H 169.92691 c 8.5e-4,-48.64059 8.5e-4,-96.25484 8.5e-4,-147.14475 z m 443.64407,451.61505 c 0,0 -81.1844,-0.18967 -85.99494,-0.0279 -0.0349,0.0116 -0.0698,0.0302 -0.10705,0.0279 -0.19899,-0.0105 -0.14779,-0.021 0.10705,-0.0279 3.75627,-1.25326 -0.69004,-78.95949 -0.69004,-78.95949 -30.07804,0 -157.04976,0.33745 -181.70519,-0.35492 v 77.17678 c 0,0 -60.2026,0.13615 -86.31027,0.13615 V 450.98926 h 88.10464 V 377.78518 H 523.3194 v 69.88884 h 90.25273 z m 90.54596,-304.1119 H 527.47014 V 224.80121 h 176.64795 z"
|
||||
id="path4"
|
||||
inkscape:connector-curvature="0"
|
||||
style="clip-rule:evenodd;fill:#1a1a1a;fill-rule:evenodd;stroke-width:1.16365039"
|
||||
sodipodi:nodetypes="ccccccccccccccccccccccccc" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
40
src/components/DailyRankings.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Rankings Tabs
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
const DailyRankings = ({ totalDailyRanking }) => (
|
||||
<div style={{ overflowY: 'auto' }}>
|
||||
<table>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>user</th>
|
||||
<th>Pixels</th>
|
||||
<th># Total</th>
|
||||
<th>Total Pixels</th>
|
||||
</tr>
|
||||
{
|
||||
totalDailyRanking.map(rank => (
|
||||
<tr>
|
||||
<td>{rank.dailyRanking}</td>
|
||||
<td>{rank.name}</td>
|
||||
<td>{rank.dailyTotalPixels}</td>
|
||||
<td>{rank.ranking}</td>
|
||||
<td>{rank.totalPixels}</td>
|
||||
</tr>))
|
||||
}
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { totalDailyRanking } = state.user;
|
||||
return { totalDailyRanking };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(DailyRankings);
|
93
src/components/DeleteAccount.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Change Password Form
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { validatePassword, parseAPIresponse } from '../utils/validation';
|
||||
|
||||
function validate(password) {
|
||||
const errors = [];
|
||||
|
||||
const passworderror = validatePassword(password);
|
||||
if (passworderror) errors.push(passworderror);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
async function submit_delete_account(password) {
|
||||
const body = JSON.stringify({
|
||||
password,
|
||||
});
|
||||
const response = await fetch('./api/auth/delete_account', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body,
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
return parseAPIresponse(response);
|
||||
}
|
||||
|
||||
class DeleteAccount extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
password: '',
|
||||
submitting: false,
|
||||
|
||||
errors: [],
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { password, submitting } = this.state;
|
||||
if (submitting) return;
|
||||
|
||||
const errors = validate(password);
|
||||
|
||||
this.setState({ errors });
|
||||
if (errors.length > 0) return;
|
||||
this.setState({ submitting: true });
|
||||
|
||||
const { errors: resperrors } = await submit_delete_account(password);
|
||||
if (resperrors) {
|
||||
this.setState({
|
||||
errors: resperrors,
|
||||
submitting: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.props.set_name(null);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<div className="inarea" style={{ backgroundColor: '#ff6666' }}>
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
{errors.map(error => (
|
||||
<p key={error} className="errormessage">Error: {error}</p>
|
||||
))}
|
||||
<input
|
||||
value={this.state.password}
|
||||
onChange={evt => this.setState({ password: evt.target.value })}
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
/>
|
||||
<br />
|
||||
<button type="submit">{(this.state.submitting) ? '...' : 'Yes, Delete My Account!'}</button>
|
||||
<button type="button" onClick={this.props.done}>Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default DeleteAccount;
|
43
src/components/DownloadButton.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdFileDownload } from 'react-icons/md';
|
||||
import fileDownload from 'react-file-download';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
/**
|
||||
* https://jsfiddle.net/AbdiasSoftware/7PRNN/
|
||||
*/
|
||||
function download(view) {
|
||||
// TODO id shouldnt be hardcoded
|
||||
const $viewport = document.getElementById('gameWindow');
|
||||
if (!$viewport) return;
|
||||
|
||||
// TODO change name
|
||||
|
||||
const [x, y] = view.map(Math.round);
|
||||
const filename = `pixelplanet-${x}-${y}.png`;
|
||||
|
||||
$viewport.toBlob(blob => fileDownload(blob, filename));
|
||||
}
|
||||
|
||||
|
||||
const DownloadButton = ({ view }) => (
|
||||
<div id="downloadbutton" className="actionbuttons" onClick={() => download(view)}>
|
||||
<MdFileDownload />
|
||||
</div>
|
||||
);
|
||||
|
||||
// TODO optimize
|
||||
function mapStateToProps(state: State) {
|
||||
const { view } = state.canvas;
|
||||
return { view };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(DownloadButton);
|
30
src/components/ExpandMenuButton.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* espand menu / show other menu buttons
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdExpandMore, MdExpandLess } from 'react-icons/md';
|
||||
|
||||
import { toggleOpenMenu } from '../actions';
|
||||
|
||||
const ExpandMenuButton = ({ menuOpen, expand }) => (
|
||||
<div id="menubutton" className="actionbuttons" onClick={expand}>
|
||||
{(menuOpen) ? <MdExpandLess /> : <MdExpandMore /> }
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { menuOpen } = state.gui;
|
||||
return { menuOpen };
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
expand() {
|
||||
dispatch(toggleOpenMenu());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ExpandMenuButton);
|
50
src/components/ForgotPasswordModal.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Modal from './Modal';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
import { showUserAreaModal } from '../actions';
|
||||
import NewPasswordForm from './NewPasswordForm';
|
||||
|
||||
const textStyle = {
|
||||
color: 'hsla(218, 5%, 47%, .6)',
|
||||
fontSize: 14,
|
||||
fontWeight: 500,
|
||||
position: 'relative',
|
||||
textAlign: 'inherit',
|
||||
float: 'none',
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
lineHeight: 'normal',
|
||||
};
|
||||
|
||||
const ForgotPasswordModal = ({ login }) => (
|
||||
<Modal title="Restore my Password">
|
||||
<p style={textStyle}>Enter your mail adress and we will send you a new password:</p><br />
|
||||
<p style={{ textAlign: 'center' }}>
|
||||
<NewPasswordForm back={login} />
|
||||
<p>Also join our Discord: <a href="./discord" target="_blank">pixelplanet.fun/discord</a></p>
|
||||
</p>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
login() {
|
||||
dispatch(showUserAreaModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ForgotPasswordModal);
|
34
src/components/GlobeButton.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Md3DRotation } from 'react-icons/md';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
/**
|
||||
* https://jsfiddle.net/AbdiasSoftware/7PRNN/
|
||||
*/
|
||||
function globe(canvasId, canvasIdent, canvasSize, view) {
|
||||
const [x, y] = view.map(Math.round);
|
||||
window.location.href = `go/#${canvasIdent},${canvasId},${canvasSize},${x},${y}`;
|
||||
}
|
||||
|
||||
|
||||
const GlobeButton = ({ canvasId, canvasIdent, canvasSize, view }) => (
|
||||
<div id="globebutton" className="actionbuttons" onClick={() => globe(canvasId, canvasIdent, canvasSize, view)}>
|
||||
<Md3DRotation />
|
||||
</div>
|
||||
);
|
||||
|
||||
// TODO optimize
|
||||
function mapStateToProps(state: State) {
|
||||
const { canvasId, canvasIdent, canvasSize, view } = state.canvas;
|
||||
return { canvasId, canvasIdent, canvasSize, view };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(GlobeButton);
|
32
src/components/GridButton.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { FaTh } from 'react-icons/fa';
|
||||
|
||||
import { toggleGrid } from '../actions';
|
||||
|
||||
|
||||
const GridButton = ({ onToggleGrid }) => (
|
||||
<div className="actionbuttons" onClick={onToggleGrid}>
|
||||
<FaTh />
|
||||
</div>
|
||||
);
|
||||
|
||||
// TODO simplify...
|
||||
function mapStateToProps(state: State) {
|
||||
return {};
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
open() {
|
||||
dispatch(toggleGrid());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(GridButton);
|
28
src/components/HelpButton.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { FaQuestion } from 'react-icons/fa';
|
||||
|
||||
import { showHelpModal } from '../actions';
|
||||
|
||||
|
||||
const HelpButton = ({ open }) => (
|
||||
<div id="helpbutton" className="actionbuttons" onClick={open}>
|
||||
<FaQuestion />
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
open() {
|
||||
dispatch(showHelpModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(HelpButton);
|
97
src/components/HelpModal.js
Normal file
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
// import FaFacebook from 'react-icons/lib/fa/facebook';
|
||||
// import FaTwitter from 'react-icons/lib/fa/twitter';
|
||||
// import FaRedditAlien from 'react-icons/lib/fa/reddit-alien';
|
||||
|
||||
import Modal from './Modal';
|
||||
import { social, MIN_COOLDOWN, BLANK_COOLDOWN } from '../core/constants';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const linkStyle = {
|
||||
textDecoration: 'none',
|
||||
color: '#428bca',
|
||||
};
|
||||
|
||||
const titleStyle = {
|
||||
color: '#4f545c',
|
||||
marginLeft: 0,
|
||||
marginRight: 10,
|
||||
overflow: 'hidden',
|
||||
wordWrap: 'break-word',
|
||||
lineHeight: '24px',
|
||||
fontSize: 16,
|
||||
fontWeight: 500,
|
||||
// marginTop: 0,
|
||||
marginBottom: 0,
|
||||
};
|
||||
|
||||
const textStyle = {
|
||||
color: 'hsla(218, 5%, 47%, .6)',
|
||||
fontSize: 14,
|
||||
fontWeight: 500,
|
||||
position: 'relative',
|
||||
textAlign: 'inherit',
|
||||
float: 'none',
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
lineHeight: 'normal',
|
||||
};
|
||||
|
||||
|
||||
const HelpModal = ({ center }) => (
|
||||
<Modal title="Welcome to PixelPlanet.fun">
|
||||
<p style={{ textAlign: 'center' }}>
|
||||
<p style={textStyle}>Place color pixels on a large canvas with other players online!
|
||||
Cooldown is {(BLANK_COOLDOWN / 1000) | 0} seconds for fresh pixels and {(MIN_COOLDOWN / 1000) | 0}s for overwriting existing pixels!
|
||||
The current canvas size is from -32768 to +32768 in x and y.
|
||||
Higher zoomlevels take some time to update, the 3D globe gets updated at least once per day.
|
||||
Have fun!</p>
|
||||
<p>New Discord: <a href="./discord" target="_blank">pixelplanet.fun/discord</a></p>
|
||||
<p>Reddit: <a href="https://www.reddit.com/r/PixelPlanetFun/" target="_blank">r/PixelPlanetFun</a></p>
|
||||
<p>Image Converter: <a href="./convert" target="_blank">pixelplanet.fun/convert</a></p>
|
||||
<p>Image Converter for 2nd Planet: <a href="./convert2" target="_blank">pixelplanet.fun/convert2</a></p>
|
||||
<p style={titleStyle}>Map Data</p>
|
||||
<p style={textStyle}>The bare map data that we use, together with converted OpenStreetMap tiles for orientation,
|
||||
can be downloaded from mega.nz here: <a href="https://mega.nz/#!JpkBwAbJ!EnSLlZmKv3kEBE0HDhakTgAZZycD3ELjduajJxPGaXo">pixelplanetmap.zip</a> (422MB)</p>
|
||||
<p style={titleStyle}>GIMP Palette</p>
|
||||
<p style={textStyle}>The Palettes for <a href="https://www.gimp.org">GIMP</a> can be found <a href="./palette0.gpl">here</a> and <a href="./palette1.gpl">here</a>. Credit for the Palette of the second planet goes to <a href="https://twitter.com/starhousedev">starhouse</a>.</p>
|
||||
<p style={titleStyle}>Detected as Proxy?</p>
|
||||
<p style={textStyle}>If you got detected as proxy, but you are none, please send us an e-mail with <a href="https://www.whatismyip.com/">your IP</a> to pixelplanetdev@gmail.com. Don't post your IP anywhere else. We are sorry for the inconvenience.</p>
|
||||
<h3 style={titleStyle}>Controls</h3>
|
||||
<p style={textStyle}>Click a color in palette to select</p>
|
||||
<p style={textStyle}>Press <kbd>G</kbd> to toggle grid</p>
|
||||
<p style={textStyle}>Press <kbd>C</kbd> to toggle showing of pixel activity</p>
|
||||
<p style={textStyle}>Press <kbd>q</kbd> or <kbd>e</kbd> to zoom</p>
|
||||
<p style={textStyle}>Press <kbd>W</kbd>,<kbd>A</kbd>,<kbd>S</kbd>, <kbd>D</kbd> to move</p>
|
||||
<p style={textStyle}>Press <kbd>↑</kbd>,<kbd>←</kbd>,<kbd>↓</kbd>, <kbd>→</kbd> to move</p>
|
||||
<p style={textStyle}>Drag mouse to move</p>
|
||||
<p style={textStyle}>Scroll mouse wheel to zoom</p>
|
||||
<p style={textStyle}>Click middle mouse button to current hovering color</p>
|
||||
<p style={textStyle}>Pinch to zoom (on touch devices)</p>
|
||||
<p style={textStyle}>Pan to move (on touch devices)</p>
|
||||
<p style={textStyle}>Click or tab to place a pixel</p>
|
||||
<p>Partners: <a href="https://www.crazygames.com/c/io" target="_blank">crazygames.com</a></p>
|
||||
<p style={textStyle}>
|
||||
<small>This site is protected by reCAPTCHA and the Google
|
||||
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
|
||||
<a href="https://policies.google.com/terms">Terms of Service</a> apply.
|
||||
</small>
|
||||
</p>
|
||||
</p>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { center } = state.user;
|
||||
return { center };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(HelpModal);
|
84
src/components/Html.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
/* @flow */
|
||||
/**
|
||||
* React Starter Kit (https://www.reactstarterkit.com/)
|
||||
*
|
||||
* Copyright © 2014-present Kriasoft, LLC. All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.txt file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { analytics, RECAPTCHA_SITEKEY } from '../core/config';
|
||||
|
||||
class Html extends React.Component {
|
||||
static defaultProps = {
|
||||
styles: [],
|
||||
scripts: [],
|
||||
};
|
||||
|
||||
props: {
|
||||
title: string,
|
||||
description: string,
|
||||
styles: Array<{
|
||||
id: string,
|
||||
cssText: string,
|
||||
}>,
|
||||
scripts: Array<string>,
|
||||
body: string,
|
||||
code: string,
|
||||
};
|
||||
|
||||
render() {
|
||||
const { title, description, styles, scripts, body, code } = this.props;
|
||||
return (
|
||||
<html className="no-js" lang="en">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta httpEquiv="x-ua-compatible" content="ie=edge" />
|
||||
<title>{title}</title>
|
||||
<meta name="description" content={description} />
|
||||
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="apple-touch-icon.png" />
|
||||
{styles.map(style =>
|
||||
(<style
|
||||
key={style.id}
|
||||
id={style.id}
|
||||
// eslint-disable-next-line react/no-danger
|
||||
dangerouslySetInnerHTML={{ __html: style.cssText }}
|
||||
/>),
|
||||
)}
|
||||
{RECAPTCHA_SITEKEY && <script dangerouslySetInnerHTML={{ __html: `window.sitekey="${RECAPTCHA_SITEKEY}"` }} />}
|
||||
{RECAPTCHA_SITEKEY && <script src="https://www.google.com/recaptcha/api.js" async defer />}
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
{body}
|
||||
</div>
|
||||
<script
|
||||
// eslint-disable-next-line react/no-danger
|
||||
dangerouslySetInnerHTML={{ __html: code }}
|
||||
/>
|
||||
{scripts.map(script => <script key={script} src={script} />)}
|
||||
{analytics.google.trackingId &&
|
||||
<script
|
||||
// eslint-disable-next-line react/no-danger
|
||||
dangerouslySetInnerHTML={{ __html:
|
||||
'window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;' +
|
||||
`ga('create','${analytics.google.trackingId}','auto');ga('send','pageview')` }}
|
||||
/>
|
||||
}
|
||||
{analytics.google.trackingId &&
|
||||
<script src="https://www.google-analytics.com/analytics.js" async defer />
|
||||
}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Html;
|
29
src/components/LogInButton.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdPerson } from 'react-icons/md';
|
||||
|
||||
import { showUserAreaModal } from '../actions';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const LogInButton = ({ open }) => (
|
||||
<div id="loginbutton" className="actionbuttons" onClick={open}>
|
||||
<MdPerson />
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
open() {
|
||||
dispatch(showUserAreaModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(LogInButton);
|
107
src/components/LogInForm.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* LogIn Form
|
||||
* @flow
|
||||
*/
|
||||
import React from 'react';
|
||||
import { validateEMail, validateName, validatePassword, parseAPIresponse } from '../utils/validation';
|
||||
|
||||
|
||||
function validate(nameoremail, password) {
|
||||
const errors = [];
|
||||
const mailerror = (nameoremail.indexOf('@') !== -1) ?
|
||||
validateEMail(nameoremail) :
|
||||
validateName(nameoremail);
|
||||
if (mailerror) errors.push(mailerror);
|
||||
const passworderror = validatePassword(password);
|
||||
if (passworderror) errors.push(passworderror);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
async function submit_login(nameoremail, password, component) {
|
||||
const body = JSON.stringify({
|
||||
nameoremail,
|
||||
password,
|
||||
});
|
||||
const response = await fetch('./api/auth/local', {
|
||||
method: 'POST',
|
||||
body,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
return parseAPIresponse(response);
|
||||
}
|
||||
|
||||
const inputStyles = {
|
||||
display: 'block',
|
||||
width: '100%',
|
||||
};
|
||||
|
||||
class LogInForm extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
nameoremail: '',
|
||||
password: '',
|
||||
submitting: false,
|
||||
|
||||
errors: [],
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { nameoremail, password, submitting } = this.state;
|
||||
if (submitting) return;
|
||||
|
||||
const errors = validate(nameoremail, password);
|
||||
|
||||
this.setState({ errors });
|
||||
if (errors.length > 0) return;
|
||||
|
||||
this.setState({ submitting: true });
|
||||
const { errors: resperrors, me } = await submit_login(nameoremail, password);
|
||||
if (resperrors) {
|
||||
this.setState({
|
||||
errors: resperrors,
|
||||
submitting: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.props.me(me);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
{errors.map(error => (
|
||||
<p key={error}>Error: {error}</p>
|
||||
))}
|
||||
<input
|
||||
style={inputStyles}
|
||||
value={this.state.nameoremail}
|
||||
onChange={evt => this.setState({ nameoremail: evt.target.value })}
|
||||
type="text"
|
||||
placeholder="Name or Email"
|
||||
/>
|
||||
<input
|
||||
style={inputStyles}
|
||||
value={this.state.password}
|
||||
onChange={evt => this.setState({ password: evt.target.value })}
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
/>
|
||||
|
||||
<button type="submit">{(this.state.submitting) ? '...' : 'LogIn'}</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default LogInForm;
|
20
src/components/MdToggleButton.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import ToggleButton from 'react-toggle-button';
|
||||
import { MdCheck, MdClose } from 'react-icons/md';
|
||||
|
||||
|
||||
const MdToggleButton = ({ value, onToggle, ...props }) => (
|
||||
<ToggleButton
|
||||
inactiveLabel={<MdClose />}
|
||||
activeLabel={<MdCheck />}
|
||||
thumbAnimateRange={[-10, 36]}
|
||||
value={value}
|
||||
onToggle={onToggle}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
export default MdToggleButton;
|
32
src/components/MdToggleButtonHover.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import MdToggleButton from './MdToggleButton';
|
||||
|
||||
|
||||
const MdToggleButtonHover = ({ value, onToggle }) => (
|
||||
<MdToggleButton
|
||||
value={value}
|
||||
onToggle={onToggle}
|
||||
thumbStyle={{
|
||||
position: 'absolute',
|
||||
width: 30,
|
||||
height: 30,
|
||||
boxShadow: '0 0 2px rgba(0,0,0,.12),0 2px 4px rgba(0,0,0,.24)',
|
||||
display: 'flex',
|
||||
borderRadius: 15,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
thumbStyleHover={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
}}
|
||||
animateThumbStyleHover={n => ({
|
||||
boxShadow: `0 0 ${2 + (4 * n)}px rgba(0,0,0,.16),0 ${2 + (3 * n)}px ${4 + (8 * n)}px rgba(0,0,0,.32)`,
|
||||
})}
|
||||
/>
|
||||
);
|
||||
|
||||
export default MdToggleButtonHover;
|
33
src/components/Menu.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Menu with Buttons on the top left
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import HelpButton from './HelpButton';
|
||||
import SettingsButton from './SettingsButton';
|
||||
import LogInButton from './LogInButton';
|
||||
import DownloadButton from './DownloadButton';
|
||||
import MinecraftTPButton from './MinecraftTPButton.js';
|
||||
import MinecraftButton from './MinecraftButton';
|
||||
|
||||
const Menu = ({ menuOpen, minecraftname, messages, canvasId }) => (
|
||||
<div>
|
||||
{(menuOpen) ? <SettingsButton /> : null}
|
||||
{(menuOpen) ? <LogInButton /> : null}
|
||||
{(menuOpen) ? <DownloadButton /> : null}
|
||||
{(menuOpen) ? <MinecraftButton /> : null}
|
||||
{(menuOpen) ? <HelpButton /> : null}
|
||||
{(minecraftname && !messages.includes('not_mc_verified') && canvasId == 0) ? <MinecraftTPButton /> : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { menuOpen } = state.gui;
|
||||
const { minecraftname, messages } = state.user;
|
||||
const { canvasId } = state.canvas;
|
||||
return { menuOpen, minecraftname, messages, canvasId };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(Menu);
|
29
src/components/MinecraftButton.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import Creeper from './Creeper.svg';
|
||||
|
||||
import { showMinecraftModal } from '../actions';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const MinecraftButton = ({ open }) => (
|
||||
<div id="minecraftbutton" className="actionbuttons" onClick={open}>
|
||||
<Creeper />
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
open() {
|
||||
dispatch(showMinecraftModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(MinecraftButton);
|
27
src/components/MinecraftModal.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Modal from './Modal';
|
||||
|
||||
|
||||
const MinecraftModal = () => (
|
||||
<Modal title="PixelPlanet Minecraft Server">
|
||||
<p style={{ textAlign: 'center' }}>
|
||||
<p>You can also place pixels from our Minecraft Server at</p>
|
||||
<p><input type="text" value={'mc.pixelplanet.fun'} readOnly /></p>
|
||||
<p>Please Note that the Minecraft Server is down from time to time</p>
|
||||
</p>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { center } = state.user;
|
||||
return { center };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(MinecraftModal);
|
40
src/components/MinecraftTPButton.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdNearMe } from 'react-icons/md';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
async function submit_minecraft_tp(view) {
|
||||
const [x, y] = view.map(Math.round);
|
||||
const body = JSON.stringify({
|
||||
x,
|
||||
y,
|
||||
});
|
||||
const response = await fetch('./api/mctp', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body,
|
||||
credentials: 'include',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const MinecraftTPButton = ({ view }) => (
|
||||
<div id="minecrafttpbutton" className="actionbuttons" onClick={() => submit_minecraft_tp(view)}>
|
||||
<MdNearMe />
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { view } = state.canvas;
|
||||
return { view };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(MinecraftTPButton);
|
67
src/components/Modal.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import Modal from 'react-modal';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdClose } from 'react-icons/md';
|
||||
|
||||
import {
|
||||
hideModal,
|
||||
} from '../actions';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const closeStyles = {
|
||||
position: 'fixed',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
flex: '0 0 36px',
|
||||
borderWidth: 2,
|
||||
borderStyle: 'solid',
|
||||
borderRadius: '50%',
|
||||
width: 36,
|
||||
height: 36,
|
||||
cursor: 'pointer',
|
||||
backgroundColor: '#f6f6f7',
|
||||
borderColor: '#dcddde',
|
||||
top: 30,
|
||||
right: 40,
|
||||
};
|
||||
|
||||
|
||||
// TODO appear with animation
|
||||
function MyModal({ close, title, children }) {
|
||||
return (
|
||||
<Modal
|
||||
isOpen
|
||||
onClose={close}
|
||||
className="Modal"
|
||||
overlayClassName="Overlay"
|
||||
contentLabel={`${title} Modal`}
|
||||
onRequestClose={close}
|
||||
>
|
||||
<h2>{title}</h2>
|
||||
<div style={closeStyles} onClick={close}><MdClose /></div>
|
||||
{children}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
return {};
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
close() {
|
||||
dispatch(hideModal());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(MyModal);
|
42
src/components/ModalRoot.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* https://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions/35641680#35641680
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import HelpModal from './HelpModal';
|
||||
import SettingsModal from './SettingsModal';
|
||||
import UserAreaModal from './UserAreaModal';
|
||||
import RegisterModal from './RegisterModal';
|
||||
import ChatModal from './ChatModal';
|
||||
import ForgotPasswordModal from './ForgotPasswordModal';
|
||||
import MinecraftModal from './MinecraftModal';
|
||||
|
||||
|
||||
const MODAL_COMPONENTS = {
|
||||
HELP: HelpModal,
|
||||
SETTINGS: SettingsModal,
|
||||
USERAREA: UserAreaModal,
|
||||
REGISTER: RegisterModal,
|
||||
FORGOT_PASSWORD: ForgotPasswordModal,
|
||||
CHAT: ChatModal,
|
||||
MINECRAFT: MinecraftModal,
|
||||
/* other modals */
|
||||
};
|
||||
|
||||
const ModalRoot = ({ modalType, modalProps }) => {
|
||||
if (!modalType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const SpecificModal = MODAL_COMPONENTS[modalType];
|
||||
return <SpecificModal {...modalProps} />;
|
||||
};
|
||||
|
||||
export default connect(
|
||||
state => state.modal,
|
||||
)(ModalRoot);
|
104
src/components/NewPasswordForm.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Form for requesting password-reset mail
|
||||
* @flow
|
||||
*/
|
||||
import React from 'react';
|
||||
import { validateEMail, parseAPIresponse } from '../utils/validation';
|
||||
|
||||
function validate(email) {
|
||||
const errors = [];
|
||||
const mailerror = validateEMail(email);
|
||||
if (mailerror) errors.push(mailerror);
|
||||
return errors;
|
||||
}
|
||||
|
||||
async function submit_newpass(email, component) {
|
||||
const body = JSON.stringify({
|
||||
email,
|
||||
});
|
||||
const response = await fetch('./api/auth/restore_password', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
return parseAPIresponse(response);
|
||||
}
|
||||
|
||||
const inputStyles = {
|
||||
display: 'block',
|
||||
width: '100%',
|
||||
};
|
||||
|
||||
class NewPasswordForm extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
email: '',
|
||||
submitting: false,
|
||||
success: false,
|
||||
|
||||
errors: [],
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const { email, submitting } = this.state;
|
||||
if (submitting) return;
|
||||
|
||||
const errors = validate(email);
|
||||
|
||||
this.setState({ errors });
|
||||
if (errors.length > 0) return;
|
||||
|
||||
this.setState({ submitting: true });
|
||||
const { errors: resperrors } = await submit_newpass(email);
|
||||
if (resperrors) {
|
||||
this.setState({
|
||||
errors: resperrors,
|
||||
submitting: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
success: true,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { errors } = this.state;
|
||||
if (this.state.success) {
|
||||
return (
|
||||
<div>
|
||||
<p className="modalmessage">Sent you a mail with instructions to reset your password.</p>
|
||||
<button type="button" onClick={this.props.back}>Back</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
{errors.map(error => (
|
||||
<p key={error}>Error: {error}</p>
|
||||
))}
|
||||
<input
|
||||
style={inputStyles}
|
||||
value={this.state.email}
|
||||
onChange={evt => this.setState({ email: evt.target.value })}
|
||||
type="text"
|
||||
placeholder="Email"
|
||||
/>
|
||||
|
||||
<button type="submit">{(this.state.submitting) ? '...' : 'Submit'}</button>
|
||||
<button type="button" onClick={this.props.back}>Cancel</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default NewPasswordForm;
|
28
src/components/NotifyBox.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
let style = {};
|
||||
function getStyle(notification) {
|
||||
if (notification) style = { backgroundColor: (notification >= 0) ? '#a9ffb0cc' : '#ffa9a9cc' };
|
||||
return style;
|
||||
}
|
||||
|
||||
const NotifyBox = ({ notification }) => (
|
||||
<div className={(notification) ? 'notifyboxvis' : 'notifyboxhid'} style={getStyle(notification)}>
|
||||
{notification}
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { notification } = state.gui;
|
||||
return { notification };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(NotifyBox);
|
31
src/components/OnlineBox.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { numberToString } from '../core/utils';
|
||||
import { FaUser, FaPaintBrush } from 'react-icons/fa';
|
||||
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const OnlineBox = ({ online, totalPixels, name }) => (
|
||||
<div>
|
||||
{(online || name) ?
|
||||
<div className="onlinebox">
|
||||
{(online) && <span>{online} <FaUser /></span>}
|
||||
{(name != null) && <span>{numberToString(totalPixels)} <FaPaintBrush /></span>}
|
||||
</div> : null
|
||||
}
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { online, totalPixels, name } = state.user;
|
||||
return { online, totalPixels, name };
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(OnlineBox);
|
41
src/components/Palette.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { selectColor } from '../actions';
|
||||
|
||||
import type { State } from '../reducers';
|
||||
|
||||
|
||||
const Palette = ({ colors, selectedColor, paletteOpen, compactPalette, select }) => (
|
||||
<div className={`palettebox ${(compactPalette) ? 'compalette' : 'widpalette'}`} id="colors" style={{ display: (paletteOpen) ? 'flex' : 'none' }}>
|
||||
{colors.slice(2).map((color, index) => (<span
|
||||
style={{ backgroundColor: color }}
|
||||
key={index + 2}
|
||||
className={selectedColor === (index + 2) ? 'selected' : 'unselected'}
|
||||
color={color}
|
||||
onClick={() => select(index + 2)}
|
||||
/>),
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { selectedColor, paletteOpen, compactPalette } = state.gui;
|
||||
const { palette } = state.canvas;
|
||||
return { colors: palette.colors, selectedColor, paletteOpen, compactPalette };
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
select(color) {
|
||||
dispatch(selectColor(color));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(Palette);
|
34
src/components/PalselButton.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
*
|
||||
* Button to open/close palette
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { MdPalette } from 'react-icons/md';
|
||||
|
||||
import { toggleOpenPalette } from '../actions';
|
||||
|
||||
const PalselButton = ({ palette, onToggle, selectedColor, paletteOpen }) => (
|
||||
<div id="palselbutton" className={`actionbuttons ${(paletteOpen) ? '' : 'pressed'}`} style={{ color: palette.isDark(selectedColor) ? 'white' : 'black', backgroundColor: palette.colors[selectedColor] }} onClick={onToggle}>
|
||||
<MdPalette />
|
||||
</div>
|
||||
);
|
||||
|
||||
// TODO simplify...
|
||||
function mapStateToProps(state: State) {
|
||||
const { selectedColor, paletteOpen } = state.gui;
|
||||
const { palette } = state.canvas;
|
||||
return { palette, selectedColor, paletteOpen };
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
onToggle() {
|
||||
dispatch(toggleOpenPalette());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(PalselButton);
|
36
src/components/PasswordReset.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Make basic reset_password forms
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/server';
|
||||
import Html from '../components/Html';
|
||||
|
||||
const PasswordReset = ({ name, code }) => (
|
||||
<form method="post" action="reset_password">
|
||||
<h3>Reset Password</h3>
|
||||
<p>Hello {name}, you can set your new password here:</p>
|
||||
<input type="password" name="pass" placeholder="New Password" />
|
||||
<input type="password" name="passconf" placeholder="Confirm New Password" />
|
||||
<input type="hidden" name="code" value={code} />
|
||||
<button type="submit" name="submit">Submit</button>
|
||||
</form>
|
||||
);
|
||||
|
||||
const PasswordResetError = ({ message }) => (
|
||||
<div>
|
||||
<h3>Reset Password</h3>
|
||||
<p>{message}</p>
|
||||
<p><a href="./">Click here</a> to go back to pixelplanet</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
export function getPasswordResetHtml(name, code, message = null) {
|
||||
const data = {
|
||||
title: 'PixelPlanet.fun Password Reset',
|
||||
description: 'reset your password here',
|
||||
body: (message) ? <PasswordResetError message={message} /> : <PasswordReset name={name} code={code} />,
|
||||
};
|
||||
const index = `<!doctype html>${ReactDOM.renderToStaticMarkup(<Html {...data} />)}`;
|
||||
return index;
|
||||
}
|
56
src/components/Rankings.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Rankings Tabs
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import TotalRankings from './TotalRankings';
|
||||
import DailyRankings from './DailyRankings';
|
||||
|
||||
const textStyle = {
|
||||
color: 'hsla(218, 5%, 47%, .6)',
|
||||
fontSize: 14,
|
||||
fontWeight: 500,
|
||||
position: 'relative',
|
||||
textAlign: 'inherit',
|
||||
float: 'none',
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
lineHeight: 'normal',
|
||||
};
|
||||
|
||||
class Rankings extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
order_daily: false,
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
<span
|
||||
className={(!this.state.order_daily) ? 'modallinkselected' : 'modallink'}
|
||||
onClick={() => { this.setState({ order_daily: false }); }}
|
||||
>Total</span> |
|
||||
<span
|
||||
className={(this.state.order_daily) ? 'modallinkselected' : 'modallink'}
|
||||
onClick={() => { this.setState({ order_daily: true }); }}
|
||||
>Daily</span>
|
||||
</p>
|
||||
{(this.state.order_daily) ? <DailyRankings /> : <TotalRankings />}
|
||||
<p style={textStyle}>Ranking updates every 5 min. Daily rankings get reset at midnight UTC.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function mapStateToProps(state: State) {
|
||||
const { totalRanking } = state.user;
|
||||
return { totalRanking };
|
||||
}
|
||||
|
||||
export default Rankings;
|