Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ templates

.idea
scrap_engine.py
venv
11 changes: 11 additions & 0 deletions assets/lang/de_DE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "schema.json",
"error.import.scrap_engine": "Es scheint als hättest du die Erweiterung 'scrap-engine' nicht installiert",
"ui.inventory.title": "Inventar",
"ui.lang.en_us": "Englisch (Amerikanisch)",
"ui.lang.de_de": "Deutsch",
"dialog.center.welcome": "Willkommen im Pokete-Center",
"dialog.center.action": "Was möchtest du tun?",
"dialog.center.healed": "Deine Pokete sind nun geheilt!",
"dialog.center.list": "1: Schaue dein Team an\n 2: Heil alle deine Pokete\n 3: Knuddel mit deinen Pokete"
}
27 changes: 27 additions & 0 deletions assets/lang/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "schema.json",
"error.import.scrap_engine": "You seem to not have the 'scrap-engine' package installed",
"ui.inventory.title": "Inventory",
"ui.lang.en_us": "English (American)",
"ui.lang.de_de": "German",
"dialog.center.welcome": "Welcome to the Pokete-Center",
"dialog.center.action": "What do you want to do?",
"dialog.center.list": "1: See your full deck\n 2: Heal all your Poketes\n 3: Cuddle with the Poketes",
"dialog.center.healed": "Your Poketes are now healed!",
"dialog.shop.welcome": "Welcome to the Pokete-Shop",
"dialog.shop.action": "Wanna buy something?",
"dialog.shop.leave": "Have a great day!",
"dialog.trader.welcome": "I'm a trader.",
"dialog.trader.action": "Here you can trade one of your Poketes for one from another trainer.",
"npc.test_npc.hey": "Hey.",
"npc.old_man.greet": "Hello, young trainer.",
"npc.old_man.talk": "When I was your age... I also was a trainer.",
"npc.old_man.found_hyperball": "One day I found this very special Poketeball...",
"npc.old_man.hyperball": "A Hyperball!",
"npc.old_man.rarest": "It's one of the oldest and rarest of them all.",
"npc.old_man.keep": "You can keep it!",
"trainer.playmap1.franz.fight": "Wanna fight?",
"trainer.playmap1.franz.lose1": "Hahaha!",
"trainer.playmap1.franz.lose2": "You're a loser!",
"trainer.playmap1.franz.win": "You're a very good trainer!"
}
30 changes: 30 additions & 0 deletions assets/lang/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Pokete Translation File Schema",
"properties": {
"error.import.scrap_engine": {
"type": "string"
},
"ui.inventory.title": {
"type": "string"
},
"ui.lang.en_us": {
"type": "string"
},
"ui.lang.de_de": {
"type": "string"
},
"dialog.center.welcome": {
"type": "string"
},
"dialog.center.action": {
"type": "string"
},
"dialog.center.list": {
"type": "string"
},
"dialog.center.healed": {
"type": "string"
}
}
}
29 changes: 17 additions & 12 deletions pokete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""This software is licensed under the GPL3
You should have gotten an copy of the GPL3 license anlonside this software
Feel free to contribute what ever you want to this game
Expand Down Expand Up @@ -51,6 +52,8 @@
from pokete_classes.dex import Dex
from pokete_classes.loops import std_loop
from pokete_classes.periodic_event_manager import PeriodicEventManager
from pokete_classes.language import _
from pokete_classes.ui.overlays.language_overlay import LanguageOverlay
from pokete_general_use_fns import liner, sort_vers, parse_args

from release import SPEED_OF_TIME
Expand Down Expand Up @@ -259,9 +262,9 @@ def action(self, ob):
int(mvp.movemap.width / 2),
3,
[
"Welcome to the Pokete-Center",
"What do you want to do?",
"1: See your full deck\n 2: Heal all your Poketes\n 3: Cuddle with the Poketes"
"dialog.center.welcome",
"dialog.center.action",
"dialog.center.list"
]
)
while True:
Expand All @@ -277,7 +280,7 @@ def action(self, ob):
heal(figure)
time.sleep(SPEED_OF_TIME * 0.5)
mvp.movemap.text(int(mvp.movemap.width / 2), 3,
["...", "Your Poketes are now healed!"])
["...", "dialog.center.healed"])
break
elif action.triggers(Action.CANCEL, Action.ACT_3):
break
Expand All @@ -295,12 +298,12 @@ def action(self, ob):
_ev.clear()
mvp.movemap.full_show()
mvp.movemap.text(int(mvp.movemap.width / 2), 3,
["Welcome to the Pokete-Shop",
"Wanna buy something?"])
["dialog.shop.welcome",
"dialog.shop.action"])
buy()
mvp.movemap.full_show(init=True)
mvp.movemap.text(int(mvp.movemap.width / 2), 3,
["Have a great day!"])
["dialog.shop.leave"])


