Skip to content

Commit 31eb97b

Browse files
committed
Port TextBubble to coffee
1 parent b844281 commit 31eb97b

File tree

3 files changed

+62
-63
lines changed

3 files changed

+62
-63
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ src/js/generator/*.js
2222
src/js/sound/**/*.js
2323
src/js/prettyprinter/*.js
2424
src/js/Game.js
25+
src/js/TextBubble.js
2526
src/js/editor/*.js
2627

2728
test/spec/*.js

src/js/TextBubble.coffee

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
define [
2+
'Text'
3+
'Vec2'
4+
'con2d'
5+
], (
6+
Text
7+
Vec2
8+
con2d
9+
) ->
10+
'use strict'
11+
12+
TextBubble = ->
13+
@position = new Vec2(8, 8)
14+
@visible = true
15+
@text = ''
16+
@length = -Infinity
17+
@lines = []
18+
return
19+
20+
21+
TextBubble::hide = ->
22+
@visible = false
23+
@
24+
25+
26+
TextBubble::show = ->
27+
@visible = true
28+
@
29+
30+
31+
TextBubble::draw = ->
32+
return if not @visible
33+
34+
# clear bubble
35+
con2d.fillStyle = '#007B90'
36+
con2d.fillRect @position.x, @position.y, @length * 16 + 8, @lines.length * 18 + 8
37+
38+
# draw the text, line by line
39+
i = 0
40+
while i < @lines.length
41+
Text.drawAt @lines[i], @position.x + 4, @position.y + i * 18 + 4
42+
i++
43+
44+
return
45+
46+
47+
TextBubble::setText = (text) ->
48+
# remove when the character set is complete
49+
@text = text.toUpperCase()
50+
51+
@lines = @text.split '\n'
52+
.map (line) -> line.trim()
53+
54+
@length = Math.max @lines.map(({ length }) -> length)...
55+
56+
boxWidth = @length * 16 + 8
57+
@position.x = (con2d.canvas.width - boxWidth) // 2
58+
@
59+
60+
61+
TextBubble

src/js/TextBubble.js

-63
This file was deleted.

0 commit comments

Comments
 (0)