Add cg-symbols + renderer skins foundation; doc/URL consistency; README fixes

This commit is contained in:
Corwin Brust 2026-06-23 21:56:31 -05:00
parent a025434c2b
commit 2c29d5db35
11 changed files with 246 additions and 41 deletions

98
cg-render.el Normal file
View file

@ -0,0 +1,98 @@
;;; cg-render.el --- Renderer "skins" for card games -*- lexical-binding: t; -*-
;; Copyright (C) 2026 Corwin Brust
;; Author: Corwin Brust <corwin@bru.st>
;; Maintainer: Corwin Brust <corwin@bru.st>
;; Version: 1.0.50
;; Package-Requires: ((emacs "26.1"))
;; Keywords: games
;; URL: https://code.bru.st/corwin/card-game.el
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; 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 General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Concrete display treatments ("skins") built on the `cg-renderer'
;; protocol from cg-core. Each treatment is a small EIEIO class that
;; registers itself by name:
;;
;; text plain UNICODE text (works in a terminal and on Android)
;; svg SVG cards on a graphical display
;; svg-fill a full-window SVG table that grows with the window
;;
;; A game draws itself by calling `cg-render-game', which selects the
;; game's current renderer (falling back to a default treatment chosen
;; for the display) and dispatches `cg-renderer-draw'. The actual,
;; game-specific drawing is supplied as methods specialised on a
;; (TREATMENT GAME) pair in the individual game files.
;;; Code:
(require 'cg-core)
(defgroup cg-render nil
"Display treatments (\"skins\") for card games."
:group 'card-games
:prefix "cg-render-")
(defclass cg-text-renderer (cg-renderer)
((name :initform 'text))
"Plain UNICODE text treatment.")
(defclass cg-svg-renderer (cg-renderer)
((name :initform 'svg))
"SVG cards on a graphical display.")
(defclass cg-svg-fill-renderer (cg-svg-renderer)
((name :initform 'svg-fill))
"Full-window SVG table that grows to fill the window.")
(cg-register-renderer 'text 'cg-text-renderer)
(cg-register-renderer 'svg 'cg-svg-renderer)
(cg-register-renderer 'svg-fill 'cg-svg-fill-renderer)
(defcustom cg-render-default-treatment 'auto
"Default display treatment for games.
The value `auto' chooses `svg' on a graphical display and `text'
otherwise. It may instead name a treatment registered in
`cg-renderers', such as `text', `svg', or `svg-fill'."
:type '(choice (const :tag "Automatic (svg if graphical, else text)" auto)
(const text) (const svg) (const svg-fill)
(symbol :tag "Other registered treatment"))
:group 'cg-render)
(defun cg-render-resolve-treatment (&optional name)
"Return a concrete treatment name, resolving `auto' and NAME for this display.
NAME defaults to `cg-render-default-treatment'."
(let ((n (or name cg-render-default-treatment)))
(if (eq n 'auto)
(if (display-graphic-p) 'svg 'text)
n)))
(defun cg-render-game (game)
"Draw GAME with its current renderer, creating a default one if needed.
The default treatment comes from `cg-render-resolve-treatment'."
(let ((r (or (oref game renderer)
(let ((new (cg-make-renderer (cg-render-resolve-treatment))))
(oset game renderer new)
new))))
(cg-renderer-draw r game)))
(defun cg-render-set-treatment (game name)
"Switch GAME to the treatment NAME and return its new renderer."
(oset game renderer (cg-make-renderer name)))
(provide 'cg-render)
;;; cg-render.el ends here