Skip to content

Commit 23de080

Browse files
authored
New example tailored for JS backend (#152)
* New *fancy* example * backward compatibility
1 parent 49987e1 commit 23de080

File tree

5 files changed

+583
-11
lines changed

5 files changed

+583
-11
lines changed

examples/configure.ml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ let () =
6262
add_executable "spritesheet" [ "spritesheet.png" ];
6363
add_executable "draw" [ "colors.png" ];
6464
add_executable "window_with_textbox" [];
65+
add_executable "suncities" [];
6566

6667
add_executable "demo1" [];
6768
add_executable "demo2" [];

examples/dune.inc

+8
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@
175175
(libraries ocaml-canvas react))
176176

177177

178+
(executable
179+
(name suncities)
180+
(public_name ocaml-canvas-suncities)
181+
(modes byte_complete native js)
182+
(modules suncities)
183+
(libraries ocaml-canvas react))
184+
185+
178186
(executable
179187
(name demo1)
180188
(public_name ocaml-canvas-demo1)

examples/make_index/make_index.ml

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11

22
let gen_sample_index file =
3-
let tl = open_in "sample_template.html" in
4-
let out = open_out (file ^ ".html") in
5-
try
6-
while true do
7-
let l = input_line tl in
8-
let l' = Str.global_replace (Str.regexp_string "%%FILE%%") file l in
9-
Printf.fprintf out "%s\n" l'
10-
done;
11-
with End_of_file ->
12-
close_in tl;
13-
close_out out
3+
let filename = file ^ ".html" in
4+
if Sys.file_exists filename then () else
5+
let tl = open_in "sample_template.html" in
6+
let out = open_out filename in
7+
try
8+
while true do
9+
let l = input_line tl in
10+
let l' = Str.global_replace (Str.regexp_string "%%FILE%%") file l in
11+
Printf.fprintf out "%s\n" l'
12+
done;
13+
with End_of_file ->
14+
close_in tl;
15+
close_out out
1416

1517
let gen_global_index file files =
1618
let tl = open_in "global_template.html" in

examples/suncities.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
6+
<title>Sun Empire</title>
7+
<style>
8+
canvas {image-rendering:auto;}
9+
</style>
10+
</head>
11+
<body>
12+
<noscript>Sorry, you need to enable JavaScript to see this page.</noscript>
13+
<script type="text/javascript" defer="defer" src="suncities.bc.js"></script>
14+
<div style="float:left">
15+
<h1>Cities under the Sun</h1>
16+
</div>
17+
<div style="float:left">
18+
<ul>
19+
<li><b>Space</b> to change city</li>
20+
<li><b>Left-click</b> drag to move viewpoint</li>
21+
<li><b>Right-click</b> drag to change daytime</li>
22+
</ul>
23+
</div>
24+
<div id="can"></div>
25+
</body>
26+
</html>

0 commit comments

Comments
 (0)