MCPcopy Create free account
hub / github.com/codecombat/codecombat / codeToAction

Function codeToAction

app/lib/level-generation.js:995–1006  ·  view source on GitHub ↗
(line)

Source from the content-addressed store, hash-verified

993}
994
995function codeToAction (line) {
996 const type = line.trim().split('(')[0].trim()
997 const directionStr = line.match(/'(up|down|left|right)'/)?.[1]
998 const direction = directionStr ? new Direction(directionStr) : undefined
999 const distanceStr = line.match(/(\d+)/)?.[1]
1000 const distance = distanceStr ? parseInt(distanceStr, 10) : undefined
1001 const forLoop = line.match(/for \(let (.+?) = 0; .+? < (\d+); \+?\+?.+?\+?\+?\) {/)
1002 const loopVariable = forLoop?.[1]
1003 const loopCountStr = forLoop?.[2]
1004 const loopCount = loopCountStr ? parseInt(loopCountStr, 10) : undefined
1005 return new Action({ type, direction, distance, loopVariable, loopCount })
1006}
1007
1008function actionToCode (action) {
1009 // This could be a method of Action class

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected