Skip to content

Commit

Permalink
add all
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Jul 3, 2024
1 parent b9ac063 commit ff037e2
Show file tree
Hide file tree
Showing 42 changed files with 1,830 additions and 0 deletions.
19 changes: 19 additions & 0 deletions перебрать/Sprites/dev/Test.dms/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Author: "themanyfaceddemon"

License: "NONE. IT IS TEST FOLD"

Sprites:
- name: "sprite1"
size: {x: 32, y: 32}
is_mask: false
frames: 0

- name: "sprite2"
size: {x: 32, y: 32}
is_mask: false
frames: 0

- name: "sprite3"
size: {x: 32, y: 32}
is_mask: false
frames: 0
Binary file added перебрать/Sprites/dev/Test.dms/sprite1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added перебрать/Sprites/dev/Test.dms/sprite2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added перебрать/Sprites/dev/Test.dms/sprite3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions перебрать/Sprites/dev/error.dms/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Author: "themanyfaceddemon"

License: "NONE. IT IS ERROR FOLD"

Sprites:
- name: "not_found"
size: {x: 64, y: 64}
is_mask: false
frames: 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added перебрать/Sprites/in_process_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added перебрать/Sprites/in_process_banner2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions перебрать/handle_show_popup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask_socketio import emit
from html_code.socketio_regester import socketio


@socketio.on('show_popup')
def handle_show_popup(data):
emit('popup_notification', {'message': data['message'], 'type': data['type']}, broadcast=True)
2 changes: 2 additions & 0 deletions перебрать/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from html_code.pages.changelog import render_changelog_main_page
from html_code.pages.settings_main import render_settings_main_page
34 changes: 34 additions & 0 deletions перебрать/pages/changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os

import yaml
from flask import render_template, request, url_for


def render_changelog_main_page():
base_dir = os.path.dirname(os.path.abspath(__file__))
changelog_path = os.path.join(base_dir, '..', '..', '..', 'changelog.yml')

with open(changelog_path, 'r', encoding='utf-8') as file:
data = yaml.safe_load(file)
changelog = data.get('changelog', [])

# Параметры пагинации
page = request.args.get('page', 1, type=int)
per_page = 5
total = len(changelog)
pages = (total // per_page) + (1 if total % per_page else 0)

# Срез данных для текущей страницы
start = (page - 1) * per_page
end = start + per_page
changelog_paginated = changelog[start:end]

# Формируем данные для пагинации
pagination = {
'prev': url_for('main.changelog_page', page=page-1) if page > 1 else None,
'next': url_for('main.changelog_page', page=page+1) if page < pages else None,
'pages': [(p, url_for('main.changelog_page', page=p)) for p in range(1, pages+1)],
'current_page': page
}

return render_template('changelog.html', changelog=changelog_paginated, pagination=pagination)
42 changes: 42 additions & 0 deletions перебрать/pages/settings_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import asyncio

from auto_updater import needs_update
from db_work import SettingsManager
from flask import render_template
from html_code.socketio_regester import socketio


def render_settings_main_page():
return render_template('settings/settings_main.html')

# Работа с автоматическим обновлением
@socketio.on('settingSetUpAutoUpdate')
def get_auto_update(data) -> None:
flag: bool

try:
asyncio.run(SettingsManager().set_setting("app.auto_update", data))
flag = True

except Exception:
flag = False

socketio.emit("settingAutoUpdateStatusPopup", flag)
handle_check_auto_update_status()

@socketio.on('settingCheckAutoUpdate')
def handle_check_auto_update_status():
auto_update = asyncio.run(SettingsManager().get_setting("app.auto_update"))
socketio.emit('settingAutoUpdateStatusUpdate', auto_update)

# Получение информации о версиях
@socketio.on('getVersionInfo')
def handle_get_version_info():
_, current_version, latest_version = needs_update()

version_info = {
"currentVersion": current_version,
"latestVersion": latest_version
}

socketio.emit('versionInfo', version_info)
130 changes: 130 additions & 0 deletions перебрать/tests/Texture/DMSValidator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import os
import unittest

from Code.texture_manager import (DMSValidator, InvalidSpriteError,
SpriteValidationError)


class TestDMSValidator(unittest.TestCase):
def setUp(self):
self.base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
self.test_dir = os.path.join(self.base_path, 'test_sprites')
self.dms_dir = os.path.join(self.test_dir, 'test.dms')
self.info_yml_path = os.path.join(self.dms_dir, 'info.yml')

os.makedirs(self.dms_dir, exist_ok=True)

with open(self.info_yml_path, 'w') as f:
f.write("""
Author: "themanyfaceddemon"
License: "NONE. IT IS TEST"
Sprites:
- name: "sprite1"
size: {x: 10, y: 20}
is_mask: false
frames: 5
- name: "sprite2"
size: {x: 15, y: 25}
is_mask: true
frames: 10
""")

for sprite in ['sprite1', 'sprite2']:
open(os.path.join(self.dms_dir, f"{sprite}.png"), 'a').close()

def tearDown(self):
for root, dirs, files in os.walk(self.test_dir, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))

