diff options
| author | nokoe <nokoe@mailbox.org> | 2025-10-09 23:50:01 +0200 |
|---|---|---|
| committer | nokoe <nokoe@mailbox.org> | 2025-10-09 23:50:55 +0200 |
| commit | 5879059a6757d471218eac3508ba3d28fcce8604 (patch) | |
| tree | 33979305fc773bf1a3c5707bfd18a8434d44405e /client/message_parser.gd | |
| parent | 0dc7bc9f3cf8088b670d5444fc4e0ce58a7ec1cc (diff) | |
| download | hurrycurry-5879059a6757d471218eac3508ba3d28fcce8604.tar hurrycurry-5879059a6757d471218eac3508ba3d28fcce8604.tar.bz2 hurrycurry-5879059a6757d471218eac3508ba3d28fcce8604.tar.zst | |
add book
Diffstat (limited to 'client/message_parser.gd')
| -rw-r--r-- | client/message_parser.gd | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/client/message_parser.gd b/client/message_parser.gd new file mode 100644 index 00000000..64be0411 --- /dev/null +++ b/client/message_parser.gd @@ -0,0 +1,48 @@ +# Hurry Curry! - a game about cooking +# Copyright (C) 2025 Hurry Curry! contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +class_name MessageParser +extends Object + +var raw: Dictionary +var kind := Kind.UNKNOWN +var result = null + +enum Kind { + ITEM, + TILE, + TEXT, + TRANSLATION, + UNKNOWN +} + +func _init(raw_: Dictionary) -> void: + raw = raw_ + +func parse(game: Game) -> String: + if "text" in raw: + kind = Kind.TEXT + result = raw["text"] + elif "translation" in raw: + kind = Kind.TRANSLATION + # TODO: move function here + result = Global.get_message_str(raw) + elif "tile" in raw: + kind = Kind.TILE + result = game.tile_names[raw["tile"]] + elif "item" in raw: + kind = Kind.ITEM + result = game.item_names[raw["item"]] + return result |