自动拆分大图成tilemap并生成json格式数据信息的脚本

2060阅读 0评论2014-03-03 风间星魂
分类:LINUX


(require 'json)
(require 'cl)

(defvar image-magic-sh "./img_clip.sh")
(setq magic-argv '("home_bg.png" "128x128" "c_bg.png"))

(defun expend-args-to-process (cmd args)
  (apply  (append `(process-lines ,cmd) args)))

(defun make-clip-img-info ()
  (let* ((outstr) (result))
      (setq outstr  (expend-args-to-process
                            (expand-file-name image-magic-sh) magic-argv))
      (dolist (str outstr result)
        (let ((ts))
          (setq ts (split-string str " "))
          (let ( (size) (pos) (node) )
              (setq size (split-string (nth 2 ts) "x"))
              (setq pos (split-string (nth 3 ts) "x\\|+"))
              (setq size (mapcar 'string-to-number size))
              (setq pos (mapcar 'string-to-number pos))

              (setq node (list :name (file-name-nondirectory  (car ts))
                               :fmt (downcase (cadr ts))
                               :width (car size)
                               :height (cadr size)
                               :sw (car pos)
                               :sh (cadr pos)
                               :x (nth 2 pos)
                               :y (nth 3 pos)
                               :id  (string-to-number (cadr (split-string (file-name-base (car ts)) "-")))
                             ))
              (setq result (cons node result)))
          )
        )
      (message "%s" (json-encode (vconcat (sort result (lambda (x  y)
                                                         (< (plist-get x ':id) (plist-get y ':id))
                                                         )))))))

(make-clip-img-info)

上一篇:osx emacs brew编译的cocoa版vc-mode svn提交编码错误。
下一篇:emacs-ipython