Skip to content

Almarch/pygotchi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyGoTcHi The Tamagotchi is live online !

The goal of this Python package is to deliver TamaLIB as a web service.

The web server-client logic makes a special sense for Tamagotchis as it unlocks two key functionnalities of the original game:

  • Ubiquity: Just like the original toy could be carried everywhere in a kid's pocket, a web service can be accessed from anywhere using a smartphone.
  • Real-time consistency: The creature has a strict schedule that the player has to deal with all along the day. The server can endorse the role to keep track of time.

A web app is readily available and dockerized for ease of deployment.

1. Run the app

Start by cloning the repo:

git clone https://github.com/almarch/pygotchi.git

1.1. Run with Docker

cd pygotchi
docker build -t tama .
docker run -d -p 8000:80 tama

The app is now available at http://localhost:8000.

1.2. Run with Python

Build the package with build and install it with pip:

pip install build
python -m build ./pygotchi
pip install ./pygotchi

It may then be launched using Python:

python -m pygotchi

The app is now available at http://localhost:8000.

1.3. Swagger

FastAPI apps come with a swagger. Once the app is launched, have a look at: http://localhost:8000/docs. Not all API are implemented on the UI.

2. How to use

The game is controlled with 3 buttons (A, B, C) with respect to the original toy. Click the screen to "poke" the toy.

A menu (☰) allows administration over the game.

2.1. Load a ROM

From the administration menu, flash a ROM. It should be a 12ko .bin file. Use the switch button to get the emulation started. The ROM is loaded on the server, and the emulation runs server-side.

2.2. Save the game

The game may be saved any time using the Save CPU button from the administration menu. The save.bin file may then be loaded again. Ensure consistency between the loaded CPU and the ROM.

2.3. Control the sound

The buzzer may be controlled at 2 levels:

  • Using the 🔊 icon: controls the sound on the client side.
  • Using the A+C button: controls the sound on the server side, using the native Tamagotchi functionnality.

2. Deploy the app

Now that the app is available at port 8000, it may be deployed online. The server will be assumed to be a linux computer behind a router with a fixed public IP. It may just as well be a VPS.

First of all, you need the public IP of your network and the private IP of your server. The public IP can be accessed from one of the many benevolent website, for instance this one. The private IP can be accessed with the command:

hostname -I

2.1. Router

The router configuration depends on the internet supplier. The router configuration page may for instance be reached from within the network at http://<public ip>:80. Because port 80 might be in competition with other resources, for instance the internet supplier configuration page, we will set up the application to listen to port 8000, which is less commonly used.

The router should be parameterized as such:

  • port 8000 should be open to TCP ;

  • port 8000 should redirect to your linux server, identified with its private IP.

2.2. Firewall

Using a firewall is a first security step for a web server. For instance, ufw is free, open-source and easy to use.

sudo apt install ufw
sudo ufw enable
sudo systemctl enable ufw

Port 8000 should be open to TCP. After configuring the router it may be checked and it has to be restarted.

sudo ufw allow 8000/tcp
sudo ufw status
sudo systemctl restart ufw

2.3. Web server

A web server software is required to deploy the shiny app with its functionalities. For instance, nginx is a free, open-source popular solution.

sudo apt install nginx
sudo systemctl enable nginx

A configuration file should be provided for the app. Place the following configuration in an app file in the /etc/nginx/sites-available/ folder:

server {
        listen 8000;
        server_name _;

        location / {
                proxy_pass http://localhost:8000;
                proxy_redirect http://localhost:8000/ $scheme://$http_host/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_read_timeout 20d;
                proxy_buffering off;
        }
}

Create a symlink in the /etc/nginx/sites-enabled/ folder, and restart nginx:

sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/app
sudo systemctl restart nginx

2.4. Connection

The app is now available world-wide at http://<public ip>:8000

It can be played from a smartphone. A shortcut to the webpage may be added to the home screen.

The Tamagotchi runs backend, so it remains alive when the user disconnects.

3. Background

zucchitchi

The Tamagotchi has been a social phenomenon back in the 1990's. The original game has been revived through TamaLIB, an agnostic, cross platform emulator. TamaLIB has then been implemented on Arduino with a refactoring. From the Arduino version, I ported tamaLIB on 2 high-abstraction level, object-oriented languages: R and Python.

The R project was developed aiming the sole P1 ROM that was available at this time. The app encompassed a function to switch the sprites to the P2 ones, and an algorithm to automatically care for the pet. Nevertheless, the core functionnality of the R project had been to deploy TamaLIB as a web app, in a server-client logic.

More recently, new first-generation ROMs have been released and TamaLIB has been adapted to allow the emulation for all first-gen Tamagotchis. In this view, I recycled the R project into a Python framework. Python is more production oriented, with a broad community and far better performances than R. The goal of this new version is to deliver an improved version of TamaLIB as a web service.

On the technical side, all C++ code has been merged into a monolithic tamalib.cpp file as the dependency management was not trivial for binding to Python. The same code and dependencies compiled on both windows and linux in the tamaR project, but currently pygotchi only builds on linux (or the WSL).

Adaptation to the new first-generation ROM collection is being developed.

5. License

This work is licensed under Attribution-NonCommercial 4.0 International.

All graphical resources come from the extraordinarily rich Tamagotchi fandom.

About

The Tamagotchi is live online !

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published