Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wolf3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
wolf3d
Commits
4c9701ef
Commit
4c9701ef
authored
Jul 21, 2019
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Add direct image output of maps to Emacs and Terminology.
parent
10e8d8bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
parse-map.scm
+83
-29
83 additions, 29 deletions
parse-map.scm
with
83 additions
and
29 deletions
parse-map.scm
+
83
−
29
View file @
4c9701ef
...
@@ -63,6 +63,33 @@
...
@@ -63,6 +63,33 @@
(
string-trim-right
(
bytevector->string
bv
transcoder
)
(
string-trim-right
(
bytevector->string
bv
transcoder
)
#\nul
))
#\nul
))
(
define
(
string->filename
str
)
(
use-modules
(
ice-9
regex
))
(
regexp-substitute/global
#f
"[ ]"
str
'pre
"_"
'post
))
;; Calls thunk with current working directory changed to dir
(
define
(
call-with-cwd
dir
thunk
)
(
let
((
old-dir
#f
))
(
dynamic-wind
(
lambda
()
(
set!
old-dir
(
getcwd
))
(
chdir
dir
))
thunk
(
lambda
()
(
chdir
old-dir
)))))
;; Attempts to display the given image file through w3m's terminal image magick;
;; currently always places it in the top left corner.
(
define
(
w3m-display-image
filename
)
(
let
((
pipe
((
@
(
ice-9
popen
)
open-output-pipe
)
"/usr/lib/w3m/w3mimgdisplay"
)))
(
format
pipe
"0;1;0;0;64;64;;;;;~a~%;4;~%3;~%"
filename
)
((
@
(
ice-9
popen
)
close-pipe
)
pipe
)))
;; Constants
;; Constants
...
@@ -109,6 +136,22 @@
...
@@ -109,6 +136,22 @@
(
height
get-height
)
(
height
get-height
)
(
name
get-name
))
(
name
get-name
))
;; My scheme level object above wolf map data
(
define-record-type
<wolf-map>
(
make-wolf-map
metadata
data
file
)
wolf-map?
(
metadata
get-metadata
)
(
data
get-data
)
(
file
get-file
set-file!
))
;; Emacs actually renders the #<Image: ...> tag!
(
set-record-type-printer!
<wolf-map>
(
lambda
(
r
p
)
(
if
(
get-file
r
)
(
format
p
"#<Image: ~a>"
(
get-file
r
))
(
format
p
"#<Wolf Map: ~a>"
(
->
r
get-metadata
get-name
)))))
;; Pure procedures
;; Pure procedures
...
@@ -250,10 +293,13 @@ else insert the value as given"
...
@@ -250,10 +293,13 @@ else insert the value as given"
(
lambda
(
el
)
(
put-bytevector
port
(
mapper
el
)))
(
lambda
(
el
)
(
put-bytevector
port
(
mapper
el
)))
array
))
array
))
(
define
(
dump-tilemap
map-head
tilemap
)
(
let
((
fname
(
format
#f
"~a.ppm"
(
get-name
map-head
))))
(
define
(
dump-tilemap!
wolf-map
)
(
let
((
fname
(
format
#f
"~a/~a.ppm"
(
getcwd
)
(
string->filename
(
get-name
(
get-metadata
wolf-map
))))))
(
call-with-output-file
fname
(
call-with-output-file
fname
(
lambda
(
port
)
(
array->ppm
port
tile
map
(
lambda
(
port
)
(
array->ppm
port
(
get-data
wolf-
map
)
(
lambda
(
tile
)
; WL_GAME.C, 624
(
lambda
(
tile
)
; WL_GAME.C, 624
(
cond
((
=
tile
0
)
rgb:black
)
; floor
(
cond
((
=
tile
0
)
rgb:black
)
; floor
((
<=
90
tile
101
)
rgb:brown
)
; door
((
<=
90
tile
101
)
rgb:brown
)
; door
...
@@ -261,34 +307,42 @@ else insert the value as given"
...
@@ -261,34 +307,42 @@ else insert the value as given"
(
else
rgb:red
))
(
else
rgb:red
))
)))
)))
#
:binary
#t
)
#
:binary
#t
)
(
format
#t
"Wrote map to ~a~%"
fname
)))
(
set-file!
wolf-map
fname
)))
(
define
(
main
args
)
(
define
get-map
(
define
og-dir
(
getcwd
))
(
call-with-cwd
(
chdir
"/home/hugo/wolf/full/"
)
"/home/hugo/wolf/full/"
(
lambda
()
(
define
map-file
(
open-input-file
"GAMEMAPS.WL6"
#
:binary
#t
))
(
let*
((
maphead
(
call-with-input-file
"MAPHEAD.WL6"
(
let*
((
maphead
(
call-with-input-file
"MAPHEAD.WL6"
parse-maphead
#
:binary
#t
))
parse-maphead
#
:binary
#t
))
(
mapmeta
(
call-with-input-file
"GAMEMAPS.WL6"
(
mapmeta
(
parse-map-metadata
maphead
map-file
)))
(
lambda
(
port
)
(
parse-map-metadata
maphead
port
))
#
:binary
#t
)))
;; function bound to get-map
(
lambda
(
idx
)
(
if
(
eq?
idx
'list
)
(
zip
(
iota
(
length
mapmeta
))
(
map
get-name
mapmeta
))
(
let
((
maph
(
list-ref
mapmeta
idx
)))
(
make-wolf-map
maph
(
->
maph
(
parse-map-data
map-file
)
car
tile-list->tilemap
)
#f
))))))))
(
define
(
main
args
)
(
when
(
or
(
=
1
(
length
args
))
(
when
(
or
(
=
1
(
length
args
))
(
member
(
cadr
args
)
'
(
"--help"
"-h"
"-?"
"--list"
"-l"
)))
(
member
(
cadr
args
)
'
(
"--help"
"-h"
"-?"
"--list"
"-l"
)))
(
format
#t
"Available maps:~%"
)
(
format
#t
"Available maps:~%~:{~2,a: ~a~%~}"
(
for-each
(
lambda
(
i
m
)
(
format
#t
"~2,a : ~a~%"
i
(
get-name
m
)))
(
get-map
'list
))
(
iota
(
length
mapmeta
))
mapmeta
)
(
exit
))
(
exit
))
(
let*
((
maph
(
list-ref
mapmeta
(
string->number
(
cadr
args
))))
(
let
((
wolf-map
(
get-map
(
string->number
(
cadr
args
)))))
(
data
(
call-with-input-file
"GAMEMAPS.WL6"
(
dump-tilemap!
wolf-map
)
(
lambda
(
port
)
(
parse-map-data
maph
port
))
(
format
#t
"Wrote image to ~a~%"
(
get-file
wolf-map
))
#
:binary
#t
)))
(
if
(
getenv
"TERMINOLOGY"
)
(
chdir
og-dir
)
(
system*
"tycat"
(
get-file
wolf-map
))
(
let
((
tilemap
(
->
data
car
tile-list->tilemap
)))
(
w3m-display-image
(
get-file
wolf-map
)))))
(
display-tilemap
tilemap
)
(
dump-tilemap
maph
tilemap
)))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment