<commit_before>import Canvas from "./canvas"
import Game from "./game"

function start(id, x, y) {
    if (Game.top.contains(x, y)) {
        Game.top.controlWith(id)
    } else if (Game.bot.contains(x, y)) {
        Game.bot.controlWith(id)
    }
    maintain(id, x, y)
}

function maintain(id, x, y) {
    if (Game.top.isControlledBy(id)) {
        Game.top.moveTo(x, y)
    } else if (Game.bot.isControlledBy(id)) {
        Game.bot.moveTo(x, y)
    }
}

function stop(id) {
    if (Game.top.isControlledBy(id)) {
        Game.top.stop()
    } else if (Game.bot.isControlledBy(id)) {
        Game.bot.stop()
    }
}

function all(f) {
    return e => {
        e.preventDefault()
        for (const {identifier, pageX, pageY} of e.changedTouches) {
            f(identifier, pageX * Canvas.dim.scale, pageY * Canvas.dim.scale)
        }
    }
}

function setup() {
    ontouchstart = all(start)
    ontouchmove = all(maintain)
    ontouchend = ontouchcancel = all(stop)
}

export default {setup}<commit_msg>fix a loop<commit_after>import Canvas from "./canvas"
import Game from "./game"

function start(id, x, y) {
    if (Game.top.contains(x, y)) {
        Game.top.controlWith(id)
    } else if (Game.bot.contains(x, y)) {
        Game.bot.controlWith(id)
    }
    maintain(id, x, y)
}

function maintain(id, x, y) {
    if (Game.top.isControlledBy(id)) {
        Game.top.moveTo(x, y)
    } else if (Game.bot.isControlledBy(id)) {
        Game.bot.moveTo(x, y)
    }
}

function stop(id) {
    if (Game.top.isControlledBy(id)) {
        Game.top.stop()
    } else if (Game.bot.isControlledBy(id)) {
        Game.bot.stop()
    }
}

function all(f) {
    return e => {
        e.preventDefault()
        for (let i = 0; i < e.changedTouches.length; i++) {
            const {identifier, pageX, pageY} = e.changedTouches[i]
            f(identifier, pageX * Canvas.dim.scale, pageY * Canvas.dim.scale)
        }
    }
}

function setup() {
    ontouchstart = all(start)
    ontouchmove = all(maintain)
    ontouchend = ontouchcancel = all(stop)
}

export default {setup}
{'fraction_non_alphanumeric': 0.1527710843373494, 'fraction_numerical': 0.00048192771084337347, 'mean_word_length': 2.4200988467874796, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4010862', 'n_tokens_mistral': 770, 'n_tokens_neox': 769, 'n_words': 156}