Skip to content

Commit

Permalink
October 28, 2023: Merge with PS (scoopapa#12)
Browse files Browse the repository at this point in the history
* Populate Tooltips with information from OTS (#2161)

* Fix `showteam` in replays (#2164)

* Fix speed buttons on downloaded replays (#2162)

* fix package.json

* remove DH2 sub

---------

Co-authored-by: Karthik <[email protected]>
  • Loading branch information
Rezzo64 and Karthik99999 authored Oct 28, 2023
1 parent 546476e commit e1e1749
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 17 deletions.
24 changes: 17 additions & 7 deletions js/replay-embed.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var Replays = {
paused: true,
});

this.$('.replay-controls-2').html('<div class="chooser leftchooser speedchooser"> <em>Speed:</em> <div><button class="sel" value="fast">Fast</button><button value="normal">Normal</button><button value="slow">Slow</button><button value="reallyslow">Really Slow</button></div> </div> <div class="chooser colorchooser"> <em>Color&nbsp;scheme:</em> <div><button class="sel" value="light">Light</button><button value="dark">Dark</button></div> </div> <div class="chooser soundchooser" style="display:none"> <em>Music:</em> <div><button class="sel" value="on">On</button><button value="off">Off</button></div> </div>');
this.$('.replay-controls-2').html('<div class="chooser leftchooser speedchooser"> <em>Speed:</em> <div><button value="hyperfast">Hyperfast</button><button value="fast">Fast</button><button value="normal" class="sel">Normal</button><button value="slow">Slow</button><button value="reallyslow">Really Slow</button></div> </div> <div class="chooser colorchooser"> <em>Color&nbsp;scheme:</em> <div><button class="sel" value="light">Light</button><button value="dark">Dark</button></div> </div> <div class="chooser soundchooser" style="display:none"> <em>Music:</em> <div><button class="sel" value="on">On</button><button value="off">Off</button></div> </div>');

// this works around a WebKit/Blink bug relating to float layout
var rc2 = this.$('.replay-controls-2')[0];
Expand Down Expand Up @@ -141,13 +141,23 @@ var Replays = {
break;

case 'speed':
var speedTable = {
fast: 8,
normal: 800,
slow: 2500,
reallyslow: 5000
var fadeTable = {
hyperfast: 40,
fast: 50,
normal: 300,
slow: 500,
reallyslow: 1000
};
this.battle.messageDelay = speedTable[value];
var delayTable = {
hyperfast: 1,
fast: 1,
normal: 1,
slow: 1000,
reallyslow: 3000
};
this.battle.messageShownTime = delayTable[value];
this.battle.messageFadeTime = fadeTable[value];
this.battle.scene.updateAcceleration();
break;
}
},
Expand Down
2 changes: 1 addition & 1 deletion replays/battle.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function userid($username) {
<div class="replay-controls-2">
<div class="chooser leftchooser speedchooser">
<em>Speed:</em>
<div><button value="hyperfast">Hyperfast</button> <button value="fast">Fast</button><button value="normal" class="sel">Normal</button><button value="slow">Slow</button><button value="reallyslow">Really Slow</button></div>
<div><button value="hyperfast">Hyperfast</button><button value="fast">Fast</button><button value="normal" class="sel">Normal</button><button value="slow">Slow</button><button value="reallyslow">Really Slow</button></div>
</div>
<div class="chooser colorchooser">
<em>Color&nbsp;scheme:</em>
Expand Down
29 changes: 23 additions & 6 deletions src/battle-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class BattleLog {
}
add(args: Args, kwArgs?: KWArgs, preempt?: boolean) {
if (kwArgs?.silent) return;
if (this.scene?.battle.seeking) {
const battle = this.scene.battle;
const battle = this.scene?.battle;
if (battle?.seeking) {
if (battle.stepQueue.length > 2000) {
// adding elements gets slower and slower the more there are
// (so showing 100 turns takes around 2 seconds, and 1000 turns takes around a minute)
Expand All @@ -122,7 +122,6 @@ export class BattleLog {
if (!['name', 'n'].includes(args[0])) this.lastRename = null;
switch (args[0]) {
case 'chat': case 'c': case 'c:':
let battle = this.scene?.battle;
let name;
let message;
if (args[0] === 'c:') {
Expand Down Expand Up @@ -259,6 +258,27 @@ export class BattleLog {
app.rooms[roomid].notifyOnce(title, body, 'highlight');
break;

case 'showteam': {
if (!battle) return;
const team = battle.unpackTeam(args[2]);
if (!team.length) return;
const side = battle.getSide(args[1]);
const exportedTeam = team.map(set => {
let buf = battle.exportTeam([set]).replace(/\n/g, '<br />');
if (set.name && set.name !== set.species) {
buf = buf.replace(set.name, BattleLog.sanitizeHTML(`<span class="picon" style="${Dex.getPokemonIcon(set.species)}"></span><br />${set.name}`));
} else {
buf = buf.replace(set.species, `<span class="picon" style="${Dex.getPokemonIcon(set.species)}"></span><br />${set.species}`);
}
if (set.item) {
buf = buf.replace(set.item, `${set.item} <span class="itemicon" style="${Dex.getItemIcon(set.item)}"></span>`);
}
return buf;
}).join('');
divHTML = `<div class="infobox"><details><summary>Open Team Sheet for ${side.name}</summary>${exportedTeam}</details></div>`;
break;
}

case 'seed': case 'choice': case ':': case 'timer': case 't:':
case 'J': case 'L': case 'N': case 'spectator': case 'spectatorleave':
case 'initdone':
Expand Down Expand Up @@ -1140,9 +1160,6 @@ export class BattleLog {
buf += '<meta charset="utf-8" />\n';
buf += '<!-- version 1 -->\n';
buf += `<title>${BattleLog.escapeHTML(battle.tier)} replay: ${BattleLog.escapeHTML(battle.p1.name)} vs. ${BattleLog.escapeHTML(battle.p2.name)}</title>\n`;
buf += '<style>\n';
buf += 'html,body {font-family:Verdana, sans-serif;font-size:10pt;margin:0;padding:0;}body{padding:12px 0;} .battle-log {font-family:Verdana, sans-serif;font-size:10pt;} .battle-log-inline {border:1px solid #AAAAAA;background:#EEF2F5;color:black;max-width:640px;margin:0 auto 80px;padding-bottom:5px;} .battle-log .inner {padding:4px 8px 0px 8px;} .battle-log .inner-preempt {padding:0 8px 4px 8px;} .battle-log .inner-after {margin-top:0.5em;} .battle-log h2 {margin:0.5em -8px;padding:4px 8px;border:1px solid #AAAAAA;background:#E0E7EA;border-left:0;border-right:0;font-family:Verdana, sans-serif;font-size:13pt;} .battle-log .chat {vertical-align:middle;padding:3px 0 3px 0;font-size:8pt;} .battle-log .chat strong {color:#40576A;} .battle-log .chat em {padding:1px 4px 1px 3px;color:#000000;font-style:normal;} .chat.mine {background:rgba(0,0,0,0.05);margin-left:-8px;margin-right:-8px;padding-left:8px;padding-right:8px;} .spoiler {color:#BBBBBB;background:#BBBBBB;padding:0px 3px;} .spoiler:hover, .spoiler:active, .spoiler-shown {color:#000000;background:#E2E2E2;padding:0px 3px;} .spoiler a {color:#BBBBBB;} .spoiler:hover a, .spoiler:active a, .spoiler-shown a {color:#2288CC;} .chat code, .chat .spoiler:hover code, .chat .spoiler:active code, .chat .spoiler-shown code {border:1px solid #C0C0C0;background:#EEEEEE;color:black;padding:0 2px;} .chat .spoiler code {border:1px solid #CCCCCC;background:#CCCCCC;color:#CCCCCC;} .battle-log .rated {padding:3px 4px;} .battle-log .rated strong {color:white;background:#89A;padding:1px 4px;border-radius:4px;} .spacer {margin-top:0.5em;} .message-announce {background:#6688AA;color:white;padding:1px 4px 2px;} .message-announce a, .broadcast-green a, .broadcast-blue a, .broadcast-red a {color:#DDEEFF;} .broadcast-green {background-color:#559955;color:white;padding:2px 4px;} .broadcast-blue {background-color:#6688AA;color:white;padding:2px 4px;} .infobox {border:1px solid #6688AA;padding:2px 4px;} .infobox-limited {max-height:200px;overflow:auto;overflow-x:hidden;} .broadcast-red {background-color:#AA5544;color:white;padding:2px 4px;} .message-learn-canlearn {font-weight:bold;color:#228822;text-decoration:underline;} .message-learn-cannotlearn {font-weight:bold;color:#CC2222;text-decoration:underline;} .message-effect-weak {font-weight:bold;color:#CC2222;} .message-effect-resist {font-weight:bold;color:#6688AA;} .message-effect-immune {font-weight:bold;color:#666666;} .message-learn-list {margin-top:0;margin-bottom:0;} .message-throttle-notice, .message-error {color:#992222;} .message-overflow, .chat small.message-overflow {font-size:0pt;} .message-overflow::before {font-size:9pt;content:\'...\';} .subtle {color:#3A4A66;}\n';
buf += '</style>\n';
buf += '<div class="wrapper replay-wrapper" style="max-width:1180px;margin:0 auto">\n';
buf += '<input type="hidden" name="replayid" value="' + replayid + '" />\n';
buf += '<div class="battle"></div><div class="battle-log"></div><div class="replay-controls"></div><div class="replay-controls-2"></div>\n';
Expand Down
2 changes: 1 addition & 1 deletion src/battle-text-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BattleTextParser {
case 'fieldhtml': case 'controlshtml': case 'bigerror':
case 'debug': case 'tier': case 'challstr': case 'popup': case '':
return [cmd, line.slice(index + 1)];
case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': case 'queryresponse':
case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': case 'queryresponse': case 'showteam':
// three parts
const index2a = line.indexOf('|', index + 1);
return [cmd, line.slice(index + 1, index2a), line.slice(index2a + 1)];
Expand Down
Loading

0 comments on commit e1e1749

Please sign in to comment.