RYECATCHER.CA


© opyright ryecatcher Intellectual Property 2021

javascript source code for Burby Score Keeping Program Pitching Functions




            



                // PIT HIT FUNC ====================================================================================================
                function pit_hit_func() {
                console.log("test hit");

                if ((pitchers_inning.get(current_pitcher[0])[HIT] <= 0) && (document.getElementById("pit_subtract").textContent === "+ mode")) {
                return
                };

                undo_pit_inning_events_func();

                pitchers_inning.get(current_pitcher[0])[HIT] = pitchers_inning.get(current_pitcher[0])[HIT] + pit_increment[0];
                pitchers_game.get(current_pitcher[0])[HIT] = pitchers_game.get(current_pitcher[0])[HIT] + pit_increment[0];
                // call display function
                console.log("HIT count: " + pitchers_inning.get(current_pitcher[0])[HIT]);
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));

                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                //undo_pit_events_func();
                undo_pit_game_events_func()


                return
                }

                // PIT BB FUNC =====================================================================================================
                function pit_bb_func() {
                console.log("test walk");

                if ((pitchers_inning.get(current_pitcher[0])[WALK] < 1) && (document.getElementById("pit_subtract").textContent === "+ mode")) {
                return
                };

                undo_pit_inning_events_func();

                pitchers_inning.get(current_pitcher[0])[WALK] = pitchers_inning.get(current_pitcher[0])[WALK] + pit_increment[0];
                pitchers_game.get(current_pitcher[0])[WALK] = pitchers_game.get(current_pitcher[0])[WALK] + pit_increment[0];
                // call display function
                console.log("WALK count: " + pitchers_inning.get(current_pitcher[0])[WALK]);
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));

                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                //undo_pit_events_func();
                undo_pit_game_events_func()

                return
                }

                // PIT K FUNC =====================================================================================================
                function pit_k_func() {
                console.log("test strike out");
                if ((pitchers_inning.get(current_pitcher[0])[K] < 1) && (document.getElementById("pit_subtract").textContent === "+ mode")) {
                return
                }

                undo_pit_inning_events_func();

                pit_out_type[0] = "strkout";

                pitchers_inning.get(current_pitcher[0])[K] = pitchers_inning.get(current_pitcher[0])[K] + pit_increment[0];
                //if (pitchers_inning.get(current_pitcher[0])[K] < 0) {
                //  pitchers_inning.get(current_pitcher[0])[K] = 0;
                //return
                //}
                pitchers_game.get(current_pitcher[0])[K] = pitchers_game.get(current_pitcher[0])[K] + pit_increment[0];
                // call display function
                console.log("K count: " + pitchers_inning.get(current_pitcher[0])[K]);
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));

                inning_out[0] = inning_out[0] + pit_increment[0];

                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                //undo_pit_events_func();
                undo_pit_game_events_func()

                if (inning_out[0] === 2) {
                document.getElementById("pitcher_btns_ctnr").style.display = "none";
                document.getElementById("two_outs_pitching_box").style.display = "block";
                }

                return
                }

                // PIT FGOUT FUNC =====================================================================================================
                function pit_fgout_func() {
                console.log("test fly grd out");

                if ((pitchers_inning.get(current_pitcher[0])[FG] < 1) && (document.getElementById("pit_subtract").textContent === "+ mode")) {
                return
                };

                undo_pit_inning_events_func();

                pit_out_type[0] = "fgout";

                pitchers_inning.get(current_pitcher[0])[FG] = pitchers_inning.get(current_pitcher[0])[FG] + pit_increment[0];
                pitchers_game.get(current_pitcher[0])[FG] = pitchers_game.get(current_pitcher[0])[FG] + pit_increment[0];
                // call display function
                console.log("FG count: " + pitchers_inning.get(current_pitcher[0])[FG]);
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));

                inning_out[0] = inning_out[0] + pit_increment[0];

                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                //undo_pit_events_func();
                undo_pit_game_events_func()

                if (inning_out[0] === 2) {
                document.getElementById("pitcher_btns_ctnr").style.display = "none";
                document.getElementById("two_outs_pitching_box").style.display = "block";
                }

                return
                }


                function pitch_go_back_func() {
                document.getElementById("pitcher_btns_ctnr").style.display = "grid";
                document.getElementById("two_outs_pitchinging_box").style.display = "none";
                //undo_func();
                //update_interface();
                //update_bat_stats();

                if (pit_out_type[0] === "fgout") {
                pitchers_inning.get(current_pitcher[0])[FG] = pitchers_inning.get(current_pitcher[0])[FG] - pit_increment[0];
                pitchers_game.get(current_pitcher[0])[FG] = pitchers_game.get(current_pitcher[0])[FG] - pit_increment[0];
                }
                if (pit_out_type[0] === "strkout") {
                pitchers_inning.get(current_pitcher[0])[K] = pitchers_inning.get(current_pitcher[0])[K] - pit_increment[0];
                pitchers_game.get(current_pitcher[0])[K] = pitchers_game.get(current_pitcher[0])[K] - pit_increment[0];
                }

                inning_out[0] = inning_out[0] - pit_increment[0];

                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                }



                //PITCH PRECEED FUNCTION  ==================================================================================================================
                function pitch_proceed_func() {
                //return

                document.getElementById("pitcher_btns_ctnr").style.display = "grid";
                document.getElementById("two_outs_pitching_box").style.display = "none";

                document.getElementById("bat_main_ctnr").style.display = "grid";           // display batting interface window
                document.getElementById("pitcher_main_ctnr").style.display = "none";       // hide pitching interface window

                document.getElementById("div_ref666").style.display = "none";          // hide pitching activity table

                document.getElementById("div_ref").style.display = "block";             // display batting activity table

                inning_out[0] = 0;
                //base = ["0", "0", "0"];
                //sit_base[0] = "empty";



                for (let [kkey, vvalue] of pitchers_inning.entries()) {
                let kaat = [...vvalue];
                console.log("kaat: " + kaat);
                kaat.unshift(kkey);
                console.log("kaat: " + kaat);
                pic.push(kaat);
                console.log("pic: " + pic);
                }



                if (LOC[0] === " at ") {

                chronological_events_pitching_func();

                inning_half[0] = "top";
                inning[0] = inning[0] + 1;
                let temp_header = "INNING " + inning[0] + " (" + inning_half[0] + ")  HITTING ACTIVITY:";
                document.getElementById("inning_hitting_activity_header").textContent = temp_header;
                };
                if (LOC[0] === " vs ") {

                chronological_events_pitching_func();

                inning_half[0] = "bot";
                //inning[0] = inning[0] + 1;
                let temp_header = "INNING " + inning[0] + " (" + inning_half[0] + ")  HITTING ACTIVITY:";
                document.getElementById("inning_hitting_activity_header").textContent = temp_header;
                };

                /*
                for (let [kkey, vvalue] of pitchers_inning.entries()) {
                let kaat = [...vvalue];
                console.log("kaat: " + kaat);
                kaat.unshift(kkey);
                console.log("kaat: " + kaat);
                pic.push(kaat);
                console.log("pic: " + pic);
                }     */

                //chronological_events_pitching_func();
                pgc.push(pic);
                console.log("pgc: " + pgc);
                console.log("pgc length: " + pgc.length);
                pic = [["PITCHER", "H", "BB", "K", "F/G", "R", "ER"]];


                create_rows("BATTER", "RESULT", "IMPACT 1", "IMPACT 2", "IMPACT 3", "IMPACT 4");
                playmode[0] = "batting";

                pit_increment[0] = 1;
                pitching_remove_rows();
                pitchers_inning.clear();
                pitchers_inning.set(current_pitcher[0], [0, 0, 0, 0, 0, 0,]);
                pitching_create_rows();

                undo_pitchers_game = [];

                let temp_pitttt_game = pitchers_game.get(current_pitcher[0]);
                temp_pitttt_game = [...temp_pitttt_game];
                undo_pitchers_game.push([String(current_pitcher[0]), temp_pitttt_game]);

                undo_pitchers_inning = [];

                update_interface()

                return
                }


                // PIT RUN FUNC =====================================================================================================
                function pit_run_func() {
                console.log("test run");

                if ((pitchers_inning.get(current_pitcher[0])[R] < 1) && (document.getElementById("pit_subtract").textContent === "+ mode")) {
                return
                };

                undo_pit_inning_events_func();

                pitchers_inning.get(current_pitcher[0])[R] = pitchers_inning.get(current_pitcher[0])[R] + pit_increment[0];
                pitchers_game.get(current_pitcher[0])[R] = pitchers_game.get(current_pitcher[0])[R] + pit_increment[0];
                OPP_SCORE[0] = OPP_SCORE[0] + pit_increment[0];
                // call display function
                console.log("R count: " + pitchers_inning.get(current_pitcher[0])[R]);
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));

                let inning_pitchers_list = pitchers_inning.keys();
                console.log("pitchers inning keys" + inning_pitchers_list);

                // for (inning_pitchers of inning_pitchers_list) {
                //   console.log("inning pitchers: " + inning_pitchers);
                //}

                document.getElementById("pitcher_btns_ctnr").style.display = "none";
                document.getElementById("bullpen_main_ctnr").style.display = "grid";
                document.getElementById("change_text").textContent = "EARNED RUN: click applicable name to charge";

                //for (let i = 0; i < bat_order.length; i++) {
                //  id_name = "bullpen" + String(i);
                let id_name = "";
                let i = 0;
                for (inning_pitchers of inning_pitchers_list) {
                id_name = "bullpen" + String(i);
                document.getElementById(id_name).textContent = inning_pitchers;
                document.getElementById(id_name).addEventListener("click", pit_er_func);
                i = i + 1;
                }

                id_name = "bullpen" + String(i);
                document.getElementById(id_name).textContent = "not applicable";
                document.getElementById(id_name).addEventListener("click", pit_er_func);

                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                //undo_pit_events_func();
                undo_pit_game_events_func()

                return
                }

                // PIT ER FUNC =====================================================================================================
                function pit_er_func(e) {
                console.log("test earned run");

                let earned = e.target.textContent;

                if (earned === "not applicable") {
                document.getElementById("pitcher_btns_ctnr").style.display = "grid";
                document.getElementById("bullpen_main_ctnr").style.display = "none";
                }

                else {
                pitchers_inning.get(earned)[ER] = pitchers_inning.get(earned)[ER] + pit_increment[0];
                pitchers_game.get(earned)[ER] = pitchers_game.get(earned)[ER] + pit_increment[0];
                // call display function
                console.log("ER count: " + pitchers_inning.get(earned)[ER]);
                console.log("pitchers inning: " + pitchers_inning.get(earned[0]));

                undo_pit_inning_events_func();

                document.getElementById("pitcher_btns_ctnr").style.display = "grid";
                document.getElementById("bullpen_main_ctnr").style.display = "none";
                }


                /*
                if ((pitchers_inning.get(current_pitcher[0])[ER] < 1) && (document.getElementById("pit_subtract").textContent === "+ mode")) {
                return
                };

                pitchers_inning.get(current_pitcher[0])[ER] = pitchers_inning.get(current_pitcher[0])[ER] + pit_increment[0];
                pitchers_game.get(current_pitcher[0])[ER] = pitchers_game.get(current_pitcher[0])[ER] + pit_increment[0];
                // call display function
                console.log("ER count: " + pitchers_inning.get(current_pitcher[0])[ER]);
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));
                */

                let inning_pitchers_list = pitchers_inning.keys();
                console.log("pitchers inning keys" + inning_pitchers_list);
                let id_name = "";
                let i = 0;
                for (inning_pitchers of inning_pitchers_list) {
                id_name = "bullpen" + String(i);
                document.getElementById(id_name).textContent = "";
                document.getElementById(id_name).removeEventListener("click", pit_er_func);
                i = i + 1;
                }

                id_name = "bullpen" + String(i);
                document.getElementById(id_name).textContent = "";
                document.getElementById(id_name).removeEventListener("click", pit_er_func);


                temp_stats_display();
                update_pitcher_stats();
                pitching_remove_rows();
                pitching_create_rows();

                //undo_pit_events_func();
                undo_pit_game_events_func()

                return
                }

                // PIT SUBTRACT FUNC =====================================================================================================
                function pit_subtract_func() {
                if (document.getElementById("pit_subtract").textContent === "- mode") {
                document.getElementById("pit_hit").textContent = "- hit";
                document.getElementById("pit_bb").textContent = "- walk";
                document.getElementById("pit_k").textContent = "- strike out";
                document.getElementById("pit_fgout").textContent = "- fly/grd out";
                document.getElementById("pit_run").textContent = "- run";
                document.getElementById("pit_er").textContent = "- earned run";
                document.getElementById("pit_subtract").textContent = "+ mode";
                document.getElementById("pit_subtract").title = "click to switch to increment/add mode";
                pit_increment[0] = -1;
                }
                else {
                document.getElementById("pit_hit").textContent = "+ hit";
                document.getElementById("pit_bb").textContent = "+ walk";
                document.getElementById("pit_k").textContent = "+ strike out";
                document.getElementById("pit_fgout").textContent = "+ fly/grd out";
                document.getElementById("pit_run").textContent = "+ run";
                document.getElementById("pit_er").textContent = "+ earned run";
                document.getElementById("pit_subtract").textContent = "- mode";
                document.getElementById("pit_subtract").title = "click to switch to decrement/subtract mode";
                pit_increment[0] = 1;
                }



                console.log("test");
                return
                }


                function pit_bullpen_func() {
                //return
                let id_name = "";
                document.getElementById("pitcher_btns_ctnr").style.display = "none";
                document.getElementById("bullpen_main_ctnr").style.display = "grid";
                document.getElementById("change_text").textContent = "BULLPEN: click name to select reliever";

                for (let i = 0; i < bat_order.length; i++) {
                id_name = "bullpen" + String(i);
                document.getElementById(id_name).textContent = bat_order[i];
                document.getElementById(id_name).addEventListener("click", bullpen_submit_func);
                }

                id_name = "bullpen" + String(bat_order.length);
                document.getElementById(id_name).textContent = "cancel";
                document.getElementById(id_name).addEventListener("click", bullpen_submit_func);

                }


                function bullpen_submit_func(e) {
                let reliever = e.target.textContent;

                if (reliever === "cancel") {
                document.getElementById("pitcher_btns_ctnr").style.display = "grid";
                document.getElementById("bullpen_main_ctnr").style.display = "none";
                }

                console.log("bullpen submit func: " + reliever);
                if (reliever !== "cancel") {
                current_pitcher[0] = reliever;
                }

                if (!pitchers_inning.has(reliever) && reliever !== "cancel") {
                //console.log("advanced");
                pitchers_inning.set(reliever, [0, 0, 0, 0, 0, 0]);
                }
                console.log("pitchers inning: " + pitchers_inning.get(current_pitcher[0]));

                if (!pitchers_game.has(reliever) && reliever !== "cancel") {
                //console.log("advanced");
                pitchers_game.set(reliever, [0, 0, 0, 0, 0, 0]);
                create_pitcher_stats_grid();
                pitcher_game_list.push(reliever);       // used to access pitcher in pitcher manual override

                console.log("UNDO PITCHERS GAME LENGTH: " + undo_pitchers_game.length);
                console.log("undo pitchers game contents: " + undo_pitchers_game);

                //undo_pitchers_game.pop();
                let temp_pitttt_game = pitchers_game.get(current_pitcher[0]);
                temp_pitttt_game = [...temp_pitttt_game];
                undo_pitchers_game.push([String(current_pitcher[0]), temp_pitttt_game]);
                //undo_pitchers_game.push([String(current_pitcher[0]), [0, 0, 0, 0, 0, 0]]);

                console.log("UNDO PITCHERS GAME LENGTH: " + undo_pitchers_game.length);
                console.log("undo pitchers game contents: " + undo_pitchers_game);


                /*
                console.log("pitchers game size: " + pitchers_game.size);
                let xxxxx = pitchers_game.size;
                for (let pp = 0; pp < (xxxxx * 6); pp++) {
                console.log("pp increment: " + pp);
                let pit_man_over_btns = document.querySelectorAll("button.pitchermanual")[pp];      // get reference to every button with class name "manual"
                pit_man_over_btns.addEventListener("click", function () { pit_manual_func(pp, pit_man_over_btns); });    // add event listeners to all the isolated buttons
                //pit_man_over_btns.style.backgroundColor = "orange";
                }    */



                }

                pitching_remove_rows();
                pitching_create_rows();
                update_interface();

                document.getElementById("pitcher_btns_ctnr").style.display = "grid";
                document.getElementById("bullpen_main_ctnr").style.display = "none";

                // remove text and event listeners from bullpen buttons:
                let id_name = "";
                for (let i = 0; i < bat_order.length; i++) {
                id_name = "bullpen" + String(i);
                document.getElementById(id_name).textContent = "";
                document.getElementById(id_name).removeEventListener("click", bullpen_submit_func);
                }

                id_name = "bullpen" + String(bat_order.length);
                document.getElementById(id_name).textContent = "";
                document.getElementById(id_name).removeEventListener("click", bullpen_submit_func);

                return
                }






                // TEMP STATS DISPLAY FUNCTION ===========================================================================================
                function temp_stats_display() {
                let kkeys = pitchers_inning.keys();
                for (let hh of kkeys) {
                console.log("pitchers inning key: " + hh + "  value: " + pitchers_inning.get(hh));
                }

                let kkkeys = pitchers_game.keys();
                for (let hhh of kkkeys) {
                console.log("pitchers game key: " + hhh + "  value: " + pitchers_game.get(hhh));
                }
                }

            
Back To Top