summaryrefslogtreecommitdiff
path: root/wrap.fnl
blob: 04e6290b5d0586d54b375e0a936c002e176f59ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;;;; Copyright (C) 2018 Jakob L. Kreuze, All Rights Reserved.
;;;;
;;;; This file is part of swanky.
;;;;
;;;; swanky 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.
;;;;
;;;; swanky 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 swanky. If not, see <http://www.gnu.org/licenses/>.

;;;; ---

;;;; This module contains non-game-specific bits and mode-changing logic.

(var scale 2)
(local canvas-width 640)
(local canvas-height 480)

(global screen-width (math.floor (/ canvas-width scale)))
(global screen-height (math.floor (/ canvas-height scale)))

(local canvas (love.graphics.newCanvas canvas-width canvas-height))
(local font (love.graphics.newImageFont "art/font.png"
                                        (.. " !\"#$%&*()*+,-./"
                                            "0123456789"
                                            ":;<=>?@"
                                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                            "abcdefghijklmnopqrstuvwxyz"
                                            "[\\]^_`{|}~")))

(var mode (require :sandbox))

(fn set-mode [mode-name ...]
  (set mode (require mode-name))
  (when mode.activate
    (mode.activate ...)))

(fn love.load []
  (: canvas :setFilter "nearest" "nearest")
  (love.graphics.setFont font))

(fn love.draw []
  (love.graphics.setCanvas canvas)
  (love.graphics.clear)
  (love.graphics.setColor 1 1 1)
  (mode.draw)
  (love.graphics.setCanvas)
  (love.graphics.setColor 1 1 1)
  (love.graphics.draw canvas 0 0 0 scale scale))

(fn love.update [dt]
  (mode.update dt set-mode))

(fn love.keypressed [key]
  (if (and (= key "f11") (= scale 2))
    (let [(dw dh) (love.window.getDesktopDimensions)]
      (love.window.setMode dw dh {:fullscreen true :fullscreentype :desktop})
      (set scale (/ dh 225)))

    (= key "f11")
    (do (set scale 2) (love.window.setMode (* 720 scale) (* 450 scale)))

    (and (love.keyboard.isDown "lctrl" "rctrl" "capslock") (= key "q"))
    (love.event.quit)

    (love.keyboard.isDown "m")
    (sound.toggle)

    :else
    (mode.keypressed key set-mode)))

(fn love.keyreleased [key]
  (mode.keyreleased key set-mode))