Local Installation

You can install Mongo and NodeJS locally to test the server without hosting it on the cloud. This can help for development.

Install NodeJS and Mongo on Windows

Install the LTS version of NodeJS

https://nodejs.org/en/

Download and Install MongoDB community

https://www.mongodb.com/try/download/community

And Mongo Compass to access the database with an interface (It may have installed already when installing MongoDB).

https://www.mongodb.com/products/compass

You can open windows services to see if Mongo is running (Start -> search for "services"), then search for Mongo in the list of services. You can also use this Services window to restart mongo if needed.

Inside TcgEngine/Install, there is a folder containing all the server code. Unzip it in a new project folder outside of your Unity Project (to prevent Unity from generating a meta file for each file).

Once the files are unzipped, open windows command line (click on Start-> type CMD)

Navigate to your NodejS code folder, where you extracted the files, that folder should contain the server.js file and package.json file.

cd C:\Marc\Unity\TcgEngineAPI

Install the NodeJS modules

npm install

Then try to run node

node server.js

Click ctrl-C at anytime to exit

You should now be able to access the API either from Unity or from Insomnia.

To access from Unity, make sure that Resources/ApiData has the api path set to 127.0.0.1, https is turned off, and auth_type is set to API. Then, run the LoginMenu scene and try registering a new user.

If you want to edit the API code, I would suggest to use an IDE such as Visual Studio Code.

Use Mongo Compass to check the database

Open Mongo compass, click on new connection, and enter this string

mongodb://127.0.0.1:27017/tcgengine

If it connects correctly, you can click on tcgengine to see your current data.

If tcgengine doesn't appear on the left, it may be because there is no data yet. To add data you can register a new user, either through the Unity demo, or with Insomnia.

If you click on "users" you should be able to see the list of all current active users and their data.

Demo Config

In Unity, go to Resources/NetworkData

From that file, you can set the api url and whether it is using https or not.

To test locally, use these config

Auth_type: API

Api URL: 127.0.0.1

Api Https: false

And then run the LoginMenu scene.

In newest versions of Unity (2022+), HTTP is blocked by default and only HTTPS is allowed, but since our API doesn't have a SSL certificate yet, we need to test with HTTP. To allow HTTP request, go in Edit -> Project Settings -> Player Settings -> Other Settings -> Allow Download over HTTP.

Upload Data to API

You will need to sync your data (cards, packs and more...) with the API so that some features work properly, such as pack opening, level rewards and starter decks selection.

To do this, go in the Scenes/Tools and open the scene CardUploader. Run it from unity and login with an admin user. It will start uploading automatically all your data to your API database.

Whenever you add or edit cards, packs, decks or rewards, you should do this step again if you want your API to be up to date.

Last updated