<commit_before>// vim: ts=4 sw=4 et :
class Menu {
    constructor(choices) {
        this.choices = choices; // save menu options
        this.selected = 0;
        this.unselected_pics = this.choices.map(name => makeImage(`img/menu_${name}.png`))
        this.selected_pics = this.choices.map(name => makeImage(`img/menu_${name}_sel.png`))
        this.dudes_img = makeImage("img/p2.png")
        this.age = 0
    }
    update(dt, delta) {
        for (let sp_key of ['ENTER', 'LEFT', 'RIGHT']) {
            if (app.keys.is_new_press(sp_key)) {
                let ev_name = `${this.choices[this.selected]}_${sp_key}`
                if (this[ev_name])
                    this[ev_name]()
            }
            if (app.keys.is_new_press('DOWN')) {
                if (this.selected < this.choices.length - 1) {
                    this.selected = this.selected + 1;
                }
            } else if (app.keys.is_new_press("UP")) {
                if (this.selected > 0) {
                    this.selected = this.selected - 1;
                }
            }
        }
    }
    draw(dt, delta) {
        app.display.context.save()
        let fade_time = 3
        let globalAlpha = 1
        if (this.age < fade_time) {
            globalAlpha = this.age / fade_time
            this.age += delta
            if (this.age > fade_time) this.age = fade_time
        }
        app.display.context.globalAlpha = globalAlpha;
        let i = 0,
            x = 100,
            y = 100,
            factor = 0;
        app.display.context.translate(-100 * (fade_time - this.age), 0)
        for (i = 0; i < this.choices.length; i++) {
            if (this.selected == i) {
                factor = Math.max(0.15, Math.abs(Math.sin((dt / 725) % Math.PI)))
                app.display.context.globalAlpha = globalAlpha * (1 - factor);
                app.display.context.drawImage(this.unselected_pics[i], x, y);
                app.display.context.globalAlpha = globalAlpha * factor;
                app.display.context.drawImage(this.selected_pics[i], x, y);
                app.display.context.globalAlpha = globalAlpha;
            } else {
                app.display.context.drawImage(this.unselected_pics[i], x, y);
            }
            y += 125;
        }
        this.draw_extra()
        app.display.context.restore()
    }
}
class MainMenu extends Menu {
    constructor() {
        super(["NewGame", "Enemies", "Options"]);<commit_msg>nicer animation for Menu<commit_after>// vim: ts=4 sw=4 et :
class Menu {
    constructor(choices) {
        this.choices = choices; // save menu options
        this.selected = 0;
        this.unselected_pics = this.choices.map(name => makeImage(`img/menu_${name}.png`))
        this.selected_pics = this.choices.map(name => makeImage(`img/menu_${name}_sel.png`))
        this.dudes_img = makeImage("img/p2.png")
        this.age = 0
        this.pos = {x: -150, y: 0}
        this.requested_pos = {x: 0, y: 0}
    }
    update(dt, delta) {
        this.pos.x = ((ANIM_FRAMES-1)*this.pos.x + this.requested_pos.x)/ANIM_FRAMES
        this.pos.y = ((ANIM_FRAMES-1)*this.pos.y + this.requested_pos.y)/ANIM_FRAMES
        for (let sp_key of ['ENTER', 'LEFT', 'RIGHT']) {
            if (app.keys.is_new_press(sp_key)) {
                let ev_name = `${this.choices[this.selected]}_${sp_key}`
                if (this[ev_name])
                    this[ev_name]()
            }
            if (app.keys.is_new_press('DOWN')) {
                if (this.selected < this.choices.length - 1) {
                    this.selected = this.selected + 1;
                }
            } else if (app.keys.is_new_press("UP")) {
                if (this.selected > 0) {
                    this.selected = this.selected - 1;
                }
            }
        }
    }
    draw(dt, delta) {
        app.display.context.save()
        let fade_time = 3
        let globalAlpha = 1
        if (this.age < fade_time) {
            globalAlpha = this.age / fade_time
            this.age += delta
            if (this.age > fade_time) this.age = fade_time
        }
        app.display.context.globalAlpha = globalAlpha;
        app.display.context.translate(this.pos.x, this.pos.y)
        let i = 0,
            x = 100,
            y = 100,
            factor = 0;
        for (i = 0; i < this.choices.length; i++) {
            if (this.selected == i) {
                factor = Math.max(0.15, Math.abs(Math.sin((dt / 725) % Math.PI)))
                app.display.context.globalAlpha = globalAlpha * (1 - factor);
                app.display.context.drawImage(this.unselected_pics[i], x, y);
                app.display.context.globalAlpha = globalAlpha * factor;
                app.display.context.drawImage(this.selected_pics[i], x, y);
                app.display.context.globalAlpha = globalAlpha;
            } else {
                app.display.context.drawImage(this.unselected_pics[i], x, y);
            }
            y += 125;
        }
        this.draw_extra()
        app.display.context.restore()
    }
}
class MainMenu extends Menu {
    constructor() {
        super(["NewGame", "Enemies", "Options"]);
{'fraction_non_alphanumeric': 0.13752417794970986, 'fraction_numerical': 0.013926499032882012, 'mean_word_length': 1.6142568250758342, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '444793', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1607, 'n_words': 300}