os.rmdir(self.test_dir)

def test_validate_dms(self):
self.assertTrue(DMSValidator.validate_dms(self.test_dir, 'test.dms'))

def test_validate_all_dms(self):
self.assertTrue(DMSValidator.validate_all_dms(self.test_dir))

def test_missing_info_yml(self):
os.remove(self.info_yml_path)
with self.assertRaises(SpriteValidationError) as context:
DMSValidator.validate_dms(self.test_dir, 'test.dms')

self.assertTrue("info.yml not found" in str(context.exception))

def test_invalid_sprite_format(self):
with open(self.info_yml_path, 'w') as f:
f.write("""
Author: Test Author
License: Test License
Sprites:
- name: sprite1
size: {x: 10}
is_mask: false
frames: 5
""")

with self.assertRaises(InvalidSpriteError) as context:
DMSValidator.validate_dms(self.test_dir, 'test.dms')

self.assertTrue("Each sprite 'size' must be a dictionary with 'x' and 'y' fields" in str(context.exception))

def test_missing_sprite_file(self):
os.remove(os.path.join(self.dms_dir, 'sprite1.png'))
with self.assertRaises(InvalidSpriteError) as context:
DMSValidator.validate_dms(self.test_dir, 'test.dms')

self.assertTrue("Missing files" in str(context.exception))

def test_check_forbidden_files(self):
forbidden_file_path = os.path.join(self.dms_dir, '_compiled_file.txt')
with open(forbidden_file_path, 'w') as f:
f.write("This is a forbidden file.")

with self.assertRaises(InvalidSpriteError) as context:
DMSValidator.validate_dms(self.test_dir, 'test.dms')

self.assertTrue("Forbidden file or directory found" in str(context.exception))

def test_sprite_name_contains_forbidden_pattern(self):
with open(self.info_yml_path, 'w') as f:
f.write("""
Author: "themanyfaceddemon"
License: "NONE. IT IS TEST"
Sprites:
- name: "_compiled_sprite1"
size: {x: 10, y: 20}
is_mask: false
frames: 5
- name: "sprite2"
size: {x: 15, y: 25}
is_mask: true
frames: 10
""")

with self.assertRaises(InvalidSpriteError) as context:
DMSValidator.validate_dms(self.test_dir, 'test.dms')

self.assertTrue("contains forbidden pattern" in str(context.exception))

def test_non_existent_directory(self):
non_existent_dir = os.path.join(self.test_dir, 'non_existent.dms')
with self.assertRaises(SpriteValidationError) as context:
DMSValidator.validate_dms(self.test_dir, 'non_existent.dms')

self.assertTrue("DMS does not exist" in str(context.exception))

def test_not_a_directory(self):
not_a_directory_path = os.path.join(self.test_dir, 'not_a_directory.dms')
with open(not_a_directory_path, 'w') as f:
f.write("This is not a directory.")

with self.assertRaises(SpriteValidationError) as context:
DMSValidator.validate_dms(self.test_dir, 'not_a_directory.dms')

self.assertTrue("DMS is not a directory" in str(context.exception))

if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit ff037e2

Please sign in to comment.