game: Inventar-Raster mit Icons, Klassenregeln, Gold und Verbrauch

This commit is contained in:
torsten 2026-11-17 15:15:06 +01:00
parent 3fae74b1e8
commit a78de0ffec
61 changed files with 1047 additions and 148 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://doqinpxu7nf0w"
path="res://.godot/imported/item_dolch_64.png-5ba3c9f48682a49f578979157ab5b812.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_dolch_64.png"
dest_files=["res://.godot/imported/item_dolch_64.png-5ba3c9f48682a49f578979157ab5b812.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bkl7oxhn4a705"
path="res://.godot/imported/item_kette_64.png-8589e2e600dce0d482c1e9cbb450d6bb.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_kette_64.png"
dest_files=["res://.godot/imported/item_kette_64.png-8589e2e600dce0d482c1e9cbb450d6bb.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://1lx6eq7dmqtd"
path="res://.godot/imported/item_keule_64.png-9e14329ca2fc8593ccea4653c95e1cfd.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_keule_64.png"
dest_files=["res://.godot/imported/item_keule_64.png-9e14329ca2fc8593ccea4653c95e1cfd.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b68fuwp4rktek"
path="res://.godot/imported/item_laterne_64.png-75fe6c53021027132d619edd9ed39133.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_laterne_64.png"
dest_files=["res://.godot/imported/item_laterne_64.png-75fe6c53021027132d619edd9ed39133.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bv0a6761xtxcj"
path="res://.godot/imported/item_leder_64.png-c727e531824447b73cd54778114ecdab.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_leder_64.png"
dest_files=["res://.godot/imported/item_leder_64.png-c727e531824447b73cd54778114ecdab.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://sdq0lac24wwi"
path="res://.godot/imported/item_platte_64.png-3cd44ffa026cbb7cc837c881865b55fa.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_platte_64.png"
dest_files=["res://.godot/imported/item_platte_64.png-3cd44ffa026cbb7cc837c881865b55fa.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://qm777pyc5u5t"
path="res://.godot/imported/item_schild_64.png-824eb212dcc17f66f27cc47974f41a0e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_schild_64.png"
dest_files=["res://.godot/imported/item_schild_64.png-824eb212dcc17f66f27cc47974f41a0e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dfisyg14fqkss"
path="res://.godot/imported/item_schwert_64.png-8768e0caa5b6513b3639d40c815c1d38.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_schwert_64.png"
dest_files=["res://.godot/imported/item_schwert_64.png-8768e0caa5b6513b3639d40c815c1d38.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://csayb2dah4o41"
path="res://.godot/imported/item_seil_64.png-830e0b0be2ab0f8082fbe0c41dc5aa76.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_seil_64.png"
dest_files=["res://.godot/imported/item_seil_64.png-830e0b0be2ab0f8082fbe0c41dc5aa76.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 757 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cpcnmb0v6wbik"
path="res://.godot/imported/item_stab_64.png-e225734de56fd862d42e8fee6fe0d838.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_stab_64.png"
dest_files=["res://.godot/imported/item_stab_64.png-e225734de56fd862d42e8fee6fe0d838.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://xd2kxfekewfd"
path="res://.godot/imported/item_vorrat_64.png-d6e9ef72f1005e418f3e8df8287bfc4b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/objects/item_vorrat_64.png"
dest_files=["res://.godot/imported/item_vorrat_64.png-d6e9ef72f1005e418f3e8df8287bfc4b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -1,9 +1,9 @@
extends Control
## Inventar als Modal über der Karte (docs/ui.md §1).
##
## Zeigt pro Party-Figur die ausgerüsteten Slots und den Rucksack. Ausrüsten
## nimmt ein Stück aus dem Rucksack, Ablegen legt es zurück; die RK kommt aus
## `Game.rk()` und ändert sich sofort.
## 5×3-Raster mit Item-Icons, ausgerüstete Slots links, Details und Aktionen
## rechts. Ausrüsten prüft die Klassenbeschränkung aus `classes.json`;
## Verbrauchsgüter laufen über `Game.benutzen()`.
signal geschlossen
@ -14,9 +14,17 @@ const SLOTS := [
{"key": "armor", "label": "Rüstung"},
{"key": "shield", "label": "Schild"},
]
const SPALTEN := 5
const ZEILEN := 3
const KACHEL := 88
const ABSTAND := 8
const RASTER := Vector2(640, 200)
var _index := 0
var _wurzel: Control
var _sel_id := ""
var _sel_quelle := "" ## "inventar" oder "slot"
var _meldung := ""
func _ready() -> void:
@ -41,13 +49,47 @@ func _bauen() -> void:
p.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
_wurzel.add_child(p)
var titel := Label.new()
titel.text = "INVENTAR"
titel.position = Vector2(40, 24)
titel.add_theme_color_override("font_color", UiTheme.GOLD)
p.add_child(titel)
_titel(p)
_reiter(p)
_gold(p)
# Partei-Reiter
if Game.party.is_empty():
_label(p, "Keine Figur in der Party.", Vector2(40, 200))
_schliessen_knopf(p)
return
var figur: Dictionary = Game.party[_index]
_ausgeruestet(p, figur)
_rucksack(p, figur)
_details(p, figur)
_label(p, "RK %d Angriff +%d TP %d/%d" % [
Game.rk(figur), Game.angriffsbonus(figur),
int(figur["hp"]["current"]), int(figur["hp"]["max"])],
Vector2(40, 680), Vector2(700, 40))
_schliessen_knopf(p)
func _titel(p: Panel) -> void:
var l := Label.new()
l.text = "INVENTAR"
l.position = Vector2(40, 24)
l.add_theme_color_override("font_color", UiTheme.GOLD)
p.add_child(l)
func _gold(p: Panel) -> void:
var l := Label.new()
l.text = "Gold: %d" % Game.gold
l.position = Vector2(1080, 24)
l.size = Vector2(280, 40)
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
l.clip_text = true
l.add_theme_color_override("font_color", UiTheme.GOLD)
p.add_child(l)
func _reiter(p: Panel) -> void:
var x := 40
for i in Game.party.size():
var b := Button.new()
@ -57,53 +99,21 @@ func _bauen() -> void:
b.focus_mode = Control.FOCUS_NONE
b.clip_text = true
b.modulate = Color(1.45, 1.25, 0.95) if i == _index else Color(1, 1, 1)
b.pressed.connect(_waehlen.bind(i))
b.pressed.connect(_waehlen_figur.bind(i))
p.add_child(b)
x += 180
if Game.party.is_empty():
var leer := Label.new()
leer.text = "Keine Figur in der Party."
leer.position = Vector2(40, 180)
p.add_child(leer)
_schliessen_knopf(p)
return
var figur: Dictionary = Game.party[_index]
_ausgeruestet(p, figur)
_rucksack(p, figur)
var werte := Label.new()
werte.text = "RK %d Angriff +%d TP %d/%d" % [
Game.rk(figur), Game.angriffsbonus(figur),
int(figur["hp"]["current"]), int(figur["hp"]["max"])]
werte.position = Vector2(40, 680)
werte.size = Vector2(700, 40)
werte.clip_text = true
p.add_child(werte)
_schliessen_knopf(p)
# ------------------------------------------------------------- ausgerüstet --
func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
var kopf := Label.new()
kopf.text = "AUSGERÜSTET"
kopf.position = Vector2(40, 160)
kopf.add_theme_color_override("font_color", UiTheme.GOLD)
p.add_child(kopf)
_label(p, "AUSGERÜSTET", Vector2(40, 160),
Vector2(300, 40), UiTheme.GOLD)
var equipment: Dictionary = figur.get("equipment", {})
for i in SLOTS.size():
var slot: Dictionary = SLOTS[i]
var y := 210 + i * 84
var slot_label := Label.new()
slot_label.text = str(slot["label"])
slot_label.position = Vector2(40, y)
slot_label.size = Vector2(160, 52)
slot_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
slot_label.clip_text = true
p.add_child(slot_label)
var y := 210 + i * 100
var id := ""
if str(slot["key"]) == "shield":
if bool(equipment.get("shield", false)):
@ -111,19 +121,17 @@ func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
else:
id = str(equipment.get(slot["key"], ""))
var wert := Label.new()
wert.text = _item_name(id) if not id.is_empty() else "—"
wert.position = Vector2(210, y)
wert.size = Vector2(260, 52)
wert.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
wert.clip_text = true
wert.modulate = Color(0.9, 0.84, 0.70)
p.add_child(wert)
if not id.is_empty():
_icon(p, id, Vector2(40, y))
_label(p, str(slot["label"]), Vector2(120, y + 12),
Vector2(260, 40), UiTheme.CREAM_D)
_label(p, _item_name(id) if not id.is_empty() else "—",
Vector2(120, y + 44), Vector2(260, 40))
if not id.is_empty():
var b := Button.new()
b.text = "Ablegen"
b.position = Vector2(480, y)
b.position = Vector2(400, y + 6)
b.size = Vector2(200, 52)
b.focus_mode = Control.FOCUS_NONE
b.clip_text = true
@ -131,62 +139,205 @@ func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
p.add_child(b)
# ---------------------------------------------------------------- Rucksack --
func _rucksack(p: Panel, figur: Dictionary) -> void:
var kopf := Label.new()
kopf.text = "RUCKSACK"
kopf.position = Vector2(720, 160)
kopf.add_theme_color_override("font_color", UiTheme.GOLD)
p.add_child(kopf)
_label(p, "RUCKSACK", RASTER + Vector2(0, -40),
Vector2(300, 40), UiTheme.GOLD)
var inventar: Array = figur.get("inventory", [])
if inventar.is_empty():
var leer := Label.new()
leer.text = "leer"
leer.position = Vector2(720, 210)
leer.modulate = Color(0.75, 0.70, 0.60)
p.add_child(leer)
for i in SPALTEN * ZEILEN:
var x := RASTER.x + (i % SPALTEN) * (KACHEL + ABSTAND)
var y := RASTER.y + (i / SPALTEN) * (KACHEL + ABSTAND)
if i < inventar.size():
var eintrag = inventar[i]
var id := ""
var anzahl := 1
if typeof(eintrag) == TYPE_DICTIONARY:
id = str(eintrag.get("id", ""))
anzahl = int(eintrag.get("count", 1))
else:
id = str(eintrag)
_slot_knopf(p, id, anzahl, Vector2(x, y))
else:
_leerer_slot(p, Vector2(x, y))
func _slot_knopf(p: Panel, id: String, anzahl: int, pos: Vector2) -> void:
var b := Button.new()
b.position = pos
b.size = Vector2(KACHEL, KACHEL)
b.focus_mode = Control.FOCUS_NONE
b.tooltip_text = _item_name(id)
_slot_style(b, _sel_id == id and _sel_quelle == "inventar")
b.pressed.connect(_waehlen_item.bind(id))
p.add_child(b)
var t := _item_textur(id)
if t != null:
var icon := TextureRect.new()
icon.texture = t
icon.position = Vector2(12, 6)
icon.size = Vector2(64, 64)
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
icon.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
b.add_child(icon)
if anzahl > 1:
var zahl := Label.new()
zahl.text = str(anzahl)
zahl.position = Vector2(44, 54)
zahl.size = Vector2(40, 30)
zahl.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
zahl.add_theme_color_override("font_outline_color", UiTheme.INK)
zahl.add_theme_constant_override("outline_size", 6)
zahl.mouse_filter = Control.MOUSE_FILTER_IGNORE
b.add_child(zahl)
func _leerer_slot(p: Panel, pos: Vector2) -> void:
var panel := Panel.new()
panel.position = pos
panel.size = Vector2(KACHEL, KACHEL)
var sb := StyleBoxFlat.new()
sb.bg_color = Color(UiTheme.PANEL_LO, 0.7)
sb.border_color = Color(UiTheme.LINE, 0.45)
sb.set_border_width_all(2)
panel.add_theme_stylebox_override("panel", sb)
p.add_child(panel)
func _slot_style(b: Button, gewaehlt: bool) -> void:
var normal := StyleBoxFlat.new()
normal.bg_color = UiTheme.PANEL_LO
normal.border_color = UiTheme.GOLD if gewaehlt else UiTheme.LINE
normal.set_border_width_all(2)
var heiss := normal.duplicate() as StyleBoxFlat
heiss.bg_color = UiTheme.PANEL_HI
heiss.border_color = UiTheme.GOLD
b.add_theme_stylebox_override("normal", normal)
b.add_theme_stylebox_override("hover", heiss)
b.add_theme_stylebox_override("pressed", heiss)
b.add_theme_stylebox_override("focus", normal)
# ----------------------------------------------------------------- Details --
func _details(p: Panel, figur: Dictionary) -> void:
var box := Panel.new()
box.position = Vector2(640, 510)
box.size = Vector2(720, 150)
box.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
p.add_child(box)
if _sel_id.is_empty():
_label(box, "Wähle einen Gegenstand.", Vector2(20, 20),
Vector2(680, 40), UiTheme.CREAM_D)
if not _meldung.is_empty():
_label(box, _meldung, Vector2(20, 80), Vector2(680, 36),
Color(0.88, 0.78, 0.55))
return
for i in inventar.size():
var eintrag = inventar[i]
var id := ""
var anzahl := 1
if typeof(eintrag) == TYPE_DICTIONARY:
id = str(eintrag.get("id", ""))
anzahl = int(eintrag.get("count", 1))
_label(box, _item_name(_sel_id), Vector2(20, 16),
Vector2(420, 40), UiTheme.GOLD)
var typ := _item_typ(_sel_id)
var item: Dictionary = Content.entry("items", _sel_id)
var beschreibung := "Sonstiges"
match typ:
"weapon":
beschreibung = "Waffe - %s" % str(item.get("damage", "?"))
"armor":
beschreibung = "Rüstung - RK +%d" % int(item.get("ac_bonus", 0))
"shield":
beschreibung = "Schild - RK +%d" % int(item.get("ac_bonus", 0))
_label(box, beschreibung, Vector2(20, 58), Vector2(420, 36), UiTheme.CREAM_D)
if _sel_quelle == "slot":
_aktions_knopf(box, "Ablegen", _ablegen.bind(_sel_id))
elif typ in ["weapon", "armor", "shield"]:
var erlaubt: bool = Game.ausruesten_erlaubt(figur, _sel_id)
if erlaubt:
_aktions_knopf(box, "Ausrüsten", _ausruesten.bind(_sel_id))
else:
id = str(eintrag)
if id.is_empty():
continue
var y := 210 + i * 56
if y > 700:
break
_label(box, "Diese Klasse darf das nicht tragen.",
Vector2(20, 104), Vector2(560, 36), Color(0.85, 0.55, 0.42))
else:
_aktions_knopf(box, "Benutzen", _benutzen.bind(_sel_id))
var item_label := Label.new()
item_label.text = _item_name(id)
item_label.position = Vector2(720, y)
item_label.size = Vector2(340, 44)
item_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
item_label.clip_text = true
p.add_child(item_label)
if not _meldung.is_empty():
_label(box, _meldung, Vector2(20, 104), Vector2(660, 36),
Color(0.88, 0.78, 0.55))
if anzahl > 1:
var zahl := Label.new()
zahl.text = "x%d" % anzahl
zahl.position = Vector2(1070, y)
zahl.size = Vector2(40, 44)
zahl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
p.add_child(zahl)
if _ist_ausruestbar(id):
var b := Button.new()
b.text = "Ausrüsten"
b.position = Vector2(1120, y)
b.size = Vector2(250, 44)
b.focus_mode = Control.FOCUS_NONE
b.clip_text = true
b.pressed.connect(_ausruesten.bind(id))
p.add_child(b)
func _aktions_knopf(box: Panel, text: String, cb: Callable) -> void:
var b := Button.new()
b.text = text
b.position = Vector2(450, 30)
b.size = Vector2(250, 56)
b.focus_mode = Control.FOCUS_NONE
b.clip_text = true
b.pressed.connect(cb)
box.add_child(b)
# -------------------------------------------------------------- Aktionen ----
func _waehlen_figur(index: int) -> void:
_index = index
_sel_id = ""
_sel_quelle = ""
_meldung = ""
_bauen()
func _waehlen_item(id: String) -> void:
_sel_id = id
_sel_quelle = "inventar"
_meldung = ""
_bauen()
func _ausruesten(id: String) -> void:
if Game.party.is_empty():
return
if Game.ausruesten(Game.party[_index], id):
_meldung = "%s ausgerüstet." % _item_name(id)
_sel_id = ""
_sel_quelle = ""
else:
_meldung = "Nicht erlaubt oder nicht im Rucksack."
_bauen()
func _ablegen(slot: String) -> void:
if Game.party.is_empty():
return
var figur: Dictionary = Game.party[_index]
var id := ""
if slot == "shield":
id = "schild"
else:
id = str(figur.get("equipment", {}).get(slot, ""))
if Game.ablegen(figur, slot):
_meldung = "%s abgelegt." % _item_name(id)
_sel_id = ""
_sel_quelle = ""
else:
_meldung = "Slot ist leer."
_bauen()
func _benutzen(id: String) -> void:
if Game.party.is_empty():
return
_meldung = Game.benutzen(Game.party[_index], id)
if Game.inventar_hat(Game.party[_index], id) <= 0:
_sel_id = ""
_sel_quelle = ""
_bauen()
func _schliessen_knopf(p: Panel) -> void:
@ -200,23 +351,41 @@ func _schliessen_knopf(p: Panel) -> void:
p.add_child(b)
func _waehlen(index: int) -> void:
_index = index
_bauen()
# --------------------------------------------------------------- Bausteine --
func _label(eltern: Node, text: String, pos: Vector2,
groesse: Vector2 = Vector2(300, 40), farbe: Color = UiTheme.CREAM) -> Label:
var l := Label.new()
l.text = text
l.position = pos
l.size = groesse
l.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
l.clip_text = true
l.add_theme_color_override("font_color", farbe)
eltern.add_child(l)
return l
func _ausruesten(id: String) -> void:
if Game.party.is_empty():
func _icon(eltern: Node, id: String, pos: Vector2) -> void:
var t := _item_textur(id)
if t == null:
return
Game.ausruesten(Game.party[_index], id)
_bauen()
var icon := TextureRect.new()
icon.texture = t
icon.position = pos
icon.size = Vector2(64, 64)
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
icon.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
eltern.add_child(icon)
func _ablegen(slot: String) -> void:
if Game.party.is_empty():
return
Game.ablegen(Game.party[_index], slot)
_bauen()
func _item_textur(id: String) -> Texture2D:
var pfad := "res://assets/objects/item_%s_64.png" % id
if not ResourceLoader.exists(pfad):
return null
return load(pfad)
func _item_name(id: String) -> String:
@ -226,9 +395,8 @@ func _item_name(id: String) -> String:
return str(item.get("name", id))
func _ist_ausruestbar(id: String) -> bool:
var typ := str(Content.entry("items", id).get("type", ""))
return typ in ["weapon", "armor", "shield"]
func _item_typ(id: String) -> String:
return str(Content.entry("items", id).get("type", ""))
func _leeren(node: Node) -> void:

View file

@ -268,6 +268,23 @@ func _selbstpruefung() -> bool:
Game.ausruesten(figur, "dolch")
and str(figur["equipment"].get("weapon", "")) == "dolch"
and Game.inventar_hat(figur, "schwert") == 1) and ok
var magier := Game.neue_figur("pc_magier", {
"name": "Probe-Magier", "race": "elf", "class": "magier",
"attributes": {"str": 8, "dex": 14, "con": 10, "int": 17,
"wis": 12, "cha": 10}})
Game.inventar_hinzufuegen(magier, "leder")
ok = _pruefe("Klassenbeschränkung: Magier trägt kein Leder",
Game.ausruesten(magier, "leder") == false
and Game.inventar_hat(magier, "leder") == 1) and ok
ok = _pruefe("Klassenbeschränkung: Magier führt den Stab",
Game.ausruesten_erlaubt(magier, "stab")
and not Game.ausruesten_erlaubt(magier, "schwert")) and ok
figur["hp"]["current"] = 1
var vorrat_text: String = Game.benutzen(figur, "vorrat")
ok = _pruefe("Verbrauch: Vorrat heilt und verschwindet",
int(figur["hp"]["current"]) > 1
and Game.inventar_hat(figur, "vorrat") == 0
and vorrat_text.begins_with("Vorrat")) and ok
# Roster: 1..6, siebte Figur abgelehnt, Entfernen gibt den Platz frei.
var sicherung: Array = Game.party.duplicate(true)
@ -293,12 +310,15 @@ func _selbstpruefung() -> bool:
# JSON kennt nur "Zahl", Godot liest sie als float zurück; vor dem Vergleich
# werden ganze Zahlen normalisiert (1.0 -> 1), sonst wäre der Test unehrlich
# streng an einer Typfrage statt am Inhalt.
Game.gold = 37
var vorher := JSON.stringify(_normalisiere(Game.to_dict()))
ok = _pruefe("Spielstand schreiben", Saves.write(9)) and ok
var geladen: Dictionary = Saves.read(9)
Game.from_dict(geladen)
ok = _pruefe("Gold im Spielstand", Game.gold == 37) and ok
var nachher := JSON.stringify(_normalisiere(Game.to_dict()))
ok = _pruefe("Spielstand identisch nach Neustart", vorher == nachher) and ok
Game.gold = Game.START_GOLD
DirAccess.remove_absolute(Saves.pfad(9))
print("\nSelbstprüfung: %s" % ("bestanden" if ok else "FEHLGESCHLAGEN"))

View file

@ -7,8 +7,10 @@ extends Node
const START = "garana"
const PARTY_MAX := 6
const START_GOLD := 20
var party: Array = [] ## Array von Dictionaries (ids + Werte)
var gold := START_GOLD ## Parteigold; Ausgaben kommen später dazu
var place: Dictionary = {"id": START, "x": 9, "y": 9}
var time: Dictionary = {"day": 1, "slot": 0}
var flags: Dictionary = {}
@ -188,6 +190,21 @@ func inventar_entfernen(figur: Dictionary, id: String, anzahl: int = 1) -> bool:
return false
## Klassenbeschränkung aus `classes.json` (`weapons`, `armor`).
func ausruesten_erlaubt(figur: Dictionary, id: String) -> bool:
var item: Dictionary = Content.entry("items", id)
var typ := str(item.get("type", ""))
var klasse: Dictionary = Content.class_def(str(figur.get("class", "")))
match typ:
"weapon":
return klasse.get("weapons", []).has(id)
"armor":
return klasse.get("armor", []).has(id)
"shield":
return klasse.get("armor", []).has("schild")
return false
func ausruesten(figur: Dictionary, id: String) -> bool:
var item: Dictionary = Content.entry("items", id)
if item.is_empty():
@ -195,6 +212,8 @@ func ausruesten(figur: Dictionary, id: String) -> bool:
var typ := str(item.get("type", ""))
if typ not in ["weapon", "armor", "shield"]:
return false
if not ausruesten_erlaubt(figur, id):
return false
if inventar_hat(figur, id) <= 0:
return false
var equipment: Dictionary = figur.get("equipment", {})
@ -212,6 +231,29 @@ func ausruesten(figur: Dictionary, id: String) -> bool:
return true
## Verbrauchsgüter. Gibt eine Meldung für die UI zurück.
func benutzen(figur: Dictionary, id: String) -> String:
if inventar_hat(figur, id) <= 0:
return "Nicht im Rucksack."
match id:
"vorrat":
var tp: Dictionary = figur.get("hp", {})
if int(tp.get("current", 0)) >= int(tp.get("max", 0)):
return "TP sind voll."
var heilung: int = Dice.roll("1d6")
tp["current"] = mini(int(tp.get("max", 0)),
int(tp.get("current", 0)) + heilung)
figur["hp"] = tp
inventar_entfernen(figur, id)
return "Vorrat: +%d TP." % heilung
"laterne":
flags["licht"] = not bool(flags.get("licht", false))
return "Laterne %s." % ("an" if flags["licht"] else "aus")
"seil":
return "Seil: noch keine Anwendung."
return "Nicht benutzbar."
func ablegen(figur: Dictionary, slot: String) -> bool:
var equipment: Dictionary = figur.get("equipment", {})
if slot == "shield":
@ -240,6 +282,7 @@ func to_dict() -> Dictionary:
"save_version": Saves.VERSION,
"place": place,
"time": time,
"gold": gold,
"party": party,
"flags": flags,
"log": log_lines,
@ -248,6 +291,7 @@ func to_dict() -> Dictionary:
func from_dict(d: Dictionary) -> void:
place = d.get("place", place)
time = d.get("time", time)
gold = int(d.get("gold", gold))
party = d.get("party", party)
flags = d.get("flags", {})
log_lines = []

View file

@ -28,6 +28,14 @@ func _ready() -> void:
ok("Kette liegt im Rucksack", Game.inventar_hat(figur, "kette") == 1)
ok("Ablegen legt zurück", Game.ablegen(figur, "armor")
and Game.inventar_hat(figur, "leder") == 1)
ok("Magier: Leder gesperrt",
not Game.ausruesten_erlaubt(Game.party[2], "leder")
and Game.ausruesten_erlaubt(Game.party[2], "stab"))
# Zustand für den Screenshot wiederherstellen und Leder auswählen.
Game.ausruesten(figur, "kette")
Game.ausruesten(figur, "schwert")
ui.call("_waehlen_item", "leder")
print("\nProbe: %s" % ("bestanden" if fehler == 0 else "FEHLGESCHLAGEN"))
if OS.get_cmdline_user_args().has("--check"):