emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pacmacs 91e432111b 145/472: Implement basic score table me


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs 91e432111b 145/472: Implement basic score table mechnism (#92)
Date: Thu, 6 Jan 2022 21:59:20 -0500 (EST)

branch: elpa/pacmacs
commit 91e432111b1ed34aab3b401ced3ee508ff1becc8
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>

    Implement basic score table mechnism (#92)
---
 pacmacs-score.el | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pacmacs-utils.el |  5 ++++
 pacmacs.el       |  5 ----
 3 files changed, 91 insertions(+), 5 deletions(-)

diff --git a/pacmacs-score.el b/pacmacs-score.el
new file mode 100644
index 0000000000..aa07a202d9
--- /dev/null
+++ b/pacmacs-score.el
@@ -0,0 +1,86 @@
+;;; pacmacs-score.el --- Pacman for Emacs
+
+;; Copyright (C) 2015 Codingteam
+
+;; Author: Codingteam <codingteam@conference.jabber.ru>
+;; Maintainer: Alexey Kutepov <reximkut@gmail.com>
+;; URL: http://github.com/rexim/pacmacs.el
+
+;; Permission is hereby granted, free of charge, to any person
+;; obtaining a copy of this software and associated documentation
+;; files (the "Software"), to deal in the Software without
+;; restriction, including without limitation the rights to use, copy,
+;; modify, merge, publish, distribute, sublicense, and/or sell copies
+;; of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+;; SOFTWARE.
+
+;;; Commentary:
+
+;; Routines for working with score
+
+;;; Code:
+
+(require 'dash)
+
+(defconst pacmacs--score-file-name "~/.pacmacs-score")
+(defconst pacmacs--score-buffer-name "*Pacmacs Score*")
+
+(defun pacmacs-score ()
+  (interactive)
+  (switch-to-buffer-other-window pacmacs--score-buffer-name)
+  (text-mode)
+  (read-only-mode)
+  (with-current-buffer pacmacs--score-buffer-name
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (-> (pacmacs--read-score-table)
+          (pacmacs--sort-score-table)
+          (pacmacs--render-score-table)))))
+
+(defun pacmacs--read-score-table ()
+  (-> pacmacs--score-file-name
+      (pacmacs--file-content)
+      (read-from-string)
+      (car)))
+
+(defun pacmacs--write-score-table (score-table)
+  (with-temp-buffer
+    (-> score-table
+        (pp-to-string)
+        (insert))
+    (write-file pacmacs--score-file-name)))
+
+(defun pacmacs--sort-score-table (score-table)
+  (sort score-table
+        (-lambda ((_ . score1) (_ . score2))
+          (> score1 score2))))
+
+(defun pacmacs--render-score-table (score-table)
+  (let ((max-nickname-length
+         (--> (pacmacs--read-score-table)
+              (-map (-compose #'length #'car) it)
+              (apply #'max it))))
+    (-each score-table
+      (-lambda ((nickname . score))
+        (insert (format "%s%s %d\n"
+                        nickname
+                        (make-string (- max-nickname-length
+                                        (length nickname))
+                                     ?\s)
+                        score))))))
+
+(provide 'pacmacs-score)
+
+;;; pacmacs-score.el ends here
diff --git a/pacmacs-utils.el b/pacmacs-utils.el
index f8301b5b62..798e7b4d31 100644
--- a/pacmacs-utils.el
+++ b/pacmacs-utils.el
@@ -65,6 +65,11 @@ side-effects."
     (cdr (assoc direction-vector
                 direction-table))))
 
+(defun pacmacs--file-content (filename)
+  (with-temp-buffer
+    (insert-file-contents filename)
+    (buffer-string)))
+
 (provide 'pacmacs-utils)
 
 ;;; pacmacs.el ends here
diff --git a/pacmacs.el b/pacmacs.el
index f9cef87e1f..91c321571f 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -447,11 +447,6 @@
   (when (equal pacmacs-game-state 'play)
     (pacmacs--switch-direction pacmacs-player-state 'right)))
 
-(defun pacmacs--file-content (filename)
-  (with-temp-buffer
-    (insert-file-contents filename)
-    (buffer-string)))
-
 (defun pacmacs-load-map (map-name)
   (let* ((lines (split-string (pacmacs--file-content (format "maps/%s.txt" 
map-name)) "\n" t))
          (board-width (apply 'max (mapcar #'length lines)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]