Fix duplicate item handling, readable weapon display in status
- Numbered candidates in completing-read (1. Nůž, 2. Nůž) so duplicates are distinguishable and index is always correct - alien-rpg--remove-nth replaces broken cl-subseq/remove patterns - Weapon status now: "Nůž, mod +1, DMG 2, Long, munice 3, váha 2" instead of "Nůž mod+1/DMG2/Long/3ks/W2" — screen reader friendly Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
77
alien-rpg.el
77
alien-rpg.el
@@ -1077,7 +1077,7 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
(progn
|
||||
(insert "Zbraně:\n")
|
||||
(dolist (w weapons)
|
||||
(insert (format " %s mod%+d/DMG%d/%s/%dks/W%d\n"
|
||||
(insert (format " %s, mod %+d, DMG %d, %s, munice %d, váha %d\n"
|
||||
(plist-get w :name)
|
||||
(or (plist-get w :modifier) 0)
|
||||
(or (plist-get w :damage) 0)
|
||||
@@ -1382,6 +1382,24 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
;; SPRAVA INVENTARE
|
||||
;; ====================================================================
|
||||
|
||||
(defun alien-rpg--numbered-candidates (items &optional format-fn)
|
||||
"Očísluj ITEMS pro completing-read. Vrací alist (label . index).
|
||||
FORMAT-FN dostane item, vrátí string. Bez FORMAT-FN se item použije přímo."
|
||||
(let ((i 0))
|
||||
(mapcar (lambda (item)
|
||||
(prog1
|
||||
(cons (format "%d. %s" (1+ i)
|
||||
(if format-fn (funcall format-fn item) item))
|
||||
i)
|
||||
(setq i (1+ i))))
|
||||
items)))
|
||||
|
||||
(defun alien-rpg--remove-nth (n lst)
|
||||
"Odstraň N-tý prvek z LST (0-based)."
|
||||
(append (cl-subseq lst 0 n)
|
||||
(when (< (1+ n) (length lst))
|
||||
(cl-subseq lst (1+ n)))))
|
||||
|
||||
(defun alien-rpg-gear ()
|
||||
"Výbava — přidat nebo odebrat."
|
||||
(interactive)
|
||||
@@ -1398,11 +1416,23 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
(alien-rpg--autosave)
|
||||
(message "Výbava: %s" item)))
|
||||
((string= action "Odebrat")
|
||||
(let* ((choice (completing-read "Odebrat: " extra nil t))
|
||||
(new-list (remove choice extra)))
|
||||
(setq alien-rpg-state (plist-put alien-rpg-state :extra-gear new-list))
|
||||
(let* ((candidates (alien-rpg--numbered-candidates extra))
|
||||
(choice (completing-read "Odebrat: " candidates nil t))
|
||||
(idx (cdr (assoc choice candidates))))
|
||||
(setq alien-rpg-state (plist-put alien-rpg-state :extra-gear
|
||||
(alien-rpg--remove-nth idx extra)))
|
||||
(alien-rpg--autosave)
|
||||
(message "Odebráno: %s" choice))))))
|
||||
(message "Odebráno: %s" (nth idx extra)))))))
|
||||
|
||||
(defun alien-rpg--weapon-label (w)
|
||||
"Formátuj zbraň W pro zobrazení."
|
||||
(format "%s mod%+d/DMG%d/%s/%dks/W%d"
|
||||
(plist-get w :name)
|
||||
(or (plist-get w :modifier) 0)
|
||||
(or (plist-get w :damage) 0)
|
||||
(or (plist-get w :range) "?")
|
||||
(or (plist-get w :ammo) 0)
|
||||
(or (plist-get w :weight) 0)))
|
||||
|
||||
(defun alien-rpg-weapon ()
|
||||
"Zbraně — přidat, odebrat, upravit munici."
|
||||
@@ -1416,16 +1446,10 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
((string= action "Přidat")
|
||||
(alien-rpg--add-weapon-interactive))
|
||||
(t
|
||||
(let* ((names (mapcar (lambda (w)
|
||||
(format "%s mod%+d/DMG%d/%s/%dks"
|
||||
(plist-get w :name)
|
||||
(or (plist-get w :modifier) 0)
|
||||
(or (plist-get w :damage) 0)
|
||||
(or (plist-get w :range) "?")
|
||||
(or (plist-get w :ammo) 0)))
|
||||
weapons))
|
||||
(choice (completing-read "Která zbraň: " names nil t))
|
||||
(idx (cl-position choice names :test #'string=))
|
||||
(let* ((candidates (alien-rpg--numbered-candidates
|
||||
weapons #'alien-rpg--weapon-label))
|
||||
(choice (completing-read "Která zbraň: " candidates nil t))
|
||||
(idx (cdr (assoc choice candidates)))
|
||||
(weapon (nth idx weapons)))
|
||||
(cond
|
||||
((string= action "Munice")
|
||||
@@ -1440,8 +1464,7 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
((string= action "Odebrat")
|
||||
(setq alien-rpg-state
|
||||
(plist-put alien-rpg-state :weapons
|
||||
(append (cl-subseq weapons 0 idx)
|
||||
(cl-subseq weapons (1+ idx)))))
|
||||
(alien-rpg--remove-nth idx weapons)))
|
||||
(alien-rpg--autosave)
|
||||
(message "Odebráno: %s" (plist-get weapon :name)))
|
||||
((string= action "Upravit")
|
||||
@@ -1499,11 +1522,13 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
(alien-rpg--autosave)
|
||||
(message "Zranění: %s" injury)))
|
||||
((string= action "Vyléčit")
|
||||
(let* ((choice (completing-read "Vyléčit: " injuries nil t))
|
||||
(new-list (remove choice injuries)))
|
||||
(setq alien-rpg-state (plist-put alien-rpg-state :injuries new-list))
|
||||
(let* ((candidates (alien-rpg--numbered-candidates injuries))
|
||||
(choice (completing-read "Vyléčit: " candidates nil t))
|
||||
(idx (cdr (assoc choice candidates))))
|
||||
(setq alien-rpg-state (plist-put alien-rpg-state :injuries
|
||||
(alien-rpg--remove-nth idx injuries)))
|
||||
(alien-rpg--autosave)
|
||||
(message "Vyléčeno: %s" choice))))))
|
||||
(message "Vyléčeno: %s" (nth idx injuries)))))))
|
||||
|
||||
(defun alien-rpg-condition ()
|
||||
"Stav/podmínka — přidat nebo odebrat."
|
||||
@@ -1521,11 +1546,13 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
||||
(alien-rpg--autosave)
|
||||
(message "Stav: %s" cond-name)))
|
||||
((string= action "Odebrat")
|
||||
(let* ((choice (completing-read "Odebrat: " conditions nil t))
|
||||
(new-list (remove choice conditions)))
|
||||
(setq alien-rpg-state (plist-put alien-rpg-state :conditions new-list))
|
||||
(let* ((candidates (alien-rpg--numbered-candidates conditions))
|
||||
(choice (completing-read "Odebrat: " candidates nil t))
|
||||
(idx (cdr (assoc choice candidates))))
|
||||
(setq alien-rpg-state (plist-put alien-rpg-state :conditions
|
||||
(alien-rpg--remove-nth idx conditions)))
|
||||
(alien-rpg--autosave)
|
||||
(message "Odebráno: %s" choice))))))
|
||||
(message "Odebráno: %s" (nth idx conditions)))))))
|
||||
|
||||
;; ====================================================================
|
||||
;; DISPATCH, HELP, VIEW MODE
|
||||
|
||||
Reference in New Issue
Block a user