This describes how to run the project on a locahost only.
Also explains the compilation process
This is sub-layout for documentation pages
The required platform is linux
Using the url you got to the git repository,
you will neeed to download (clone) 2 projects.
The first one is the website (needed for the sql dumps), and
the second one is the game server itself.
git clone url/darknessorlightnodejs.git git clone url/darknessorlightwebsite.gitPlease, be advised, that this can take hours, maybe even days to complete, due to the large resource files
The following programs are needed in order to run the project.
sed
, tr
, awk
, find
...)Npm is package manager. It allows you to install packages for NodeJS, and also run predefined scripts. It uses package.json file.
sudo apt-get install npm
NodeJS is javascript server.
sudo apt-get install nodejs
Typescript is a language for application-scale JavaScript. It allows to use classes, abstract classes, inheritance etc. It provides compile time code check. Can be installed using npm:
npm install -g typescript
The point is, that in pure javascript, having class:
class A { constructor() { console.log(this.variable); } }
Now this code executes fine, and there are no errors. The point is, that accessing undefined variable gives value 'undefined'
This makes it extremelly difficult to develop huge projects, as any typo can result in bad behavior. Moreover,
in pure javascript, variables do not have type, so you can assign anything as a value. And more issues.
This
all is, however, solved
with typescript
Instructions about how to install sass can be found here
You will need to import sql dump to your local sql database.
Please, do not run the project on the real database, because the table structure
/ game code might not be compatible with the current cloned game version.
Navigate to the directory with sql dumps:
cd ./darknessorlight/dbsBackupNavigate to the directory with the most recent date
cd ./[most recent date]Import the dump
mysql -u user -p sql > source ./_glaser_cz01.sqlNote: The dumps already have stripped out the definer, so the stored procedures and triggers will work under any user
You need to define in sources the username and password
for connecting to the sql database.
In order to do that, open file ./src/server.ts and scroll all the way down,
until you see following lines:
ConsoleLogger.logWaitForCompletionEvent("Connecting to database"); if (USE_LOCALHOST) dbs.connect("localhost", "usernameHere", "passwordHere", functionCallBack); else dbs.connect("remoteSQL.com", "usernameHere", "passwordHere", functionCallBack);Obviously, fill in the appropriate username and password for your local database
gedit ./server.ts #here, change variable value to true on this line: #var USE_LOCALHOST: boolean = true;
So, considering that you have the both projects downloaded,
and the appropriate software installed,
you need to compile the game server, as the build directory
is not a part of the git repo.
This will show sorely the commands on how to do it.
The detailed explanation (in case you would wonder how the script works...)
can be found here
Here is summary of all available scripts for compilation / running the game / testing
Script name | Description |
---|---|
./compile.sh | Compiles server-side code |
./copyJsons.sh | Copies server-side JSONS (map jsons for example) into the build directory |
./compileClient.sh slow and memory consuming! |
Copiles client-side .ts code (along with all necessary substitutions explained above), and copies all html / css / js and all client side assets to the build directory |
./copyClientSideResources.sh | Copies all html / css / js and all client side assets to the build directory. Does not compile any code what so ever |
./runTests.sh | Allows to run specific tests (online / offline / sql) or benchmarks. Use -h for help |
./cleanCompileTempFiles.sh run this ONLY on files inside BUILD directory! |
Irreversibly deletes all files that are not neeed for final project runtime. This includes (but is not only limited to): *.scss, *.ts.md5 *.ts.bak *.ts *.css.map files. Also minifies *.json files |
This describes the necessary commands for compiling the project
Navigate to the src folder
cd darknessorlightnodejs/src
Compile the server
./compile.sh #this will take serious amount of time
Compile the client
./compileClient.sh
Run the game server
npm run node
You can navigate to the game in your browser at http://127.0.0.1:8080
Cleaning is process of recompiling entire project again. (as is normal compiling, only changed files are compiled)
Delete the build directory (do not worry, it is tested, and compiling process will create new directory and all wil work!)
rm -r ./build
Compile the server (this can take even hours to complete)
./compile.sh
Compile the client
./compileClient.sh
Server and client are now fully functional. You can run server.
npm run node
A rule of thump is: When you move a source file somewhere else, then you need to rebuild.
This applies to source code on server only: if you move a source file on a client side to different directory,
then you only need to run ./compileClient.sh
In order to run the tests on a server side,
you must have already compiled the code using the ./compile.sh command.
Then, all you have to do is execute
./runTests.sh --allWhich will run all the tests available (for the server side only).
./runTests.sh
In order to add a new test to the project, here is what you have to do:
Navigate to the test directory (preferrably, do it in IDE, not in console...)
cd ./src/testHere, you see 3 main directories:
mkdir ./src/test/offline/app/model/character/MonsterHydraTest.ts
ls ./src/app/model/character/MonsterHydra.tsFrom here, you see the conventions
Client side tests are unfortunatelly more compicated, and it was a nightmare to make them work.
Keeping that in mind, the code is not beautiful and the structure is quite
complicated...
The point of client-side tests in to test any code, which is on client side only,
which is not affected by ./compile.sh
To run the client-side tests, we first need to compile them by calling
./compileClientTests.shTo run the tests, we need to run the server first
npm run nodeand then access in web browser
http://127.0.0.1:8080/testWhich will run the tests on the client-side code
In order to add a new test to the client side, here is what you need to do.
Suppose, that we have a file
src/app/view/assets/js/forms/TextInput.tsWhich we want to test.
src/app/view/assets/js/test/forms/TextInputTest.jsThis can be done (and should be done) by copy-pasting existing test file you find there around.
src/app/view/assets/js/test/tester.tsand adding
///<reference path="../forms/TextInput.ts" />
src/app/view/html/test.ejsand add
<script src="assets/js/test/forms/TextInputTest.js"></script>