From c446090f6db7907218b00d925285f9641a77feec Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 14:25:14 -0400 Subject: [PATCH 01/22] Basic Formatting --- scripts/main.js | 135 ++++++++++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 56 deletions(-) diff --git a/scripts/main.js b/scripts/main.js index a60f6a8..0bae6fa 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,14 +1,17 @@ -//by Deftry, ADI and TheEE +/* + * by Deftry, ADI and TheEE + */ -let indev = true; -let basebuttonw = 150 -let basebuttonh = basebuttonw / 2 +let + indev = true , + basebuttonw = 150 , + basebuttonh = basebuttonw / 2 ; -Log.info("Started loading of parkour mechanics"); -Log.info("Loading ui elements"); +Log.info('Started loading of parkour mechanics'); +Log.info('Loading ui elements'); -Events.on(ClientLoadEvent, () => { +Events.on(ClientLoadEvent,() => { // ebtn // cbtn jbtn hbtn @@ -19,61 +22,78 @@ Events.on(ClientLoadEvent, () => { tablem.y = basebuttonh let cbtn = TextButton("Change Mode"); - tablem.add(ebtn).size(basebuttonw, basebuttonh).padLeft(6); + tablem + .add(ebtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); + ebtn.clicked(() => { - lock = !lock; - ebtn.setText(!lock ? "Disable Parkour mod" : "Enable parkour mod"); + + lock = ! lock; + + ebtn.setText(lock + ? 'Enable Parkour Mod' + : 'Disable Parkour Mod'); }); - table.add(cbtn).size(basebuttonw, basebuttonh).padLeft(6); + + table + .add(cbtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); + cbtn.clicked(() => { - if(mode) { - mode=0; - Vars.ui.announce("Parkour mode") + if(mode){ + mode = 0; + Vars.ui.announce('Parkour Mode') } else { - Vars.ui.showCustomConfirm("IN DEVELOPMENT!", "You trying to select [accent]Planet[] mode, but it is still buggy and in very development.", "Turn this thing on!", "Back", () => { - mode=1; Vars.ui.announce("Planet mode"); - }, () => { - mode=0; Vars.ui.announce("Parkour mode"); - }); + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce("Planet mode"); + }, + () => { + mode = 0; + Vars.ui.announce("Parkour mode"); + }); }; }); - if (Vars.mobile || indev) { - let jbtn = TextButton("Jump"); - table.add(jbtn).size(basebuttonw, basebuttonh).padLeft(6); + if(Vars.mobile || indev){ + + let jbtn = TextButton('Jump'); + + table + .add(jbtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); jbtn.clicked(() => { - if((stamina > 99) && onfloor) { + if(stamina > 99 && onfloor){ jump(bjumpvel + ajumpvel); stamina -= 100; - }; + } }); }; - table.add(hbtn).size(basebuttonw, basebuttonh).padLeft(6); - hbtn.clicked(() => { - holding = !holding; - }); - + table + .add(hbtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); - table.visibility = () => { - return !lock; + hbtn.clicked(() => holding = ! holding); - /* - if (!lock) { - return true - }; - - return false; - */ - // то что в коменте выше кринж - }; + table.visibility = () => ! lock; Vars.ui.hudGroup.addChild(tablem); Vars.ui.hudGroup.addChild(table); }); -Log.info("Loading variables"); + +Log.info('Loading variables'); let gravity = .5; // скорость гравитации let bjumpvel = 15; // скорость прыжка @@ -92,7 +112,9 @@ let unit; let mode = 0; // 0 - обычный, 1 - центр тяжести let holding = false; -Log.info("Loading main content"); + +Log.info('Loading main content'); + let getBlock = (x, y) => { var block = Vars.world.tile(x, y); @@ -141,12 +163,6 @@ let getBlockBot = () => { return Vars.world.tile(lastx, lasty - 1).block(); }; }; - - //if(gravdirect==0){return Vars.world.tile(lastx+1, lasty).block()} - //if(gravdirect==1){return Vars.world.tile(lastx, lasty+1).block()} - //if(gravdirect==2){return Vars.world.tile(lastx-1, lasty).block()} - //if(gravdirect==3){return Vars.world.tile(lastx, lasty-1).block()} - //очень тупо и ненормально }; let updateFloor = () => { @@ -460,20 +476,27 @@ var update = () => { // главный цикл hold = false; }; -Log.info("Running update task"); + +Log.info('Running update task'); + + Timer.schedule(() => { - if (lock) { + + if(lock) return - }; update(); updateHud(); updateFloor(); - if(!hold && mode == 1) { - gravityCenter(unit); - }; -}, 0, .02); + if(hold) + return; + + if(mode != 1) + return; + + gravityCenter(unit); +},0,.02); -Log.info("Done initialisation of parkour-mod."); +Log.info('Done initialisation of parkour-mod.'); From 7c7549766542605ca5119eaccf6e6c5276764f8a Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 14:27:36 -0400 Subject: [PATCH 02/22] Added EditorConfig --- .editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9d6087a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ + +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{js,hjson}] +charset = utf-8 +indent_style = space +indent_size = 4 From 702dc92863792a79f8e82c63662b66282b17d0d8 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 14:27:42 -0400 Subject: [PATCH 03/22] Formatted Manifest --- mod.hjson | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/mod.hjson b/mod.hjson index ce468b5..03dd533 100644 --- a/mod.hjson +++ b/mod.hjson @@ -1,9 +1,21 @@ -name: "parkour-mod" -displayName: "[orange]Parkour[] mod" -author: "Benry/Deftry" -description: "This mod adds some new movement mechanics, gravity and jump to player. WIP, report all bugs to Benry#5935" -version: "2.5" -minGameVersion: "136" -dependencies: [] -repo: "Def-Try/parkour-mod" -hidden: true +{ + displayName : "[orange]Parkour[] mod" + author : Benry/Deftry + repo : Def-Try/parkour-mod + name : parkour-mod + + + description: + ''' + + This mod adds some new movement mechanics, gravity and jump to player. + + WIP, report all bugs to Benry#5935 + + ''' + + minGameVersion : 136 + version : 2.5 + + hidden : true +} From 9909739cb36fd496fc1aff50868013c89a1d529c Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 16:21:44 -0400 Subject: [PATCH 04/22] More Refactoring --- scripts/main.js | 1029 ++++++++++++++++++++++++----------------------- 1 file changed, 527 insertions(+), 502 deletions(-) diff --git a/scripts/main.js b/scripts/main.js index 0bae6fa..f08fec7 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,502 +1,527 @@ -/* - * by Deftry, ADI and TheEE - */ - -let - indev = true , - basebuttonw = 150 , - basebuttonh = basebuttonw / 2 ; - - -Log.info('Started loading of parkour mechanics'); -Log.info('Loading ui elements'); - -Events.on(ClientLoadEvent,() => { - - // ebtn - // cbtn jbtn hbtn - var table = new Table().bottom().left(); - var tablem = new Table().bottom().left(); - let hbtn = TextButton("Hold"); - let ebtn = TextButton("Enable Parkour Mode"); - tablem.y = basebuttonh - let cbtn = TextButton("Change Mode"); - - tablem - .add(ebtn) - .size(basebuttonw,basebuttonh) - .padLeft(6); - - ebtn.clicked(() => { - - lock = ! lock; - - ebtn.setText(lock - ? 'Enable Parkour Mod' - : 'Disable Parkour Mod'); - }); - - table - .add(cbtn) - .size(basebuttonw,basebuttonh) - .padLeft(6); - - cbtn.clicked(() => { - if(mode){ - mode = 0; - Vars.ui.announce('Parkour Mode') - } else { - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce("Planet mode"); - }, - () => { - mode = 0; - Vars.ui.announce("Parkour mode"); - }); - }; - }); - - if(Vars.mobile || indev){ - - let jbtn = TextButton('Jump'); - - table - .add(jbtn) - .size(basebuttonw,basebuttonh) - .padLeft(6); - - jbtn.clicked(() => { - if(stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - }); - }; - - table - .add(hbtn) - .size(basebuttonw,basebuttonh) - .padLeft(6); - - hbtn.clicked(() => holding = ! holding); - - table.visibility = () => ! lock; - - Vars.ui.hudGroup.addChild(tablem); - Vars.ui.hudGroup.addChild(table); -}); - - -Log.info('Loading variables'); - -let gravity = .5; // скорость гравитации -let bjumpvel = 15; // скорость прыжка -let ajumpvel = 0; // доп. скорость прыжка -let direction = 0; // 0 - Y, 1 - X -let lock = true; // системная блокировка -let stamina = 10000; // выносливость -let onfloor = false; -let gravdirect = 3; -let hold = false; -let lastx; -let lasty; -let ltilex; -let ltiley; -let unit; -let mode = 0; // 0 - обычный, 1 - центр тяжести -let holding = false; - - -Log.info('Loading main content'); - - -let getBlock = (x, y) => { - var block = Vars.world.tile(x, y); - if(block != null && block.block() != Blocks.air) { - return block.block(); - } else { - return false; - }; -}; - -let getTile = (x, y) => { - var block = Vars.world.tile(x, y); - if(block != null) { - return block; - } else { - return false; - }; -}; - -let setGravity = (grav) => { - gravity = grav; - jump = -grav * 10 -}; - -let updateHud = () => { - Vars.ui.showInfoToast("Stamina:" + stamina / 100 + "%", .04); -}; - -//region util functions - -let getBlockBot = () => { - switch(gravdirect) { - case 0: { - return Vars.world.tile(lastx + 1, lasty).block(); - }; - - case 1: { - return Vars.world.tile(lastx, lasty + 1).block(); - }; - - case 2: { - return Vars.world.tile(lastx - 1, lasty).block(); - }; - - case 3: { - return Vars.world.tile(lastx, lasty - 1).block(); - }; - }; -}; - -let updateFloor = () => { - if(gravdirect == 0) { - if(getBlock(lastx + 1, lasty).solid) { - if(stamina < 10000) { - stamina += 100 - } else { - stamina=10000 - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else{ - onfloor = false; - }; - } else { - if(gravdirect == 2) { - if(getBlock(lastx - 1, lasty).solid) { - if(stamina < 10000) { - stamina += 100; - } else { - stamina = 10000 - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else { - onfloor = false; - }; - } else { - if(gravdirect == 1) { - if(getBlock(lastx, lasty + 1).solid) { - if(stamina < 10000) { - stamina += 100 - } else { - stamina=10000 - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else{ - onfloor=false; - }; - } else { - if(getBlock(lastx, lasty - 1).solid) { - if(stamina < 10000) { - stamina += 100 - } else { - stamina = 10000; - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else{ - onfloor=false; - }; - }; - }; - }; -}; - -let updateGravity = () => { - if(gravdirect == 0) { - unit.vel.add(gravity, 0); - }; - - if(gravdirect == 1) { - unit.vel.add(0, gravity); - }; - - if(gravdirect == 2) { - unit.vel.add(-gravity, 0); - }; - - if(gravdirect == 3) { - unit.vel.add(0, -gravity); - }; -} - -let jump = (vel) => { - if(gravdirect == 0) { - unit.vel.add(-vel, 0); - }; - - if(gravdirect == 1) { - unit.vel.add(0, -vel); - }; - - if(gravdirect == 2) { - unit.vel.add(vel, 0); - }; - - if(gravdirect == 3) { - unit.vel.add(0, vel); - }; -}; - -//endregion -//region mechanics -let gravipad = (unit) => { - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(getBlock(lastx, lasty) == Blocks.conveyor) { // гравипад - //может gravdirect = getTile(lastx, lasty).build.rotation; - if(getTile(lastx, lasty).build.rotation == 0) { // гравитация вправо - gravdirect = 0; - } else { - if(getTile(lastx, lasty).build.rotation == 1) { // гравитация вверх - gravdirect = 1; - } else { - if(getTile(lastx, lasty).build.rotation == 2) { // гравитация влево - gravdirect = 2; - } else { - if(getTile(lastx, lasty).build.rotation == 3) { // гравитация вниз - gravdirect = 3; - }; - }; - }; - }; - }; -}; - -let gravityCenter = (unit) => { - let coordinates = []; - let distances = []; - let nolock = false; - - if(!onfloor && !hold){ - for(let y = -15; y < 16; y++) { - for(let i = -15; i < 16; i++) { - if(getBlock(lastx+i, lasty + y) == Blocks.thoriumWall) { - coordinates.push({ - x: i, - y: y - }); - - nolock = true; - }; - }; - }; - - if(nolock) { - for(let j = 0; j < coordinates.length; j++) { - var dist = Math.sqrt(((lastx + coordinates[j].x - lastx) ^ 2) + ((lasty + coordinates[j].y - lasty) ^ 2)); - distances.push( dist ); - }; - - let mini = 0; - for(let j = 0; j < distances.length; j++){ - if(distances[j] < distances[mini]) { - mini = j; - }; - }; - - if (coordinates[mini].x < 0 && gravdirect != 3 && gravdirect != 1) { - unit.vel.add(-gravity, 0); - gravdirect = 2; - }; - - if (coordinates[mini].x > 0 && gravdirect != 3 && gravdirect != 1) { - unit.vel.add(gravity, 0); - gravdirect = 0; - }; - - if (coordinates[mini].y < 0 && gravdirect != 2 && gravdirect != 0) { - unit.vel.add(0, -gravity); - gravdirect = 3; - }; - - if (coordinates[mini].y > 0 && gravdirect != 2 && gravdirect != 0) { - unit.vel.add(0, gravity); - gravdirect = 1; - }; - }; - }; -}; - -//Я ЭТО МЕНЯТЬ НЕ БУДУ, Я УВОЛЬНЯЮСЬ -var gelJump = (unit) => { - lastx = unit.tileX(); - lasty = unit.tileY(); - if(getBlockBot()==Blocks.titaniumWall){ - if(gravdirect == 0 || gravdirect == 2){ - if(ltilex == lastx){ - ajumpvel = 15; - }else{ - override = false; - ajumpvel = 0; - jump(bjumpvel+15); - } - }else{ - if(ltiley == lasty){ - ajumpvel = 15; - }else{ - ajumpvel = 0; - jump(bjumpvel+15); - } - } - }else{ajumpvel = 0;} -} -var gelStick = (unit) => { - lastx = unit.tileX(); - lasty = unit.tileY(); - if(getBlock(lastx+1, lasty)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(-15, 0);} - }else if(getBlock(lastx-1, lasty)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(15, 0);} - }else if(getBlock(lastx, lasty+1)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(0, -15);} - }else if(getBlock(lastx, lasty-1)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(0, 15);} - }else if(getBlock(lastx-1, lasty-1)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(15, 15);} - }else if(getBlock(lastx+1, lasty-1)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(-15, 15);} - }else if(getBlock(lastx+1, lasty+1)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(-15, -15);} - }else if(getBlock(lastx-1, lasty+1)==Blocks.plastaniumWall){ - hold = true; - if(Core.input.keyTap(Binding.pause) && stamina > 99){unit.vel.add(15, -15);} - } -} -var wallHolding = () => { - if (holding) { - if(stamina>99){ - if(getBlock(lastx+1, lasty)!=false){ - hold = true; - stamina -= 10; - }else if(getBlock(lastx-1, lasty)!=false){ - hold = true; - stamina -= 10; - }else if(getBlock(lastx, lasty+1)!=false){ - hold = true; - stamina -= 10; - }else if(getBlock(lastx, lasty-1)!=false){ - hold = true; - stamina -= 10; - } - }else{ - hold = false; - } - } -} -var graviFunnel = (unit) => { - lastx = unit.tileX(); - lasty = unit.tileY(); - if(getBlock(lastx, lasty)==Blocks.pulseConduit){ // грави воронка - hold = true; - if(getTile(lastx, lasty).build.rotation==0){ - unit.vel.add(.55, 0); - }else if(getTile(lastx, lasty).build.rotation==1){ - unit.vel.add(0, .55); - }else if(getTile(lastx, lasty).build.rotation==2){ - unit.vel.add(-.55, 0); - }else if(getTile(lastx, lasty).build.rotation==3){ - unit.vel.add(0, -.55); - }; - }; -}; - -//не мусор -var antiGravField = (unit) => { - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(getBlock(lastx, lasty) == Blocks.shockMine){ - hold = true; - }; -}; - -//endregion -var update = () => { // главный цикл - unit = Vars.player.unit(); - if (unit == null) return; - try { - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor) { - jump(bjumpvel + ajumpvel); - stamina -= 100; - }; // работа прыжка - - gravipad(unit); - gelJump(unit); - gelStick(unit); - wallHolding(); - graviFunnel(unit); - antiGravField(unit); - - if(!hold && mode==0) { - updateGravity(); - }; - } catch(e){ - Log.err("parkour-mod: " + e + ". Maybe you in the void?") - }; - - hold = false; -}; - - -Log.info('Running update task'); - - -Timer.schedule(() => { - - if(lock) - return - - update(); - updateHud(); - updateFloor(); - - if(hold) - return; - - if(mode != 1) - return; - - gravityCenter(unit); -},0,.02); - - -Log.info('Done initialisation of parkour-mod.'); + +/* + * by Deftry, ADI and TheEE + */ + +let + indev = true , + basebuttonw = 150 , + basebuttonh = basebuttonw / 2 ; + + +Log.info('Started loading of parkour mechanics'); +Log.info('Loading ui elements'); + +Events.on(ClientLoadEvent,() => { + + // ebtn + // cbtn jbtn hbtn + + const + tablem = new Table().bottom().left() , + table = new Table().bottom().left() ; + + let + ebtn = TextButton('Enable Parkour Mode') , + hbtn = TextButton('Hold') ; + + tablem.y = basebuttonh; + + let cbtn = TextButton('Change Mode'); + + tablem + .add(ebtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); + + ebtn.clicked(() => { + + lock = ! lock; + + ebtn.setText(lock + ? 'Enable Parkour Mod' + : 'Disable Parkour Mod'); + }); + + table + .add(cbtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); + + cbtn.clicked(() => { + if(mode){ + mode = 0; + Vars.ui.announce('Parkour Mode') + } else { + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce("Planet mode"); + }, + () => { + mode = 0; + Vars.ui.announce("Parkour mode"); + }); + }; + }); + + if(Vars.mobile || indev){ + + let jbtn = TextButton('Jump'); + + table + .add(jbtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); + + jbtn.clicked(() => { + if(stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } + }); + }; + + table + .add(hbtn) + .size(basebuttonw,basebuttonh) + .padLeft(6); + + hbtn.clicked(() => holding = ! holding); + + table.visibility = () => ! lock; + + Vars.ui.hudGroup.addChild(tablem); + Vars.ui.hudGroup.addChild(table); +}); + + +Log.info('Loading variables'); + +let gravity = .5; // скорость гравитации +let bjumpvel = 15; // скорость прыжка +let ajumpvel = 0; // доп. скорость прыжка +let direction = 0; // 0 - Y, 1 - X +let lock = true; // системная блокировка +let stamina = 10000; // выносливость +let onfloor = false; +let gravdirect = 3; +let hold = false; +let lastx; +let lasty; +let ltilex; +let ltiley; +let unit; +let mode = 0; // 0 - обычный, 1 - центр тяжести +let holding = false; + + +Log.info('Loading main content'); + + +const getBlock = (x, y) => { + var block = Vars.world.tile(x, y); + if(block != null && block.block() != Blocks.air) { + return block.block(); + } else { + return false; + }; +}; + +const getTile = (x, y) => { + var block = Vars.world.tile(x, y); + if(block != null) { + return block; + } else { + return false; + }; +}; + +const setGravity = (grav) => { + gravity = grav; + jump = -grav * 10 +}; + +const updateHud = () => { + Vars.ui.showInfoToast("Stamina:" + stamina / 100 + "%", .04); +}; + +//region util functions + +const getBlockBot = () => { + switch(gravdirect) { + case 0: { + return Vars.world.tile(lastx + 1, lasty).block(); + }; + + case 1: { + return Vars.world.tile(lastx, lasty + 1).block(); + }; + + case 2: { + return Vars.world.tile(lastx - 1, lasty).block(); + }; + + case 3: { + return Vars.world.tile(lastx, lasty - 1).block(); + }; + }; +}; + +const updateFloor = () => { + if(gravdirect == 0) { + if(getBlock(lastx + 1, lasty).solid) { + if(stamina < 10000) { + stamina += 100 + } else { + stamina=10000 + }; + + onfloor = true; + ltilex = lastx; + ltiley = lasty; + } else{ + onfloor = false; + }; + } else { + if(gravdirect == 2) { + if(getBlock(lastx - 1, lasty).solid) { + if(stamina < 10000) { + stamina += 100; + } else { + stamina = 10000 + }; + + onfloor = true; + ltilex = lastx; + ltiley = lasty; + } else { + onfloor = false; + }; + } else { + if(gravdirect == 1) { + if(getBlock(lastx, lasty + 1).solid) { + if(stamina < 10000) { + stamina += 100 + } else { + stamina=10000 + }; + + onfloor = true; + ltilex = lastx; + ltiley = lasty; + } else{ + onfloor=false; + }; + } else { + if(getBlock(lastx, lasty - 1).solid) { + if(stamina < 10000) { + stamina += 100 + } else { + stamina = 10000; + }; + + onfloor = true; + ltilex = lastx; + ltiley = lasty; + } else{ + onfloor=false; + }; + }; + }; + }; +}; + +const updateGravity = () => { + if(gravdirect == 0) { + unit.vel.add(gravity, 0); + }; + + if(gravdirect == 1) { + unit.vel.add(0, gravity); + }; + + if(gravdirect == 2) { + unit.vel.add(-gravity, 0); + }; + + if(gravdirect == 3) { + unit.vel.add(0, -gravity); + }; +} + +const jump = (vel) => { + if(gravdirect == 0) { + unit.vel.add(-vel, 0); + }; + + if(gravdirect == 1) { + unit.vel.add(0, -vel); + }; + + if(gravdirect == 2) { + unit.vel.add(vel, 0); + }; + + if(gravdirect == 3) { + unit.vel.add(0, vel); + }; +}; + +//endregion +//region mechanics +const gravipad = (unit) => { + lastx = unit.tileX(); + lasty = unit.tileY(); + + if(getBlock(lastx, lasty) == Blocks.conveyor) { // гравипад + //может gravdirect = getTile(lastx, lasty).build.rotation; + if(getTile(lastx, lasty).build.rotation == 0) { // гравитация вправо + gravdirect = 0; + } else { + if(getTile(lastx, lasty).build.rotation == 1) { // гравитация вверх + gravdirect = 1; + } else { + if(getTile(lastx, lasty).build.rotation == 2) { // гравитация влево + gravdirect = 2; + } else { + if(getTile(lastx, lasty).build.rotation == 3) { // гравитация вниз + gravdirect = 3; + }; + }; + }; + }; + }; +}; + +const gravityCenter = (unit) => { + let coordinates = []; + let distances = []; + let nolock = false; + + if(!onfloor && !hold){ + for(let y = -15; y < 16; y++) { + for(let i = -15; i < 16; i++) { + if(getBlock(lastx+i, lasty + y) == Blocks.thoriumWall) { + coordinates.push({ + x: i, + y: y + }); + + nolock = true; + }; + }; + }; + + if(nolock) { + for(let j = 0; j < coordinates.length; j++) { + var dist = Math.sqrt(((lastx + coordinates[j].x - lastx) ^ 2) + ((lasty + coordinates[j].y - lasty) ^ 2)); + distances.push( dist ); + }; + + let mini = 0; + for(let j = 0; j < distances.length; j++){ + if(distances[j] < distances[mini]) { + mini = j; + }; + }; + + if (coordinates[mini].x < 0 && gravdirect != 3 && gravdirect != 1) { + unit.vel.add(-gravity, 0); + gravdirect = 2; + }; + + if (coordinates[mini].x > 0 && gravdirect != 3 && gravdirect != 1) { + unit.vel.add(gravity, 0); + gravdirect = 0; + }; + + if (coordinates[mini].y < 0 && gravdirect != 2 && gravdirect != 0) { + unit.vel.add(0, -gravity); + gravdirect = 3; + }; + + if (coordinates[mini].y > 0 && gravdirect != 2 && gravdirect != 0) { + unit.vel.add(0, gravity); + gravdirect = 1; + }; + }; + }; +}; + +//Я ЭТО МЕНЯТЬ НЕ БУДУ, Я УВОЛЬНЯЮСЬ +const gelJump = (unit) => { + lastx = unit.tileX(); + lasty = unit.tileY(); + if(getBlockBot()==Blocks.titaniumWall){ + if(gravdirect == 0 || gravdirect == 2){ + if(ltilex == lastx){ + ajumpvel = 15; + }else{ + override = false; + ajumpvel = 0; + jump(bjumpvel+15); + } + }else{ + if(ltiley == lasty){ + ajumpvel = 15; + }else{ + ajumpvel = 0; + jump(bjumpvel+15); + } + } + }else{ajumpvel = 0;} +} + + +const gelStick = (unit) => { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + const positions = [ + [ +1 , 0 , -15 , 0 ], + [ -1 , 0 , +15 , 0 ], + [ 0 , +1 , 0 , -15 ], + [ 0 , -1 , 0 , +15 ], + [ -1 , -1 , +15 , +15 ], + [ +1 , -1 , -15 , +15 ], + [ +1 , +1 , -15 , -15 ], + [ -1 , +1 , +15 , -15 ] + ]; + + for(const [ offsetx , offsety , ...velocity ] of positions) + if(getBlock(lastx + offsetx,lasty + offsety) == Blocks.plastaniumWall){ + + hold = true; + + if(Core.input.keyTab(Binding.pause) && stamina > 99) + unit.vel.add(...velocity); + + return; + } +} + + +const wallHolding = () => { + + if(!holding) + return; + + if(stamina < 100){ + hold = false; + return; + } + + if( + getBlock(lastx + 1,lasty) || + getBlock(lastx - 1,lasty) || + getBlock(lastx,lasty + 1) || + getBlock(lastx,lasty - 1) + ){ + hold = true; + stamina -= 10; + } +} + + +const graviFunnel = (unit) => { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + const tile = getBlock(lastx,lasty); + + + // грави воронка + + if(tile == Blocks.pulseConduit){ + + hold = true; + + switch(tile.build.rotation){ + case 0 : unit.vel.add(+.55,0); return; + case 1 : unit.vel.add(0,+.55); return; + case 2 : unit.vel.add(-.55,0); return; + case 3 : unit.vel.add(0,-.55); return; + } + } +} + + +//не мусор + +const antiGravField = (unit) => { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + if(getBlock(lastx,lasty) == Blocks.shockMine) + hold = true; +}; + + +//endregion + +const update = () => { + + unit = Vars.player.unit(); + + if(unit == null) + return; + + try { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } + + gravipad(unit); + gelJump(unit); + gelStick(unit); + wallHolding(); + graviFunnel(unit); + antiGravField(unit); + + if(!hold && mode == 0) + updateGravity(); + + } catch(error){ + Log.err(`Parkour Mod: ${ error }. Maybe you are in the void?`) + } + + hold = false; +} + + +Log.info('Running update task'); + + +Timer.schedule(() => { + + if(lock) + return + + update(); + updateHud(); + updateFloor(); + + if(hold) + return; + + if(mode != 1) + return; + + gravityCenter(unit); +},0,.02); + + +Log.info('Done initialisation of parkour-mod.'); From f75d3dcf52f82ea03d85a07579d64f8d9a299e6e Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 17:20:31 -0400 Subject: [PATCH 05/22] More Refactoring I wish I could use modern JS --- scripts/main.js | 68 +++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/scripts/main.js b/scripts/main.js index f08fec7..f0fb5c6 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -353,28 +353,35 @@ const gravityCenter = (unit) => { }; }; + //Я ЭТО МЕНЯТЬ НЕ БУДУ, Я УВОЛЬНЯЮСЬ + const gelJump = (unit) => { + lastx = unit.tileX(); lasty = unit.tileY(); - if(getBlockBot()==Blocks.titaniumWall){ - if(gravdirect == 0 || gravdirect == 2){ - if(ltilex == lastx){ - ajumpvel = 15; - }else{ - override = false; - ajumpvel = 0; - jump(bjumpvel+15); - } - }else{ - if(ltiley == lasty){ - ajumpvel = 15; - }else{ - ajumpvel = 0; - jump(bjumpvel+15); - } - } - }else{ajumpvel = 0;} + + if(getBlockBot() != Blocks.titaniumWall){ + ajumpvel = 0; + return; + } + + const upwards = + gravdirect == 0 || + gravdirect == 2 ; + + + const isSame = (upwards) + ? ltilex == lastx + : ltiley == lasty + + if(isSame){ + ajumpvel = 15; + } else { + override = upwards; + ajumpvel = 0; + jump(bjumpvel + 15); + } } @@ -383,24 +390,23 @@ const gelStick = (unit) => { lastx = unit.tileX(); lasty = unit.tileY(); - const positions = [ - [ +1 , 0 , -15 , 0 ], - [ -1 , 0 , +15 , 0 ], - [ 0 , +1 , 0 , -15 ], - [ 0 , -1 , 0 , +15 ], - [ -1 , -1 , +15 , +15 ], - [ +1 , -1 , -15 , +15 ], - [ +1 , +1 , -15 , -15 ], - [ -1 , +1 , +15 , -15 ] - ]; + const offsets = [ -1 , 0 , +1 ]; - for(const [ offsetx , offsety , ...velocity ] of positions) - if(getBlock(lastx + offsetx,lasty + offsety) == Blocks.plastaniumWall){ + for(let x = 0;x < 2;x++) + for(let y = 0;y < 2;y++){ + + const + offsetX = offsets[x] , + offsetY = offsets[y] ; + + + if(getBlock(lastx + offsetX,lasty + offsetY) !== Block.plastaniumWall) + return; hold = true; if(Core.input.keyTab(Binding.pause) && stamina > 99) - unit.vel.add(...velocity); + unit.vel.add(-offsetX * 15,-velocity * 15); return; } From f80a9d1a77957f9255badfaac5bcfb13399fa81c Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 19:04:48 -0400 Subject: [PATCH 06/22] Fixed Crash For Non-Flying Units --- README.md | 2 - scripts/main.js | 526 ++++++++++++++++++++++++------------------------ 2 files changed, 263 insertions(+), 265 deletions(-) diff --git a/README.md b/README.md index fb54bec..1ca725a 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,6 @@ marked with a ⬆, that is used for jumping. *The following things can crash your game.* -- Toggling parkour mode in a flying unit - - Falling into the void / outside the map
diff --git a/scripts/main.js b/scripts/main.js index f0fb5c6..302a544 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -3,100 +3,116 @@ * by Deftry, ADI and TheEE */ -let - indev = true , - basebuttonw = 150 , - basebuttonh = basebuttonw / 2 ; +let indev = true ; +let isEnabled = false; + +const ButtonStyle = { + full : 150 , + half : 75 +} + Log.info('Started loading of parkour mechanics'); Log.info('Loading ui elements'); Events.on(ClientLoadEvent,() => { - - // ebtn - // cbtn jbtn hbtn const - tablem = new Table().bottom().left() , - table = new Table().bottom().left() ; + height = ButtonStyle.half , + width = ButtonStyle.full ; + + const + menu_a = new Table().bottom().left() , + menu_b = new Table().bottom().left() ; let - ebtn = TextButton('Enable Parkour Mode') , - hbtn = TextButton('Hold') ; + button_enable = TextButton('Enable Parkour Mode') , + button_hold = TextButton('Hold') ; - tablem.y = basebuttonh; + menu_a.y = height; - let cbtn = TextButton('Change Mode'); + let button_mode = TextButton('Change Mode'); - tablem - .add(ebtn) - .size(basebuttonw,basebuttonh) + menu_a + .add(button_enable) + .size(width,height) .padLeft(6); - ebtn.clicked(() => { + button_enable.clicked(() => { + + unit = Vars.player.unit(); - lock = ! lock; + if(!unit || !unit.type.flying){ + Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); + return; + } - ebtn.setText(lock - ? 'Enable Parkour Mod' - : 'Disable Parkour Mod'); + isEnabled = ! isEnabled; + + button_enable.setText(isEnabled + ? 'Disable Parkour Mod' + : 'Enable Parkour Mod' ); }); - table - .add(cbtn) - .size(basebuttonw,basebuttonh) + menu_b + .add(button_mode) + .size(width,height) .padLeft(6); - cbtn.clicked(() => { + button_mode.clicked(() => { + if(mode){ mode = 0; - Vars.ui.announce('Parkour Mode') - } else { - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce("Planet mode"); - }, - () => { - mode = 0; - Vars.ui.announce("Parkour mode"); - }); - }; + Vars.ui.announce('Parkour Mode'); + return; + } + + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce('Planet mode'); + }, + () => { + mode = 0; + Vars.ui.announce('Parkour mode'); + }); }); if(Vars.mobile || indev){ - let jbtn = TextButton('Jump'); + let button_jump = TextButton('Jump'); - table - .add(jbtn) - .size(basebuttonw,basebuttonh) + menu_b + .add(button_jump) + .size(width,height) .padLeft(6); - jbtn.clicked(() => { + button_jump.clicked(() => { if(stamina > 99 && onfloor){ jump(bjumpvel + ajumpvel); stamina -= 100; } }); - }; + } - table - .add(hbtn) - .size(basebuttonw,basebuttonh) + menu_b + .add(button_hold) + .size(width,height) .padLeft(6); - hbtn.clicked(() => holding = ! holding); + button_hold.clicked(() => holding = ! holding); - table.visibility = () => ! lock; + menu_b.visibility = () => isEnabled; - Vars.ui.hudGroup.addChild(tablem); - Vars.ui.hudGroup.addChild(table); + const menus = Vars.ui.hudGroup; + + menus.addChild(menu_a); + menus.addChild(menu_b); }); @@ -106,7 +122,6 @@ let gravity = .5; // скорость гравитации let bjumpvel = 15; // скорость прыжка let ajumpvel = 0; // доп. скорость прыжка let direction = 0; // 0 - Y, 1 - X -let lock = true; // системная блокировка let stamina = 10000; // выносливость let onfloor = false; let gravdirect = 3; @@ -123,235 +138,208 @@ let holding = false; Log.info('Loading main content'); -const getBlock = (x, y) => { - var block = Vars.world.tile(x, y); - if(block != null && block.block() != Blocks.air) { - return block.block(); - } else { +const getBlock = (x,y) => { + + const block = Vars.world.tile(x,y); + + if(block == null) return false; - }; -}; + + const type = block.block(); + + return (type == Blocks.air) + ? block.block() + : false ; +} -const getTile = (x, y) => { - var block = Vars.world.tile(x, y); - if(block != null) { - return block; - } else { - return false; - }; -}; -const setGravity = (grav) => { - gravity = grav; - jump = -grav * 10 -}; +const getTile = (x,y) => { + + const tile = Vars.world.tile(x, y); + + return block || false; +} + + +const setGravity = (value) => { + gravity = value; + jump = -value * 10 +} + const updateHud = () => { - Vars.ui.showInfoToast("Stamina:" + stamina / 100 + "%", .04); -}; + const percent = stamina / 100; + Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); +} -//region util functions const getBlockBot = () => { - switch(gravdirect) { - case 0: { - return Vars.world.tile(lastx + 1, lasty).block(); - }; - - case 1: { - return Vars.world.tile(lastx, lasty + 1).block(); - }; - - case 2: { - return Vars.world.tile(lastx - 1, lasty).block(); - }; - - case 3: { - return Vars.world.tile(lastx, lasty - 1).block(); - }; - }; -}; + switch(gravdirect){ + case 0 : return Vars.world.tile(lastx + 1, lasty).block(); + case 1 : return Vars.world.tile(lastx, lasty + 1).block(); + case 2 : return Vars.world.tile(lastx - 1, lasty).block(); + case 3 : return Vars.world.tile(lastx, lasty - 1).block(); + } +} -const updateFloor = () => { - if(gravdirect == 0) { - if(getBlock(lastx + 1, lasty).solid) { - if(stamina < 10000) { - stamina += 100 - } else { - stamina=10000 - }; +const updateFloor = () => { + switch(gravdirect){ + case 0 : + + if(getBlock(lastx + 1,lasty).solid) + break; - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else{ - onfloor = false; - }; - } else { - if(gravdirect == 2) { - if(getBlock(lastx - 1, lasty).solid) { - if(stamina < 10000) { - stamina += 100; - } else { - stamina = 10000 - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else { - onfloor = false; - }; - } else { - if(gravdirect == 1) { - if(getBlock(lastx, lasty + 1).solid) { - if(stamina < 10000) { - stamina += 100 - } else { - stamina=10000 - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else{ - onfloor=false; - }; - } else { - if(getBlock(lastx, lasty - 1).solid) { - if(stamina < 10000) { - stamina += 100 - } else { - stamina = 10000; - }; - - onfloor = true; - ltilex = lastx; - ltiley = lasty; - } else{ - onfloor=false; - }; - }; - }; - }; -}; - -const updateGravity = () => { - if(gravdirect == 0) { - unit.vel.add(gravity, 0); - }; - - if(gravdirect == 1) { - unit.vel.add(0, gravity); - }; + onfloor = false; + return; + case 1 : + + if(getBlock(lastx - 1,lasty).solid) + break; + + onfloor = false; + return; + case 2 : + + if(getBlock(lastx,lasty + 1).solid) + break; + + onfloor = false; + return; + case 3 : + + if(getBlock(lastx,lasty - 1).solid) + break; + + onfloor = false; + return; + } + + stamina += 100; + + if(stamina > 10000) + stamina = 10000 + + onfloor = true; + ltilex = lastx; + ltiley = lasty; +} - if(gravdirect == 2) { - unit.vel.add(-gravity, 0); - }; - if(gravdirect == 3) { - unit.vel.add(0, -gravity); - }; +const updateGravity = () => { + switch(gravdirect){ + case 0 : unit.vel.add(+gravity,0); return; + case 1 : unit.vel.add(0,+gravity); return; + case 2 : unit.vel.add(-gravity,0); return; + case 3 : unit.vel.add(0,-gravity); return; + } } -const jump = (vel) => { - if(gravdirect == 0) { - unit.vel.add(-vel, 0); - }; - - if(gravdirect == 1) { - unit.vel.add(0, -vel); - }; - if(gravdirect == 2) { - unit.vel.add(vel, 0); - }; +const jump = (velocity) => { + switch(gravdirect){ + case 0 : unit.vel.add(-velocity,0); return; + case 1 : unit.vel.add(0,-velocity); return; + case 2 : unit.vel.add(+velocity,0); return; + case 3 : unit.vel.add(0,+velocity); return; + } +} - if(gravdirect == 3) { - unit.vel.add(0, vel); - }; -}; //endregion //region mechanics + const gravipad = (unit) => { + lastx = unit.tileX(); lasty = unit.tileY(); - if(getBlock(lastx, lasty) == Blocks.conveyor) { // гравипад - //может gravdirect = getTile(lastx, lasty).build.rotation; - if(getTile(lastx, lasty).build.rotation == 0) { // гравитация вправо - gravdirect = 0; - } else { - if(getTile(lastx, lasty).build.rotation == 1) { // гравитация вверх - gravdirect = 1; - } else { - if(getTile(lastx, lasty).build.rotation == 2) { // гравитация влево - gravdirect = 2; - } else { - if(getTile(lastx, lasty).build.rotation == 3) { // гравитация вниз - gravdirect = 3; - }; - }; - }; - }; - }; -}; + if(getBlock(lastx,lasty) == Blocks.conveyor) + gravdirect = getTile(lastx,lasty).build.rotation; +} + const gravityCenter = (unit) => { - let coordinates = []; - let distances = []; - let nolock = false; - - if(!onfloor && !hold){ - for(let y = -15; y < 16; y++) { - for(let i = -15; i < 16; i++) { - if(getBlock(lastx+i, lasty + y) == Blocks.thoriumWall) { - coordinates.push({ - x: i, - y: y - }); - - nolock = true; - }; - }; - }; - - if(nolock) { - for(let j = 0; j < coordinates.length; j++) { - var dist = Math.sqrt(((lastx + coordinates[j].x - lastx) ^ 2) + ((lasty + coordinates[j].y - lasty) ^ 2)); - distances.push( dist ); - }; - - let mini = 0; - for(let j = 0; j < distances.length; j++){ - if(distances[j] < distances[mini]) { - mini = j; - }; - }; - - if (coordinates[mini].x < 0 && gravdirect != 3 && gravdirect != 1) { - unit.vel.add(-gravity, 0); - gravdirect = 2; - }; - - if (coordinates[mini].x > 0 && gravdirect != 3 && gravdirect != 1) { - unit.vel.add(gravity, 0); - gravdirect = 0; - }; - - if (coordinates[mini].y < 0 && gravdirect != 2 && gravdirect != 0) { - unit.vel.add(0, -gravity); - gravdirect = 3; - }; - - if (coordinates[mini].y > 0 && gravdirect != 2 && gravdirect != 0) { - unit.vel.add(0, gravity); - gravdirect = 1; - }; - }; - }; -}; + + let + coordinates = [] ; + distances = [] , + nolock = false ; + + if(onfloor) + return; + + if(hold) + return + + for(let y = -15;y < 16;y++) + for(let x = -15;x < 16;x++) + if(getBlock(lastx + x,lasty + y) == Blocks.thoriumWall){ + coordinates.push({ x : x , y : y }); + nolock = true; + } + + if(!nolock) + return; + + for(let c = 0;c < coordinates.length;c++){ + + const distance = Math.sqrt( + ((lastx + coordinates[c].x - lastx) ^ 2) + + ((lasty + coordinates[c].y - lasty) ^ 2) ); + + distances.push(distance); + } + + let shortest = 0; + + for(let d = 0;d < distances.length;d++) + if(distances[d] < distances[shortest]) + shortest = d; + + const + x = coordinates[shortest].x , + y = coordinates[shortest].y ; + + const vertical = + gravdirect === 1 || + gravdirect === 3 ; + + + // if(x != 0 && !vertical){ + // + // if(x < 0){ + // unit.vel.add(-gravity,0); + // gravdirect = 2; + // } else { + // unit.vel.add(gravity,0); + // gravdirect = 0; + // } + // } + // + // if(y != 0 && vertical){ + // + // if(y < 0){ + // unit.vel.add(0,-gravity); + // gravdirect = 3; + // } else { + // unit.vel.add(0,+gravity); + // gravdirect = 1; + // } + // } + + const position = vertical + ? y : x ; + + if(position === 0) + return; + + unit.vel.add( + ! vertical * gravity , + vertical * gravity + ); + + gravdirect = vertical + (position < 0) * 2; +} //Я ЭТО МЕНЯТЬ НЕ БУДУ, Я УВОЛЬНЯЮСЬ @@ -400,7 +388,7 @@ const gelStick = (unit) => { offsetY = offsets[y] ; - if(getBlock(lastx + offsetX,lasty + offsetY) !== Block.plastaniumWall) + if(getBlock(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) return; hold = true; @@ -477,7 +465,10 @@ const update = () => { unit = Vars.player.unit(); - if(unit == null) + if(!unit) + return; + + if(!unit.type.flying) return; try { @@ -501,7 +492,7 @@ const update = () => { updateGravity(); } catch(error){ - Log.err(`Parkour Mod: ${ error }. Maybe you are in the void?`) + Log.err('Parkour Mod:' + error + 'Maybe you are in the void?') } hold = false; @@ -513,8 +504,16 @@ Log.info('Running update task'); Timer.schedule(() => { - if(lock) + if(!isEnabled) return + + unit = Vars.player.unit(); + + if(!unit) + return; + + if(!unit.type.flying) + return; update(); updateHud(); @@ -527,6 +526,7 @@ Timer.schedule(() => { return; gravityCenter(unit); + },0,.02); From d640a164f6be382042d9354abbe7d382e3c93b5b Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 21:00:27 -0400 Subject: [PATCH 07/22] Refactoring + Solid Ground --- scripts/main.js | 264 +++++++++++++++++++++++++----------------------- 1 file changed, 137 insertions(+), 127 deletions(-) diff --git a/scripts/main.js b/scripts/main.js index 302a544..49ef42b 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -12,6 +12,9 @@ const ButtonStyle = { } +Log.info(typeof Blocks.titaniumWall) + + Log.info('Started loading of parkour mechanics'); Log.info('Loading ui elements'); @@ -124,7 +127,6 @@ let ajumpvel = 0; // доп. скорость прыжка let direction = 0; // 0 - Y, 1 - X let stamina = 10000; // выносливость let onfloor = false; -let gravdirect = 3; let hold = false; let lastx; let lasty; @@ -135,29 +137,30 @@ let mode = 0; // 0 - обычный, 1 - центр тяжести let holding = false; +/* + * 0 : Right + * 1 : Up + * 2 : Left + * 3 : Down + */ + +let gravitation = 3; + + + Log.info('Loading main content'); -const getBlock = (x,y) => { - - const block = Vars.world.tile(x,y); - - if(block == null) - return false; - - const type = block.block(); - - return (type == Blocks.air) - ? block.block() - : false ; +function tileAt(x,y){ + return Vars.world.tile(x,y) || false; } - -const getTile = (x,y) => { - - const tile = Vars.world.tile(x, y); +function blockAt(x,y){ - return block || false; + const block = tileAt(x,y); + + return (block && block.type != Blocks.air) + ? block : false ; } @@ -173,88 +176,124 @@ const updateHud = () => { } -const getBlockBot = () => { - switch(gravdirect){ - case 0 : return Vars.world.tile(lastx + 1, lasty).block(); - case 1 : return Vars.world.tile(lastx, lasty + 1).block(); - case 2 : return Vars.world.tile(lastx - 1, lasty).block(); - case 3 : return Vars.world.tile(lastx, lasty - 1).block(); - } +const offsets = [ + [ +1 , 0 ] , + [ 0 , +1 ] , + [ -1 , 0 ] , + [ 0 , -1 ] +] + +const directToOffset = (direction) => + offsets[direction]; + + +const blockAtBot = () => { + + const offset = directToOffset(gravitation); + + return Vars.world + .tile(lastx + offset[0],lasty + offset[1]) + .block(); } -const updateFloor = () => { - switch(gravdirect){ - case 0 : - - if(getBlock(lastx + 1,lasty).solid) - break; - - onfloor = false; - return; - case 1 : + +const relativeTile = () => { - if(getBlock(lastx - 1,lasty).solid) - break; - - onfloor = false; - return; - case 2 : + const offset = directToOffset(gravitation); - if(getBlock(lastx,lasty + 1).solid) - break; - - onfloor = false; - return; - case 3 : + return tileAt( + lastx + offset[0] , + lasty + offset[1] + ); +} + +const relativeBlock = () => { - if(getBlock(lastx,lasty - 1).solid) - break; - - onfloor = false; - return; - } + const tile = relativeTile(); - stamina += 100; + return (tile) + ? tile.block() + : false ; +} - if(stamina > 10000) - stamina = 10000 + +const isFloorSolid = () => { + + const block = relativeBlock(); - onfloor = true; - ltilex = lastx; - ltiley = lasty; + return (block) + ? block.solid + : false ; +} + +const updateFloor = () => { + + onfloor = isFloorSolid(); + + if(onfloor){ + + stamina += 100; + + if(stamina > 10000) + stamina = 10000; + + ltilex = lastx; + ltiley = lasty; + + const vertical = gravitation % 2; + + let + x = unit.vel.x , + y = unit.vel.y ; + + if(vertical && (gravitation === 1 ? y > 0 : y < 0)) + y = 0; + + if(!vertical && (gravitation === 0 ? x > 0 : x < 0)) + y = 0; + + + unit.vel.set(x,y); + } } const updateGravity = () => { - switch(gravdirect){ - case 0 : unit.vel.add(+gravity,0); return; - case 1 : unit.vel.add(0,+gravity); return; - case 2 : unit.vel.add(-gravity,0); return; - case 3 : unit.vel.add(0,-gravity); return; - } + + const offset = directToOffset(gravitation); + + unit.vel.add( + gravity * offset[0] , + gravity * offset[1] + ); } +const jumpOffset = [ + [ -1 , 0 ] , + [ 0 , -1 ] , + [ +1 , 0 ] , + [ 0 , +1 ] +] + const jump = (velocity) => { - switch(gravdirect){ - case 0 : unit.vel.add(-velocity,0); return; - case 1 : unit.vel.add(0,-velocity); return; - case 2 : unit.vel.add(+velocity,0); return; - case 3 : unit.vel.add(0,+velocity); return; - } + + const offset = jumpOffset[gravitation]; + + unit.vel.add( + velocity * offset[0] , + velocity * offset[1] + ); } -//endregion -//region mechanics - const gravipad = (unit) => { lastx = unit.tileX(); lasty = unit.tileY(); - if(getBlock(lastx,lasty) == Blocks.conveyor) - gravdirect = getTile(lastx,lasty).build.rotation; + if(blockAt(lastx,lasty) == Blocks.conveyor) + gravitation = tileAt(lastx,lasty).build.rotation; } @@ -273,7 +312,7 @@ const gravityCenter = (unit) => { for(let y = -15;y < 16;y++) for(let x = -15;x < 16;x++) - if(getBlock(lastx + x,lasty + y) == Blocks.thoriumWall){ + if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ coordinates.push({ x : x , y : y }); nolock = true; } @@ -300,32 +339,7 @@ const gravityCenter = (unit) => { x = coordinates[shortest].x , y = coordinates[shortest].y ; - const vertical = - gravdirect === 1 || - gravdirect === 3 ; - - - // if(x != 0 && !vertical){ - // - // if(x < 0){ - // unit.vel.add(-gravity,0); - // gravdirect = 2; - // } else { - // unit.vel.add(gravity,0); - // gravdirect = 0; - // } - // } - // - // if(y != 0 && vertical){ - // - // if(y < 0){ - // unit.vel.add(0,-gravity); - // gravdirect = 3; - // } else { - // unit.vel.add(0,+gravity); - // gravdirect = 1; - // } - // } + const vertical = gravitation % 2; const position = vertical ? y : x ; @@ -338,38 +352,34 @@ const gravityCenter = (unit) => { vertical * gravity ); - gravdirect = vertical + (position < 0) * 2; + gravitation = vertical + (position < 0) * 2; } -//Я ЭТО МЕНЯТЬ НЕ БУДУ, Я УВОЛЬНЯЮСЬ - const gelJump = (unit) => { lastx = unit.tileX(); lasty = unit.tileY(); - if(getBlockBot() != Blocks.titaniumWall){ + if(blockAtBot() != Blocks.titaniumWall){ ajumpvel = 0; return; } - const upwards = - gravdirect == 0 || - gravdirect == 2 ; + const vertical = gravitation % 2; - const isSame = (upwards) - ? ltilex == lastx - : ltiley == lasty + const isSame = (vertical) + ? ltiley == lasty + : ltilex == lastx ; - if(isSame){ - ajumpvel = 15; - } else { - override = upwards; - ajumpvel = 0; - jump(bjumpvel + 15); - } + ajumpvel = (isSame) + ? 15 : 0 ; + + if(isSame) + return; + + jump(bjumpvel + 15); } @@ -388,7 +398,7 @@ const gelStick = (unit) => { offsetY = offsets[y] ; - if(getBlock(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) + if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) return; hold = true; @@ -412,10 +422,10 @@ const wallHolding = () => { } if( - getBlock(lastx + 1,lasty) || - getBlock(lastx - 1,lasty) || - getBlock(lastx,lasty + 1) || - getBlock(lastx,lasty - 1) + blockAt(lastx + 1,lasty) || + blockAt(lastx - 1,lasty) || + blockAt(lastx,lasty + 1) || + blockAt(lastx,lasty - 1) ){ hold = true; stamina -= 10; @@ -428,7 +438,7 @@ const graviFunnel = (unit) => { lastx = unit.tileX(); lasty = unit.tileY(); - const tile = getBlock(lastx,lasty); + const tile = blockAt(lastx,lasty); // грави воронка @@ -454,7 +464,7 @@ const antiGravField = (unit) => { lastx = unit.tileX(); lasty = unit.tileY(); - if(getBlock(lastx,lasty) == Blocks.shockMine) + if(blockAt(lastx,lasty) == Blocks.shockMine) hold = true; }; From 25a84c4d6b04ea8083074319b88a3e2d269f9e73 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 21:59:38 -0400 Subject: [PATCH 08/22] Prettified Hud Percentage --- scripts/main.js | 162 ++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/scripts/main.js b/scripts/main.js index 49ef42b..c28c9af 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -46,7 +46,7 @@ Events.on(ClientLoadEvent,() => { unit = Vars.player.unit(); - if(!unit || !unit.type.flying){ + if(!unit || unit.type.flying){ Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); return; } @@ -151,6 +151,11 @@ let gravitation = 3; Log.info('Loading main content'); +function canParkour(unit){ + return unit && ! unit.type.flying; +} + + function tileAt(x,y){ return Vars.world.tile(x,y) || false; } @@ -163,18 +168,17 @@ function blockAt(x,y){ ? block : false ; } - -const setGravity = (value) => { - gravity = value; - jump = -value * 10 +function tileIs(x,y,type){ + return tileAt(x,y) == type; } - -const updateHud = () => { - const percent = stamina / 100; - Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); +function unitOn(unit,type){ + return tileIs(unit.tileX(),unit.tileY(),type); } +function unitNear(unit,type){ + return relativeBlock() == type; +} const offsets = [ [ +1 , 0 ] , @@ -185,19 +189,8 @@ const offsets = [ const directToOffset = (direction) => offsets[direction]; - -const blockAtBot = () => { - - const offset = directToOffset(gravitation); - - return Vars.world - .tile(lastx + offset[0],lasty + offset[1]) - .block(); -} - - -const relativeTile = () => { +function relativeTile(){ const offset = directToOffset(gravitation); @@ -207,7 +200,7 @@ const relativeTile = () => { ); } -const relativeBlock = () => { +function relativeBlock(){ const tile = relativeTile(); @@ -215,9 +208,28 @@ const relativeBlock = () => { ? tile.block() : false ; } + + +function setGravity(value){ + gravity = value; + jump = -value * 10 +} + + +function updateHud(){ + + let percent = stamina / 100; + percent = percent - percent % 1; + + Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); +} + + -const isFloorSolid = () => { + + +function isFloorSolid(){ const block = relativeBlock(); @@ -258,7 +270,7 @@ const updateFloor = () => { } -const updateGravity = () => { +function updateGravity(){ const offset = directToOffset(gravitation); @@ -276,7 +288,7 @@ const jumpOffset = [ [ 0 , +1 ] ] -const jump = (velocity) => { +function jump(velocity){ const offset = jumpOffset[gravitation]; @@ -287,12 +299,8 @@ const jump = (velocity) => { } -const gravipad = (unit) => { - - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(blockAt(lastx,lasty) == Blocks.conveyor) +function gravipad(unit){ + if(unitOn(unit,Blocks.conveyor)) gravitation = tileAt(lastx,lasty).build.rotation; } @@ -356,12 +364,9 @@ const gravityCenter = (unit) => { } -const gelJump = (unit) => { +function gelJump(unit){ - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(blockAtBot() != Blocks.titaniumWall){ + if(unitNear(unit,Blocks.titaniumWall)){ ajumpvel = 0; return; } @@ -383,11 +388,8 @@ const gelJump = (unit) => { } -const gelStick = (unit) => { +function gelStick(unit){ - lastx = unit.tileX(); - lasty = unit.tileY(); - const offsets = [ -1 , 0 , +1 ]; for(let x = 0;x < 2;x++) @@ -397,14 +399,16 @@ const gelStick = (unit) => { offsetX = offsets[x] , offsetY = offsets[y] ; - if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) return; hold = true; if(Core.input.keyTab(Binding.pause) && stamina > 99) - unit.vel.add(-offsetX * 15,-velocity * 15); + unit.vel.add( + -offsetX * 15 , + -velocity * 15 + ); return; } @@ -433,52 +437,48 @@ const wallHolding = () => { } -const graviFunnel = (unit) => { - - lastx = unit.tileX(); - lasty = unit.tileY(); +function graviFunnel(unit){ const tile = blockAt(lastx,lasty); + + if(tile != Blocks.pulseConduit) + return; + + hold = true; + const offset = directToOffset(tile.build.rotation); - // грави воронка + unit.vel.add( + -.55 * offset[0] , + -.55 * offset[1] + ); +} - if(tile == Blocks.pulseConduit){ - + +function antiGravField(unit){ + + if(unitOn(unit,Blocks.shockMine)) hold = true; - - switch(tile.build.rotation){ - case 0 : unit.vel.add(+.55,0); return; - case 1 : unit.vel.add(0,+.55); return; - case 2 : unit.vel.add(-.55,0); return; - case 3 : unit.vel.add(0,-.55); return; - } - } } -//не мусор -const antiGravField = (unit) => { +function checkInteractables(unit){ - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(blockAt(lastx,lasty) == Blocks.shockMine) - hold = true; -}; - + gravipad(unit); + gelJump(unit); + gelStick(unit); + wallHolding(); + graviFunnel(unit); + antiGravField(unit); +} -//endregion const update = () => { unit = Vars.player.unit(); - if(!unit) - return; - - if(!unit.type.flying) + if(!canParkour(unit)) return; try { @@ -491,18 +491,19 @@ const update = () => { stamina -= 100; } - gravipad(unit); - gelJump(unit); - gelStick(unit); - wallHolding(); - graviFunnel(unit); - antiGravField(unit); + checkInteractables(unit); if(!hold && mode == 0) updateGravity(); } catch(error){ - Log.err('Parkour Mod:' + error + 'Maybe you are in the void?') + Log.err( + '[ Parkour Mod ]\n\n' + + error.message + + '\n\n' + + error.stack + + '\n' + ); } hold = false; @@ -519,10 +520,7 @@ Timer.schedule(() => { unit = Vars.player.unit(); - if(!unit) - return; - - if(!unit.type.flying) + if(!canParkour(unit)) return; update(); From 9cf499da74cf5cda3c8e35b53c88b5a58857f396 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 22:36:07 -0400 Subject: [PATCH 09/22] Separated Logging --- scripts/Logger.js | 18 ++++++++++ scripts/main.js | 89 ++++++++++++++++++++++++----------------------- 2 files changed, 63 insertions(+), 44 deletions(-) create mode 100644 scripts/Logger.js diff --git a/scripts/Logger.js b/scripts/Logger.js new file mode 100644 index 0000000..755d1a1 --- /dev/null +++ b/scripts/Logger.js @@ -0,0 +1,18 @@ + + +function logError(error){ + Log.err( + '[ Parkour Mod ]\n\n' + + error.message + + '\n\n' + + error.stack + + '\n' + ); +} + + + + +exports = { + logError : logError +} diff --git a/scripts/main.js b/scripts/main.js index c28c9af..d649385 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,4 +1,7 @@ +const { logError } = require('Logger'); + + /* * by Deftry, ADI and TheEE */ @@ -127,7 +130,6 @@ let ajumpvel = 0; // доп. скорость прыжка let direction = 0; // 0 - Y, 1 - X let stamina = 10000; // выносливость let onfloor = false; -let hold = false; let lastx; let lasty; let ltilex; @@ -148,6 +150,18 @@ let gravitation = 3; +let hold = false; + + +function holdOn(){ + hold = true; +} + +function letGo(){ + hold = false; +} + + Log.info('Loading main content'); @@ -227,8 +241,6 @@ function updateHud(){ - - function isFloorSolid(){ const block = relativeBlock(); @@ -394,44 +406,44 @@ function gelStick(unit){ for(let x = 0;x < 2;x++) for(let y = 0;y < 2;y++){ - + const offsetX = offsets[x] , offsetY = offsets[y] ; - + if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) return; - - hold = true; - + + holdOn(); + if(Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add( - -offsetX * 15 , - -velocity * 15 + - offsetX * 15 , + - offsetY * 15 ); - + return; } } -const wallHolding = () => { +function nextToAnyBlock(){ + return blockAt(lastx,lasty + 1) + || blockAt(lastx,lasty - 1) + || blockAt(lastx + 1,lasty) + || blockAt(lastx - 1,lasty) ; +} + +function wallHolding(){ if(!holding) return; - if(stamina < 100){ - hold = false; - return; - } + if(stamina < 100) + return letGo(); - if( - blockAt(lastx + 1,lasty) || - blockAt(lastx - 1,lasty) || - blockAt(lastx,lasty + 1) || - blockAt(lastx,lasty - 1) - ){ - hold = true; + if(nextToAnyBlock()){ + holdOn(); stamina -= 10; } } @@ -439,14 +451,14 @@ const wallHolding = () => { function graviFunnel(unit){ - const tile = blockAt(lastx,lasty); + const block = blockAt(lastx,lasty); - if(tile != Blocks.pulseConduit) + if(block != Blocks.pulseConduit) return; - hold = true; + holdOn(); - const offset = directToOffset(tile.build.rotation); + const offset = directToOffset(block.build.rotation); unit.vel.add( -.55 * offset[0] , @@ -458,7 +470,7 @@ function graviFunnel(unit){ function antiGravField(unit){ if(unitOn(unit,Blocks.shockMine)) - hold = true; + holdOn(); } @@ -474,7 +486,7 @@ function checkInteractables(unit){ } -const update = () => { +function update(){ unit = Vars.player.unit(); @@ -488,7 +500,7 @@ const update = () => { if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ jump(bjumpvel + ajumpvel); - stamina -= 100; + stamina -= 100; } checkInteractables(unit); @@ -496,17 +508,9 @@ const update = () => { if(!hold && mode == 0) updateGravity(); - } catch(error){ - Log.err( - '[ Parkour Mod ]\n\n' + - error.message + - '\n\n' + - error.stack + - '\n' - ); - } + } catch(error) { logError(error) } - hold = false; + letGo(); } @@ -527,10 +531,7 @@ Timer.schedule(() => { updateHud(); updateFloor(); - if(hold) - return; - - if(mode != 1) + if(hold || mode != 1) return; gravityCenter(unit); From 384be9ad34b904e721f24c6a2e33bb2e89842df6 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 17 Jul 2022 23:20:16 -0400 Subject: [PATCH 10/22] ES6 Transpiling --- .gitignore | 3 + Babel/Build.sh | 6 + Babel/babel.config.json | 9 + Babel/package.json | 13 + {scripts => Source}/Logger.js | 9 +- Source/Mod.js | 542 ++++++++++++++++++++++++++ scripts/main.js | 706 ++++++++++++---------------------- 7 files changed, 829 insertions(+), 459 deletions(-) create mode 100644 .gitignore create mode 100755 Babel/Build.sh create mode 100644 Babel/babel.config.json create mode 100644 Babel/package.json rename {scripts => Source}/Logger.js (69%) create mode 100644 Source/Mod.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ae78fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Babel/node_modules +Babel/package-lock.json +Babel/Build diff --git a/Babel/Build.sh b/Babel/Build.sh new file mode 100755 index 0000000..a55f403 --- /dev/null +++ b/Babel/Build.sh @@ -0,0 +1,6 @@ + +mkdir Babel/Build + +Babel/node_modules/.bin/babel Source --out-dir Babel/Build --minified + +browserify Babel/Build/Mod.js -p esmify > scripts/main.js diff --git a/Babel/babel.config.json b/Babel/babel.config.json new file mode 100644 index 0000000..8c04e84 --- /dev/null +++ b/Babel/babel.config.json @@ -0,0 +1,9 @@ +{ + "presets": [[ + "@babel/preset-env" , { + "useBuiltIns" : "usage" , + "targets" : { "rhino": "1.7.7.2" }, + "corejs" : "3.6.5" + }] + ] +} diff --git a/Babel/package.json b/Babel/package.json new file mode 100644 index 0000000..7d790e2 --- /dev/null +++ b/Babel/package.json @@ -0,0 +1,13 @@ +{ + "devDependencies": { + "@babel/cli": "^7.18.6", + "@babel/core": "^7.18.6", + "@babel/preset-env": "^7.18.6", + "babelify": "^10.0.0", + "browserify": "^17.0.0", + "esmify": "^2.1.1" + }, + "dependencies": { + "core-js": "^3.23.5" + } +} diff --git a/scripts/Logger.js b/Source/Logger.js similarity index 69% rename from scripts/Logger.js rename to Source/Logger.js index 755d1a1..1fd8484 100644 --- a/scripts/Logger.js +++ b/Source/Logger.js @@ -1,6 +1,6 @@ -function logError(error){ +export function logError(error){ Log.err( '[ Parkour Mod ]\n\n' + error.message + @@ -9,10 +9,3 @@ function logError(error){ '\n' ); } - - - - -exports = { - logError : logError -} diff --git a/Source/Mod.js b/Source/Mod.js new file mode 100644 index 0000000..600c61c --- /dev/null +++ b/Source/Mod.js @@ -0,0 +1,542 @@ + +import { logError } from './Logger.js' + + +/* + * by Deftry, ADI and TheEE + */ + +let indev = true ; +let isEnabled = false; + +const ButtonStyle = { + full : 150 , + half : 75 +} + + +Log.info(typeof Blocks.titaniumWall) + + + +Log.info('Started loading of parkour mechanics'); +Log.info('Loading ui elements'); + +Events.on(ClientLoadEvent,() => { + + const + height = ButtonStyle.half , + width = ButtonStyle.full ; + + const + menu_a = new Table().bottom().left() , + menu_b = new Table().bottom().left() ; + + let + button_enable = TextButton('Enable Parkour Mode') , + button_hold = TextButton('Hold') ; + + menu_a.y = height; + + let button_mode = TextButton('Change Mode'); + + menu_a + .add(button_enable) + .size(width,height) + .padLeft(6); + + button_enable.clicked(() => { + + unit = Vars.player.unit(); + + if(!unit || unit.type.flying){ + Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); + return; + } + + isEnabled = ! isEnabled; + + button_enable.setText(isEnabled + ? 'Disable Parkour Mod' + : 'Enable Parkour Mod' ); + }); + + menu_b + .add(button_mode) + .size(width,height) + .padLeft(6); + + button_mode.clicked(() => { + + if(mode){ + mode = 0; + Vars.ui.announce('Parkour Mode'); + return; + } + + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce('Planet mode'); + }, + () => { + mode = 0; + Vars.ui.announce('Parkour mode'); + }); + }); + + if(Vars.mobile || indev){ + + let button_jump = TextButton('Jump'); + + menu_b + .add(button_jump) + .size(width,height) + .padLeft(6); + + button_jump.clicked(() => { + if(stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } + }); + } + + menu_b + .add(button_hold) + .size(width,height) + .padLeft(6); + + button_hold.clicked(() => holding = ! holding); + + menu_b.visibility = () => isEnabled; + + const menus = Vars.ui.hudGroup; + + menus.addChild(menu_a); + menus.addChild(menu_b); +}); + + +Log.info('Loading variables'); + +let gravity = .5; // скорость гравитации +let bjumpvel = 15; // скорость прыжка +let ajumpvel = 0; // доп. скорость прыжка +let direction = 0; // 0 - Y, 1 - X +let stamina = 10000; // выносливость +let onfloor = false; +let lastx; +let lasty; +let ltilex; +let ltiley; +let unit; +let mode = 0; // 0 - обычный, 1 - центр тяжести +let holding = false; + + +/* + * 0 : Right + * 1 : Up + * 2 : Left + * 3 : Down + */ + +let gravitation = 3; + + + +let hold = false; + + +function holdOn(){ + hold = true; +} + +function letGo(){ + hold = false; +} + + +Log.info('Loading main content'); + + +function canParkour(unit){ + return unit && ! unit.type.flying; +} + + +function tileAt(x,y){ + return Vars.world.tile(x,y) || false; +} + +function blockAt(x,y){ + + const block = tileAt(x,y); + + return (block && block.type != Blocks.air) + ? block : false ; +} + +function tileIs(x,y,type){ + return tileAt(x,y) == type; +} + +function unitOn(unit,type){ + return tileIs(unit.tileX(),unit.tileY(),type); +} + +function unitNear(unit,type){ + return relativeBlock() == type; +} + +const offsets = [ + [ +1 , 0 ] , + [ 0 , +1 ] , + [ -1 , 0 ] , + [ 0 , -1 ] +] + +const directToOffset = (direction) => + offsets[direction]; + +function relativeTile(){ + + const offset = directToOffset(gravitation); + + return tileAt( + lastx + offset[0] , + lasty + offset[1] + ); +} + +function relativeBlock(){ + + const tile = relativeTile(); + + return (tile) + ? tile.block() + : false ; +} + + +function setGravity(value){ + gravity = value; + jump = -value * 10 +} + + +function updateHud(){ + + let percent = stamina / 100; + + percent = percent - percent % 1; + + Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); +} + + + +function isFloorSolid(){ + + const block = relativeBlock(); + + return (block) + ? block.solid + : false ; +} + +const updateFloor = () => { + + onfloor = isFloorSolid(); + + if(onfloor){ + + stamina += 100; + + if(stamina > 10000) + stamina = 10000; + + ltilex = lastx; + ltiley = lasty; + + const vertical = gravitation % 2; + + let + x = unit.vel.x , + y = unit.vel.y ; + + if(vertical && (gravitation === 1 ? y > 0 : y < 0)) + y = 0; + + if(!vertical && (gravitation === 0 ? x > 0 : x < 0)) + y = 0; + + + unit.vel.set(x,y); + } +} + + +function updateGravity(){ + + const offset = directToOffset(gravitation); + + unit.vel.add( + gravity * offset[0] , + gravity * offset[1] + ); +} + + +const jumpOffset = [ + [ -1 , 0 ] , + [ 0 , -1 ] , + [ +1 , 0 ] , + [ 0 , +1 ] +] + +function jump(velocity){ + + const offset = jumpOffset[gravitation]; + + unit.vel.add( + velocity * offset[0] , + velocity * offset[1] + ); +} + + +function gravipad(unit){ + if(unitOn(unit,Blocks.conveyor)) + gravitation = tileAt(lastx,lasty).build.rotation; +} + + +const gravityCenter = (unit) => { + + let + coordinates = [] ; + distances = [] , + nolock = false ; + + if(onfloor) + return; + + if(hold) + return + + for(let y = -15;y < 16;y++) + for(let x = -15;x < 16;x++) + if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ + coordinates.push({ x : x , y : y }); + nolock = true; + } + + if(!nolock) + return; + + for(let c = 0;c < coordinates.length;c++){ + + const distance = Math.sqrt( + ((lastx + coordinates[c].x - lastx) ^ 2) + + ((lasty + coordinates[c].y - lasty) ^ 2) ); + + distances.push(distance); + } + + let shortest = 0; + + for(let d = 0;d < distances.length;d++) + if(distances[d] < distances[shortest]) + shortest = d; + + const + x = coordinates[shortest].x , + y = coordinates[shortest].y ; + + const vertical = gravitation % 2; + + const position = vertical + ? y : x ; + + if(position === 0) + return; + + unit.vel.add( + ! vertical * gravity , + vertical * gravity + ); + + gravitation = vertical + (position < 0) * 2; +} + + +function gelJump(unit){ + + if(unitNear(unit,Blocks.titaniumWall)){ + ajumpvel = 0; + return; + } + + const vertical = gravitation % 2; + + + const isSame = (vertical) + ? ltiley == lasty + : ltilex == lastx ; + + ajumpvel = (isSame) + ? 15 : 0 ; + + if(isSame) + return; + + jump(bjumpvel + 15); +} + + +function gelStick(unit){ + + const offsets = [ -1 , 0 , +1 ]; + + for(let x = 0;x < 2;x++) + for(let y = 0;y < 2;y++){ + + const + offsetX = offsets[x] , + offsetY = offsets[y] ; + + if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) + return; + + holdOn(); + + if(Core.input.keyTab(Binding.pause) && stamina > 99) + unit.vel.add( + - offsetX * 15 , + - offsetY * 15 + ); + + return; + } +} + + +function nextToAnyBlock(){ + return blockAt(lastx,lasty + 1) + || blockAt(lastx,lasty - 1) + || blockAt(lastx + 1,lasty) + || blockAt(lastx - 1,lasty) ; +} + +function wallHolding(){ + + if(!holding) + return; + + if(stamina < 100) + return letGo(); + + if(nextToAnyBlock()){ + holdOn(); + stamina -= 10; + } +} + + +function graviFunnel(unit){ + + const block = blockAt(lastx,lasty); + + if(block != Blocks.pulseConduit) + return; + + holdOn(); + + const offset = directToOffset(block.build.rotation); + + unit.vel.add( + -.55 * offset[0] , + -.55 * offset[1] + ); +} + + +function antiGravField(unit){ + + if(unitOn(unit,Blocks.shockMine)) + holdOn(); +} + + + +function checkInteractables(unit){ + + gravipad(unit); + gelJump(unit); + gelStick(unit); + wallHolding(); + graviFunnel(unit); + antiGravField(unit); +} + + +function update(){ + + unit = Vars.player.unit(); + + if(!canParkour(unit)) + return; + + try { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } + + checkInteractables(unit); + + if(!hold && mode == 0) + updateGravity(); + + } catch(error) { logError(error) } + + letGo(); +} + + +Log.info('Running update task'); + + +Timer.schedule(() => { + + if(!isEnabled) + return + + unit = Vars.player.unit(); + + if(!canParkour(unit)) + return; + + update(); + updateHud(); + updateFloor(); + + if(hold || mode != 1) + return; + + gravityCenter(unit); + +},0,.02); + + +Log.info('Done initialisation of parkour-mod.'); diff --git a/scripts/main.js b/scripts/main.js index d649385..861078b 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,542 +1,346 @@ +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { + const height = ButtonStyle.half, + width = ButtonStyle.full; + const menu_a = new Table().bottom().left(), + menu_b = new Table().bottom().left(); + let button_enable = TextButton("Enable Parkour Mode"), + button_hold = TextButton("Hold"); + menu_a.y = height; + let button_mode = TextButton("Change Mode"); + menu_a.add(button_enable).size(width, height).padLeft(6); + button_enable.clicked(() => { + unit = Vars.player.unit(); + + if (!unit || unit.type.flying) { + Vars.ui.announce("You cannot use parkour mode outside of a flying unit."); + return; + } + isEnabled = !isEnabled; + button_enable.setText(isEnabled ? "Disable Parkour Mod" : "Enable Parkour Mod"); + }); + menu_b.add(button_mode).size(width, height).padLeft(6); + button_mode.clicked(() => { + if (mode) { + mode = 0; + Vars.ui.announce("Parkour Mode"); + return; + } -Log.info(typeof Blocks.titaniumWall) - - - -Log.info('Started loading of parkour mechanics'); -Log.info('Loading ui elements'); - -Events.on(ClientLoadEvent,() => { - - const - height = ButtonStyle.half , - width = ButtonStyle.full ; - - const - menu_a = new Table().bottom().left() , - menu_b = new Table().bottom().left() ; - - let - button_enable = TextButton('Enable Parkour Mode') , - button_hold = TextButton('Hold') ; - - menu_a.y = height; - - let button_mode = TextButton('Change Mode'); - - menu_a - .add(button_enable) - .size(width,height) - .padLeft(6); - - button_enable.clicked(() => { - - unit = Vars.player.unit(); - - if(!unit || unit.type.flying){ - Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); - return; - } - - isEnabled = ! isEnabled; - - button_enable.setText(isEnabled - ? 'Disable Parkour Mod' - : 'Enable Parkour Mod' ); + Vars.ui.showCustomConfirm("IN DEVELOPMENT!", "You trying to select [accent]Planet[] mode, but it is still buggy and in very development.", "Turn this thing on!", "Back", () => { + mode = 1; + Vars.ui.announce("Planet mode"); + }, () => { + mode = 0; + Vars.ui.announce("Parkour mode"); }); - - menu_b - .add(button_mode) - .size(width,height) - .padLeft(6); - - button_mode.clicked(() => { - - if(mode){ - mode = 0; - Vars.ui.announce('Parkour Mode'); - return; - } - - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce('Planet mode'); - }, - () => { - mode = 0; - Vars.ui.announce('Parkour mode'); - }); + }); + + if (Vars.mobile || indev) { + let button_jump = TextButton("Jump"); + menu_b.add(button_jump).size(width, height).padLeft(6); + button_jump.clicked(() => { + if (stamina > 99 && onfloor) { + jump(bjumpvel + ajumpvel); + stamina -= 100; + } }); + } - if(Vars.mobile || indev){ - - let button_jump = TextButton('Jump'); - - menu_b - .add(button_jump) - .size(width,height) - .padLeft(6); - - button_jump.clicked(() => { - if(stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - }); - } + menu_b.add(button_hold).size(width, height).padLeft(6); + button_hold.clicked(() => holding = !holding); - menu_b - .add(button_hold) - .size(width,height) - .padLeft(6); - - button_hold.clicked(() => holding = ! holding); + menu_b.visibility = () => isEnabled; - menu_b.visibility = () => isEnabled; - - const menus = Vars.ui.hudGroup; - - menus.addChild(menu_a); - menus.addChild(menu_b); + const menus = Vars.ui.hudGroup; + menus.addChild(menu_a); + menus.addChild(menu_b); }); - - -Log.info('Loading variables'); - +Log.info("Loading variables"); let gravity = .5; // скорость гравитации + let bjumpvel = 15; // скорость прыжка + let ajumpvel = 0; // доп. скорость прыжка + let direction = 0; // 0 - Y, 1 - X + let stamina = 10000; // выносливость -let onfloor = false; + +let onfloor = false; let lastx; let lasty; let ltilex; let ltiley; let unit; let mode = 0; // 0 - обычный, 1 - центр тяжести -let holding = false; - +let holding = false; /* - * 0 : Right - * 1 : Up - * 2 : Left - * 3 : Down - */ +* 0 : Right +* 1 : Up +* 2 : Left +* 3 : Down +*/ let gravitation = 3; - - - let hold = false; - -function holdOn(){ - hold = true; +function holdOn() { + hold = true; } -function letGo(){ - hold = false; +function letGo() { + hold = false; } +Log.info("Loading main content"); -Log.info('Loading main content'); - - -function canParkour(unit){ - return unit && ! unit.type.flying; +function canParkour(unit) { + return unit && !unit.type.flying; } - -function tileAt(x,y){ - return Vars.world.tile(x,y) || false; +function tileAt(x, y) { + return Vars.world.tile(x, y) || false; } -function blockAt(x,y){ - - const block = tileAt(x,y); - - return (block && block.type != Blocks.air) - ? block : false ; +function blockAt(x, y) { + const block = tileAt(x, y); + return block && block.type != Blocks.air ? block : false; } -function tileIs(x,y,type){ - return tileAt(x,y) == type; +function tileIs(x, y, type) { + return tileAt(x, y) == type; } -function unitOn(unit,type){ - return tileIs(unit.tileX(),unit.tileY(),type); +function unitOn(unit, type) { + return tileIs(unit.tileX(), unit.tileY(), type); } -function unitNear(unit,type){ - return relativeBlock() == type; +function unitNear(unit, type) { + return relativeBlock() == type; } -const offsets = [ - [ +1 , 0 ] , - [ 0 , +1 ] , - [ -1 , 0 ] , - [ 0 , -1 ] -] - -const directToOffset = (direction) => - offsets[direction]; - -function relativeTile(){ - - const offset = directToOffset(gravitation); - - return tileAt( - lastx + offset[0] , - lasty + offset[1] - ); -} - -function relativeBlock(){ - - const tile = relativeTile(); - - return (tile) - ? tile.block() - : false ; -} +const offsets = [[+1, 0], [0, +1], [-1, 0], [0, -1]]; +const directToOffset = direction => offsets[direction]; -function setGravity(value){ - gravity = value; - jump = -value * 10 +function relativeTile() { + const offset = directToOffset(gravitation); + return tileAt(lastx + offset[0], lasty + offset[1]); } - -function updateHud(){ - - let percent = stamina / 100; - - percent = percent - percent % 1; - - Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); +function relativeBlock() { + const tile = relativeTile(); + return tile ? tile.block() : false; } - - -function isFloorSolid(){ - - const block = relativeBlock(); - - return (block) - ? block.solid - : false ; -} - -const updateFloor = () => { - - onfloor = isFloorSolid(); - - if(onfloor){ - - stamina += 100; - - if(stamina > 10000) - stamina = 10000; - - ltilex = lastx; - ltiley = lasty; - - const vertical = gravitation % 2; - - let - x = unit.vel.x , - y = unit.vel.y ; - - if(vertical && (gravitation === 1 ? y > 0 : y < 0)) - y = 0; - - if(!vertical && (gravitation === 0 ? x > 0 : x < 0)) - y = 0; - - - unit.vel.set(x,y); - } -} - - -function updateGravity(){ - - const offset = directToOffset(gravitation); - - unit.vel.add( - gravity * offset[0] , - gravity * offset[1] - ); +function setGravity(value) { + gravity = value; + jump = -value * 10; } - -const jumpOffset = [ - [ -1 , 0 ] , - [ 0 , -1 ] , - [ +1 , 0 ] , - [ 0 , +1 ] -] - -function jump(velocity){ - - const offset = jumpOffset[gravitation]; - - unit.vel.add( - velocity * offset[0] , - velocity * offset[1] - ); +function updateHud() { + let percent = stamina / 100; + percent = percent - percent % 1; + Vars.ui.showInfoToast("Stamina:" + percent + "%", .04); } - -function gravipad(unit){ - if(unitOn(unit,Blocks.conveyor)) - gravitation = tileAt(lastx,lasty).build.rotation; +function isFloorSolid() { + const block = relativeBlock(); + return block ? block.solid : false; } +const updateFloor = () => { + onfloor = isFloorSolid(); -const gravityCenter = (unit) => { - - let - coordinates = [] ; - distances = [] , - nolock = false ; - - if(onfloor) - return; - - if(hold) - return - - for(let y = -15;y < 16;y++) - for(let x = -15;x < 16;x++) - if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ - coordinates.push({ x : x , y : y }); - nolock = true; - } - - if(!nolock) - return; - - for(let c = 0;c < coordinates.length;c++){ - - const distance = Math.sqrt( - ((lastx + coordinates[c].x - lastx) ^ 2) + - ((lasty + coordinates[c].y - lasty) ^ 2) ); - - distances.push(distance); - } - - let shortest = 0; - - for(let d = 0;d < distances.length;d++) - if(distances[d] < distances[shortest]) - shortest = d; - - const - x = coordinates[shortest].x , - y = coordinates[shortest].y ; - + if (onfloor) { + stamina += 100; + if (stamina > 10000) stamina = 10000; + ltilex = lastx; + ltiley = lasty; const vertical = gravitation % 2; - - const position = vertical - ? y : x ; - - if(position === 0) - return; - - unit.vel.add( - ! vertical * gravity , - vertical * gravity - ); - - gravitation = vertical + (position < 0) * 2; + let x = unit.vel.x, + y = unit.vel.y; + if (vertical && (gravitation === 1 ? y > 0 : y < 0)) y = 0; + if (!vertical && (gravitation === 0 ? x > 0 : x < 0)) y = 0; + unit.vel.set(x, y); + } +}; + +function updateGravity() { + const offset = directToOffset(gravitation); + unit.vel.add(gravity * offset[0], gravity * offset[1]); } +const jumpOffset = [[-1, 0], [0, -1], [+1, 0], [0, +1]]; -function gelJump(unit){ +function jump(velocity) { + const offset = jumpOffset[gravitation]; + unit.vel.add(velocity * offset[0], velocity * offset[1]); +} - if(unitNear(unit,Blocks.titaniumWall)){ - ajumpvel = 0; - return; - } - - const vertical = gravitation % 2; - - - const isSame = (vertical) - ? ltiley == lasty - : ltilex == lastx ; - - ajumpvel = (isSame) - ? 15 : 0 ; - - if(isSame) - return; - - jump(bjumpvel + 15); +function gravipad(unit) { + if (unitOn(unit, Blocks.conveyor)) gravitation = tileAt(lastx, lasty).build.rotation; } +const gravityCenter = unit => { + let coordinates = []; + distances = [], nolock = false; + if (onfloor) return; + if (hold) return; -function gelStick(unit){ - - const offsets = [ -1 , 0 , +1 ]; - - for(let x = 0;x < 2;x++) - for(let y = 0;y < 2;y++){ - - const - offsetX = offsets[x] , - offsetY = offsets[y] ; - - if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) - return; - - holdOn(); - - if(Core.input.keyTab(Binding.pause) && stamina > 99) - unit.vel.add( - - offsetX * 15 , - - offsetY * 15 - ); - - return; - } + for (let y = -15; y < 16; y++) for (let x = -15; x < 16; x++) if (blockAt(lastx + x, lasty + y) == Blocks.thoriumWall) { + coordinates.push({ + x: x, + y: y + }); + nolock = true; + } + + if (!nolock) return; + + for (let c = 0; c < coordinates.length; c++) { + const distance = Math.sqrt((lastx + coordinates[c].x - lastx ^ 2) + (lasty + coordinates[c].y - lasty ^ 2)); + distances.push(distance); + } + + let shortest = 0; + + for (let d = 0; d < distances.length; d++) if (distances[d] < distances[shortest]) shortest = d; + + const x = coordinates[shortest].x, + y = coordinates[shortest].y; + const vertical = gravitation % 2; + const position = vertical ? y : x; + if (position === 0) return; + unit.vel.add(!vertical * gravity, vertical * gravity); + gravitation = vertical + (position < 0) * 2; +}; + +function gelJump(unit) { + if (unitNear(unit, Blocks.titaniumWall)) { + ajumpvel = 0; + return; + } + + const vertical = gravitation % 2; + const isSame = vertical ? ltiley == lasty : ltilex == lastx; + ajumpvel = isSame ? 15 : 0; + if (isSame) return; + jump(bjumpvel + 15); } +function gelStick(unit) { + const offsets = [-1, 0, +1]; -function nextToAnyBlock(){ - return blockAt(lastx,lasty + 1) - || blockAt(lastx,lasty - 1) - || blockAt(lastx + 1,lasty) - || blockAt(lastx - 1,lasty) ; + for (let x = 0; x < 2; x++) for (let y = 0; y < 2; y++) { + const offsetX = offsets[x], + offsetY = offsets[y]; + if (blockAt(lastx + offsetX, lasty + offsetY) !== Blocks.plastaniumWall) return; + holdOn(); + if (Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add(-offsetX * 15, -offsetY * 15); + return; + } } -function wallHolding(){ - - if(!holding) - return; - - if(stamina < 100) - return letGo(); - - if(nextToAnyBlock()){ - holdOn(); - stamina -= 10; - } +function nextToAnyBlock() { + return blockAt(lastx, lasty + 1) || blockAt(lastx, lasty - 1) || blockAt(lastx + 1, lasty) || blockAt(lastx - 1, lasty); } +function wallHolding() { + if (!holding) return; + if (stamina < 100) return letGo(); -function graviFunnel(unit){ - - const block = blockAt(lastx,lasty); - - if(block != Blocks.pulseConduit) - return; - + if (nextToAnyBlock()) { holdOn(); - - const offset = directToOffset(block.build.rotation); - - unit.vel.add( - -.55 * offset[0] , - -.55 * offset[1] - ); + stamina -= 10; + } } - -function antiGravField(unit){ - - if(unitOn(unit,Blocks.shockMine)) - holdOn(); +function graviFunnel(unit) { + const block = blockAt(lastx, lasty); + if (block != Blocks.pulseConduit) return; + holdOn(); + const offset = directToOffset(block.build.rotation); + unit.vel.add(-.55 * offset[0], -.55 * offset[1]); } - - -function checkInteractables(unit){ - - gravipad(unit); - gelJump(unit); - gelStick(unit); - wallHolding(); - graviFunnel(unit); - antiGravField(unit); +function antiGravField(unit) { + if (unitOn(unit, Blocks.shockMine)) holdOn(); } - -function update(){ - - unit = Vars.player.unit(); - - if(!canParkour(unit)) - return; - - try { - - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - - checkInteractables(unit); - - if(!hold && mode == 0) - updateGravity(); - - } catch(error) { logError(error) } - - letGo(); +function checkInteractables(unit) { + gravipad(unit); + gelJump(unit); + gelStick(unit); + wallHolding(); + graviFunnel(unit); + antiGravField(unit); } +function update() { + unit = Vars.player.unit(); + if (!canParkour(unit)) return; -Log.info('Running update task'); + try { + lastx = unit.tileX(); + lasty = unit.tileY(); + if (Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor) { + jump(bjumpvel + ajumpvel); + stamina -= 100; + } -Timer.schedule(() => { - - if(!isEnabled) - return - - unit = Vars.player.unit(); - - if(!canParkour(unit)) - return; - - update(); - updateHud(); - updateFloor(); - - if(hold || mode != 1) - return; - - gravityCenter(unit); - -},0,.02); + checkInteractables(unit); + if (!hold && mode == 0) updateGravity(); + } catch (error) { + (0, _Logger.logError)(error); + } + letGo(); +} -Log.info('Done initialisation of parkour-mod.'); +Log.info("Running update task"); +Timer.schedule(() => { + if (!isEnabled) return; + unit = Vars.player.unit(); + if (!canParkour(unit)) return; + update(); + updateHud(); + updateFloor(); + if (hold || mode != 1) return; + gravityCenter(unit); +}, 0, .02); +Log.info("Done initialisation of parkour-mod."); + +},{"./Logger.js":1}]},{},[2]); From 9ba36d8e3ea8d9f7a8ab0e0a5d9d628fa0585f51 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Mon, 18 Jul 2022 00:12:09 -0400 Subject: [PATCH 11/22] Fixed Setup --- .gitignore | 6 +- Babel/Build.sh | 6 - Babel/babel.config.json | 9 -- Source/Logger.js | 5 +- Source/{Mod.js => main.js} | 18 +-- Tools/Build.sh | 7 + babel.config.json | 13 ++ Babel/package.json => package.json | 6 +- scripts/Logger.js | 7 + scripts/main.js | 231 +++++++++++++++-------------- 10 files changed, 161 insertions(+), 147 deletions(-) delete mode 100755 Babel/Build.sh delete mode 100644 Babel/babel.config.json rename Source/{Mod.js => main.js} (97%) create mode 100755 Tools/Build.sh create mode 100644 babel.config.json rename Babel/package.json => package.json (54%) create mode 100644 scripts/Logger.js diff --git a/.gitignore b/.gitignore index 7ae78fc..9c6ed36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -Babel/node_modules -Babel/package-lock.json -Babel/Build +node_modules +package-lock.json +Build diff --git a/Babel/Build.sh b/Babel/Build.sh deleted file mode 100755 index a55f403..0000000 --- a/Babel/Build.sh +++ /dev/null @@ -1,6 +0,0 @@ - -mkdir Babel/Build - -Babel/node_modules/.bin/babel Source --out-dir Babel/Build --minified - -browserify Babel/Build/Mod.js -p esmify > scripts/main.js diff --git a/Babel/babel.config.json b/Babel/babel.config.json deleted file mode 100644 index 8c04e84..0000000 --- a/Babel/babel.config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "presets": [[ - "@babel/preset-env" , { - "useBuiltIns" : "usage" , - "targets" : { "rhino": "1.7.7.2" }, - "corejs" : "3.6.5" - }] - ] -} diff --git a/Source/Logger.js b/Source/Logger.js index 1fd8484..e72299d 100644 --- a/Source/Logger.js +++ b/Source/Logger.js @@ -1,6 +1,6 @@ -export function logError(error){ +function logError(error){ Log.err( '[ Parkour Mod ]\n\n' + error.message + @@ -9,3 +9,6 @@ export function logError(error){ '\n' ); } + + +exports.logError = logError; diff --git a/Source/Mod.js b/Source/main.js similarity index 97% rename from Source/Mod.js rename to Source/main.js index 600c61c..8f37d85 100644 --- a/Source/Mod.js +++ b/Source/main.js @@ -1,5 +1,5 @@ -import { logError } from './Logger.js' +const { logError } = require('Logger'); /* @@ -15,10 +15,6 @@ const ButtonStyle = { } -Log.info(typeof Blocks.titaniumWall) - - - Log.info('Started loading of parkour mechanics'); Log.info('Loading ui elements'); @@ -171,15 +167,17 @@ function canParkour(unit){ function tileAt(x,y){ - return Vars.world.tile(x,y) || false; + return Vars.world.tile(x,y); } function blockAt(x,y){ - const block = tileAt(x,y); - - return (block && block.type != Blocks.air) - ? block : false ; + const tile = tileAt(x,y); + + if(tile?.type == Blocks.air) + return false; + + return tile; } function tileIs(x,y,type){ diff --git a/Tools/Build.sh b/Tools/Build.sh new file mode 100755 index 0000000..ef69e0b --- /dev/null +++ b/Tools/Build.sh @@ -0,0 +1,7 @@ + +rmdir scripts +mkdir scripts + +clear + +node_modules/.bin/babel Source --out-dir scripts # --minified diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 0000000..31ac732 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,13 @@ +{ + "plugins": [ + "@babel/plugin-proposal-nullish-coalescing-operator" , + "@babel/plugin-proposal-optional-chaining" + ], + "presets": [[ + "@babel/preset-env" , { + "useBuiltIns" : "usage" , + "targets" : { "rhino": "1.7.7" }, + "corejs" : "3.6.5" + }] + ] +} diff --git a/Babel/package.json b/package.json similarity index 54% rename from Babel/package.json rename to package.json index 7d790e2..955eec1 100644 --- a/Babel/package.json +++ b/package.json @@ -2,10 +2,10 @@ "devDependencies": { "@babel/cli": "^7.18.6", "@babel/core": "^7.18.6", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", + "@babel/plugin-proposal-optional-chaining": "^7.18.6", "@babel/preset-env": "^7.18.6", - "babelify": "^10.0.0", - "browserify": "^17.0.0", - "esmify": "^2.1.1" + "babelify": "^10.0.0" }, "dependencies": { "core-js": "^3.23.5" diff --git a/scripts/Logger.js b/scripts/Logger.js new file mode 100644 index 0000000..32b91c1 --- /dev/null +++ b/scripts/Logger.js @@ -0,0 +1,7 @@ +"use strict"; + +function logError(error) { + Log.err('[ Parkour Mod ]\n\n' + error.message + '\n\n' + error.stack + '\n'); +} + +exports.logError = logError; \ No newline at end of file diff --git a/scripts/main.js b/scripts/main.js index 861078b..a0e28a2 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,74 +1,62 @@ -(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { - const height = ButtonStyle.half, - width = ButtonStyle.full; - const menu_a = new Table().bottom().left(), - menu_b = new Table().bottom().left(); - let button_enable = TextButton("Enable Parkour Mode"), - button_hold = TextButton("Hold"); +Log.info('Started loading of parkour mechanics'); +Log.info('Loading ui elements'); +Events.on(ClientLoadEvent, function () { + var height = ButtonStyle.half, + width = ButtonStyle.full; + var menu_a = new Table().bottom().left(), + menu_b = new Table().bottom().left(); + var button_enable = TextButton('Enable Parkour Mode'), + button_hold = TextButton('Hold'); menu_a.y = height; - let button_mode = TextButton("Change Mode"); + var button_mode = TextButton('Change Mode'); menu_a.add(button_enable).size(width, height).padLeft(6); - button_enable.clicked(() => { + button_enable.clicked(function () { unit = Vars.player.unit(); if (!unit || unit.type.flying) { - Vars.ui.announce("You cannot use parkour mode outside of a flying unit."); + Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); return; } isEnabled = !isEnabled; - button_enable.setText(isEnabled ? "Disable Parkour Mod" : "Enable Parkour Mod"); + button_enable.setText(isEnabled ? 'Disable Parkour Mod' : 'Enable Parkour Mod'); }); menu_b.add(button_mode).size(width, height).padLeft(6); - button_mode.clicked(() => { + button_mode.clicked(function () { if (mode) { mode = 0; - Vars.ui.announce("Parkour Mode"); + Vars.ui.announce('Parkour Mode'); return; } - Vars.ui.showCustomConfirm("IN DEVELOPMENT!", "You trying to select [accent]Planet[] mode, but it is still buggy and in very development.", "Turn this thing on!", "Back", () => { + Vars.ui.showCustomConfirm('IN DEVELOPMENT!', 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.', 'Turn this thing on!', 'Back', function () { mode = 1; - Vars.ui.announce("Planet mode"); - }, () => { + Vars.ui.announce('Planet mode'); + }, function () { mode = 0; - Vars.ui.announce("Parkour mode"); + Vars.ui.announce('Parkour mode'); }); }); if (Vars.mobile || indev) { - let button_jump = TextButton("Jump"); + var button_jump = TextButton('Jump'); menu_b.add(button_jump).size(width, height).padLeft(6); - button_jump.clicked(() => { + button_jump.clicked(function () { if (stamina > 99 && onfloor) { jump(bjumpvel + ajumpvel); stamina -= 100; @@ -77,43 +65,47 @@ Events.on(ClientLoadEvent, () => { } menu_b.add(button_hold).size(width, height).padLeft(6); - button_hold.clicked(() => holding = !holding); + button_hold.clicked(function () { + return holding = !holding; + }); - menu_b.visibility = () => isEnabled; + menu_b.visibility = function () { + return isEnabled; + }; - const menus = Vars.ui.hudGroup; + var menus = Vars.ui.hudGroup; menus.addChild(menu_a); menus.addChild(menu_b); }); -Log.info("Loading variables"); -let gravity = .5; // скорость гравитации +Log.info('Loading variables'); +var gravity = .5; // скорость гравитации -let bjumpvel = 15; // скорость прыжка +var bjumpvel = 15; // скорость прыжка -let ajumpvel = 0; // доп. скорость прыжка +var ajumpvel = 0; // доп. скорость прыжка -let direction = 0; // 0 - Y, 1 - X +var direction = 0; // 0 - Y, 1 - X -let stamina = 10000; // выносливость +var stamina = 10000; // выносливость -let onfloor = false; -let lastx; -let lasty; -let ltilex; -let ltiley; -let unit; -let mode = 0; // 0 - обычный, 1 - центр тяжести +var onfloor = false; +var lastx; +var lasty; +var ltilex; +var ltiley; +var unit; +var mode = 0; // 0 - обычный, 1 - центр тяжести -let holding = false; +var holding = false; /* -* 0 : Right -* 1 : Up -* 2 : Left -* 3 : Down -*/ + * 0 : Right + * 1 : Up + * 2 : Left + * 3 : Down + */ -let gravitation = 3; -let hold = false; +var gravitation = 3; +var hold = false; function holdOn() { hold = true; @@ -123,19 +115,20 @@ function letGo() { hold = false; } -Log.info("Loading main content"); +Log.info('Loading main content'); function canParkour(unit) { return unit && !unit.type.flying; } function tileAt(x, y) { - return Vars.world.tile(x, y) || false; + return Vars.world.tile(x, y); } function blockAt(x, y) { - const block = tileAt(x, y); - return block && block.type != Blocks.air ? block : false; + var tile = tileAt(x, y); + if ((tile === null || tile === void 0 ? void 0 : tile.type) == Blocks.air) return false; + return tile; } function tileIs(x, y, type) { @@ -150,17 +143,19 @@ function unitNear(unit, type) { return relativeBlock() == type; } -const offsets = [[+1, 0], [0, +1], [-1, 0], [0, -1]]; +var offsets = [[+1, 0], [0, +1], [-1, 0], [0, -1]]; -const directToOffset = direction => offsets[direction]; +var directToOffset = function directToOffset(direction) { + return offsets[direction]; +}; function relativeTile() { - const offset = directToOffset(gravitation); + var offset = directToOffset(gravitation); return tileAt(lastx + offset[0], lasty + offset[1]); } function relativeBlock() { - const tile = relativeTile(); + var tile = relativeTile(); return tile ? tile.block() : false; } @@ -170,17 +165,17 @@ function setGravity(value) { } function updateHud() { - let percent = stamina / 100; + var percent = stamina / 100; percent = percent - percent % 1; - Vars.ui.showInfoToast("Stamina:" + percent + "%", .04); + Vars.ui.showInfoToast('Stamina:' + percent + '%', .04); } function isFloorSolid() { - const block = relativeBlock(); + var block = relativeBlock(); return block ? block.solid : false; } -const updateFloor = () => { +var updateFloor = function updateFloor() { onfloor = isFloorSolid(); if (onfloor) { @@ -188,8 +183,8 @@ const updateFloor = () => { if (stamina > 10000) stamina = 10000; ltilex = lastx; ltiley = lasty; - const vertical = gravitation % 2; - let x = unit.vel.x, + var vertical = gravitation % 2; + var x = unit.vel.x, y = unit.vel.y; if (vertical && (gravitation === 1 ? y > 0 : y < 0)) y = 0; if (!vertical && (gravitation === 0 ? x > 0 : x < 0)) y = 0; @@ -198,14 +193,14 @@ const updateFloor = () => { }; function updateGravity() { - const offset = directToOffset(gravitation); + var offset = directToOffset(gravitation); unit.vel.add(gravity * offset[0], gravity * offset[1]); } -const jumpOffset = [[-1, 0], [0, -1], [+1, 0], [0, +1]]; +var jumpOffset = [[-1, 0], [0, -1], [+1, 0], [0, +1]]; function jump(velocity) { - const offset = jumpOffset[gravitation]; + var offset = jumpOffset[gravitation]; unit.vel.add(velocity * offset[0], velocity * offset[1]); } @@ -213,35 +208,41 @@ function gravipad(unit) { if (unitOn(unit, Blocks.conveyor)) gravitation = tileAt(lastx, lasty).build.rotation; } -const gravityCenter = unit => { - let coordinates = []; +var gravityCenter = function gravityCenter(unit) { + var coordinates = []; distances = [], nolock = false; if (onfloor) return; if (hold) return; - for (let y = -15; y < 16; y++) for (let x = -15; x < 16; x++) if (blockAt(lastx + x, lasty + y) == Blocks.thoriumWall) { - coordinates.push({ - x: x, - y: y - }); - nolock = true; + for (var _y = -15; _y < 16; _y++) { + for (var _x = -15; _x < 16; _x++) { + if (blockAt(lastx + _x, lasty + _y) == Blocks.thoriumWall) { + coordinates.push({ + x: _x, + y: _y + }); + nolock = true; + } + } } if (!nolock) return; - for (let c = 0; c < coordinates.length; c++) { - const distance = Math.sqrt((lastx + coordinates[c].x - lastx ^ 2) + (lasty + coordinates[c].y - lasty ^ 2)); + for (var c = 0; c < coordinates.length; c++) { + var distance = Math.sqrt((lastx + coordinates[c].x - lastx ^ 2) + (lasty + coordinates[c].y - lasty ^ 2)); distances.push(distance); } - let shortest = 0; + var shortest = 0; - for (let d = 0; d < distances.length; d++) if (distances[d] < distances[shortest]) shortest = d; + for (var d = 0; d < distances.length; d++) { + if (distances[d] < distances[shortest]) shortest = d; + } - const x = coordinates[shortest].x, - y = coordinates[shortest].y; - const vertical = gravitation % 2; - const position = vertical ? y : x; + var x = coordinates[shortest].x, + y = coordinates[shortest].y; + var vertical = gravitation % 2; + var position = vertical ? y : x; if (position === 0) return; unit.vel.add(!vertical * gravity, vertical * gravity); gravitation = vertical + (position < 0) * 2; @@ -253,23 +254,25 @@ function gelJump(unit) { return; } - const vertical = gravitation % 2; - const isSame = vertical ? ltiley == lasty : ltilex == lastx; + var vertical = gravitation % 2; + var isSame = vertical ? ltiley == lasty : ltilex == lastx; ajumpvel = isSame ? 15 : 0; if (isSame) return; jump(bjumpvel + 15); } function gelStick(unit) { - const offsets = [-1, 0, +1]; + var offsets = [-1, 0, +1]; - for (let x = 0; x < 2; x++) for (let y = 0; y < 2; y++) { - const offsetX = offsets[x], + for (var x = 0; x < 2; x++) { + for (var y = 0; y < 2; y++) { + var offsetX = offsets[x], offsetY = offsets[y]; - if (blockAt(lastx + offsetX, lasty + offsetY) !== Blocks.plastaniumWall) return; - holdOn(); - if (Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add(-offsetX * 15, -offsetY * 15); - return; + if (blockAt(lastx + offsetX, lasty + offsetY) !== Blocks.plastaniumWall) return; + holdOn(); + if (Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add(-offsetX * 15, -offsetY * 15); + return; + } } } @@ -288,10 +291,10 @@ function wallHolding() { } function graviFunnel(unit) { - const block = blockAt(lastx, lasty); + var block = blockAt(lastx, lasty); if (block != Blocks.pulseConduit) return; holdOn(); - const offset = directToOffset(block.build.rotation); + var offset = directToOffset(block.build.rotation); unit.vel.add(-.55 * offset[0], -.55 * offset[1]); } @@ -324,14 +327,14 @@ function update() { checkInteractables(unit); if (!hold && mode == 0) updateGravity(); } catch (error) { - (0, _Logger.logError)(error); + logError(error); } letGo(); } -Log.info("Running update task"); -Timer.schedule(() => { +Log.info('Running update task'); +Timer.schedule(function () { if (!isEnabled) return; unit = Vars.player.unit(); if (!canParkour(unit)) return; @@ -341,6 +344,4 @@ Timer.schedule(() => { if (hold || mode != 1) return; gravityCenter(unit); }, 0, .02); -Log.info("Done initialisation of parkour-mod."); - -},{"./Logger.js":1}]},{},[2]); +Log.info('Done initialisation of parkour-mod.'); \ No newline at end of file From b96aeb33b9feb4b4d12f0852834626fbaa3aa034 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Mon, 18 Jul 2022 00:54:38 -0400 Subject: [PATCH 12/22] Revert "Fixed Setup" This reverts commit 9ba36d8e3ea8d9f7a8ab0e0a5d9d628fa0585f51. --- .gitignore | 6 +- Babel/Build.sh | 6 + Babel/babel.config.json | 9 ++ package.json => Babel/package.json | 6 +- Source/Logger.js | 5 +- Source/{main.js => Mod.js} | 18 ++- Tools/Build.sh | 7 - babel.config.json | 13 -- scripts/Logger.js | 7 - scripts/main.js | 231 ++++++++++++++--------------- 10 files changed, 147 insertions(+), 161 deletions(-) create mode 100755 Babel/Build.sh create mode 100644 Babel/babel.config.json rename package.json => Babel/package.json (54%) rename Source/{main.js => Mod.js} (97%) delete mode 100755 Tools/Build.sh delete mode 100644 babel.config.json delete mode 100644 scripts/Logger.js diff --git a/.gitignore b/.gitignore index 9c6ed36..7ae78fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -node_modules -package-lock.json -Build +Babel/node_modules +Babel/package-lock.json +Babel/Build diff --git a/Babel/Build.sh b/Babel/Build.sh new file mode 100755 index 0000000..a55f403 --- /dev/null +++ b/Babel/Build.sh @@ -0,0 +1,6 @@ + +mkdir Babel/Build + +Babel/node_modules/.bin/babel Source --out-dir Babel/Build --minified + +browserify Babel/Build/Mod.js -p esmify > scripts/main.js diff --git a/Babel/babel.config.json b/Babel/babel.config.json new file mode 100644 index 0000000..8c04e84 --- /dev/null +++ b/Babel/babel.config.json @@ -0,0 +1,9 @@ +{ + "presets": [[ + "@babel/preset-env" , { + "useBuiltIns" : "usage" , + "targets" : { "rhino": "1.7.7.2" }, + "corejs" : "3.6.5" + }] + ] +} diff --git a/package.json b/Babel/package.json similarity index 54% rename from package.json rename to Babel/package.json index 955eec1..7d790e2 100644 --- a/package.json +++ b/Babel/package.json @@ -2,10 +2,10 @@ "devDependencies": { "@babel/cli": "^7.18.6", "@babel/core": "^7.18.6", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", - "@babel/plugin-proposal-optional-chaining": "^7.18.6", "@babel/preset-env": "^7.18.6", - "babelify": "^10.0.0" + "babelify": "^10.0.0", + "browserify": "^17.0.0", + "esmify": "^2.1.1" }, "dependencies": { "core-js": "^3.23.5" diff --git a/Source/Logger.js b/Source/Logger.js index e72299d..1fd8484 100644 --- a/Source/Logger.js +++ b/Source/Logger.js @@ -1,6 +1,6 @@ -function logError(error){ +export function logError(error){ Log.err( '[ Parkour Mod ]\n\n' + error.message + @@ -9,6 +9,3 @@ function logError(error){ '\n' ); } - - -exports.logError = logError; diff --git a/Source/main.js b/Source/Mod.js similarity index 97% rename from Source/main.js rename to Source/Mod.js index 8f37d85..600c61c 100644 --- a/Source/main.js +++ b/Source/Mod.js @@ -1,5 +1,5 @@ -const { logError } = require('Logger'); +import { logError } from './Logger.js' /* @@ -15,6 +15,10 @@ const ButtonStyle = { } +Log.info(typeof Blocks.titaniumWall) + + + Log.info('Started loading of parkour mechanics'); Log.info('Loading ui elements'); @@ -167,17 +171,15 @@ function canParkour(unit){ function tileAt(x,y){ - return Vars.world.tile(x,y); + return Vars.world.tile(x,y) || false; } function blockAt(x,y){ - const tile = tileAt(x,y); - - if(tile?.type == Blocks.air) - return false; - - return tile; + const block = tileAt(x,y); + + return (block && block.type != Blocks.air) + ? block : false ; } function tileIs(x,y,type){ diff --git a/Tools/Build.sh b/Tools/Build.sh deleted file mode 100755 index ef69e0b..0000000 --- a/Tools/Build.sh +++ /dev/null @@ -1,7 +0,0 @@ - -rmdir scripts -mkdir scripts - -clear - -node_modules/.bin/babel Source --out-dir scripts # --minified diff --git a/babel.config.json b/babel.config.json deleted file mode 100644 index 31ac732..0000000 --- a/babel.config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "plugins": [ - "@babel/plugin-proposal-nullish-coalescing-operator" , - "@babel/plugin-proposal-optional-chaining" - ], - "presets": [[ - "@babel/preset-env" , { - "useBuiltIns" : "usage" , - "targets" : { "rhino": "1.7.7" }, - "corejs" : "3.6.5" - }] - ] -} diff --git a/scripts/Logger.js b/scripts/Logger.js deleted file mode 100644 index 32b91c1..0000000 --- a/scripts/Logger.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; - -function logError(error) { - Log.err('[ Parkour Mod ]\n\n' + error.message + '\n\n' + error.stack + '\n'); -} - -exports.logError = logError; \ No newline at end of file diff --git a/scripts/main.js b/scripts/main.js index a0e28a2..861078b 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,62 +1,74 @@ +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { + const height = ButtonStyle.half, + width = ButtonStyle.full; + const menu_a = new Table().bottom().left(), + menu_b = new Table().bottom().left(); + let button_enable = TextButton("Enable Parkour Mode"), + button_hold = TextButton("Hold"); menu_a.y = height; - var button_mode = TextButton('Change Mode'); + let button_mode = TextButton("Change Mode"); menu_a.add(button_enable).size(width, height).padLeft(6); - button_enable.clicked(function () { + button_enable.clicked(() => { unit = Vars.player.unit(); if (!unit || unit.type.flying) { - Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); + Vars.ui.announce("You cannot use parkour mode outside of a flying unit."); return; } isEnabled = !isEnabled; - button_enable.setText(isEnabled ? 'Disable Parkour Mod' : 'Enable Parkour Mod'); + button_enable.setText(isEnabled ? "Disable Parkour Mod" : "Enable Parkour Mod"); }); menu_b.add(button_mode).size(width, height).padLeft(6); - button_mode.clicked(function () { + button_mode.clicked(() => { if (mode) { mode = 0; - Vars.ui.announce('Parkour Mode'); + Vars.ui.announce("Parkour Mode"); return; } - Vars.ui.showCustomConfirm('IN DEVELOPMENT!', 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.', 'Turn this thing on!', 'Back', function () { + Vars.ui.showCustomConfirm("IN DEVELOPMENT!", "You trying to select [accent]Planet[] mode, but it is still buggy and in very development.", "Turn this thing on!", "Back", () => { mode = 1; - Vars.ui.announce('Planet mode'); - }, function () { + Vars.ui.announce("Planet mode"); + }, () => { mode = 0; - Vars.ui.announce('Parkour mode'); + Vars.ui.announce("Parkour mode"); }); }); if (Vars.mobile || indev) { - var button_jump = TextButton('Jump'); + let button_jump = TextButton("Jump"); menu_b.add(button_jump).size(width, height).padLeft(6); - button_jump.clicked(function () { + button_jump.clicked(() => { if (stamina > 99 && onfloor) { jump(bjumpvel + ajumpvel); stamina -= 100; @@ -65,47 +77,43 @@ Events.on(ClientLoadEvent, function () { } menu_b.add(button_hold).size(width, height).padLeft(6); - button_hold.clicked(function () { - return holding = !holding; - }); + button_hold.clicked(() => holding = !holding); - menu_b.visibility = function () { - return isEnabled; - }; + menu_b.visibility = () => isEnabled; - var menus = Vars.ui.hudGroup; + const menus = Vars.ui.hudGroup; menus.addChild(menu_a); menus.addChild(menu_b); }); -Log.info('Loading variables'); -var gravity = .5; // скорость гравитации +Log.info("Loading variables"); +let gravity = .5; // скорость гравитации -var bjumpvel = 15; // скорость прыжка +let bjumpvel = 15; // скорость прыжка -var ajumpvel = 0; // доп. скорость прыжка +let ajumpvel = 0; // доп. скорость прыжка -var direction = 0; // 0 - Y, 1 - X +let direction = 0; // 0 - Y, 1 - X -var stamina = 10000; // выносливость +let stamina = 10000; // выносливость -var onfloor = false; -var lastx; -var lasty; -var ltilex; -var ltiley; -var unit; -var mode = 0; // 0 - обычный, 1 - центр тяжести +let onfloor = false; +let lastx; +let lasty; +let ltilex; +let ltiley; +let unit; +let mode = 0; // 0 - обычный, 1 - центр тяжести -var holding = false; +let holding = false; /* - * 0 : Right - * 1 : Up - * 2 : Left - * 3 : Down - */ +* 0 : Right +* 1 : Up +* 2 : Left +* 3 : Down +*/ -var gravitation = 3; -var hold = false; +let gravitation = 3; +let hold = false; function holdOn() { hold = true; @@ -115,20 +123,19 @@ function letGo() { hold = false; } -Log.info('Loading main content'); +Log.info("Loading main content"); function canParkour(unit) { return unit && !unit.type.flying; } function tileAt(x, y) { - return Vars.world.tile(x, y); + return Vars.world.tile(x, y) || false; } function blockAt(x, y) { - var tile = tileAt(x, y); - if ((tile === null || tile === void 0 ? void 0 : tile.type) == Blocks.air) return false; - return tile; + const block = tileAt(x, y); + return block && block.type != Blocks.air ? block : false; } function tileIs(x, y, type) { @@ -143,19 +150,17 @@ function unitNear(unit, type) { return relativeBlock() == type; } -var offsets = [[+1, 0], [0, +1], [-1, 0], [0, -1]]; +const offsets = [[+1, 0], [0, +1], [-1, 0], [0, -1]]; -var directToOffset = function directToOffset(direction) { - return offsets[direction]; -}; +const directToOffset = direction => offsets[direction]; function relativeTile() { - var offset = directToOffset(gravitation); + const offset = directToOffset(gravitation); return tileAt(lastx + offset[0], lasty + offset[1]); } function relativeBlock() { - var tile = relativeTile(); + const tile = relativeTile(); return tile ? tile.block() : false; } @@ -165,17 +170,17 @@ function setGravity(value) { } function updateHud() { - var percent = stamina / 100; + let percent = stamina / 100; percent = percent - percent % 1; - Vars.ui.showInfoToast('Stamina:' + percent + '%', .04); + Vars.ui.showInfoToast("Stamina:" + percent + "%", .04); } function isFloorSolid() { - var block = relativeBlock(); + const block = relativeBlock(); return block ? block.solid : false; } -var updateFloor = function updateFloor() { +const updateFloor = () => { onfloor = isFloorSolid(); if (onfloor) { @@ -183,8 +188,8 @@ var updateFloor = function updateFloor() { if (stamina > 10000) stamina = 10000; ltilex = lastx; ltiley = lasty; - var vertical = gravitation % 2; - var x = unit.vel.x, + const vertical = gravitation % 2; + let x = unit.vel.x, y = unit.vel.y; if (vertical && (gravitation === 1 ? y > 0 : y < 0)) y = 0; if (!vertical && (gravitation === 0 ? x > 0 : x < 0)) y = 0; @@ -193,14 +198,14 @@ var updateFloor = function updateFloor() { }; function updateGravity() { - var offset = directToOffset(gravitation); + const offset = directToOffset(gravitation); unit.vel.add(gravity * offset[0], gravity * offset[1]); } -var jumpOffset = [[-1, 0], [0, -1], [+1, 0], [0, +1]]; +const jumpOffset = [[-1, 0], [0, -1], [+1, 0], [0, +1]]; function jump(velocity) { - var offset = jumpOffset[gravitation]; + const offset = jumpOffset[gravitation]; unit.vel.add(velocity * offset[0], velocity * offset[1]); } @@ -208,41 +213,35 @@ function gravipad(unit) { if (unitOn(unit, Blocks.conveyor)) gravitation = tileAt(lastx, lasty).build.rotation; } -var gravityCenter = function gravityCenter(unit) { - var coordinates = []; +const gravityCenter = unit => { + let coordinates = []; distances = [], nolock = false; if (onfloor) return; if (hold) return; - for (var _y = -15; _y < 16; _y++) { - for (var _x = -15; _x < 16; _x++) { - if (blockAt(lastx + _x, lasty + _y) == Blocks.thoriumWall) { - coordinates.push({ - x: _x, - y: _y - }); - nolock = true; - } - } + for (let y = -15; y < 16; y++) for (let x = -15; x < 16; x++) if (blockAt(lastx + x, lasty + y) == Blocks.thoriumWall) { + coordinates.push({ + x: x, + y: y + }); + nolock = true; } if (!nolock) return; - for (var c = 0; c < coordinates.length; c++) { - var distance = Math.sqrt((lastx + coordinates[c].x - lastx ^ 2) + (lasty + coordinates[c].y - lasty ^ 2)); + for (let c = 0; c < coordinates.length; c++) { + const distance = Math.sqrt((lastx + coordinates[c].x - lastx ^ 2) + (lasty + coordinates[c].y - lasty ^ 2)); distances.push(distance); } - var shortest = 0; + let shortest = 0; - for (var d = 0; d < distances.length; d++) { - if (distances[d] < distances[shortest]) shortest = d; - } + for (let d = 0; d < distances.length; d++) if (distances[d] < distances[shortest]) shortest = d; - var x = coordinates[shortest].x, - y = coordinates[shortest].y; - var vertical = gravitation % 2; - var position = vertical ? y : x; + const x = coordinates[shortest].x, + y = coordinates[shortest].y; + const vertical = gravitation % 2; + const position = vertical ? y : x; if (position === 0) return; unit.vel.add(!vertical * gravity, vertical * gravity); gravitation = vertical + (position < 0) * 2; @@ -254,25 +253,23 @@ function gelJump(unit) { return; } - var vertical = gravitation % 2; - var isSame = vertical ? ltiley == lasty : ltilex == lastx; + const vertical = gravitation % 2; + const isSame = vertical ? ltiley == lasty : ltilex == lastx; ajumpvel = isSame ? 15 : 0; if (isSame) return; jump(bjumpvel + 15); } function gelStick(unit) { - var offsets = [-1, 0, +1]; + const offsets = [-1, 0, +1]; - for (var x = 0; x < 2; x++) { - for (var y = 0; y < 2; y++) { - var offsetX = offsets[x], + for (let x = 0; x < 2; x++) for (let y = 0; y < 2; y++) { + const offsetX = offsets[x], offsetY = offsets[y]; - if (blockAt(lastx + offsetX, lasty + offsetY) !== Blocks.plastaniumWall) return; - holdOn(); - if (Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add(-offsetX * 15, -offsetY * 15); - return; - } + if (blockAt(lastx + offsetX, lasty + offsetY) !== Blocks.plastaniumWall) return; + holdOn(); + if (Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add(-offsetX * 15, -offsetY * 15); + return; } } @@ -291,10 +288,10 @@ function wallHolding() { } function graviFunnel(unit) { - var block = blockAt(lastx, lasty); + const block = blockAt(lastx, lasty); if (block != Blocks.pulseConduit) return; holdOn(); - var offset = directToOffset(block.build.rotation); + const offset = directToOffset(block.build.rotation); unit.vel.add(-.55 * offset[0], -.55 * offset[1]); } @@ -327,14 +324,14 @@ function update() { checkInteractables(unit); if (!hold && mode == 0) updateGravity(); } catch (error) { - logError(error); + (0, _Logger.logError)(error); } letGo(); } -Log.info('Running update task'); -Timer.schedule(function () { +Log.info("Running update task"); +Timer.schedule(() => { if (!isEnabled) return; unit = Vars.player.unit(); if (!canParkour(unit)) return; @@ -344,4 +341,6 @@ Timer.schedule(function () { if (hold || mode != 1) return; gravityCenter(unit); }, 0, .02); -Log.info('Done initialisation of parkour-mod.'); \ No newline at end of file +Log.info("Done initialisation of parkour-mod."); + +},{"./Logger.js":1}]},{},[2]); From 0a06be2417944886dfc9ae3b045d784d27beee5d Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Mon, 18 Jul 2022 00:54:44 -0400 Subject: [PATCH 13/22] Revert "ES6 Transpiling" This reverts commit 384be9ad34b904e721f24c6a2e33bb2e89842df6. --- .gitignore | 3 - Babel/Build.sh | 6 - Babel/babel.config.json | 9 - Babel/package.json | 13 - Source/Mod.js | 542 -------------------------- {Source => scripts}/Logger.js | 9 +- scripts/main.js | 706 ++++++++++++++++++++++------------ 7 files changed, 459 insertions(+), 829 deletions(-) delete mode 100644 .gitignore delete mode 100755 Babel/Build.sh delete mode 100644 Babel/babel.config.json delete mode 100644 Babel/package.json delete mode 100644 Source/Mod.js rename {Source => scripts}/Logger.js (69%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7ae78fc..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -Babel/node_modules -Babel/package-lock.json -Babel/Build diff --git a/Babel/Build.sh b/Babel/Build.sh deleted file mode 100755 index a55f403..0000000 --- a/Babel/Build.sh +++ /dev/null @@ -1,6 +0,0 @@ - -mkdir Babel/Build - -Babel/node_modules/.bin/babel Source --out-dir Babel/Build --minified - -browserify Babel/Build/Mod.js -p esmify > scripts/main.js diff --git a/Babel/babel.config.json b/Babel/babel.config.json deleted file mode 100644 index 8c04e84..0000000 --- a/Babel/babel.config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "presets": [[ - "@babel/preset-env" , { - "useBuiltIns" : "usage" , - "targets" : { "rhino": "1.7.7.2" }, - "corejs" : "3.6.5" - }] - ] -} diff --git a/Babel/package.json b/Babel/package.json deleted file mode 100644 index 7d790e2..0000000 --- a/Babel/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "devDependencies": { - "@babel/cli": "^7.18.6", - "@babel/core": "^7.18.6", - "@babel/preset-env": "^7.18.6", - "babelify": "^10.0.0", - "browserify": "^17.0.0", - "esmify": "^2.1.1" - }, - "dependencies": { - "core-js": "^3.23.5" - } -} diff --git a/Source/Mod.js b/Source/Mod.js deleted file mode 100644 index 600c61c..0000000 --- a/Source/Mod.js +++ /dev/null @@ -1,542 +0,0 @@ - -import { logError } from './Logger.js' - - -/* - * by Deftry, ADI and TheEE - */ - -let indev = true ; -let isEnabled = false; - -const ButtonStyle = { - full : 150 , - half : 75 -} - - -Log.info(typeof Blocks.titaniumWall) - - - -Log.info('Started loading of parkour mechanics'); -Log.info('Loading ui elements'); - -Events.on(ClientLoadEvent,() => { - - const - height = ButtonStyle.half , - width = ButtonStyle.full ; - - const - menu_a = new Table().bottom().left() , - menu_b = new Table().bottom().left() ; - - let - button_enable = TextButton('Enable Parkour Mode') , - button_hold = TextButton('Hold') ; - - menu_a.y = height; - - let button_mode = TextButton('Change Mode'); - - menu_a - .add(button_enable) - .size(width,height) - .padLeft(6); - - button_enable.clicked(() => { - - unit = Vars.player.unit(); - - if(!unit || unit.type.flying){ - Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); - return; - } - - isEnabled = ! isEnabled; - - button_enable.setText(isEnabled - ? 'Disable Parkour Mod' - : 'Enable Parkour Mod' ); - }); - - menu_b - .add(button_mode) - .size(width,height) - .padLeft(6); - - button_mode.clicked(() => { - - if(mode){ - mode = 0; - Vars.ui.announce('Parkour Mode'); - return; - } - - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce('Planet mode'); - }, - () => { - mode = 0; - Vars.ui.announce('Parkour mode'); - }); - }); - - if(Vars.mobile || indev){ - - let button_jump = TextButton('Jump'); - - menu_b - .add(button_jump) - .size(width,height) - .padLeft(6); - - button_jump.clicked(() => { - if(stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - }); - } - - menu_b - .add(button_hold) - .size(width,height) - .padLeft(6); - - button_hold.clicked(() => holding = ! holding); - - menu_b.visibility = () => isEnabled; - - const menus = Vars.ui.hudGroup; - - menus.addChild(menu_a); - menus.addChild(menu_b); -}); - - -Log.info('Loading variables'); - -let gravity = .5; // скорость гравитации -let bjumpvel = 15; // скорость прыжка -let ajumpvel = 0; // доп. скорость прыжка -let direction = 0; // 0 - Y, 1 - X -let stamina = 10000; // выносливость -let onfloor = false; -let lastx; -let lasty; -let ltilex; -let ltiley; -let unit; -let mode = 0; // 0 - обычный, 1 - центр тяжести -let holding = false; - - -/* - * 0 : Right - * 1 : Up - * 2 : Left - * 3 : Down - */ - -let gravitation = 3; - - - -let hold = false; - - -function holdOn(){ - hold = true; -} - -function letGo(){ - hold = false; -} - - -Log.info('Loading main content'); - - -function canParkour(unit){ - return unit && ! unit.type.flying; -} - - -function tileAt(x,y){ - return Vars.world.tile(x,y) || false; -} - -function blockAt(x,y){ - - const block = tileAt(x,y); - - return (block && block.type != Blocks.air) - ? block : false ; -} - -function tileIs(x,y,type){ - return tileAt(x,y) == type; -} - -function unitOn(unit,type){ - return tileIs(unit.tileX(),unit.tileY(),type); -} - -function unitNear(unit,type){ - return relativeBlock() == type; -} - -const offsets = [ - [ +1 , 0 ] , - [ 0 , +1 ] , - [ -1 , 0 ] , - [ 0 , -1 ] -] - -const directToOffset = (direction) => - offsets[direction]; - -function relativeTile(){ - - const offset = directToOffset(gravitation); - - return tileAt( - lastx + offset[0] , - lasty + offset[1] - ); -} - -function relativeBlock(){ - - const tile = relativeTile(); - - return (tile) - ? tile.block() - : false ; -} - - -function setGravity(value){ - gravity = value; - jump = -value * 10 -} - - -function updateHud(){ - - let percent = stamina / 100; - - percent = percent - percent % 1; - - Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); -} - - - -function isFloorSolid(){ - - const block = relativeBlock(); - - return (block) - ? block.solid - : false ; -} - -const updateFloor = () => { - - onfloor = isFloorSolid(); - - if(onfloor){ - - stamina += 100; - - if(stamina > 10000) - stamina = 10000; - - ltilex = lastx; - ltiley = lasty; - - const vertical = gravitation % 2; - - let - x = unit.vel.x , - y = unit.vel.y ; - - if(vertical && (gravitation === 1 ? y > 0 : y < 0)) - y = 0; - - if(!vertical && (gravitation === 0 ? x > 0 : x < 0)) - y = 0; - - - unit.vel.set(x,y); - } -} - - -function updateGravity(){ - - const offset = directToOffset(gravitation); - - unit.vel.add( - gravity * offset[0] , - gravity * offset[1] - ); -} - - -const jumpOffset = [ - [ -1 , 0 ] , - [ 0 , -1 ] , - [ +1 , 0 ] , - [ 0 , +1 ] -] - -function jump(velocity){ - - const offset = jumpOffset[gravitation]; - - unit.vel.add( - velocity * offset[0] , - velocity * offset[1] - ); -} - - -function gravipad(unit){ - if(unitOn(unit,Blocks.conveyor)) - gravitation = tileAt(lastx,lasty).build.rotation; -} - - -const gravityCenter = (unit) => { - - let - coordinates = [] ; - distances = [] , - nolock = false ; - - if(onfloor) - return; - - if(hold) - return - - for(let y = -15;y < 16;y++) - for(let x = -15;x < 16;x++) - if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ - coordinates.push({ x : x , y : y }); - nolock = true; - } - - if(!nolock) - return; - - for(let c = 0;c < coordinates.length;c++){ - - const distance = Math.sqrt( - ((lastx + coordinates[c].x - lastx) ^ 2) + - ((lasty + coordinates[c].y - lasty) ^ 2) ); - - distances.push(distance); - } - - let shortest = 0; - - for(let d = 0;d < distances.length;d++) - if(distances[d] < distances[shortest]) - shortest = d; - - const - x = coordinates[shortest].x , - y = coordinates[shortest].y ; - - const vertical = gravitation % 2; - - const position = vertical - ? y : x ; - - if(position === 0) - return; - - unit.vel.add( - ! vertical * gravity , - vertical * gravity - ); - - gravitation = vertical + (position < 0) * 2; -} - - -function gelJump(unit){ - - if(unitNear(unit,Blocks.titaniumWall)){ - ajumpvel = 0; - return; - } - - const vertical = gravitation % 2; - - - const isSame = (vertical) - ? ltiley == lasty - : ltilex == lastx ; - - ajumpvel = (isSame) - ? 15 : 0 ; - - if(isSame) - return; - - jump(bjumpvel + 15); -} - - -function gelStick(unit){ - - const offsets = [ -1 , 0 , +1 ]; - - for(let x = 0;x < 2;x++) - for(let y = 0;y < 2;y++){ - - const - offsetX = offsets[x] , - offsetY = offsets[y] ; - - if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) - return; - - holdOn(); - - if(Core.input.keyTab(Binding.pause) && stamina > 99) - unit.vel.add( - - offsetX * 15 , - - offsetY * 15 - ); - - return; - } -} - - -function nextToAnyBlock(){ - return blockAt(lastx,lasty + 1) - || blockAt(lastx,lasty - 1) - || blockAt(lastx + 1,lasty) - || blockAt(lastx - 1,lasty) ; -} - -function wallHolding(){ - - if(!holding) - return; - - if(stamina < 100) - return letGo(); - - if(nextToAnyBlock()){ - holdOn(); - stamina -= 10; - } -} - - -function graviFunnel(unit){ - - const block = blockAt(lastx,lasty); - - if(block != Blocks.pulseConduit) - return; - - holdOn(); - - const offset = directToOffset(block.build.rotation); - - unit.vel.add( - -.55 * offset[0] , - -.55 * offset[1] - ); -} - - -function antiGravField(unit){ - - if(unitOn(unit,Blocks.shockMine)) - holdOn(); -} - - - -function checkInteractables(unit){ - - gravipad(unit); - gelJump(unit); - gelStick(unit); - wallHolding(); - graviFunnel(unit); - antiGravField(unit); -} - - -function update(){ - - unit = Vars.player.unit(); - - if(!canParkour(unit)) - return; - - try { - - lastx = unit.tileX(); - lasty = unit.tileY(); - - if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - - checkInteractables(unit); - - if(!hold && mode == 0) - updateGravity(); - - } catch(error) { logError(error) } - - letGo(); -} - - -Log.info('Running update task'); - - -Timer.schedule(() => { - - if(!isEnabled) - return - - unit = Vars.player.unit(); - - if(!canParkour(unit)) - return; - - update(); - updateHud(); - updateFloor(); - - if(hold || mode != 1) - return; - - gravityCenter(unit); - -},0,.02); - - -Log.info('Done initialisation of parkour-mod.'); diff --git a/Source/Logger.js b/scripts/Logger.js similarity index 69% rename from Source/Logger.js rename to scripts/Logger.js index 1fd8484..755d1a1 100644 --- a/Source/Logger.js +++ b/scripts/Logger.js @@ -1,6 +1,6 @@ -export function logError(error){ +function logError(error){ Log.err( '[ Parkour Mod ]\n\n' + error.message + @@ -9,3 +9,10 @@ export function logError(error){ '\n' ); } + + + + +exports = { + logError : logError +} diff --git a/scripts/main.js b/scripts/main.js index 861078b..d649385 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,346 +1,542 @@ -(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { - const height = ButtonStyle.half, - width = ButtonStyle.full; - const menu_a = new Table().bottom().left(), - menu_b = new Table().bottom().left(); - let button_enable = TextButton("Enable Parkour Mode"), - button_hold = TextButton("Hold"); - menu_a.y = height; - let button_mode = TextButton("Change Mode"); - menu_a.add(button_enable).size(width, height).padLeft(6); - button_enable.clicked(() => { - unit = Vars.player.unit(); - if (!unit || unit.type.flying) { - Vars.ui.announce("You cannot use parkour mode outside of a flying unit."); - return; - } +const ButtonStyle = { + full : 150 , + half : 75 +} - isEnabled = !isEnabled; - button_enable.setText(isEnabled ? "Disable Parkour Mod" : "Enable Parkour Mod"); - }); - menu_b.add(button_mode).size(width, height).padLeft(6); - button_mode.clicked(() => { - if (mode) { - mode = 0; - Vars.ui.announce("Parkour Mode"); - return; - } - Vars.ui.showCustomConfirm("IN DEVELOPMENT!", "You trying to select [accent]Planet[] mode, but it is still buggy and in very development.", "Turn this thing on!", "Back", () => { - mode = 1; - Vars.ui.announce("Planet mode"); - }, () => { - mode = 0; - Vars.ui.announce("Parkour mode"); +Log.info(typeof Blocks.titaniumWall) + + + +Log.info('Started loading of parkour mechanics'); +Log.info('Loading ui elements'); + +Events.on(ClientLoadEvent,() => { + + const + height = ButtonStyle.half , + width = ButtonStyle.full ; + + const + menu_a = new Table().bottom().left() , + menu_b = new Table().bottom().left() ; + + let + button_enable = TextButton('Enable Parkour Mode') , + button_hold = TextButton('Hold') ; + + menu_a.y = height; + + let button_mode = TextButton('Change Mode'); + + menu_a + .add(button_enable) + .size(width,height) + .padLeft(6); + + button_enable.clicked(() => { + + unit = Vars.player.unit(); + + if(!unit || unit.type.flying){ + Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); + return; + } + + isEnabled = ! isEnabled; + + button_enable.setText(isEnabled + ? 'Disable Parkour Mod' + : 'Enable Parkour Mod' ); }); - }); - - if (Vars.mobile || indev) { - let button_jump = TextButton("Jump"); - menu_b.add(button_jump).size(width, height).padLeft(6); - button_jump.clicked(() => { - if (stamina > 99 && onfloor) { - jump(bjumpvel + ajumpvel); - stamina -= 100; - } + + menu_b + .add(button_mode) + .size(width,height) + .padLeft(6); + + button_mode.clicked(() => { + + if(mode){ + mode = 0; + Vars.ui.announce('Parkour Mode'); + return; + } + + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce('Planet mode'); + }, + () => { + mode = 0; + Vars.ui.announce('Parkour mode'); + }); }); - } - menu_b.add(button_hold).size(width, height).padLeft(6); - button_hold.clicked(() => holding = !holding); + if(Vars.mobile || indev){ + + let button_jump = TextButton('Jump'); + + menu_b + .add(button_jump) + .size(width,height) + .padLeft(6); + + button_jump.clicked(() => { + if(stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } + }); + } - menu_b.visibility = () => isEnabled; + menu_b + .add(button_hold) + .size(width,height) + .padLeft(6); + + button_hold.clicked(() => holding = ! holding); - const menus = Vars.ui.hudGroup; - menus.addChild(menu_a); - menus.addChild(menu_b); + menu_b.visibility = () => isEnabled; + + const menus = Vars.ui.hudGroup; + + menus.addChild(menu_a); + menus.addChild(menu_b); }); -Log.info("Loading variables"); -let gravity = .5; // скорость гравитации -let bjumpvel = 15; // скорость прыжка -let ajumpvel = 0; // доп. скорость прыжка +Log.info('Loading variables'); +let gravity = .5; // скорость гравитации +let bjumpvel = 15; // скорость прыжка +let ajumpvel = 0; // доп. скорость прыжка let direction = 0; // 0 - Y, 1 - X - let stamina = 10000; // выносливость - -let onfloor = false; +let onfloor = false; let lastx; let lasty; let ltilex; let ltiley; let unit; let mode = 0; // 0 - обычный, 1 - центр тяжести - let holding = false; + + /* -* 0 : Right -* 1 : Up -* 2 : Left -* 3 : Down -*/ + * 0 : Right + * 1 : Up + * 2 : Left + * 3 : Down + */ let gravitation = 3; + + + let hold = false; -function holdOn() { - hold = true; + +function holdOn(){ + hold = true; } -function letGo() { - hold = false; +function letGo(){ + hold = false; } -Log.info("Loading main content"); -function canParkour(unit) { - return unit && !unit.type.flying; -} +Log.info('Loading main content'); -function tileAt(x, y) { - return Vars.world.tile(x, y) || false; -} -function blockAt(x, y) { - const block = tileAt(x, y); - return block && block.type != Blocks.air ? block : false; +function canParkour(unit){ + return unit && ! unit.type.flying; } -function tileIs(x, y, type) { - return tileAt(x, y) == type; + +function tileAt(x,y){ + return Vars.world.tile(x,y) || false; } -function unitOn(unit, type) { - return tileIs(unit.tileX(), unit.tileY(), type); +function blockAt(x,y){ + + const block = tileAt(x,y); + + return (block && block.type != Blocks.air) + ? block : false ; } -function unitNear(unit, type) { - return relativeBlock() == type; +function tileIs(x,y,type){ + return tileAt(x,y) == type; } -const offsets = [[+1, 0], [0, +1], [-1, 0], [0, -1]]; +function unitOn(unit,type){ + return tileIs(unit.tileX(),unit.tileY(),type); +} -const directToOffset = direction => offsets[direction]; +function unitNear(unit,type){ + return relativeBlock() == type; +} -function relativeTile() { - const offset = directToOffset(gravitation); - return tileAt(lastx + offset[0], lasty + offset[1]); +const offsets = [ + [ +1 , 0 ] , + [ 0 , +1 ] , + [ -1 , 0 ] , + [ 0 , -1 ] +] + +const directToOffset = (direction) => + offsets[direction]; + +function relativeTile(){ + + const offset = directToOffset(gravitation); + + return tileAt( + lastx + offset[0] , + lasty + offset[1] + ); } -function relativeBlock() { - const tile = relativeTile(); - return tile ? tile.block() : false; +function relativeBlock(){ + + const tile = relativeTile(); + + return (tile) + ? tile.block() + : false ; } -function setGravity(value) { - gravity = value; - jump = -value * 10; + +function setGravity(value){ + gravity = value; + jump = -value * 10 } -function updateHud() { - let percent = stamina / 100; - percent = percent - percent % 1; - Vars.ui.showInfoToast("Stamina:" + percent + "%", .04); + +function updateHud(){ + + let percent = stamina / 100; + + percent = percent - percent % 1; + + Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); } -function isFloorSolid() { - const block = relativeBlock(); - return block ? block.solid : false; + + +function isFloorSolid(){ + + const block = relativeBlock(); + + return (block) + ? block.solid + : false ; } const updateFloor = () => { - onfloor = isFloorSolid(); + + onfloor = isFloorSolid(); + + if(onfloor){ + + stamina += 100; + + if(stamina > 10000) + stamina = 10000; + + ltilex = lastx; + ltiley = lasty; + + const vertical = gravitation % 2; + + let + x = unit.vel.x , + y = unit.vel.y ; + + if(vertical && (gravitation === 1 ? y > 0 : y < 0)) + y = 0; + + if(!vertical && (gravitation === 0 ? x > 0 : x < 0)) + y = 0; + + + unit.vel.set(x,y); + } +} - if (onfloor) { - stamina += 100; - if (stamina > 10000) stamina = 10000; - ltilex = lastx; - ltiley = lasty; - const vertical = gravitation % 2; - let x = unit.vel.x, - y = unit.vel.y; - if (vertical && (gravitation === 1 ? y > 0 : y < 0)) y = 0; - if (!vertical && (gravitation === 0 ? x > 0 : x < 0)) y = 0; - unit.vel.set(x, y); - } -}; - -function updateGravity() { - const offset = directToOffset(gravitation); - unit.vel.add(gravity * offset[0], gravity * offset[1]); + +function updateGravity(){ + + const offset = directToOffset(gravitation); + + unit.vel.add( + gravity * offset[0] , + gravity * offset[1] + ); } -const jumpOffset = [[-1, 0], [0, -1], [+1, 0], [0, +1]]; -function jump(velocity) { - const offset = jumpOffset[gravitation]; - unit.vel.add(velocity * offset[0], velocity * offset[1]); +const jumpOffset = [ + [ -1 , 0 ] , + [ 0 , -1 ] , + [ +1 , 0 ] , + [ 0 , +1 ] +] + +function jump(velocity){ + + const offset = jumpOffset[gravitation]; + + unit.vel.add( + velocity * offset[0] , + velocity * offset[1] + ); } -function gravipad(unit) { - if (unitOn(unit, Blocks.conveyor)) gravitation = tileAt(lastx, lasty).build.rotation; + +function gravipad(unit){ + if(unitOn(unit,Blocks.conveyor)) + gravitation = tileAt(lastx,lasty).build.rotation; } -const gravityCenter = unit => { - let coordinates = []; - distances = [], nolock = false; - if (onfloor) return; - if (hold) return; - for (let y = -15; y < 16; y++) for (let x = -15; x < 16; x++) if (blockAt(lastx + x, lasty + y) == Blocks.thoriumWall) { - coordinates.push({ - x: x, - y: y - }); - nolock = true; - } - - if (!nolock) return; - - for (let c = 0; c < coordinates.length; c++) { - const distance = Math.sqrt((lastx + coordinates[c].x - lastx ^ 2) + (lasty + coordinates[c].y - lasty ^ 2)); - distances.push(distance); - } - - let shortest = 0; - - for (let d = 0; d < distances.length; d++) if (distances[d] < distances[shortest]) shortest = d; - - const x = coordinates[shortest].x, - y = coordinates[shortest].y; - const vertical = gravitation % 2; - const position = vertical ? y : x; - if (position === 0) return; - unit.vel.add(!vertical * gravity, vertical * gravity); - gravitation = vertical + (position < 0) * 2; -}; - -function gelJump(unit) { - if (unitNear(unit, Blocks.titaniumWall)) { - ajumpvel = 0; - return; - } - - const vertical = gravitation % 2; - const isSame = vertical ? ltiley == lasty : ltilex == lastx; - ajumpvel = isSame ? 15 : 0; - if (isSame) return; - jump(bjumpvel + 15); +const gravityCenter = (unit) => { + + let + coordinates = [] ; + distances = [] , + nolock = false ; + + if(onfloor) + return; + + if(hold) + return + + for(let y = -15;y < 16;y++) + for(let x = -15;x < 16;x++) + if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ + coordinates.push({ x : x , y : y }); + nolock = true; + } + + if(!nolock) + return; + + for(let c = 0;c < coordinates.length;c++){ + + const distance = Math.sqrt( + ((lastx + coordinates[c].x - lastx) ^ 2) + + ((lasty + coordinates[c].y - lasty) ^ 2) ); + + distances.push(distance); + } + + let shortest = 0; + + for(let d = 0;d < distances.length;d++) + if(distances[d] < distances[shortest]) + shortest = d; + + const + x = coordinates[shortest].x , + y = coordinates[shortest].y ; + + const vertical = gravitation % 2; + + const position = vertical + ? y : x ; + + if(position === 0) + return; + + unit.vel.add( + ! vertical * gravity , + vertical * gravity + ); + + gravitation = vertical + (position < 0) * 2; } -function gelStick(unit) { - const offsets = [-1, 0, +1]; - for (let x = 0; x < 2; x++) for (let y = 0; y < 2; y++) { - const offsetX = offsets[x], - offsetY = offsets[y]; - if (blockAt(lastx + offsetX, lasty + offsetY) !== Blocks.plastaniumWall) return; - holdOn(); - if (Core.input.keyTab(Binding.pause) && stamina > 99) unit.vel.add(-offsetX * 15, -offsetY * 15); - return; - } +function gelJump(unit){ + + if(unitNear(unit,Blocks.titaniumWall)){ + ajumpvel = 0; + return; + } + + const vertical = gravitation % 2; + + + const isSame = (vertical) + ? ltiley == lasty + : ltilex == lastx ; + + ajumpvel = (isSame) + ? 15 : 0 ; + + if(isSame) + return; + + jump(bjumpvel + 15); } -function nextToAnyBlock() { - return blockAt(lastx, lasty + 1) || blockAt(lastx, lasty - 1) || blockAt(lastx + 1, lasty) || blockAt(lastx - 1, lasty); + +function gelStick(unit){ + + const offsets = [ -1 , 0 , +1 ]; + + for(let x = 0;x < 2;x++) + for(let y = 0;y < 2;y++){ + + const + offsetX = offsets[x] , + offsetY = offsets[y] ; + + if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) + return; + + holdOn(); + + if(Core.input.keyTab(Binding.pause) && stamina > 99) + unit.vel.add( + - offsetX * 15 , + - offsetY * 15 + ); + + return; + } } -function wallHolding() { - if (!holding) return; - if (stamina < 100) return letGo(); - if (nextToAnyBlock()) { - holdOn(); - stamina -= 10; - } +function nextToAnyBlock(){ + return blockAt(lastx,lasty + 1) + || blockAt(lastx,lasty - 1) + || blockAt(lastx + 1,lasty) + || blockAt(lastx - 1,lasty) ; } -function graviFunnel(unit) { - const block = blockAt(lastx, lasty); - if (block != Blocks.pulseConduit) return; - holdOn(); - const offset = directToOffset(block.build.rotation); - unit.vel.add(-.55 * offset[0], -.55 * offset[1]); +function wallHolding(){ + + if(!holding) + return; + + if(stamina < 100) + return letGo(); + + if(nextToAnyBlock()){ + holdOn(); + stamina -= 10; + } } -function antiGravField(unit) { - if (unitOn(unit, Blocks.shockMine)) holdOn(); + +function graviFunnel(unit){ + + const block = blockAt(lastx,lasty); + + if(block != Blocks.pulseConduit) + return; + + holdOn(); + + const offset = directToOffset(block.build.rotation); + + unit.vel.add( + -.55 * offset[0] , + -.55 * offset[1] + ); } -function checkInteractables(unit) { - gravipad(unit); - gelJump(unit); - gelStick(unit); - wallHolding(); - graviFunnel(unit); - antiGravField(unit); + +function antiGravField(unit){ + + if(unitOn(unit,Blocks.shockMine)) + holdOn(); } -function update() { - unit = Vars.player.unit(); - if (!canParkour(unit)) return; - try { - lastx = unit.tileX(); - lasty = unit.tileY(); - if (Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor) { - jump(bjumpvel + ajumpvel); - stamina -= 100; - } +function checkInteractables(unit){ + + gravipad(unit); + gelJump(unit); + gelStick(unit); + wallHolding(); + graviFunnel(unit); + antiGravField(unit); +} - checkInteractables(unit); - if (!hold && mode == 0) updateGravity(); - } catch (error) { - (0, _Logger.logError)(error); - } - letGo(); +function update(){ + + unit = Vars.player.unit(); + + if(!canParkour(unit)) + return; + + try { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } + + checkInteractables(unit); + + if(!hold && mode == 0) + updateGravity(); + + } catch(error) { logError(error) } + + letGo(); } -Log.info("Running update task"); + +Log.info('Running update task'); + + Timer.schedule(() => { - if (!isEnabled) return; - unit = Vars.player.unit(); - if (!canParkour(unit)) return; - update(); - updateHud(); - updateFloor(); - if (hold || mode != 1) return; - gravityCenter(unit); -}, 0, .02); -Log.info("Done initialisation of parkour-mod."); - -},{"./Logger.js":1}]},{},[2]); + + if(!isEnabled) + return + + unit = Vars.player.unit(); + + if(!canParkour(unit)) + return; + + update(); + updateHud(); + updateFloor(); + + if(hold || mode != 1) + return; + + gravityCenter(unit); + +},0,.02); + + +Log.info('Done initialisation of parkour-mod.'); From e522903a2e6ab8c28135b80b9fe4e454aa102d9b Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Mon, 18 Jul 2022 04:33:26 -0400 Subject: [PATCH 14/22] More Refactoring --- scripts/Logger.js | 9 +- scripts/main.js | 239 +++++++++++++++++++++++++++------------------- 2 files changed, 147 insertions(+), 101 deletions(-) diff --git a/scripts/Logger.js b/scripts/Logger.js index 755d1a1..bb27315 100644 --- a/scripts/Logger.js +++ b/scripts/Logger.js @@ -11,8 +11,11 @@ function logError(error){ } +function info(values){ + Log.info(values.join('\n')); +} -exports = { - logError : logError -} + +exports.logError = logError; +exports.info = info; diff --git a/scripts/main.js b/scripts/main.js index d649385..2c33477 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,5 +1,5 @@ -const { logError } = require('Logger'); +const { logError , info } = require('Logger'); /* @@ -9,117 +9,146 @@ const { logError } = require('Logger'); let indev = true ; let isEnabled = false; -const ButtonStyle = { - full : 150 , - half : 75 -} +const needsJumpUI = + Vars.mobile || indev; -Log.info(typeof Blocks.titaniumWall) +let button_enable; -Log.info('Started loading of parkour mechanics'); -Log.info('Loading ui elements'); +info([ + 'Started loading of parkour mechanics' , + 'Loading ui elements' +]) -Events.on(ClientLoadEvent,() => { - - const - height = ButtonStyle.half , - width = ButtonStyle.full ; +function toggleMod(){ - const - menu_a = new Table().bottom().left() , - menu_b = new Table().bottom().left() ; + unit = Vars.player.unit(); - let - button_enable = TextButton('Enable Parkour Mode') , - button_hold = TextButton('Hold') ; + if(!unit || unit.type.flying){ + Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); + return; + } - menu_a.y = height; + isEnabled = ! isEnabled; - let button_mode = TextButton('Change Mode'); + button_enable.setText(isEnabled + ? 'Disable Parkour Mod' + : 'Enable Parkour Mod' ); +} + +function toggleMode(){ - menu_a - .add(button_enable) - .size(width,height) - .padLeft(6); + if(mode){ + mode = 0; + Vars.ui.announce('Parkour Mode'); + return; + } - button_enable.clicked(() => { - - unit = Vars.player.unit(); - - if(!unit || unit.type.flying){ - Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); - return; - } - - isEnabled = ! isEnabled; + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce('Planet mode'); + }, + () => { + mode = 0; + Vars.ui.announce('Parkour mode'); + }); +} + +function table(){ + + const table = new Table() + .bottom() + .left(); - button_enable.setText(isEnabled - ? 'Disable Parkour Mod' - : 'Enable Parkour Mod' ); - }); + Vars.ui.hudGroup.addChild(table); + + return table; +} + +function button(options){ + + const { menu , name , click } = options; + + const button = TextButton(name); - menu_b - .add(button_mode) - .size(width,height) + menu + .add(button) + .size(150,75) .padLeft(6); - button_mode.clicked(() => { - - if(mode){ - mode = 0; - Vars.ui.announce('Parkour Mode'); - return; - } - - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce('Planet mode'); - }, - () => { - mode = 0; - Vars.ui.announce('Parkour mode'); - }); - }); + button.clicked(click); + + return button; +} - if(Vars.mobile || indev){ - - let button_jump = TextButton('Jump'); - - menu_b - .add(button_jump) - .size(width,height) - .padLeft(6); +function pressJump(){ + + if(stamina < 100) + return; - button_jump.clicked(() => { - if(stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - }); - } + if(!onfloor) + return; + + jump(bjumpvel + ajumpvel); - menu_b - .add(button_hold) - .size(width,height) - .padLeft(6); + stamina -= 100; +} + +function toggleHold(){ + holding = ! holding; +} + +function buildHUD(){ - button_hold.clicked(() => holding = ! holding); + buildMainMenu(); + buildSubMenu(); +} - menu_b.visibility = () => isEnabled; +function buildMainMenu(){ + + const menu = table(); + menu.y = 75; + + button_enable = button({ + menu : menu , + name : 'Enable Parkour Mode' , + click : toggleMod + }); +} - const menus = Vars.ui.hudGroup; +function buildSubMenu(){ + + const menu = table() ; + menu.visibility = () => isEnabled; - menus.addChild(menu_a); - menus.addChild(menu_b); -}); + button({ + menu : menu , + name : 'Change Mode' , + click : toggleMode + }); + + if(needsJumpUI) + button({ + menu : menu , + name : 'Jump' , + click : pressJump + }); + + button({ + menu : menu , + name : 'Hold' , + click : toggleHold + }); +} + +Events.on(ClientLoadEvent,buildHUD); Log.info('Loading variables'); @@ -317,19 +346,28 @@ function gravipad(unit){ } -const gravityCenter = (unit) => { - - let - coordinates = [] ; - distances = [] , - nolock = false ; +const square = (value) => + value * value; + +function delta(ax,ay,bx,by){ + return Math.sqrt( + square(ax + bx) + + square(ay + by) + ); +} + +function gravityCenter(unit){ + if(onfloor) return; if(hold) return + const coordinates = []; + let nolock = false; + for(let y = -15;y < 16;y++) for(let x = -15;x < 16;x++) if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ @@ -339,12 +377,17 @@ const gravityCenter = (unit) => { if(!nolock) return; + + const distances = []; for(let c = 0;c < coordinates.length;c++){ - const distance = Math.sqrt( - ((lastx + coordinates[c].x - lastx) ^ 2) + - ((lasty + coordinates[c].y - lasty) ^ 2) ); + const cord = coordinates[c]; + + const distance = delta( + cord.x , cord.y , + lastx , lasty + ); distances.push(distance); } From a86d073f0a309d314b3a3e4214b2b911d51c4e9c Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Thu, 21 Jul 2022 11:11:31 -0400 Subject: [PATCH 15/22] Replaced Stamina Toast With Label --- scripts/main.js | 70 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/scripts/main.js b/scripts/main.js index 2c33477..aed0bf4 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -109,6 +109,7 @@ function buildHUD(){ buildMainMenu(); buildSubMenu(); + buildStaminaMenu(); } function buildMainMenu(){ @@ -148,6 +149,29 @@ function buildSubMenu(){ }); } +let label_stamina; + +function buildStaminaMenu(){ + + Log.info('[cyan]Builing Stamina Menu') + + const menu_stamina = new Table() + .left() + .bottom(); + + menu_stamina.visibility = () => isEnabled; + menu_stamina.y = 400; + + label_stamina = Label(''); + label_stamina.setStyle(Styles.outlineLabel); + + menu_stamina.add(label_stamina) + .size(150,75) + .padLeft(6); + + Vars.ui.hudGroup.addChild(menu_stamina); +} + Events.on(ClientLoadEvent,buildHUD); @@ -261,11 +285,14 @@ function setGravity(value){ function updateHud(){ + if(!canWork()) + return; + let percent = stamina / 100; percent = percent - percent % 1; - Vars.ui.showInfoToast('Stamina:' + percent + '%',.04); + label_stamina.setText('Stamina:' + percent + '%'); } @@ -357,13 +384,10 @@ function delta(ax,ay,bx,by){ } -function gravityCenter(unit){ +function gravityCenter(){ - if(onfloor) + if(onfloor || hold) return; - - if(hold) - return const coordinates = []; let nolock = false; @@ -556,30 +580,36 @@ function update(){ letGo(); } +function player(){ + return Vars.player.unit() +} -Log.info('Running update task'); - +function canWork(){ + return isEnabled && canParkour(player()); +} -Timer.schedule(() => { - - if(!isEnabled) - return - - unit = Vars.player.unit(); +function tick(){ - if(!canParkour(unit)) + if(!canWork()) return; - + + unit = player(); + update(); - updateHud(); updateFloor(); if(hold || mode != 1) return; - gravityCenter(unit); - -},0,.02); + gravityCenter(); +} + + +Log.info('Running update task'); + + +Timer.schedule(tick,0,.02); +Timer.schedule(updateHud,0,.1); Log.info('Done initialisation of parkour-mod.'); From 6ae443b925e8cca129085c837b941f524886405c Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Thu, 21 Jul 2022 12:19:46 -0400 Subject: [PATCH 16/22] Separated Some Code --- scripts/Gravity.js | 36 ++++++++++++ scripts/Logger.js | 35 ++++++++++++ scripts/Tile.js | 23 ++++++++ scripts/main.js | 134 ++++++++++++++++++++++----------------------- 4 files changed, 160 insertions(+), 68 deletions(-) create mode 100644 scripts/Gravity.js create mode 100644 scripts/Tile.js diff --git a/scripts/Gravity.js b/scripts/Gravity.js new file mode 100644 index 0000000..425def7 --- /dev/null +++ b/scripts/Gravity.js @@ -0,0 +1,36 @@ + +module.exports = (() => { + + const global = this; + + + if(global.Gravity) + return global.Gravity; + + + /* + * 0 : Right + * 1 : Up + * 2 : Left + * 3 : Down + */ + + let direction = 3; + + + let strength = .5; + + + const Gravity = {}; + + + Gravity.__defineGetter__('direction',() => direction); + Gravity.__defineGetter__('strength',() => strength); + + Gravity.__defineSetter__('direction',(value) => direction = value); + Gravity.__defineSetter__('strength',(value) => strength = value); + + + return global.Gravity = Gravity; + +})(); diff --git a/scripts/Logger.js b/scripts/Logger.js index bb27315..aca2901 100644 --- a/scripts/Logger.js +++ b/scripts/Logger.js @@ -17,5 +17,40 @@ function info(values){ +function valueToString(key,value,depth){ + + switch(typeof value){ + default: + return 'Unknown Type : ' + typeof value; + case 'undefined': + case 'string': + case 'number': + return key + ' : ' + value; + case 'object': + return layer(value,depth - 1); + case 'array': + return value.join(' : '); + case 'function': + return key + '()'; + } +} + +function layer(object,depth,string){ + + string = string || ''; + + if(depth > 0) + for(let key in object.prototype) + string += '\n' + valueToString(key,object[key],depth); + + return string; +} + +function object(object,depth){ + return layer(object,depth || 1); +} + + exports.logError = logError; +exports.object = object; exports.info = info; diff --git a/scripts/Tile.js b/scripts/Tile.js new file mode 100644 index 0000000..6e081c5 --- /dev/null +++ b/scripts/Tile.js @@ -0,0 +1,23 @@ + + + +function tileAt(x,y){ + return Vars.world.tile(x,y) || false; +} + +function blockAt(x,y){ + + const block = tileAt(x,y); + + return (block && block.type != Blocks.air) + ? block : false ; +} + +function tileIs(x,y,type){ + return tileAt(x,y) == type; +} + + +exports.blockAt = blockAt; +exports.tileAt = tileAt; +exports.tileIs = tileIs; diff --git a/scripts/main.js b/scripts/main.js index aed0bf4..65928f1 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,5 +1,44 @@ +const { logError , object ,info } = require('Logger'); -const { logError , info } = require('Logger'); + + +const { blockAt , tileIs , tileAt } = require('Tile'); + +const Gravity = require('Gravity'); + + +const offsets = [ + [ +1 , 0 ] , + [ 0 , +1 ] , + [ -1 , 0 ] , + [ 0 , -1 ] +] + +const directToOffset = (direction) => + offsets[direction]; + +function relativeTile(){ + + Log.info('Gravity: ' + Gravity.direction); + + return; + + const offset = directToOffset(Gravity.direction); + + return tileAt( + lastx + offset[0] , + lasty + offset[1] + ); +} + +function relativeBlock(){ + + const tile = relativeTile(); + + return (tile) + ? tile.block() + : false ; +} /* @@ -177,29 +216,29 @@ Events.on(ClientLoadEvent,buildHUD); Log.info('Loading variables'); -let gravity = .5; // скорость гравитации let bjumpvel = 15; // скорость прыжка let ajumpvel = 0; // доп. скорость прыжка -let direction = 0; // 0 - Y, 1 - X let stamina = 10000; // выносливость -let onfloor = false; let lastx; let lasty; let ltilex; let ltiley; let unit; -let mode = 0; // 0 - обычный, 1 - центр тяжести -let holding = false; - /* - * 0 : Right - * 1 : Up - * 2 : Left - * 3 : Down + * Gravity + * 0 : Downwards + * 1 : Central */ -let gravitation = 3; +let mode = 0; + +let + holding = false , + onfloor = false ; + + + @@ -223,21 +262,7 @@ function canParkour(unit){ } -function tileAt(x,y){ - return Vars.world.tile(x,y) || false; -} -function blockAt(x,y){ - - const block = tileAt(x,y); - - return (block && block.type != Blocks.air) - ? block : false ; -} - -function tileIs(x,y,type){ - return tileAt(x,y) == type; -} function unitOn(unit,type){ return tileIs(unit.tileX(),unit.tileY(),type); @@ -247,38 +272,11 @@ function unitNear(unit,type){ return relativeBlock() == type; } -const offsets = [ - [ +1 , 0 ] , - [ 0 , +1 ] , - [ -1 , 0 ] , - [ 0 , -1 ] -] - -const directToOffset = (direction) => - offsets[direction]; -function relativeTile(){ - - const offset = directToOffset(gravitation); - - return tileAt( - lastx + offset[0] , - lasty + offset[1] - ); -} - -function relativeBlock(){ - - const tile = relativeTile(); - - return (tile) - ? tile.block() - : false ; -} function setGravity(value){ - gravity = value; + Gravity.strength = value; jump = -value * 10 } @@ -292,7 +290,7 @@ function updateHud(){ percent = percent - percent % 1; - label_stamina.setText('Stamina:' + percent + '%'); + label_stamina.setText('Stamina: ' + percent + '%'); } @@ -320,16 +318,16 @@ const updateFloor = () => { ltilex = lastx; ltiley = lasty; - const vertical = gravitation % 2; + const vertical = Gravity.direction % 2; let x = unit.vel.x , y = unit.vel.y ; - if(vertical && (gravitation === 1 ? y > 0 : y < 0)) + if(vertical && (Gravity.direction === 1 ? y > 0 : y < 0)) y = 0; - if(!vertical && (gravitation === 0 ? x > 0 : x < 0)) + if(!vertical && (Gravity.direction === 0 ? x > 0 : x < 0)) y = 0; @@ -340,11 +338,11 @@ const updateFloor = () => { function updateGravity(){ - const offset = directToOffset(gravitation); + const offset = directToOffset(Gravity.direction); unit.vel.add( - gravity * offset[0] , - gravity * offset[1] + Gravity.strength * offset[0] , + Gravity.strength * offset[1] ); } @@ -358,7 +356,7 @@ const jumpOffset = [ function jump(velocity){ - const offset = jumpOffset[gravitation]; + const offset = jumpOffset[Gravity.direction]; unit.vel.add( velocity * offset[0] , @@ -369,7 +367,7 @@ function jump(velocity){ function gravipad(unit){ if(unitOn(unit,Blocks.conveyor)) - gravitation = tileAt(lastx,lasty).build.rotation; + Gravity.direction = tileAt(lastx,lasty).build.rotation; } @@ -426,7 +424,7 @@ function gravityCenter(){ x = coordinates[shortest].x , y = coordinates[shortest].y ; - const vertical = gravitation % 2; + const vertical = Gravity.direction % 2; const position = vertical ? y : x ; @@ -435,11 +433,11 @@ function gravityCenter(){ return; unit.vel.add( - ! vertical * gravity , - vertical * gravity + ! vertical * Gravity.strength , + vertical * Gravity.strength ); - gravitation = vertical + (position < 0) * 2; + Gravity.direction = vertical + (position < 0) * 2; } @@ -450,7 +448,7 @@ function gelJump(unit){ return; } - const vertical = gravitation % 2; + const vertical = Gravity.direction % 2; const isSame = (vertical) From 1c51282b9a8d01267183cc5626402d5ce3031425 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:37:37 -0400 Subject: [PATCH 17/22] Better Logging --- scripts/Logger.js | 103 +++--- scripts/Player.js | 36 ++ scripts/UI.js | 31 ++ scripts/main.js | 926 ++++++++++++++++++++++------------------------ 4 files changed, 575 insertions(+), 521 deletions(-) create mode 100644 scripts/Player.js create mode 100644 scripts/UI.js diff --git a/scripts/Logger.js b/scripts/Logger.js index aca2901..5042fca 100644 --- a/scripts/Logger.js +++ b/scripts/Logger.js @@ -1,56 +1,73 @@ +(() => { + + function exception(error){ + Log.err( + '[ Parkour Mod ]\n\n' + + error.message + + '\n\n' + + error.stack + + '\n' + ); + } -function logError(error){ - Log.err( - '[ Parkour Mod ]\n\n' + - error.message + - '\n\n' + - error.stack + - '\n' - ); -} + function log(a,b,c,d,e,f){ -function info(values){ - Log.info(values.join('\n')); -} + const values = [ a , b , c , d , e , f ]; + let value; + while(!(value = values.pop())) + continue; -function valueToString(key,value,depth){ - - switch(typeof value){ - default: - return 'Unknown Type : ' + typeof value; - case 'undefined': - case 'string': - case 'number': - return key + ' : ' + value; - case 'object': - return layer(value,depth - 1); - case 'array': - return value.join(' : '); - case 'function': - return key + '()'; + values.push(value); + + info(values); } -} -function layer(object,depth,string){ - - string = string || ''; - - if(depth > 0) - for(let key in object.prototype) - string += '\n' + valueToString(key,object[key],depth); + function info(values){ + Log.log(Log.LogLevel.none,'[#1e8cbe] Parkour [#DDDDDD]' + values.join(' ')); + } + + + + function valueToString(key,value,depth){ + + switch(typeof value){ + default: + return 'Unknown Type : ' + typeof value; + case 'undefined': + case 'string': + case 'number': + return key + ' : ' + value; + case 'object': + return layer(value,depth - 1); + case 'array': + return value.join(' : '); + case 'function': + return key + '()'; + } + } + + function layer(object,depth,string){ - return string; -} + string = string || ''; + + if(depth > 0) + for(let key in object.prototype) + string += '\n' + valueToString(key,object[key],depth); + + return string; + } -function object(object,depth){ - return layer(object,depth || 1); -} + function object(object,depth){ + return layer(object,depth || 1); + } -exports.logError = logError; -exports.object = object; -exports.info = info; + exports.exception = exception; + exports.info = info; + exports.log = log; + +})(); diff --git a/scripts/Player.js b/scripts/Player.js new file mode 100644 index 0000000..7e5a7b0 --- /dev/null +++ b/scripts/Player.js @@ -0,0 +1,36 @@ + +module.exports = (() => { + + const global = this; + + + if(global.Player) + return global.Player; + + + /* + * 0 : Right + * 1 : Up + * 2 : Left + * 3 : Down + */ + + let direction = 3; + + + let strength = .5; + + + const Player = {}; + + + Gravity.__defineGetter__('direction',() => direction); + Gravity.__defineGetter__('strength',() => strength); + + Gravity.__defineSetter__('direction',(value) => direction = value); + Gravity.__defineSetter__('strength',(value) => strength = value); + + + return global.Player = Player; + +})(); diff --git a/scripts/UI.js b/scripts/UI.js new file mode 100644 index 0000000..8ef3ecb --- /dev/null +++ b/scripts/UI.js @@ -0,0 +1,31 @@ + +function table(){ + + const table = new Table() + .bottom() + .left(); + + Vars.ui.hudGroup.addChild(table); + + return table; +} + +function button(options){ + + const { menu , name , click } = options; + + const button = TextButton(name); + + menu + .add(button) + .size(150,75) + .padLeft(6); + + button.clicked(click); + + return button; +} + + +exports.button = button; +exports.table = table; diff --git a/scripts/main.js b/scripts/main.js index 65928f1..8937bf9 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,613 +1,583 @@ -const { logError , object ,info } = require('Logger'); +{ + const { blockAt , tileIs , tileAt } = require('Tile'); + const { exception , info ,log } = require('Logger'); + const { button , table } = require('UI'); -const { blockAt , tileIs , tileAt } = require('Tile'); -const Gravity = require('Gravity'); + const Gravity = require('Gravity'); + const offsets = [ + [ +1 , 0 ] , + [ 0 , +1 ] , + [ -1 , 0 ] , + [ 0 , -1 ] + ] -const offsets = [ - [ +1 , 0 ] , - [ 0 , +1 ] , - [ -1 , 0 ] , - [ 0 , -1 ] -] + const directToOffset = (direction) => + offsets[direction]; -const directToOffset = (direction) => - offsets[direction]; - -function relativeTile(){ - - Log.info('Gravity: ' + Gravity.direction); - - return; - - const offset = directToOffset(Gravity.direction); - - return tileAt( - lastx + offset[0] , - lasty + offset[1] - ); -} + function relativeTile(){ + + log('Gravity:',Gravity.direction); + + return; + + const offset = directToOffset(Gravity.direction); + + return tileAt( + lastx + offset[0] , + lasty + offset[1] + ); + } -function relativeBlock(){ - - const tile = relativeTile(); - - return (tile) - ? tile.block() - : false ; -} + function relativeBlock(){ + + const tile = relativeTile(); + + return (tile) + ? tile.block() + : false ; + } -/* - * by Deftry, ADI and TheEE - */ + /* + * by Deftry, ADI and TheEE + */ -let indev = true ; -let isEnabled = false; + let indev = true ; + let isEnabled = false; -const needsJumpUI = - Vars.mobile || indev; + const needsJumpUI = + Vars.mobile || indev; -let button_enable; + let button_enable; -info([ - 'Started loading of parkour mechanics' , - 'Loading ui elements' -]) + log('Started loading of parkour mechanics'); + log('Loading ui elements'); -function toggleMod(){ + function toggleMod(){ - unit = Vars.player.unit(); - - if(!unit || unit.type.flying){ - Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); - return; + unit = Vars.player.unit(); + + if(!unit || unit.type.flying){ + Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); + return; + } + + isEnabled = ! isEnabled; + + button_enable.setText(isEnabled + ? 'Disable Parkour Mod' + : 'Enable Parkour Mod' ); } - - isEnabled = ! isEnabled; - - button_enable.setText(isEnabled - ? 'Disable Parkour Mod' - : 'Enable Parkour Mod' ); -} -function toggleMode(){ - - if(mode){ - mode = 0; - Vars.ui.announce('Parkour Mode'); - return; - } - - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce('Planet mode'); - }, - () => { + function toggleMode(){ + + if(mode){ mode = 0; - Vars.ui.announce('Parkour mode'); - }); -} - -function table(){ - - const table = new Table() - .bottom() - .left(); + Vars.ui.announce('Parkour Mode'); + return; + } - Vars.ui.hudGroup.addChild(table); - - return table; -} - -function button(options){ - - const { menu , name , click } = options; - - const button = TextButton(name); - - menu - .add(button) - .size(150,75) - .padLeft(6); - - button.clicked(click); - - return button; -} + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + () => { + mode = 1; + Vars.ui.announce('Planet mode'); + }, + () => { + mode = 0; + Vars.ui.announce('Parkour mode'); + }); + } -function pressJump(){ - - if(stamina < 100) - return; + function pressJump(){ - if(!onfloor) - return; - - jump(bjumpvel + ajumpvel); + if(stamina < 100) + return; + + if(!onfloor) + return; + + jump(bjumpvel + ajumpvel); - stamina -= 100; -} + stamina -= 100; + } -function toggleHold(){ - holding = ! holding; -} + function toggleHold(){ + holding = ! holding; + } -function buildHUD(){ - - buildMainMenu(); - buildSubMenu(); - buildStaminaMenu(); -} + function buildHUD(){ + + buildMainMenu(); + buildSubMenu(); + buildStaminaMenu(); + } -function buildMainMenu(){ - - const menu = table(); - menu.y = 75; - - button_enable = button({ - menu : menu , - name : 'Enable Parkour Mode' , - click : toggleMod - }); -} + function buildMainMenu(){ + + const menu = table(); + menu.y = 75; + + button_enable = button({ + menu : menu , + name : 'Enable Parkour Mode' , + click : toggleMod + }); + } -function buildSubMenu(){ - - const menu = table() ; - menu.visibility = () => isEnabled; - - button({ - menu : menu , - name : 'Change Mode' , - click : toggleMode - }); - - if(needsJumpUI) + function buildSubMenu(){ + + const menu = table() ; + menu.visibility = () => isEnabled; + button({ menu : menu , - name : 'Jump' , - click : pressJump + name : 'Change Mode' , + click : toggleMode }); - - button({ - menu : menu , - name : 'Hold' , - click : toggleHold - }); -} - -let label_stamina; - -function buildStaminaMenu(){ - - Log.info('[cyan]Builing Stamina Menu') - - const menu_stamina = new Table() - .left() - .bottom(); - - menu_stamina.visibility = () => isEnabled; - menu_stamina.y = 400; - - label_stamina = Label(''); - label_stamina.setStyle(Styles.outlineLabel); - - menu_stamina.add(label_stamina) - .size(150,75) - .padLeft(6); - - Vars.ui.hudGroup.addChild(menu_stamina); -} - -Events.on(ClientLoadEvent,buildHUD); - -Log.info('Loading variables'); + if(needsJumpUI) + button({ + menu : menu , + name : 'Jump' , + click : pressJump + }); + + button({ + menu : menu , + name : 'Hold' , + click : toggleHold + }); + } -let bjumpvel = 15; // скорость прыжка -let ajumpvel = 0; // доп. скорость прыжка -let stamina = 10000; // выносливость -let lastx; -let lasty; -let ltilex; -let ltiley; -let unit; + let label_stamina; -/* - * Gravity - * 0 : Downwards - * 1 : Central - */ + function buildStaminaMenu(){ + + log('Builing Stamina Menu') + + const menu_stamina = new Table() + .left() + .bottom(); + + menu_stamina.visibility = () => isEnabled; + menu_stamina.y = 400; + + label_stamina = Label(''); + label_stamina.setStyle(Styles.outlineLabel); + + menu_stamina.add(label_stamina) + .size(150,75) + .padLeft(6); + + Vars.ui.hudGroup.addChild(menu_stamina); + } -let mode = 0; + Events.on(ClientLoadEvent,buildHUD); -let - holding = false , - onfloor = false ; + log('Loading variables'); + let bjumpvel = 15; // скорость прыжка + let ajumpvel = 0; // доп. скорость прыжка + let stamina = 10000; // выносливость + let lastx; + let lasty; + let ltilex; + let ltiley; + let unit; + /* + * Gravity + * 0 : Downwards + * 1 : Central + */ + let mode = 0; + let + holding = false , + onfloor = false ; -let hold = false; + let hold = false; -function holdOn(){ - hold = true; -} -function letGo(){ - hold = false; -} + function holdOn(){ + hold = true; + } + function letGo(){ + hold = false; + } -Log.info('Loading main content'); + log('Loading main content'); -function canParkour(unit){ - return unit && ! unit.type.flying; -} + function canParkour(unit){ + return unit && ! unit.type.flying; + } -function unitOn(unit,type){ - return tileIs(unit.tileX(),unit.tileY(),type); -} -function unitNear(unit,type){ - return relativeBlock() == type; -} + function unitOn(unit,type){ + return tileIs(unit.tileX(),unit.tileY(),type); + } + function unitNear(unit,type){ + return relativeBlock() == type; + } -function setGravity(value){ - Gravity.strength = value; - jump = -value * 10 -} + function setGravity(value){ + Gravity.strength = value; + jump = -value * 10 + } -function updateHud(){ - - if(!canWork()) - return; - - let percent = stamina / 100; - - percent = percent - percent % 1; - - label_stamina.setText('Stamina: ' + percent + '%'); -} + function updateHud(){ + + if(!canWork()) + return; + + let percent = stamina / 100; + + percent = percent - percent % 1; + + label_stamina.setText('Stamina: ' + percent + '%'); + } -function isFloorSolid(){ - - const block = relativeBlock(); - - return (block) - ? block.solid - : false ; -} -const updateFloor = () => { - - onfloor = isFloorSolid(); - - if(onfloor){ + function isFloorSolid(){ - stamina += 100; + const block = relativeBlock(); - if(stamina > 10000) - stamina = 10000; - - ltilex = lastx; - ltiley = lasty; - - const vertical = Gravity.direction % 2; + return (block) + ? block.solid + : false ; + } + + const updateFloor = () => { - let - x = unit.vel.x , - y = unit.vel.y ; + onfloor = isFloorSolid(); - if(vertical && (Gravity.direction === 1 ? y > 0 : y < 0)) - y = 0; + if(onfloor){ + + stamina += 100; + + if(stamina > 10000) + stamina = 10000; + + ltilex = lastx; + ltiley = lasty; + + const vertical = Gravity.direction % 2; + + let + x = unit.vel.x , + y = unit.vel.y ; + + if(vertical && (Gravity.direction === 1 ? y > 0 : y < 0)) + y = 0; + + if(!vertical && (Gravity.direction === 0 ? x > 0 : x < 0)) + y = 0; + + + unit.vel.set(x,y); + } + } + + + function updateGravity(){ - if(!vertical && (Gravity.direction === 0 ? x > 0 : x < 0)) - y = 0; - + const offset = directToOffset(Gravity.direction); - unit.vel.set(x,y); + unit.vel.add( + Gravity.strength * offset[0] , + Gravity.strength * offset[1] + ); } -} -function updateGravity(){ - - const offset = directToOffset(Gravity.direction); - - unit.vel.add( - Gravity.strength * offset[0] , - Gravity.strength * offset[1] - ); -} + const jumpOffset = [ + [ -1 , 0 ] , + [ 0 , -1 ] , + [ +1 , 0 ] , + [ 0 , +1 ] + ] + function jump(velocity){ + + const offset = jumpOffset[Gravity.direction]; + + unit.vel.add( + velocity * offset[0] , + velocity * offset[1] + ); + } -const jumpOffset = [ - [ -1 , 0 ] , - [ 0 , -1 ] , - [ +1 , 0 ] , - [ 0 , +1 ] -] - -function jump(velocity){ - - const offset = jumpOffset[Gravity.direction]; - - unit.vel.add( - velocity * offset[0] , - velocity * offset[1] - ); -} + function gravipad(unit){ + if(unitOn(unit,Blocks.conveyor)) + Gravity.direction = tileAt(lastx,lasty).build.rotation; + } -function gravipad(unit){ - if(unitOn(unit,Blocks.conveyor)) - Gravity.direction = tileAt(lastx,lasty).build.rotation; -} + const square = (value) => + value * value; -const square = (value) => - value * value; + function delta(ax,ay,bx,by){ + return Math.sqrt( + square(ax + bx) + + square(ay + by) + ); + } -function delta(ax,ay,bx,by){ - return Math.sqrt( - square(ax + bx) + - square(ay + by) - ); -} + function gravityCenter(){ + + if(onfloor || hold) + return; -function gravityCenter(){ - - if(onfloor || hold) - return; + const coordinates = []; + let nolock = false; - const coordinates = []; - let nolock = false; + for(let y = -15;y < 16;y++) + for(let x = -15;x < 16;x++) + if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ + coordinates.push({ x : x , y : y }); + nolock = true; + } - for(let y = -15;y < 16;y++) - for(let x = -15;x < 16;x++) - if(blockAt(lastx + x,lasty + y) == Blocks.thoriumWall){ - coordinates.push({ x : x , y : y }); - nolock = true; - } + if(!nolock) + return; + + const distances = []; + + for(let c = 0;c < coordinates.length;c++){ + + const cord = coordinates[c]; + + const distance = delta( + cord.x , cord.y , + lastx , lasty + ); + + distances.push(distance); + } - if(!nolock) - return; + let shortest = 0; - const distances = []; - - for(let c = 0;c < coordinates.length;c++){ + for(let d = 0;d < distances.length;d++) + if(distances[d] < distances[shortest]) + shortest = d; + + const + x = coordinates[shortest].x , + y = coordinates[shortest].y ; + + const vertical = Gravity.direction % 2; - const cord = coordinates[c]; + const position = vertical + ? y : x ; + + if(position === 0) + return; - const distance = delta( - cord.x , cord.y , - lastx , lasty + unit.vel.add( + ! vertical * Gravity.strength , + vertical * Gravity.strength ); - distances.push(distance); + Gravity.direction = vertical + (position < 0) * 2; } - let shortest = 0; - - for(let d = 0;d < distances.length;d++) - if(distances[d] < distances[shortest]) - shortest = d; - const - x = coordinates[shortest].x , - y = coordinates[shortest].y ; + function gelJump(unit){ + + if(unitNear(unit,Blocks.titaniumWall)){ + ajumpvel = 0; + return; + } - const vertical = Gravity.direction % 2; - - const position = vertical - ? y : x ; + const vertical = Gravity.direction % 2; - if(position === 0) - return; - - unit.vel.add( - ! vertical * Gravity.strength , - vertical * Gravity.strength - ); - - Gravity.direction = vertical + (position < 0) * 2; -} - - -function gelJump(unit){ - - if(unitNear(unit,Blocks.titaniumWall)){ - ajumpvel = 0; - return; - } - - const vertical = Gravity.direction % 2; - - - const isSame = (vertical) - ? ltiley == lasty - : ltilex == lastx ; - - ajumpvel = (isSame) - ? 15 : 0 ; - - if(isSame) - return; - jump(bjumpvel + 15); -} + const isSame = (vertical) + ? ltiley == lasty + : ltilex == lastx ; + + ajumpvel = (isSame) + ? 15 : 0 ; + + if(isSame) + return; + + jump(bjumpvel + 15); + } -function gelStick(unit){ + function gelStick(unit){ - const offsets = [ -1 , 0 , +1 ]; - - for(let x = 0;x < 2;x++) - for(let y = 0;y < 2;y++){ - - const - offsetX = offsets[x] , - offsetY = offsets[y] ; - - if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) + const offsets = [ -1 , 0 , +1 ]; + + for(let x = 0;x < 2;x++) + for(let y = 0;y < 2;y++){ + + const + offsetX = offsets[x] , + offsetY = offsets[y] ; + + if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) + return; + + holdOn(); + + if(Core.input.keyTab(Binding.pause) && stamina > 99) + unit.vel.add( + - offsetX * 15 , + - offsetY * 15 + ); + return; - - holdOn(); - - if(Core.input.keyTab(Binding.pause) && stamina > 99) - unit.vel.add( - - offsetX * 15 , - - offsetY * 15 - ); - - return; - } -} + } + } -function nextToAnyBlock(){ - return blockAt(lastx,lasty + 1) - || blockAt(lastx,lasty - 1) - || blockAt(lastx + 1,lasty) - || blockAt(lastx - 1,lasty) ; -} + function nextToAnyBlock(){ + return blockAt(lastx,lasty + 1) + || blockAt(lastx,lasty - 1) + || blockAt(lastx + 1,lasty) + || blockAt(lastx - 1,lasty) ; + } -function wallHolding(){ - - if(!holding) - return; + function wallHolding(){ - if(stamina < 100) - return letGo(); - - if(nextToAnyBlock()){ - holdOn(); - stamina -= 10; + if(!holding) + return; + + if(stamina < 100) + return letGo(); + + if(nextToAnyBlock()){ + holdOn(); + stamina -= 10; + } } -} - -function graviFunnel(unit){ - - const block = blockAt(lastx,lasty); - if(block != Blocks.pulseConduit) - return; + function graviFunnel(unit){ - holdOn(); - - const offset = directToOffset(block.build.rotation); - - unit.vel.add( - -.55 * offset[0] , - -.55 * offset[1] - ); -} - + const block = blockAt(lastx,lasty); -function antiGravField(unit){ - - if(unitOn(unit,Blocks.shockMine)) + if(block != Blocks.pulseConduit) + return; + holdOn(); -} + + const offset = directToOffset(block.build.rotation); + + unit.vel.add( + -.55 * offset[0] , + -.55 * offset[1] + ); + } + function antiGravField(unit){ + + if(unitOn(unit,Blocks.shockMine)) + holdOn(); + } -function checkInteractables(unit){ - - gravipad(unit); - gelJump(unit); - gelStick(unit); - wallHolding(); - graviFunnel(unit); - antiGravField(unit); -} -function update(){ - - unit = Vars.player.unit(); - - if(!canParkour(unit)) - return; - - try { + function checkInteractables(unit){ - lastx = unit.tileX(); - lasty = unit.tileY(); + gravipad(unit); + gelJump(unit); + gelStick(unit); + wallHolding(); + graviFunnel(unit); + antiGravField(unit); + } - if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); - stamina -= 100; - } - checkInteractables(unit); + function update(){ + + unit = Vars.player.unit(); + + if(!canParkour(unit)) + return; - if(!hold && mode == 0) - updateGravity(); + try { + + lastx = unit.tileX(); + lasty = unit.tileY(); + + if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ + jump(bjumpvel + ajumpvel); + stamina -= 100; + } - } catch(error) { logError(error) } + checkInteractables(unit); + + if(!hold && mode == 0) + updateGravity(); - letGo(); -} + } catch(error) { exception(error) } -function player(){ - return Vars.player.unit() -} + letGo(); + } -function canWork(){ - return isEnabled && canParkour(player()); -} + function player(){ + return Vars.player.unit() + } -function tick(){ - - if(!canWork()) - return; - - unit = player(); + function canWork(){ + return isEnabled && canParkour(player()); + } + + function tick(){ - update(); - updateFloor(); + if(!canWork()) + return; + + unit = player(); + + update(); + updateFloor(); - if(hold || mode != 1) - return; + if(hold || mode != 1) + return; + + gravityCenter(); + } - gravityCenter(); -} + log('Running update task'); -Log.info('Running update task'); + Timer.schedule(tick,0,.02); -Timer.schedule(tick,0,.02); + Timer.schedule(updateHud,0,.1); -Timer.schedule(updateHud,0,.1); + log('Done initialisation of parkour-mod.'); -Log.info('Done initialisation of parkour-mod.'); +} From 7f737841d7301e3fe7ce91eb1d43930d48f80182 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:58:22 -0400 Subject: [PATCH 18/22] Debug Logger --- scripts/Debug.js | 2 ++ scripts/Jump.js | 30 ++++++++++++++++++++++ scripts/Logger.js | 38 ++++++++++++++++++++------- scripts/Math.js | 18 +++++++++++++ scripts/main.js | 65 +++++++++++++++-------------------------------- 5 files changed, 99 insertions(+), 54 deletions(-) create mode 100644 scripts/Debug.js create mode 100644 scripts/Jump.js create mode 100644 scripts/Math.js diff --git a/scripts/Debug.js b/scripts/Debug.js new file mode 100644 index 0000000..75b15aa --- /dev/null +++ b/scripts/Debug.js @@ -0,0 +1,2 @@ + +module.exports = true; diff --git a/scripts/Jump.js b/scripts/Jump.js new file mode 100644 index 0000000..19007ce --- /dev/null +++ b/scripts/Jump.js @@ -0,0 +1,30 @@ + +(() => { + + const { debug } = require('Logger'); + const Gravity = require('Gravity'); + + + const offsets = [ + [ -1 , 0 ] , + [ 0 , -1 ] , + [ +1 , 0 ] , + [ 0 , +1 ] + ] + + function jump(unit,velocity){ + + debug('Jumped:',velocity); + + const offset = offsets[Gravity.direction]; + + unit.vel.add( + velocity * offset[0] , + velocity * offset[1] + ); + } + + + exports.jump = jump; + +})(); diff --git a/scripts/Logger.js b/scripts/Logger.js index 5042fca..c6b1f40 100644 --- a/scripts/Logger.js +++ b/scripts/Logger.js @@ -1,6 +1,9 @@ (() => { + const Debug = require('Debug'); + + function exception(error){ Log.err( '[ Parkour Mod ]\n\n' + @@ -12,22 +15,36 @@ } - function log(a,b,c,d,e,f){ - - const values = [ a , b , c , d , e , f ]; - + function parse(values){ + let value; while(!(value = values.pop())) continue; - values.push(value); + values.push(value); + + return values.join(' '); + } + + function debug(a,b,c,d,e,f){ + debugText(parse([ a , b , c , d , e , f ])); + } - info(values); + function log(a,b,c,d,e,f){ + logText(parse([ a , b , c , d , e , f ])); + } + + function debugText(text){ + print('[#dfb317] Parkour [#DDDDDD]' + text); + } + + function logText(text){ + print('[#1e8cbe] Parkour [#DDDDDD]' + text); } - function info(values){ - Log.log(Log.LogLevel.none,'[#1e8cbe] Parkour [#DDDDDD]' + values.join(' ')); + function print(text){ + Log.log(Log.LogLevel.none,text); } @@ -67,7 +84,10 @@ exports.exception = exception; - exports.info = info; exports.log = log; + exports.debug = Debug + ? debug + : () => {}; + })(); diff --git a/scripts/Math.js b/scripts/Math.js new file mode 100644 index 0000000..218386c --- /dev/null +++ b/scripts/Math.js @@ -0,0 +1,18 @@ + +(() => { + + const square = (value) => + value * value; + + function delta(ax,ay,bx,by){ + return Math.sqrt( + square(ax + bx) + + square(ay + by) + ); + } + + + exports.square = square; + exports.delta = delta; + +})(); diff --git a/scripts/main.js b/scripts/main.js index 8937bf9..75cf907 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,8 +1,10 @@ { const { blockAt , tileIs , tileAt } = require('Tile'); - const { exception , info ,log } = require('Logger'); + const { exception , log , debug } = require('Logger'); const { button , table } = require('UI'); + const { delta } = require('Math'); + const { jump } = require('Jump'); @@ -20,10 +22,6 @@ function relativeTile(){ - log('Gravity:',Gravity.direction); - - return; - const offset = directToOffset(Gravity.direction); return tileAt( @@ -40,6 +38,17 @@ ? tile.block() : false ; } + + function isFloorSolid(){ + + const block = relativeBlock(); + + return (block) + ? block.solid + : false ; + } + + /* @@ -107,7 +116,7 @@ if(!onfloor) return; - jump(bjumpvel + ajumpvel); + jump(unit,bjumpvel + ajumpvel); stamina -= 100; } @@ -243,12 +252,6 @@ - function setGravity(value){ - Gravity.strength = value; - jump = -value * 10 - } - - function updateHud(){ if(!canWork()) @@ -263,14 +266,7 @@ - function isFloorSolid(){ - - const block = relativeBlock(); - - return (block) - ? block.solid - : false ; - } + const updateFloor = () => { @@ -315,22 +311,7 @@ } - const jumpOffset = [ - [ -1 , 0 ] , - [ 0 , -1 ] , - [ +1 , 0 ] , - [ 0 , +1 ] - ] - function jump(velocity){ - - const offset = jumpOffset[Gravity.direction]; - - unit.vel.add( - velocity * offset[0] , - velocity * offset[1] - ); - } function gravipad(unit){ @@ -339,15 +320,9 @@ } - const square = (value) => - value * value; + - function delta(ax,ay,bx,by){ - return Math.sqrt( - square(ax + bx) + - square(ay + by) - ); - } + function gravityCenter(){ @@ -429,7 +404,7 @@ if(isSame) return; - jump(bjumpvel + 15); + jump(unit,bjumpvel + 15); } @@ -532,7 +507,7 @@ lasty = unit.tileY(); if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ - jump(bjumpvel + ajumpvel); + jump(unit,bjumpvel + ajumpvel); stamina -= 100; } From 2c30d516a5ec83c1a560ae08bfecd0aeb815de86 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Thu, 21 Jul 2022 15:03:11 -0400 Subject: [PATCH 19/22] Fixed Jumping --- scripts/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/main.js b/scripts/main.js index 75cf907..424188e 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -110,6 +110,8 @@ function pressJump(){ + debug('Pressed Jump') + if(stamina < 100) return; @@ -386,7 +388,7 @@ function gelJump(unit){ - if(unitNear(unit,Blocks.titaniumWall)){ + if(!unitNear(unit,Blocks.titaniumWall)){ ajumpvel = 0; return; } From 2d10abbbf193763144c7c204a0106c4a859b392b Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Fri, 22 Jul 2022 09:46:48 -0400 Subject: [PATCH 20/22] Refactoring + Problem --- scripts/Gravity.js | 14 +-- scripts/Interface.js | 120 +++++++++++++++++++ scripts/Logger.js | 7 +- scripts/Mod.js | 90 ++++++++++++++ scripts/Player.js | 100 ++++++++++++---- scripts/Tile.js | 35 +++--- scripts/UI.js | 54 +++++---- scripts/main.js | 273 +++++++++---------------------------------- 8 files changed, 400 insertions(+), 293 deletions(-) create mode 100644 scripts/Interface.js create mode 100644 scripts/Mod.js diff --git a/scripts/Gravity.js b/scripts/Gravity.js index 425def7..ff3be5e 100644 --- a/scripts/Gravity.js +++ b/scripts/Gravity.js @@ -1,12 +1,8 @@ -module.exports = (() => { - - const global = this; - +module.exports = this._Gravity || init(this); - if(global.Gravity) - return global.Gravity; - + +function init(global){ /* * 0 : Right @@ -31,6 +27,6 @@ module.exports = (() => { Gravity.__defineSetter__('strength',(value) => strength = value); - return global.Gravity = Gravity; + return global._Gravity = Gravity; -})(); +} diff --git a/scripts/Interface.js b/scripts/Interface.js new file mode 100644 index 0000000..35932dd --- /dev/null +++ b/scripts/Interface.js @@ -0,0 +1,120 @@ + + +module.exports = this._Interface || init(this); + + +function init(global){ + + const { button , table } = require('UI'); + const { log , object } = require('Logger'); + + const Player = require('Player'); + const Debug = require('Debug'); + const Mod = require('Mod'); + + + const onMobile = + Vars.mobile || Debug; + + let + button_enable , + label_stamina ; + + + function build(){ + + log('Building UI'); + + buildMainMenu(); + buildSubMenu(); + buildStaminaMenu(); + } + + function buildMainMenu(){ + + const menu = table(); + menu.y = 75; + + button_enable = button({ + menu : menu , + name : 'Enable Parkour Mode' , + click : Mod.toggle + }); + } + + function buildSubMenu(){ + + const menu = table(); + menu.visibility = () => Mod.enabled; + + button({ + menu : menu , + name : 'Change Mode' , + click : Mod.toggleMode + }); + + if(onMobile) + button({ + menu : menu , + name : 'Jump' , + click : Player.jump + }); + + button({ + menu : menu , + name : 'Hold' , + click : Player.toggleHold + }); + } + + + function buildStaminaMenu(){ + + log('Builing Stamina Menu') + + const menu_stamina = new Table() + .left() + .bottom(); + + menu_stamina.visibility = () => Mod.enabled; + menu_stamina.y = 400; + + label_stamina = Label(''); + label_stamina.setStyle(Styles.outlineLabel); + + menu_stamina.add(label_stamina) + .size(150,75) + .padLeft(6); + + Vars.ui.hudGroup.addChild(menu_stamina); + } + + + function updateEnableButton(){ + + const action = (Mod.enabled) + ? 'Disable' + : 'Enable' ; + + button_enable.setText(action + 'Parkour Mode'); + } + + function updateStamina(){ + + const percent = Math.round(Player.stamina / 100); + + label_stamina.setText('Stamina: ' + percent + '%'); + } + + + const Interface = { + updateEnableButton : updateEnableButton , + updateStamina : updateStamina , + build : build , + test : 1 + } + + log('Int',object(Interface)); + + return global._Interface = Interface; +} diff --git a/scripts/Logger.js b/scripts/Logger.js index c6b1f40..a830d49 100644 --- a/scripts/Logger.js +++ b/scripts/Logger.js @@ -69,13 +69,13 @@ function layer(object,depth,string){ - string = string || ''; + string = string || '{'; if(depth > 0) - for(let key in object.prototype) + for(let key in object) string += '\n' + valueToString(key,object[key],depth); - return string; + return string + '}'; } function object(object,depth){ @@ -84,6 +84,7 @@ exports.exception = exception; + exports.object = object; exports.log = log; exports.debug = Debug diff --git a/scripts/Mod.js b/scripts/Mod.js new file mode 100644 index 0000000..4504bd0 --- /dev/null +++ b/scripts/Mod.js @@ -0,0 +1,90 @@ + +module.exports = this._Mod || init(this); + + +function init(global){ + + const { log , object } = require('Logger'); + const Interface = require('Interface'); + const Player = require('Player'); + + log('Interface:',object(Interface)); + + + /* + * Gravity + * 0 : Downwards + * 1 : Central + */ + + let mode = 0; + + let enabled = false; + + + function inParkour(){ + return mode === 0; + } + + function onPlanet(){ + return mode === 1; + } + + function toggle(){ + + const unit = Player.unit(); + + if(!unit || unit.type.flying){ + Vars.ui.announce('You cannot use parkour mode inside of a flying unit.'); + return; + } + + enabled = ! enabled; + + Interface.updateEnableButton(); + } + + function toggleMode(){ + + if(onPlanet()) + return parkour(); + + Vars.ui.showCustomConfirm( + 'IN DEVELOPMENT!' , + 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , + 'Turn this thing on!' , + 'Back' , + planet, + () => {} + ); + } + + function parkour(){ + mode = 0; + Vars.ui.announce('Parkour Mode'); + } + + function planet(){ + mode = 1; + Vars.ui.announce('Planet mode'); + } + + + const Mod = { + toggleMode : toggleMode , + inParkour : inParkour , + onPlanet : onPlanet , + parkour : parkour , + toggle : toggle , + planet : planet + } + + Mod.__defineGetter__('mode',() => mode); + Mod.__defineGetter__('enabled',() => enabled); + + Mod.__defineSetter__('mode',(value) => mode = value); + Mod.__defineSetter__('enabled',(value) => enabled = value); + + + return global._Mod = Mod; +} diff --git a/scripts/Player.js b/scripts/Player.js index 7e5a7b0..2936167 100644 --- a/scripts/Player.js +++ b/scripts/Player.js @@ -1,36 +1,90 @@ -module.exports = (() => { - - const global = this; - - - if(global.Player) - return global.Player; - +module.exports = this._Player || init(this); - /* - * 0 : Right - * 1 : Up - * 2 : Left - * 3 : Down - */ - let direction = 3; +function init(global){ + + const { debug } = require('Logger'); + const Jump = require('Jump'); - let strength = .5; + let + bjumpvel = 15 , + ajumpvel = 0 , + holding = false , + onfloor = false , + stamina = 10000 ; + + let x , y ; + + function toggleHold(){ + + debug('Holding:',holding); + + holding = ! holding; + } + + function jump(){ + + debug('Pressed Jump') + + if(stamina < 100) + return; + + if(!onfloor) + return; + + Jump.jump(unit(),bjumpvel + ajumpvel); - const Player = {}; + stamina -= 100; + } + + function unit(){ + return Vars.player.unit(); + } + + function hasStamina(){ + return stamina > 99; + } + + function updatePosition(){ + + const player = unit(); + + x = player.tileX(); + y = player.tileY(); + } + function canParkour(){ - Gravity.__defineGetter__('direction',() => direction); - Gravity.__defineGetter__('strength',() => strength); + const player = unit(); - Gravity.__defineSetter__('direction',(value) => direction = value); - Gravity.__defineSetter__('strength',(value) => strength = value); + return player && ! player.type.flying; + } - return global.Player = Player; + const Player = { + updatePosition : updatePosition , + hasStamina : hasStamina , + toggleHold : toggleHold , + unit : unit , + jump : jump , + canParkour : canParkour + } + + Player.__defineGetter__('bjumpvel',() => bjumpvel); + Player.__defineGetter__('ajumpvel',() => ajumpvel); + Player.__defineGetter__('holding',() => holding); + Player.__defineGetter__('onfloor',() => onfloor); + Player.__defineGetter__('stamina',() => stamina); + + Player.__defineSetter__('bjumpvel',(value) => bjumpvel = value); + Player.__defineSetter__('ajumpvel',(value) => ajumpvel = value); + Player.__defineSetter__('holding',(value) => holding = value); + Player.__defineSetter__('onfloor',(value) => onfloor = value); + Player.__defineSetter__('stamina',(value) => stamina = value); + + return global._Player = Player; -})(); +} diff --git a/scripts/Tile.js b/scripts/Tile.js index 6e081c5..75dd075 100644 --- a/scripts/Tile.js +++ b/scripts/Tile.js @@ -1,23 +1,26 @@ - -function tileAt(x,y){ - return Vars.world.tile(x,y) || false; -} - -function blockAt(x,y){ +(() => { - const block = tileAt(x,y); + function tileAt(x,y){ + return Vars.world.tile(x,y) || false; + } - return (block && block.type != Blocks.air) - ? block : false ; -} + function blockAt(x,y){ + + const block = tileAt(x,y); -function tileIs(x,y,type){ - return tileAt(x,y) == type; -} + return (block && block.type != Blocks.air) + ? block : false ; + } + function tileIs(x,y,type){ + return tileAt(x,y) == type; + } -exports.blockAt = blockAt; -exports.tileAt = tileAt; -exports.tileIs = tileIs; + + exports.blockAt = blockAt; + exports.tileAt = tileAt; + exports.tileIs = tileIs; + +})(); diff --git a/scripts/UI.js b/scripts/UI.js index 8ef3ecb..2b1b8a9 100644 --- a/scripts/UI.js +++ b/scripts/UI.js @@ -1,31 +1,35 @@ -function table(){ +(() => { - const table = new Table() - .bottom() - .left(); + function table(){ - Vars.ui.hudGroup.addChild(table); - - return table; -} + const table = new Table() + .bottom() + .left(); + + Vars.ui.hudGroup.addChild(table); + + return table; + } -function button(options){ - - const { menu , name , click } = options; - - const button = TextButton(name); - - menu - .add(button) - .size(150,75) - .padLeft(6); - - button.clicked(click); - - return button; -} + function button(options){ + + const { menu , name , click } = options; + + const button = TextButton(name); + + menu + .add(button) + .size(150,75) + .padLeft(6); + + button.clicked(click); + + return button; + } -exports.button = button; -exports.table = table; + exports.button = button; + exports.table = table; + +})(); diff --git a/scripts/main.js b/scripts/main.js index dc6ae77..f06b9e9 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,15 +1,19 @@ +/* + * Original code had been written by Deftry, ADI and TheEE + */ +(() => { -{ const { blockAt , tileIs , tileAt } = require('Tile'); const { exception , log , debug } = require('Logger'); - const { button , table } = require('UI'); + const Interface = require('Interface'); const { delta } = require('Math'); const { jump } = require('Jump'); - - - const Gravity = require('Gravity'); + const Player = require('Player'); + const Debug = require('Debug'); + const Mod = require('Mod'); + const offsets = [ [ +1 , 0 ] , @@ -49,178 +53,24 @@ : false ; } - - - - /* - * by Deftry, ADI and TheEE - */ - - let indev = true ; - let isEnabled = false; - - - const needsJumpUI = - Vars.mobile || indev; - - - let button_enable; - - - log('Started loading of parkour mechanics'); - log('Loading ui elements'); - - function toggleMod(){ - - unit = Vars.player.unit(); - - if(!unit || unit.type.flying){ - Vars.ui.announce('You cannot use parkour mode outside of a flying unit.'); - return; - } - - isEnabled = ! isEnabled; - - button_enable.setText(isEnabled - ? 'Disable Parkour Mod' - : 'Enable Parkour Mod' ); - } - - function toggleMode(){ - - if(mode){ - mode = 0; - Vars.ui.announce('Parkour Mode'); - return; - } - - Vars.ui.showCustomConfirm( - 'IN DEVELOPMENT!' , - 'You trying to select [accent]Planet[] mode, but it is still buggy and in very development.' , - 'Turn this thing on!' , - 'Back' , - () => { - mode = 1; - Vars.ui.announce('Planet mode'); - }, - () => { - mode = 0; - Vars.ui.announce('Parkour mode'); - }); - } - - function pressJump(){ - - debug('Pressed Jump') - - if(stamina < 100) - return; - - if(!onfloor) - return; - - jump(unit,bjumpvel + ajumpvel); - - stamina -= 100; - } - - function toggleHold(){ - holding = ! holding; - } - - function buildHUD(){ - - buildMainMenu(); - buildSubMenu(); - buildStaminaMenu(); - } - - function buildMainMenu(){ - - const menu = table(); - menu.y = 75; - - button_enable = button({ - menu : menu , - name : 'Enable Parkour Mode' , - click : toggleMod - }); - } - - function buildSubMenu(){ - - const menu = table() ; - menu.visibility = () => isEnabled; - - button({ - menu : menu , - name : 'Change Mode' , - click : toggleMode - }); - - if(needsJumpUI) - button({ - menu : menu , - name : 'Jump' , - click : pressJump - }); - - button({ - menu : menu , - name : 'Hold' , - click : toggleHold - }); + function unitNear(unit,type){ + return relativeBlock() == type; } + - let label_stamina; - - function buildStaminaMenu(){ - - log('Builing Stamina Menu') - - const menu_stamina = new Table() - .left() - .bottom(); - - menu_stamina.visibility = () => isEnabled; - menu_stamina.y = 400; - - label_stamina = Label(''); - label_stamina.setStyle(Styles.outlineLabel); - - menu_stamina.add(label_stamina) - .size(150,75) - .padLeft(6); - - Vars.ui.hudGroup.addChild(menu_stamina); - } - Events.on(ClientLoadEvent,buildHUD); + Events.on(ClientLoadEvent,Interface.build); log('Loading variables'); - let bjumpvel = 15; // скорость прыжка - let ajumpvel = 0; // доп. скорость прыжка - let stamina = 10000; // выносливость + let lastx; let lasty; let ltilex; let ltiley; let unit; - /* - * Gravity - * 0 : Downwards - * 1 : Central - */ - - let mode = 0; - - let - holding = false , - onfloor = false ; - let hold = false; @@ -237,21 +87,13 @@ log('Loading main content'); - function canParkour(unit){ - return unit && ! unit.type.flying; - } - - function unitOn(unit,type){ return tileIs(unit.tileX(),unit.tileY(),type); } - function unitNear(unit,type){ - return relativeBlock() == type; - } - + @@ -260,27 +102,20 @@ if(!canWork()) return; - let percent = stamina / 100; - - percent = percent - percent % 1; - - label_stamina.setText('Stamina: ' + percent + '%'); + Interface.updateStamina(); } - - - const updateFloor = () => { - onfloor = isFloorSolid(); + Player.onfloor = isFloorSolid(); - if(onfloor){ + if(Player.onfloor){ - stamina += 100; + Player.stamina += 100; - if(stamina > 10000) - stamina = 10000; + if(Player.stamina > 10000) + Player.stamina = 10000; ltilex = lastx; ltiley = lasty; @@ -330,7 +165,7 @@ function gravityCenter(){ - if(onfloor || hold) + if(Player.onfloor || hold) return; const coordinates = []; @@ -390,7 +225,7 @@ function gelJump(unit){ if(!unitNear(unit,Blocks.titaniumWall)){ - ajumpvel = 0; + Player.ajumpvel = 0; return; } @@ -401,13 +236,13 @@ ? ltiley == lasty : ltilex == lastx ; - ajumpvel = (isSame) + Player.ajumpvel = (isSame) ? 15 : 0 ; if(isSame) return; - jump(unit,bjumpvel + 15); + jump(unit,Player.bjumpvel + 15); } @@ -427,11 +262,16 @@ holdOn(); - if(Core.input.keyTab(Binding.pause) && stamina > 99) - unit.vel.add( - - offsetX * 15 , - - offsetY * 15 - ); + if(!Core.input.keyTab(Binding.pause)) + continue; + + if(!Player.hasStamina()) + continue; + + unit.vel.add( + - offsetX * 15 , + - offsetY * 15 + ); return; } @@ -447,15 +287,17 @@ function wallHolding(){ - if(!holding) + if(!Player.holding) return; - if(stamina < 100) - return letGo(); + if(!Player.hasStamina()){ + letGo(); + return; + } if(nextToAnyBlock()){ holdOn(); - stamina -= 10; + Player.stamina -= 10; } } @@ -499,24 +341,26 @@ function update(){ - unit = Vars.player.unit(); + unit = Player.unit(); - if(!canParkour(unit)) + if(!Player.canParkour()) return; - + try { + Player.updatePosition(); + lastx = unit.tileX(); lasty = unit.tileY(); - if(Core.input.keyTap(Binding.pause) && stamina > 99 && onfloor){ - jump(unit,bjumpvel + ajumpvel); - stamina -= 100; + if(Core.input.keyTap(Binding.pause) && Player.hasStamina() && Player.onfloor){ + jump(unit,Player.bjumpvel + Player.ajumpvel); + Player.stamina -= 100; } checkInteractables(unit); - if(!hold && mode == 0) + if(!hold && Mod.downwardGravity()) updateGravity(); } catch(error) { exception(error) } @@ -524,12 +368,8 @@ letGo(); } - function player(){ - return Vars.player.unit() - } - function canWork(){ - return isEnabled && canParkour(player()); + return Mod.enabled && Player.canParkour(); } function tick(){ @@ -537,25 +377,24 @@ if(!canWork()) return; - unit = player(); + unit = Player.unit(); update(); updateFloor(); - if(hold || mode != 1) + if(hold || Mod.downwardGravity()) return; gravityCenter(); } - log('Running update task'); - + log('Starting schedulers'); Timer.schedule(tick,0,.02); Timer.schedule(updateHud,0,.1); - log('Done initialisation of parkour-mod.'); + log('Finished setup'); -} +})(); From c080ae2fa6e149b1dec43ec2b3ca9eac72e0157c Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Tue, 16 Aug 2022 16:33:00 -0400 Subject: [PATCH 21/22] Fixed Rhino / ES5 State / Module idiocy --- scripts/Gravity.js | 15 ++--- scripts/Interface.js | 17 +++--- scripts/Mod.js | 35 +++++++---- scripts/Player.js | 12 ++-- scripts/main.js | 142 +++++++++++++++++++++---------------------- 5 files changed, 116 insertions(+), 105 deletions(-) diff --git a/scripts/Gravity.js b/scripts/Gravity.js index ff3be5e..629762d 100644 --- a/scripts/Gravity.js +++ b/scripts/Gravity.js @@ -1,8 +1,5 @@ -module.exports = this._Gravity || init(this); - - -function init(global){ +module.exports = (() => { /* * 0 : Right @@ -25,8 +22,8 @@ function init(global){ Gravity.__defineSetter__('direction',(value) => direction = value); Gravity.__defineSetter__('strength',(value) => strength = value); - - - return global._Gravity = Gravity; - -} + + + return Gravity; + +})(); diff --git a/scripts/Interface.js b/scripts/Interface.js index 35932dd..bc885c6 100644 --- a/scripts/Interface.js +++ b/scripts/Interface.js @@ -1,9 +1,7 @@ - -module.exports = this._Interface || init(this); - - -function init(global){ +module.exports = (() => { + + Log.log(Log.LogLevel.none,'Interface Start'); const { button , table } = require('UI'); const { log , object } = require('Logger'); @@ -13,6 +11,9 @@ function init(global){ const Mod = require('Mod'); + Mod.onToggle(updateEnableButton); + + const onMobile = Vars.mobile || Debug; @@ -116,5 +117,7 @@ function init(global){ log('Int',object(Interface)); - return global._Interface = Interface; -} + + return Interface; + +})(); diff --git a/scripts/Mod.js b/scripts/Mod.js index 4504bd0..b5800fd 100644 --- a/scripts/Mod.js +++ b/scripts/Mod.js @@ -1,14 +1,15 @@ -module.exports = this._Mod || init(this); - - -function init(global){ - +module.exports = (() => { + const { log , object } = require('Logger'); - const Interface = require('Interface'); const Player = require('Player'); - log('Interface:',object(Interface)); + let a = ''; + + for(let key in this) + a += key + ' '; + + log('This',a); /* @@ -20,6 +21,7 @@ function init(global){ let mode = 0; let enabled = false; + const listeners_onToggle = new Set; function inParkour(){ @@ -41,7 +43,7 @@ function init(global){ enabled = ! enabled; - Interface.updateEnableButton(); + listeners_onToggle.forEach((listener) => listener()); } function toggleMode(){ @@ -68,6 +70,15 @@ function init(global){ mode = 1; Vars.ui.announce('Planet mode'); } + + + function onToggle(listener){ + listeners_onToggle.add(listener); + } + + function downwardGravity(){ + return mode === 0; + } const Mod = { @@ -76,7 +87,9 @@ function init(global){ onPlanet : onPlanet , parkour : parkour , toggle : toggle , - planet : planet + planet : planet , + onToggle : onToggle , + downwardGravity : downwardGravity } Mod.__defineGetter__('mode',() => mode); @@ -85,6 +98,6 @@ function init(global){ Mod.__defineSetter__('mode',(value) => mode = value); Mod.__defineSetter__('enabled',(value) => enabled = value); + return Mod; - return global._Mod = Mod; -} +})(); diff --git a/scripts/Player.js b/scripts/Player.js index 2936167..00ab8ac 100644 --- a/scripts/Player.js +++ b/scripts/Player.js @@ -1,8 +1,5 @@ -module.exports = this._Player || init(this); - - -function init(global){ +module.exports = (() => { const { debug } = require('Logger'); const Jump = require('Jump'); @@ -85,6 +82,7 @@ function init(global){ Player.__defineSetter__('onfloor',(value) => onfloor = value); Player.__defineSetter__('stamina',(value) => stamina = value); - return global._Player = Player; - -} + + return Player; + +})(); diff --git a/scripts/main.js b/scripts/main.js index f06b9e9..553401e 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -26,9 +26,9 @@ offsets[direction]; function relativeTile(){ - + const offset = directToOffset(Gravity.direction); - + return tileAt( lastx + offset[0] , lasty + offset[1] @@ -36,27 +36,27 @@ } function relativeBlock(){ - + const tile = relativeTile(); - + return (tile) ? tile.block() : false ; } - + function isFloorSolid(){ - + const block = relativeBlock(); - + return (block) ? block.solid : false ; } - + function unitNear(unit,type){ return relativeBlock() == type; } - + Events.on(ClientLoadEvent,Interface.build); @@ -64,7 +64,7 @@ log('Loading variables'); - + let lastx; let lasty; let ltilex; @@ -93,55 +93,55 @@ return tileIs(unit.tileX(),unit.tileY(),type); } - + function updateHud(){ - + if(!canWork()) return; - + Interface.updateStamina(); } const updateFloor = () => { - + Player.onfloor = isFloorSolid(); - + if(Player.onfloor){ - + Player.stamina += 100; - + if(Player.stamina > 10000) Player.stamina = 10000; - + ltilex = lastx; ltiley = lasty; - + const vertical = Gravity.direction % 2; - + let x = unit.vel.x , y = unit.vel.y ; - + if(vertical && (Gravity.direction === 1 ? y > 0 : y < 0)) y = 0; - + if(!vertical && (Gravity.direction === 0 ? x > 0 : x < 0)) y = 0; - - + + unit.vel.set(x,y); } } function updateGravity(){ - + const offset = directToOffset(Gravity.direction); - + unit.vel.add( Gravity.strength * offset[0] , Gravity.strength * offset[1] @@ -158,13 +158,13 @@ } - - + + function gravityCenter(){ - + if(Player.onfloor || hold) return; @@ -180,23 +180,23 @@ if(!nolock) return; - + const distances = []; for(let c = 0;c < coordinates.length;c++){ - + const cord = coordinates[c]; - + const distance = delta( cord.x , cord.y , lastx , lasty ); - + distances.push(distance); } let shortest = 0; - + for(let d = 0;d < distances.length;d++) if(distances[d] < distances[shortest]) shortest = d; @@ -204,20 +204,20 @@ const x = coordinates[shortest].x , y = coordinates[shortest].y ; - + const vertical = Gravity.direction % 2; - + const position = vertical ? y : x ; - + if(position === 0) return; - + unit.vel.add( ! vertical * Gravity.strength , vertical * Gravity.strength ); - + Gravity.direction = vertical + (position < 0) * 2; } @@ -228,20 +228,20 @@ Player.ajumpvel = 0; return; } - + const vertical = Gravity.direction % 2; - - + + const isSame = (vertical) ? ltiley == lasty : ltilex == lastx ; - + Player.ajumpvel = (isSame) ? 15 : 0 ; - + if(isSame) return; - + jump(unit,Player.bjumpvel + 15); } @@ -249,30 +249,30 @@ function gelStick(unit){ const offsets = [ -1 , 0 , +1 ]; - + for(let x = 0;x < 2;x++) for(let y = 0;y < 2;y++){ - + const offsetX = offsets[x] , offsetY = offsets[y] ; - + if(blockAt(lastx + offsetX,lasty + offsetY) !== Blocks.plastaniumWall) return; - + holdOn(); - + if(!Core.input.keyTab(Binding.pause)) continue; - + if(!Player.hasStamina()) continue; - + unit.vel.add( - offsetX * 15 , - offsetY * 15 ); - + return; } } @@ -286,15 +286,15 @@ } function wallHolding(){ - + if(!Player.holding) return; - + if(!Player.hasStamina()){ letGo(); return; } - + if(nextToAnyBlock()){ holdOn(); Player.stamina -= 10; @@ -303,16 +303,16 @@ function graviFunnel(unit){ - + const block = blockAt(lastx,lasty); if(block != Blocks.pulseConduit) return; - + holdOn(); - + const offset = directToOffset(block.build.rotation); - + unit.vel.add( -.55 * offset[0] , -.55 * offset[1] @@ -321,7 +321,7 @@ function antiGravField(unit){ - + if(unitOn(unit,Blocks.shockMine)) holdOn(); } @@ -329,7 +329,7 @@ function checkInteractables(unit){ - + gravipad(unit); gelJump(unit); gelStick(unit); @@ -340,16 +340,16 @@ function update(){ - + unit = Player.unit(); - + if(!Player.canParkour()) return; - + try { - + Player.updatePosition(); - + lastx = unit.tileX(); lasty = unit.tileY(); @@ -359,7 +359,7 @@ } checkInteractables(unit); - + if(!hold && Mod.downwardGravity()) updateGravity(); @@ -373,12 +373,12 @@ } function tick(){ - + if(!canWork()) return; - + unit = Player.unit(); - + update(); updateFloor(); From 396bb8c1843390a1d8b634be2982b8bc80e8a43d Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Tue, 16 Aug 2022 16:51:47 -0400 Subject: [PATCH 22/22] General Cleanup --- scripts/Gravity.js | 32 +++++++++++++++++--------------- scripts/Interface.js | 9 +-------- scripts/JS.js | 28 ++++++++++++++++++++++++++++ scripts/Mod.js | 7 ------- scripts/Player.js | 29 ++++++++++++++++------------- scripts/main.js | 17 ----------------- 6 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 scripts/JS.js diff --git a/scripts/Gravity.js b/scripts/Gravity.js index 629762d..7c324c1 100644 --- a/scripts/Gravity.js +++ b/scripts/Gravity.js @@ -1,28 +1,30 @@ module.exports = (() => { + + const { access } = require('JS'); + /* - * 0 : Right - * 1 : Up - * 2 : Left - * 3 : Down + * 0 : → + * 1 : ← + * 2 : ↑ + * 3 : ↓ */ - let direction = 3; - - - let strength = .5; + let + direction = 3 , + strength = .5 ; const Gravity = {}; - - Gravity.__defineGetter__('direction',() => direction); - Gravity.__defineGetter__('strength',() => strength); - - Gravity.__defineSetter__('direction',(value) => direction = value); - Gravity.__defineSetter__('strength',(value) => strength = value); - + access(Gravity,{ + direction : () => direction , + strength : () => strength + },{ + direction : (value) => direction = value, + strength : (value) => strength = value + }); return Gravity; diff --git a/scripts/Interface.js b/scripts/Interface.js index bc885c6..f429ed8 100644 --- a/scripts/Interface.js +++ b/scripts/Interface.js @@ -1,8 +1,6 @@ module.exports = (() => { - Log.log(Log.LogLevel.none,'Interface Start'); - const { button , table } = require('UI'); const { log , object } = require('Logger'); @@ -108,16 +106,11 @@ module.exports = (() => { } - const Interface = { + return { updateEnableButton : updateEnableButton , updateStamina : updateStamina , build : build , test : 1 } - log('Int',object(Interface)); - - - return Interface; - })(); diff --git a/scripts/JS.js b/scripts/JS.js new file mode 100644 index 0000000..c0cde46 --- /dev/null +++ b/scripts/JS.js @@ -0,0 +1,28 @@ + + +module.exports = (() => { + + function get(object,getters){ + + for(let name in getters) + object.__defineGetter__(name,getters[name]); + } + + function set(object,setters){ + + for(let name in setters) + object.__defineSetter__(name,setters[name]); + } + + function access(object,getters,setters){ + get(object,getters); + set(object,setters); + } + + + return { + access : access , + get : get , + set : set + }; +})(); diff --git a/scripts/Mod.js b/scripts/Mod.js index b5800fd..6d7849e 100644 --- a/scripts/Mod.js +++ b/scripts/Mod.js @@ -4,14 +4,7 @@ module.exports = (() => { const { log , object } = require('Logger'); const Player = require('Player'); - let a = ''; - for(let key in this) - a += key + ' '; - - log('This',a); - - /* * Gravity * 0 : Downwards diff --git a/scripts/Player.js b/scripts/Player.js index 00ab8ac..639c019 100644 --- a/scripts/Player.js +++ b/scripts/Player.js @@ -1,6 +1,7 @@ module.exports = (() => { + const { access } = require('JS'); const { debug } = require('Logger'); const Jump = require('Jump'); @@ -65,22 +66,24 @@ module.exports = (() => { updatePosition : updatePosition , hasStamina : hasStamina , toggleHold : toggleHold , + canParkour : canParkour , unit : unit , - jump : jump , - canParkour : canParkour + jump : jump } - Player.__defineGetter__('bjumpvel',() => bjumpvel); - Player.__defineGetter__('ajumpvel',() => ajumpvel); - Player.__defineGetter__('holding',() => holding); - Player.__defineGetter__('onfloor',() => onfloor); - Player.__defineGetter__('stamina',() => stamina); - - Player.__defineSetter__('bjumpvel',(value) => bjumpvel = value); - Player.__defineSetter__('ajumpvel',(value) => ajumpvel = value); - Player.__defineSetter__('holding',(value) => holding = value); - Player.__defineSetter__('onfloor',(value) => onfloor = value); - Player.__defineSetter__('stamina',(value) => stamina = value); + access(Player,{ + bjumpvel : () => bjumpvel , + ajumpvel : () => ajumpvel , + holding : () => holding , + onfloor : () => onfloor , + stamina : () => stamina + },{ + bjumpvel : (value) => bjumpvel = value , + ajumpvel : (value) => ajumpvel = value , + holding : (value) => holding = value , + onfloor : (value) => onfloor = value , + stamina : (value) => stamina = value + }) return Player; diff --git a/scripts/main.js b/scripts/main.js index 553401e..6bab070 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -87,16 +87,10 @@ log('Loading main content'); - - function unitOn(unit,type){ return tileIs(unit.tileX(),unit.tileY(),type); } - - - - function updateHud(){ if(!canWork()) @@ -148,21 +142,11 @@ ); } - - - - function gravipad(unit){ if(unitOn(unit,Blocks.conveyor)) Gravity.direction = tileAt(lastx,lasty).build.rotation; } - - - - - - function gravityCenter(){ if(Player.onfloor || hold) @@ -327,7 +311,6 @@ } - function checkInteractables(unit){ gravipad(unit);