class CenterMap(PlayMap):
Expand All @@ -324,9 +327,8 @@ def __init__(self, _he, _wi):
self.dor_back1 = CenterDoor(" ", state="float")
self.dor_back2 = CenterDoor(" ", state="float")
self.trader = NPC("trader",
["I'm a trader.",
"Here you can trade one of your Poketes for \
one from another trainer."],
["dialog.trader.welcome",
"dialog.trader.action"],
"swap_poke")
# adding
self.dor_back1.add(self, int(self.width / 2), 8)
Expand Down Expand Up @@ -506,7 +508,7 @@ class Inv:

def __init__(self, _map):
self.map = _map
self.box = ChooseBox(_map.height - 3, 35, "Inventory",
self.box = ChooseBox(_map.height - 3, 35, _("ui.inventory.title"),
f"{Action.REMOVE.mapping}:remove")
self.box2 = Box(7, 21)
self.money_label = se.Text(f"${figure.get_money()}")
Expand Down Expand Up @@ -641,6 +643,7 @@ def __init__(self, _map):
self.about_label = se.Text("About", state="float")
self.save_label = se.Text("Save", state="float")
self.exit_label = se.Text("Exit", state="float")
self.language_label = se.Text("Language", state="float")
self.realname_label = se.Text(session_info["user"], state="float")
self.char_label = se.Text(figure.char, state="float")
self.box.add_c_obs([self.playername_label,
Expand All @@ -655,7 +658,7 @@ def __init__(self, _map):
{True: "On", False: "Off"}),
VisSetting("Load mods", "load_mods",
{True: "On", False: "Off"}),
self.mods_label, self.ach_label,
self.language_label, self.mods_label, self.ach_label,
self.about_label, self.save_label,
self.exit_label])
# adding
Expand Down Expand Up @@ -708,6 +711,8 @@ def __call__(self, pevm):
about()
elif i == self.ach_label:
AchievementOverview()(mvp.movemap)
elif i == self.language_label:
LanguageOverlay()(mvp.movemap)
else:
i.change()
elif action.triggers(Action.UP, Action.DOWN):
Expand Down
6 changes: 5 additions & 1 deletion pokete_classes/achievements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import datetime
import logging
import scrap_engine as se
from pokete_general_use_fns import liner
from .hotkeys import ACTION_DIRECTIONS, Action, get_action
from .loops import std_loop, easy_exit_loop
from .ui_elements import BetterChooseBox, LabelBox
from .color import Color
from .notify import notifier

try:
import scrap_engine as se
except ImportError:
print("You seem to not have the 'scrap-engine' package installed")

Comment on lines +13 to +17
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is really necessary, since python itself will throw an error about this and this isn't even the first file to import scrap_engine.

Copy link
Author

@HumansAreWeak HumansAreWeak Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was kind of a test I forgot to remove. I thought it would be nice to fetch all the required packages on startup first and see if all are available, otherwise a message with all the missing packages will be printed. But I wasn't able to implement this behavior yet :o


class Achievement:
"""The Achievement class that groups identifier, title and description
Expand Down
5 changes: 5 additions & 0 deletions pokete_classes/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pathlib import Path

# Holds the path to the main pokete folder. Every path related task should be
# referring to this constant to get access to all the internal files. READ-ONLY
CWD: Path = Path(__file__).parent.parent.resolve()
Empty file.
13 changes: 13 additions & 0 deletions pokete_classes/entities/language_entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pathlib import Path
from dataclasses import dataclass
from ..constants import CWD


@dataclass(frozen=True)
class LanguageEntity:
"""
Stores general information about a language. This is READ-ONLY so this
data class is marked as frozen to prevent accidental writes.
"""
name: str = "en_US"
path: Path = (CWD / "assets" / "lang" / "en_US.json").resolve()
134 changes: 134 additions & 0 deletions pokete_classes/language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from __future__ import annotations
from pathlib import Path
import json
import locale
from .entities.language_entity import LanguageEntity
from .color import Color


def get_system_locale() -> str:
"""
Fetches the main language of the user's operating system.

