diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/chess_backend.iml b/.idea/chess_backend.iml new file mode 100644 index 0000000..6714126 --- /dev/null +++ b/.idea/chess_backend.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..736b465 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,63 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8993317 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8b93af3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/chess_backend/__init__.py b/chess_backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chess_backend/__pycache__/__init__.cpython-310.pyc b/chess_backend/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..f3e0ade Binary files /dev/null and b/chess_backend/__pycache__/__init__.cpython-310.pyc differ diff --git a/chess_backend/__pycache__/settings.cpython-310.pyc b/chess_backend/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..6f4c028 Binary files /dev/null and b/chess_backend/__pycache__/settings.cpython-310.pyc differ diff --git a/chess_backend/__pycache__/urls.cpython-310.pyc b/chess_backend/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..91af12e Binary files /dev/null and b/chess_backend/__pycache__/urls.cpython-310.pyc differ diff --git a/chess_backend/asgi.py b/chess_backend/asgi.py new file mode 100644 index 0000000..a4c59e0 --- /dev/null +++ b/chess_backend/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for chess_backend project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chess_backend.settings') + +application = get_asgi_application() diff --git a/chess_backend/settings.py b/chess_backend/settings.py new file mode 100644 index 0000000..aad56f8 --- /dev/null +++ b/chess_backend/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for chess_backend project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-%_8sy196w4hzo9^cp9(@r=i+amh47r4mxfhq_(ok&=c(@%bhmk' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + "game" +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'chess_backend.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR / 'templates'] + , + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'chess_backend.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/chess_backend/urls.py b/chess_backend/urls.py new file mode 100644 index 0000000..11b17bb --- /dev/null +++ b/chess_backend/urls.py @@ -0,0 +1,21 @@ +"""chess_backend URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/chess_backend/wsgi.py b/chess_backend/wsgi.py new file mode 100644 index 0000000..f8b1f1e --- /dev/null +++ b/chess_backend/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for chess_backend project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chess_backend.settings') + +application = get_wsgi_application() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..3f428ae Binary files /dev/null and b/db.sqlite3 differ diff --git a/game/__init__.py b/game/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/game/__pycache__/__init__.cpython-310.pyc b/game/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..2d895be Binary files /dev/null and b/game/__pycache__/__init__.cpython-310.pyc differ diff --git a/game/__pycache__/admin.cpython-310.pyc b/game/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..ab1feef Binary files /dev/null and b/game/__pycache__/admin.cpython-310.pyc differ diff --git a/game/__pycache__/apps.cpython-310.pyc b/game/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..4d2e8af Binary files /dev/null and b/game/__pycache__/apps.cpython-310.pyc differ diff --git a/game/__pycache__/models.cpython-310.pyc b/game/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..9cac6a5 Binary files /dev/null and b/game/__pycache__/models.cpython-310.pyc differ diff --git a/game/admin.py b/game/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/game/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/game/apps.py b/game/apps.py new file mode 100644 index 0000000..8ad49cb --- /dev/null +++ b/game/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GameConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'game' diff --git a/game/migrations/__init__.py b/game/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/game/migrations/__pycache__/__init__.cpython-310.pyc b/game/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..374cda5 Binary files /dev/null and b/game/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/game/models.py b/game/models.py new file mode 100644 index 0000000..7f97516 --- /dev/null +++ b/game/models.py @@ -0,0 +1,57 @@ +import uuid + +from django.core.validators import MinValueValidator, MaxValueValidator +from django.db import models + +HER0_TYPES = [("WIZARD", "wizard"), ("ARCHER", "archer"), ("WARRIOR", "warrior")] + + +class Player(models.Model): + """base model to handle and store users""" + + # TODO: connect real TON wallet + ton_wallet = models.CharField(max_length=50, verbose_name="TON wallet") + name = models.CharField(max_length=100, blank=True) + added = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.name + + class Meta: + indexes = [models.Index(fields=["ton_wallet"])] + ordering = ["-added"] + verbose_name = "player" + verbose_name_plural = "players" + + +class Hero(models.Model): + """Model to store heroes and their stats, connected to player""" + + uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) + player = models.ForeignKey( + Player, + on_delete=models.CASCADE, + related_name="heroes", + related_query_name="hero", + ) + added = models.DateTimeField(auto_now_add=True) + + type = models.CharField(blank=False, choices=HER0_TYPES, max_length=1) + idle_img = models.ImageField(upload_to="uploads/idle", blank=False) + attack_img = models.ImageField(upload_to="uploads/attack", blank=False) + die_img = models.ImageField(upload_to="uploads/die", blank=False) + health = models.IntegerField( + validators=[MinValueValidator(0), MaxValueValidator(10)], blank=False + ) + speed = models.IntegerField( + validators=[MinValueValidator(0), MaxValueValidator(10)], blank=False + ) + + def __str__(self): + return f"{self.type} {self.player.name}" + + class Meta: + indexes = [models.Index(fields=["uuid"])] + ordering = ["-added"] + verbose_name = "hero" + verbose_name_plural = "heroes" diff --git a/game/tests.py b/game/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/game/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/game/views.py b/game/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/game/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..9d7d2e2 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chess_backend.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main()