Skip to content

Commit 784768f

Browse files
committed
Update code examples
Closes #3
1 parent 1a41310 commit 784768f

File tree

3 files changed

+46
-59
lines changed

3 files changed

+46
-59
lines changed

assets/layout/landing.html

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@
2727

2828
type Vector = [number, number, number];
2929

30-
declare class Unit {
31-
getLevel(): number;
30+
declare function findUnits(this: void, center: Vector, radius: number): Unit[];
31+
declare interface Unit {
3232
isEnemy(other: Unit): boolean;
3333
kill(): void;
34-
FindUnitsInRadius(radius: number): Unit[];
3534
}</div>
3635
<!-- prettier-ignore -->
3736
<div class="example-item" id="ts-source"><b>// TS Source</b>
3837

39-
function onSpellStart(caster: Unit, targetLocation: Vector): void {
40-
const units = FindUnitsInRadius(targetLocation, 500);
38+
function onAbilityCast(this: void, caster: Unit, targetLocation: Vector) {
39+
const units = findUnits(targetLocation, 500);
4140
const enemies = units.filter(unit => caster.isEnemy(unit));
4241

4342
for (const enemy of enemies) {
@@ -48,13 +47,11 @@
4847
<!-- prettier-ignore -->
4948
<div class="example-item" id="lua"><b>-- Lua Output</b>
5049

51-
function onSpellStart(caster, targetLocation)
52-
local units = FindUnitsInRadius(targetLocation, 500);
53-
local enemies = __TS__ArrayFilter(units, function(unit) return caster:isEnemy(unit) end);
54-
for _, enemy in ipairs(enemies) do
55-
do
56-
enemy:kill();
57-
end
50+
function onAbilityCast(caster, targetLocation)
51+
local units = findUnits(targetLocation, 500)
52+
local enemies = __TS__ArrayFilter(units, function(____, unit) return caster:isEnemy(unit) end)
53+
for ____, enemy in ipairs(enemies) do
54+
enemy:kill()
5855
end
5956
end</div>
6057
</div>

assets/styles/landing.scss

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
main,
44
header {
5-
width: 900px;
65
overflow: hidden;
76
margin-left: auto;
87
margin-right: auto;
@@ -47,7 +46,14 @@ nav {
4746
}
4847
}
4948

49+
main {
50+
display: flex;
51+
flex-flow: column;
52+
align-items: center;
53+
}
54+
5055
#features {
56+
max-width: 900px;
5157
margin-top: 30px;
5258
margin-bottom: 20px;
5359
display: flex;
@@ -66,44 +72,42 @@ nav {
6672
margin-bottom: 10px;
6773
}
6874

69-
.example-item {
70-
padding: (15px !important);
71-
white-space: pre;
72-
font-size: 12px;
73-
font-family: $console-fonts;
75+
#example {
76+
max-width: 100%;
77+
margin-top: 70px;
7478
}
7579

7680
#example #ts {
7781
display: flex;
78-
border-bottom: solid 2px #5690fc;
82+
@media screen and (max-width: 1200px) {
83+
flex-direction: column;
84+
}
7985
}
8086

81-
#example {
82-
margin-top: 70px;
83-
width: 100%;
87+
.example-item {
88+
padding: (15px !important);
89+
white-space: pre;
90+
font-size: 12px;
91+
font-family: $console-fonts;
8492
}
8593

86-
#ts-declarations,
87-
#ts-source {
88-
display: inline-block;
89-
overflow: hidden;
94+
@media screen and (max-width: 1200px) {
95+
.example-item:not(#lua) {
96+
border-bottom: solid 2px #5690fc;
97+
}
9098
}
9199

92-
#ts-declarations {
93-
flex: 40%;
94-
}
100+
@media screen and (min-width: 1201px) {
101+
#example #ts {
102+
border-bottom: solid 2px #5690fc;
103+
}
95104

96-
#ts-source {
97-
flex: 60%;
98-
border-left: solid 2px #5690fc;
105+
#ts-source {
106+
border-left: solid 2px #5690fc;
107+
}
99108
}
100109

101110
@media screen and (max-width: 900px) {
102-
main,
103-
header {
104-
width: 100%;
105-
}
106-
107111
nav {
108112
font-size: 24px;
109113
}
@@ -113,10 +117,6 @@ nav {
113117
margin-top: 15px;
114118
}
115119

116-
.example-item {
117-
font-size: 9px;
118-
}
119-
120120
#example {
121121
margin-top: 25px;
122122
}

src/playground/code.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
const example = `/** @noSelfInFile */
2-
3-
// Declare exposed API
1+
const example = `// Declare exposed API
42
type Vector = [number, number, number];
53
6-
declare interface OnSpellStartEvent {
7-
caster: Unit;
8-
targetLocation: Vector;
9-
}
10-
11-
declare class Unit {
12-
getLevel(): number;
4+
declare function findUnits(this: void, center: Vector, radius: number): Unit[];
5+
declare interface Unit {
136
isEnemy(other: Unit): boolean;
147
kill(): void;
158
}
169
17-
declare function print(...messages: any[]): void;
18-
declare function FindUnitsInRadius(location: Vector, radius: number): Unit[];
1910
2011
// Use declared API in code
21-
function onSpellStart(event: OnSpellStartEvent): void {
22-
const units = FindUnitsInRadius(event.targetLocation, 500);
23-
const enemies = units.filter(unit => event.caster.isEnemy(unit));
12+
function onAbilityCast(this: void, caster: Unit, targetLocation: Vector) {
13+
const units = findUnits(targetLocation, 500);
14+
const enemies = units.filter(unit => caster.isEnemy(unit));
2415
25-
for (const unit of enemies) {
26-
print(unit, unit.getLevel());
27-
unit.kill();
16+
for (const enemy of enemies) {
17+
enemy.kill();
2818
}
2919
}
3020
`;

0 commit comments

Comments
 (0)