Returns: ISO language code
"""
locale.setlocale(locale.LC_ALL, "")
return locale.getlocale(locale.LC_CTYPE)[0]


class Language:
"""
Class for loading and managing translation files.
"""

__instance = None

@classmethod
def instance(cls) -> Language:
"""
Returns: Singleton instance of language class
"""
if Language.__instance is None:
Language.__instance = Language()
return Language.__instance

def __init__(self, default_lang=None):
self._language_file: dict = dict()
self.language: LanguageEntity = LanguageEntity()
self.language_path: Path = self.language.path.parent
self.change_language(default_lang or get_system_locale())

def str(self, key: str) -> str:
"""
Fetch a localized string at from the currently used language.

Args:
key: Identifier of the string to fetch

Returns: Localized string
"""
if key in self._language_file:
return str(self._language_file.get(key))

# Temporarily - So previous code is not broken
return key

# raise RuntimeWarning(f"No entry with key '{key}' was found in the
# translation file '{self.language.path}'")

def change_language(self, language: str) -> LanguageEntity:
"""
Changes the current language. If parsed language identifier is invalid
then the fallback language 'en_US' will be used.

Args:
language: Language file to look for

Returns: Language entity. Will fall back to 'en_US' if no translation
file has been found.
"""
self.language = self._get_language_entity(language)
self._load_language_file(self.language.path)
return self.language

def get_selected_language(self) -> LanguageEntity:
"""
Returns

Returns: Selected language
"""
return self.language

def get_languages(self) -> list:
"""
Fetches and returns a list of all available language files.

Returns: List of available language files in the assets directory
"""
available_languages = []

for item in self.language_path.glob("*.json"):
if item.is_file():
language_name = item.name.replace(".json", "")

if language_name != "schema":
available_languages.append(language_name)

return available_languages

def _get_language_entity(self, language: str) -> LanguageEntity:
"""
This method will return a language entity, which contains its name
and its absolute path.

Args:
language: Language file to look for

Returns: Language entity. Will fall back to 'en_US' if no translation
file has been found.
"""
entity = LanguageEntity()

language_file = self.language_path / f"{language}.json"

if language_file.exists() and language_file.is_file():
entity = LanguageEntity(language, language_file.resolve())

return entity

def _load_language_file(self, language_path: Path) -> None:
"""
Loads the language file into the internal dictionary.

Args:
language_path: Path to the language file
"""
with open(language_path, encoding="utf-8") as language_file:
self._language_file = json.load(language_file)


# For convenient use later in the program ~ origin
_ = Language.instance().str

if __name__ == "__main__":
print(f"\033[31;1mDo not execute this!{Color.reset}")
6 changes: 3 additions & 3 deletions pokete_classes/mods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""This file contains all classes related to mods"""

from .color import Color
from .side_loops import About
from .ui_elements import InfoBox
from .settings import settings
Expand All @@ -16,7 +16,7 @@ def __init__(self):

class ModError(Exception):
"""
An Error that is thrown, when an inproper module is loaded
An Error that is thrown, when an improper module is loaded
ARGS:
name: The mod's name
err: The error that was thrown"""
Expand Down Expand Up @@ -45,4 +45,4 @@ def __init__(self, _map, mod_info):


if __name__ == "__main__":
print("\033[31;1mDo not execute this!\033[0m")
print(f"\033[31;1mDo not execute this!{Color.reset}")
6 changes: 4 additions & 2 deletions pokete_classes/movemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .color import Color
from .event import _ev
from .hotkeys import Action
from .language import Language, _
from release import SPEED_OF_TIME


Expand All @@ -23,6 +24,7 @@ class Movemap(gm.GameSubmap):
def __init__(self, height, width):
super().__init__(obmp.ob_maps["playmap_1"], 0, 0,
height=height, width=width, name="movemap")
self.language = Language.instance()
self.name_label = se.Text("")
self.balls_label = se.Text("")
self.label_bg = se.Square(" ", self.width, 1, state="float")
Expand Down Expand Up @@ -74,8 +76,8 @@ def text(self, x, y, inp_arr):
self.assure_distance(x, y, 17, 10)
self.multitext.rechar("")
self.multitext.add(self, x - self.x + 1, y - self.y)
arr = [" < " + i + (" >" if j != len(inp_arr) - 1 else "")
for j, i in enumerate(inp_arr)]
arr = [" < " + _(key) + (" >" if index != len(inp_arr) - 1 else "")
for index, key in enumerate(inp_arr)]
for text in arr:
# Clear events and animate text appearing until any key is pressed. Then wait until another key is pressed to close dialogue.
_ev.clear()
Expand Down
Loading