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
|
(progn
|
||||||
(insert "Zbraně:\n")
|
(insert "Zbraně:\n")
|
||||||
(dolist (w weapons)
|
(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)
|
(plist-get w :name)
|
||||||
(or (plist-get w :modifier) 0)
|
(or (plist-get w :modifier) 0)
|
||||||
(or (plist-get w :damage) 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
|
;; 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 ()
|
(defun alien-rpg-gear ()
|
||||||
"Výbava — přidat nebo odebrat."
|
"Výbava — přidat nebo odebrat."
|
||||||
(interactive)
|
(interactive)
|
||||||
@@ -1398,11 +1416,23 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
|||||||
(alien-rpg--autosave)
|
(alien-rpg--autosave)
|
||||||
(message "Výbava: %s" item)))
|
(message "Výbava: %s" item)))
|
||||||
((string= action "Odebrat")
|
((string= action "Odebrat")
|
||||||
(let* ((choice (completing-read "Odebrat: " extra nil t))
|
(let* ((candidates (alien-rpg--numbered-candidates extra))
|
||||||
(new-list (remove choice extra)))
|
(choice (completing-read "Odebrat: " candidates nil t))
|
||||||
(setq alien-rpg-state (plist-put alien-rpg-state :extra-gear new-list))
|
(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)
|
(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 ()
|
(defun alien-rpg-weapon ()
|
||||||
"Zbraně — přidat, odebrat, upravit munici."
|
"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")
|
((string= action "Přidat")
|
||||||
(alien-rpg--add-weapon-interactive))
|
(alien-rpg--add-weapon-interactive))
|
||||||
(t
|
(t
|
||||||
(let* ((names (mapcar (lambda (w)
|
(let* ((candidates (alien-rpg--numbered-candidates
|
||||||
(format "%s mod%+d/DMG%d/%s/%dks"
|
weapons #'alien-rpg--weapon-label))
|
||||||
(plist-get w :name)
|
(choice (completing-read "Která zbraň: " candidates nil t))
|
||||||
(or (plist-get w :modifier) 0)
|
(idx (cdr (assoc choice candidates)))
|
||||||
(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=))
|
|
||||||
(weapon (nth idx weapons)))
|
(weapon (nth idx weapons)))
|
||||||
(cond
|
(cond
|
||||||
((string= action "Munice")
|
((string= action "Munice")
|
||||||
@@ -1440,8 +1464,7 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
|||||||
((string= action "Odebrat")
|
((string= action "Odebrat")
|
||||||
(setq alien-rpg-state
|
(setq alien-rpg-state
|
||||||
(plist-put alien-rpg-state :weapons
|
(plist-put alien-rpg-state :weapons
|
||||||
(append (cl-subseq weapons 0 idx)
|
(alien-rpg--remove-nth idx weapons)))
|
||||||
(cl-subseq weapons (1+ idx)))))
|
|
||||||
(alien-rpg--autosave)
|
(alien-rpg--autosave)
|
||||||
(message "Odebráno: %s" (plist-get weapon :name)))
|
(message "Odebráno: %s" (plist-get weapon :name)))
|
||||||
((string= action "Upravit")
|
((string= action "Upravit")
|
||||||
@@ -1499,11 +1522,13 @@ Průlezy G<->H: G3<->H3, G4<->H4, G7<->H7, G8<->H8, G9<->H9
|
|||||||
(alien-rpg--autosave)
|
(alien-rpg--autosave)
|
||||||
(message "Zranění: %s" injury)))
|
(message "Zranění: %s" injury)))
|
||||||
((string= action "Vyléčit")
|
((string= action "Vyléčit")
|
||||||
(let* ((choice (completing-read "Vyléčit: " injuries nil t))
|
(let* ((candidates (alien-rpg--numbered-candidates injuries))
|
||||||
(new-list (remove choice injuries)))
|
(choice (completing-read "Vyléčit: " candidates nil t))
|
||||||
(setq alien-rpg-state (plist-put alien-rpg-state :injuries new-list))
|
(idx (cdr (assoc choice candidates))))
|
||||||
|
(setq alien-rpg-state (plist-put alien-rpg-state :injuries
|
||||||
|
(alien-rpg--remove-nth idx injuries)))
|
||||||
(alien-rpg--autosave)
|
(alien-rpg--autosave)
|
||||||
(message "Vyléčeno: %s" choice))))))
|
(message "Vyléčeno: %s" (nth idx injuries)))))))
|
||||||
|
|
||||||
(defun alien-rpg-condition ()
|
(defun alien-rpg-condition ()
|
||||||
"Stav/podmínka — přidat nebo odebrat."
|
"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)
|
(alien-rpg--autosave)
|
||||||
(message "Stav: %s" cond-name)))
|
(message "Stav: %s" cond-name)))
|
||||||
((string= action "Odebrat")
|
((string= action "Odebrat")
|
||||||
(let* ((choice (completing-read "Odebrat: " conditions nil t))
|
(let* ((candidates (alien-rpg--numbered-candidates conditions))
|
||||||
(new-list (remove choice conditions)))
|
(choice (completing-read "Odebrat: " candidates nil t))
|
||||||
(setq alien-rpg-state (plist-put alien-rpg-state :conditions new-list))
|
(idx (cdr (assoc choice candidates))))
|
||||||
|
(setq alien-rpg-state (plist-put alien-rpg-state :conditions
|
||||||
|
(alien-rpg--remove-nth idx conditions)))
|
||||||
(alien-rpg--autosave)
|
(alien-rpg--autosave)
|
||||||
(message "Odebráno: %s" choice))))))
|
(message "Odebráno: %s" (nth idx conditions)))))))
|
||||||
|
|
||||||
;; ====================================================================
|
;; ====================================================================
|
||||||
;; DISPATCH, HELP, VIEW MODE
|
;; DISPATCH, HELP, VIEW MODE
|
||||||
|
|||||||
Reference in New Issue
Block a user