Skip to content

Commit

Permalink
feat(scripting/ScriptSubroutine): add invokeType parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Sep 23, 2023
1 parent a2d825a commit 91a52c3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/scripting/ScriptSubroutine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Script, ScriptHandler } from '@src/Script.js'
export class ScriptSubroutine {
name: string
command: ScriptHandler
invokeType: 'goto' | 'gosub'

constructor(name: string, command: ScriptHandler) {
constructor(name: string, command: ScriptHandler, invokeType: 'goto' | 'gosub' = 'gosub') {
this.name = name
this.command = command
this.invokeType = invokeType
}

toString() {
Expand All @@ -15,10 +17,14 @@ export class ScriptSubroutine {
return ''
}

return [`>>${this.name} {`, renderedScript, ' return', '}'].join('\n')
return [`>>${this.name} {`, renderedScript, this.invokeType === 'gosub' ? ' return' : ' accept', '}'].join('\n')
}

invoke() {
return `gosub ${this.name}`
if (this.invokeType === 'gosub') {
return `gosub ${this.name}`
} else {
return `goto ${this.name}`
}
}
}

0 comments on commit 91a52c3

Please sign in to comment.