Skip to content

Commit

Permalink
refactor(templates): refactor to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed May 29, 2024
1 parent 2be6301 commit 7daf5fc
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/levels/0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 0
export const title = 'Hello, World!'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(50, 50), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 1
export const title = 'Comments'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(50, 50), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 10
export const title = 'forEach'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
loadSprite('spike', 'sprites/spike.png')
const player = add([
Expand Down
4 changes: 2 additions & 2 deletions src/levels/11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 11
export const title = 'Loops'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
loadSprite('enemy', 'sprites/ghosty.png')
loadSprite('wall', 'sprites/steel.png')
Expand Down
4 changes: 2 additions & 2 deletions src/levels/12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 12
export const title = 'setTimeout'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(50, 50), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 13
export const title = 'setInterval'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(50, 80), area(), anchor('center'), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/14.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 14
export const title = 'Timer'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
loadSprite('key', 'sprites/key.png')
const player = add([sprite('player'), pos(center()), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const title = 'JSON.stringify'
const password = JSON.stringify({ level, year: new Date().getFullYear() })

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
loadSprite('key', 'sprites/key.png')
const player = add([sprite('player'), pos(100, 100), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 2
export const title = 'Strings'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(center()), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 3
export const title = 'Numbers'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(500, 500), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const level = 4
export const title = 'Booleans'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(center()), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const level = 5
export const title = 'Arrays'

export const prescript = `
${loadPlayer}
${loadPlayer()}
loadSprite('wall', 'sprites/steel.png')
${loadExit}
${loadExit()}
const player = add([sprite('player'), pos(center()), area(), body(), 'player'])
add([sprite('exit'), pos(500, 500), area(), 'exit'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const level = 6
export const title = 'Objects'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
const player = add([sprite('player'), pos(0, 36), area(), body(), 'player'])
add([sprite('exit'), pos(516, 516), area(), 'exit'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const level = 7
export const title = 'Functions'

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
add([sprite('player'), pos(0, 36), area(), 'player'])
add([sprite('exit'), pos(center().x, 500), area(), 'exit'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const title = 'Variables'
const password = (new Date().getFullYear() + level) * 31337

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
loadSprite('key', 'sprites/key.png')
const player = add([sprite('player'), pos(100, 100), area(), 'player'])
Expand Down
4 changes: 2 additions & 2 deletions src/levels/9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const password = Array.from(Array(42).keys())
.join('')

export const prescript = `
${loadPlayer}
${loadExit}
${loadPlayer()}
${loadExit()}
loadSprite('key', 'sprites/key.png')
const player = add([sprite('player'), pos(100, 100), area(), 'player'])
Expand Down
4 changes: 1 addition & 3 deletions src/templates/layouts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export function wrapGame(code: string) {
return `
export const wrapGame = (code: string) => `
<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -37,4 +36,3 @@ ${code}
</body>
</html>
`
}
4 changes: 2 additions & 2 deletions src/templates/sprites.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const loadExit = `loadSprite('exit', 'sprites/door.png')`
export const loadExit = () => `loadSprite('exit', 'sprites/door.png')`

export const loadPlayer = `loadSprite('player', 'sprites/bean.png')`
export const loadPlayer = () => `loadSprite('player', 'sprites/bean.png')`

0 comments on commit 7daf5fc

Please sign in to comment.