@pkmn/protocol
Advanced tools
Comparing version 0.6.2 to 0.6.3
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkK7K4LEXQjs = require('./chunk-K7K4LEXQ.js'); | ||
var _chunkHYZTBSMXjs = require('./chunk-HYZTBSMX.js'); | ||
exports.Protocol = _chunkK7K4LEXQjs.Protocol; | ||
exports.Protocol = _chunkHYZTBSMXjs.Protocol; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";window.pkmn=window.pkmn||{};window.pkmn.protocol=(()=>{var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var A=(t,e)=>{for(var o in e)p(t,o,{get:e[o],enumerable:!0})},f=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of g(e))!u.call(t,a)&&a!==o&&p(t,a,{get:()=>e[a],enumerable:!(r=y(e,a))||r.enumerable});return t};var N=t=>f(p({},"__esModule",{value:!0}),t);var I={};A(I,{Protocol:()=>d});function c(t){return(""+t).toLowerCase().replace(/[^a-z0-9]+/g,"")}var d=new class{constructor(){this.ARGS={"|init|":1,"|title|":1,"|userlist|":1,"||":1,"|html|":1,"|uhtml|":1,"|uhtmlchange|":1,"|join|":1,"|leave|":1,"|name|":1,"|chat|":1,"|notify|":1,"|:|":1,"|c:|":1,"|t:|":1,"|battle|":1,"|popup|":1,"|pm|":1,"|usercount|":1,"|nametaken|":1,"|challstr|":1,"|updateuser|":1,"|formats|":1,"|updatesearch|":1,"|message|":1,"|updatechallenges|":1,"|queryresponse|":1,"|unlink|":1,"|raw|":1,"|error|":1,"|bigerror|":1,"|chatmsg|":1,"|chatmsg-raw|":1,"|controlshtml|":1,"|fieldhtml|":1,"|debug|":1,"|deinit|":1,"|selectorhtml|":1,"|refresh|":1,"|tempnotify|":1,"|tempnotifyoff|":1,"|noinit|":1,"|hidelines|":1,"|expire|":1,"|askreg|":1,"|tournament|create|":1,"|tournament|update|":1,"|tournament|updateEnd|":1,"|tournament|error|":1,"|tournament|forceend|":1,"|tournament|join|":1,"|tournament|leave|":1,"|tournament|replace|":1,"|tournament|start|":1,"|tournament|disqualify|":1,"|tournament|battlestart|":1,"|tournament|battleend|":1,"|tournament|end|":1,"|tournament|scouting|":1,"|tournament|autostart|":1,"|tournament|autodq|":1,"|player|":1,"|teamsize|":1,"|gametype|":1,"|gen|":1,"|tier|":1,"|rated|":1,"|seed|":1,"|rule|":1,"|split|":1,"|teampreview|":1,"|clearpoke|":1,"|poke|":1,"|start|":1,"|done|":1,"|request|":1,"|inactive|":1,"|inactiveoff|":1,"|upkeep|":1,"|turn|":1,"|win|":1,"|tie|":1,"|move|":1,"|switch|":1,"|drag|":1,"|detailschange|":1,"|replace|":1,"|swap|":1,"|cant|":1,"|faint|":1,"|-formechange|":1,"|-fail|":1,"|-block|":1,"|-notarget|":1,"|-miss|":1,"|-damage|":1,"|-heal|":1,"|-sethp|":1,"|-status|":1,"|-curestatus|":1,"|-cureteam|":1,"|-boost|":1,"|-unboost|":1,"|-setboost|":1,"|-swapboost|":1,"|-invertboost|":1,"|-clearboost|":1,"|-clearallboost|":1,"|-clearpositiveboost|":1,"|-ohko|":1,"|-clearnegativeboost|":1,"|-copyboost|":1,"|-weather|":1,"|-fieldstart|":1,"|-fieldend|":1,"|-sidestart|":1,"|-sideend|":1,"|-start|":1,"|-end|":1,"|-crit|":1,"|-supereffective|":1,"|-resisted|":1,"|-immune|":1,"|-item|":1,"|-enditem|":1,"|-ability|":1,"|-endability|":1,"|-transform|":1,"|-mega|":1,"|-primal|":1,"|-burst|":1,"|-zpower|":1,"|-zbroken|":1,"|-activate|":1,"|-fieldactivate|":1,"|-hint|":1,"|-center|":1,"|-message|":1,"|-combine|":1,"|-waiting|":1,"|-prepare|":1,"|-mustrecharge|":1,"|-hitcount|":1,"|-singlemove|":1,"|-singleturn|":1,"|-anim|":1,"|warning|":1,"|-candynamax|":1,"|updatepoke|":1,"|-swapsideconditions|":1,"|-terastallize|":1};this.ARGS_WITH_KWARGS={"|move|":1,"|detailschange|":1,"|cant|":1,"|-formechange|":1,"|-fail|":1,"|-block|":1,"|-damage|":1,"|-heal|":1,"|-sethp|":1,"|-status|":1,"|swap|":1,"|-curestatus|":1,"|-cureteam|":1,"|-boost|":1,"|-unboost|":1,"|-setboost|":1,"|-swapboost|":1,"|-invertboost|":1,"|-clearnegativeboost|":1,"|-weather|":1,"|-fieldactivate|":1,"|-fieldstart|":1,"|-fieldend|":1,"|-sidestart|":1,"|-sideend|":1,"|-start|":1,"|-end|":1,"|-immune|":1,"|-item|":1,"|-enditem|":1,"|-ability|":1,"|-endability|":1,"|-transform|":1,"|-activate|":1,"|-singleturn|":1,"|-miss|":1,"|-clearallboost|":1,"|-anim|":1,"|-copyboost|":1,"|-clearboost|":1,"|-clearpositiveboost|":1,"|-singlemove|":1,"|switch|":1}}*parse(t){let e=t.split(` | ||
"use strict";window.pkmn=window.pkmn||{};window.pkmn.protocol=(()=>{var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var A=(t,e)=>{for(var o in e)p(t,o,{get:e[o],enumerable:!0})},f=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of g(e))!u.call(t,a)&&a!==o&&p(t,a,{get:()=>e[a],enumerable:!(r=y(e,a))||r.enumerable});return t};var N=t=>f(p({},"__esModule",{value:!0}),t);var I={};A(I,{Protocol:()=>d});function c(t){return(""+t).toLowerCase().replace(/[^a-z0-9]+/g,"")}var d=new class{constructor(){this.ARGS={"|init|":1,"|title|":1,"|userlist|":1,"||":1,"|html|":1,"|uhtml|":1,"|uhtmlchange|":1,"|join|":1,"|leave|":1,"|name|":1,"|chat|":1,"|notify|":1,"|:|":1,"|c:|":1,"|t:|":1,"|battle|":1,"|popup|":1,"|pm|":1,"|usercount|":1,"|nametaken|":1,"|challstr|":1,"|updateuser|":1,"|formats|":1,"|updatesearch|":1,"|message|":1,"|updatechallenges|":1,"|queryresponse|":1,"|unlink|":1,"|raw|":1,"|error|":1,"|bigerror|":1,"|chatmsg|":1,"|chatmsg-raw|":1,"|controlshtml|":1,"|fieldhtml|":1,"|debug|":1,"|deinit|":1,"|selectorhtml|":1,"|refresh|":1,"|tempnotify|":1,"|tempnotifyoff|":1,"|noinit|":1,"|hidelines|":1,"|expire|":1,"|askreg|":1,"|tournament|create|":1,"|tournament|update|":1,"|tournament|updateEnd|":1,"|tournament|error|":1,"|tournament|forceend|":1,"|tournament|join|":1,"|tournament|leave|":1,"|tournament|replace|":1,"|tournament|start|":1,"|tournament|disqualify|":1,"|tournament|battlestart|":1,"|tournament|battleend|":1,"|tournament|end|":1,"|tournament|scouting|":1,"|tournament|autostart|":1,"|tournament|autodq|":1,"|player|":1,"|teamsize|":1,"|gametype|":1,"|gen|":1,"|tier|":1,"|rated|":1,"|seed|":1,"|rule|":1,"|teampreview|":1,"|clearpoke|":1,"|poke|":1,"|start|":1,"|done|":1,"|request|":1,"|inactive|":1,"|inactiveoff|":1,"|upkeep|":1,"|turn|":1,"|win|":1,"|tie|":1,"|move|":1,"|switch|":1,"|drag|":1,"|detailschange|":1,"|replace|":1,"|swap|":1,"|cant|":1,"|faint|":1,"|-formechange|":1,"|-fail|":1,"|-block|":1,"|-notarget|":1,"|-miss|":1,"|-damage|":1,"|-heal|":1,"|-sethp|":1,"|-status|":1,"|-curestatus|":1,"|-cureteam|":1,"|-boost|":1,"|-unboost|":1,"|-setboost|":1,"|-swapboost|":1,"|-invertboost|":1,"|-clearboost|":1,"|-clearallboost|":1,"|-clearpositiveboost|":1,"|-ohko|":1,"|-clearnegativeboost|":1,"|-copyboost|":1,"|-weather|":1,"|-fieldstart|":1,"|-fieldend|":1,"|-sidestart|":1,"|-sideend|":1,"|-start|":1,"|-end|":1,"|-crit|":1,"|-supereffective|":1,"|-resisted|":1,"|-immune|":1,"|-item|":1,"|-enditem|":1,"|-ability|":1,"|-endability|":1,"|-transform|":1,"|-mega|":1,"|-primal|":1,"|-burst|":1,"|-zpower|":1,"|-zbroken|":1,"|-activate|":1,"|-fieldactivate|":1,"|-hint|":1,"|-center|":1,"|-message|":1,"|-combine|":1,"|-waiting|":1,"|-prepare|":1,"|-mustrecharge|":1,"|-hitcount|":1,"|-singlemove|":1,"|-singleturn|":1,"|-anim|":1,"|warning|":1,"|-candynamax|":1,"|updatepoke|":1,"|-swapsideconditions|":1,"|-terastallize|":1};this.ARGS_WITH_KWARGS={"|move|":1,"|detailschange|":1,"|cant|":1,"|-formechange|":1,"|-fail|":1,"|-block|":1,"|-damage|":1,"|-heal|":1,"|-sethp|":1,"|-status|":1,"|swap|":1,"|-curestatus|":1,"|-cureteam|":1,"|-boost|":1,"|-unboost|":1,"|-setboost|":1,"|-swapboost|":1,"|-invertboost|":1,"|-clearnegativeboost|":1,"|-weather|":1,"|-fieldactivate|":1,"|-fieldstart|":1,"|-fieldend|":1,"|-sidestart|":1,"|-sideend|":1,"|-start|":1,"|-end|":1,"|-immune|":1,"|-item|":1,"|-enditem|":1,"|-ability|":1,"|-endability|":1,"|-transform|":1,"|-activate|":1,"|-singleturn|":1,"|-miss|":1,"|-clearallboost|":1,"|-anim|":1,"|-copyboost|":1,"|-clearboost|":1,"|-clearpositiveboost|":1,"|-singlemove|":1,"|switch|":1}}*parse(t){let e=t.split(` | ||
`),o="";for(let[r,a]of e.entries())if(r===0&&a[0]===">"){o=a.slice(1);continue}else if(a){let{args:n,kwArgs:s}=this.parseBattleLine(a);yield{roomid:o,args:n,kwArgs:s}}}key(t){let e=t[0]==="tournament"?`|${t[0]}|${t[1]}|`:`|${t[0]}|`;return e in this.ARGS?e:void 0}parseLine(t,e){if(!t.startsWith("|"))return["",t];if(t==="|")return["done"];let o=t.indexOf("|",1),r=t.slice(1,o);switch(r){case"chatmsg":case"chatmsg-raw":case"raw":case"error":case"html":case"inactive":case"inactiveoff":case"warning":case"fieldhtml":case"controlshtml":case"bigerror":case"debug":case"tier":case"challstr":case"popup":case"":return m([r,t.slice(o+1)]);case"c":case"chat":case"uhtml":case"uhtmlchange":let a=t.indexOf("|",o+1);return m([r,t.slice(o+1,a),t.slice(a+1)]);case"c:":case"pm":let n=t.indexOf("|",o+1),s=t.indexOf("|",n+1);return m([r,t.slice(o+1,n),t.slice(n+1,s),t.slice(s+1)])}return e?null:m(t.slice(1).split("|"))}parseBattleLine(t){let e=d.parseLine(t,!0);if(e)return{args:e,kwArgs:{}};e=t.slice(1).split("|");let o={};for(;e.length>1;){let r=e[e.length-1];if(r.charAt(0)!=="[")break;let a=r.indexOf("]");if(a<=0)break;o[r.slice(1,a)]=r.slice(a+1).trim()||!0,e.pop()}return b({args:m(e),kwArgs:o})}parsePokemonIdent(t){let e=t.indexOf(":"),o=t.slice(0,e),r=t.slice(e+2),a,n;return o.length<3?(a=o,n=null):(a=o.slice(0,2),n=o.charAt(2)),{player:a,position:n,name:r}}parseDetails(t,e,o="",r={}){r.details=o;let a=!t;r.name=t,r.speciesForme=t,r.level=100,r.shiny=!1,r.gender=void 0,r.ident=a?"":e,r.searchid=a?"":`${e}|${o}`;let n=o.split(", ");n[n.length-1]==="shiny"&&(r.shiny=!0,n.pop());let s=n[n.length-1];return(s==="M"||s==="F")&&(r.gender=s,n.pop()),n[1]&&(r.level=parseInt(n[1].substr(1))||100),n[0]&&(r.speciesForme=n[0]),r}parseHealth(t,e={}){let[o,r]=t.split(" ");if(e.hpcolor="",o==="0"||o==="0.0")e.maxhp||(e.maxhp=100),e.hp=0;else if(o.indexOf("/")>0){let[a,n]=o.split("/");if(isNaN(parseFloat(a))||isNaN(parseFloat(n)))return null;e.hp=parseFloat(a),e.maxhp=parseFloat(n),e.hp>e.maxhp&&(e.hp=e.maxhp);let s=n.slice(-1);(s==="y"||s==="g")&&(e.hpcolor=s)}else isNaN(parseFloat(o))||(e.maxhp||(e.maxhp=100),e.hp=e.maxhp*parseFloat(o)/100);return r?r==="par"||r==="brn"||r==="slp"||r==="frz"||r==="tox"||r==="psn"&&e.status!=="tox"?e.status=r:r==="fnt"&&(e.hp=0,e.fainted=!0):e.status=void 0,e}parseEffect(t,e=o=>o.trim()){return t?t.startsWith("item:")||t.startsWith("move:")?{name:e(t.slice(5)),type:t.slice(0,4)}:t.startsWith("ability:")?{name:e(t.slice(8)),type:"ability"}:{name:e(t)}:{name:e("")}}parseRequest(t){let e=JSON.parse(t);if(e.requestType||(e.requestType="move",e.forceSwitch?e.requestType="switch":e.teamPreview?e.requestType="team":e.wait&&(e.requestType="wait")),e.requestType==="wait"&&(e.noCancel=!0),e.side)for(let o of e.side.pokemon)this.parseDetails(o.ident.substr(4),o.ident,o.details,o),this.parseHealth(o.condition,o),o.ability=o.ability||o.baseAbility;if(e.active){e.active=e.active.map((o,r)=>e.side.pokemon[r].fainted?null:o);for(let o of e.active)if(!!o){for(let r of o.moves)r.move&&(r.name=r.move),r.id=c(r.name);if(o.maxMoves){o.maxMoves.maxMoves&&(o.canGigantamax=o.maxMoves.gigantamax,o.maxMoves=o.maxMoves.maxMoves);for(let r of o.maxMoves)r.id=r.move}if(o.canZMove){o.zMoves=o.canZMove;for(let r of o.zMoves)!r||(r.move&&(r.name=r.move),r.id=c(r.name))}}}return e}parseChallenges(t){return JSON.parse(t)}parseSearchState(t){return JSON.parse(t)}parseTournamentUpdate(t){return JSON.parse(t)}parseNameParts(t){let e="";/[A-Za-z0-9]/.test(t.charAt(0))||(e=t.charAt(0),t=t.slice(1));let o=t,r=t.indexOf("@"),a="",n=!1;return r>0&&(o=t.slice(0,r),a=t.slice(r+1),a.startsWith("!")&&(n=!0,a=a.slice(1))),{group:e,name:o,away:n,status:a}}};function m(t){switch(t[0]){case"name":case"n":case"N":{let[e,o,r]=t;return["name",o,r,e==="N"]}case"chat":case"c":{let[,e,o]=t;return["chat",e,o]}case"join":case"j":case"J":{let[e,o]=t;return["join",o,e==="J"]}case"leave":case"l":case"L":{let[e,o]=t;return["leave",o,e==="L"]}case"battle":case"b":{let[,e,o,r]=t;return["battle",e,o,r]}}return t}var P=new Set(["ingrain","quickguard","wideguard","craftyshield","matblock","protect","mist","safeguard","electricterrain","mistyterrain","psychicterrain","telepathy","stickyhold","suctioncups","aromaveil","flowerveil","sweetveil","disguise","safetygoggles","protectivepads"]),h=new Set(["ability: Damp","ability: Dazzling","ability: Queenly Majesty","ability: Armor Tail"]),x=new Set(["thundercage","clamp","whirlpool","firespin","magmastorm","sandtomb","infestation","trapped","bind","snaptrap","wrap"]),k=new Set(["eeriespell","gmaxdepletion","spite","grudge","forewarn","sketch","leppaberry","mysteryberry"]);function b({args:t,kwArgs:e}){switch(t[0]){case"-activate":{if(e.item||e.move||e.number||e.ability)return{args:t,kwArgs:e};let[,o,r,a,n]=t,s=r,i=e.of,l=d.parseEffect(s,c).name;if(e.block)return{args:["-fail",o],kwArgs:e};if(l==="sturdy")return{args:["-activate",o,"ability: Sturdy"],kwArgs:e};if(l==="wonderguard")return{args:["-immune",o],kwArgs:{from:"ability: Wonder Guard"}};if(l==="beatup"&&e.of)return{args:t,kwArgs:{name:e.of}};if(P.has(l))return i?(e.of=o,{args:["-block",i,s,a||""],kwArgs:e}):{args:["-block",o,s,a||""],kwArgs:e};if(l==="charge")return{args:["-singlemove",o,"Charge"],kwArgs:{of:i||void 0}};if(x.has(l))return{args:["-start",o,s],kwArgs:{of:i||""}};if(l==="fairylock")return{args:["-fieldactivate",s],kwArgs:{}};if(l==="symbiosis"||l==="poltergeist")e.item=a;else if(l==="magnitude")e.number=a;else if(l==="skillswap"||l==="mummy")e.ability=a,e.ability2=n;else if(l==="wanderingspirit")if(a)e.ability=a,e.ability2=n;else return{args:["-ability",o,"Wandering Spirit"],kwArgs:{}};else k.has(l)&&(e.move=a,e.number=n);return{args:["-activate",o,s,i||""],kwArgs:e}}case"-start":{(e.from==="Protean"||e.from==="Color Change")&&(e.from="ability:"+e.from);break}case"move":{e.from==="Magic Bounce"&&(e.from="ability: Magic Bounce");break}case"cant":{let[,o,r,a]=t;if(h.has(r))return{args:["-block",o,r,a,e.of||""],kwArgs:{}};break}case"gen":{let[,o]=t;return{args:["gen",Number(o)],kwArgs:{}}}case"-nothing":t=["-activate","","move: Splash"]}return{args:t,kwArgs:e}}return N(I);})(); |
@@ -108,3 +108,2 @@ import { Protocol, Args, KWArgs } from '../index.js'; | ||
'|faint|'(args: Args['|faint|']): boolean; | ||
'|split|'(args: Args['|split|']): boolean; | ||
'|-formechange|'(args: Args['|-formechange|'], kwArgs: KWArgs['|-formechange|']): boolean; | ||
@@ -111,0 +110,0 @@ '|-fail|'(args: Args['|-fail|'], kwArgs: KWArgs['|-fail|']): boolean; |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkK7K4LEXQjs = require('../chunk-K7K4LEXQ.js'); | ||
var _chunkHYZTBSMXjs = require('../chunk-HYZTBSMX.js'); | ||
@@ -541,5 +541,2 @@ // src/verifier/index.ts | ||
} | ||
"|split|"(args) { | ||
return args.length === 2 && verifyPlayer(args[1]); | ||
} | ||
"|-formechange|"(args, kwArgs) { | ||
@@ -825,3 +822,3 @@ if (!(verifyPokemonIdent(args[1]) && verifySpeciesName(args[2], this.gen) && verifyKWArgs(kwArgs, [...KWARGS, "msg"], this.gen))) { | ||
verify(data) { | ||
for (const { roomid, args, kwArgs } of _chunkK7K4LEXQjs.Protocol.parse(data)) { | ||
for (const { roomid, args, kwArgs } of _chunkHYZTBSMXjs.Protocol.parse(data)) { | ||
if (!verifyRoomID(roomid)) | ||
@@ -835,3 +832,3 @@ return data; | ||
verifyLine(line) { | ||
const parsed = _chunkK7K4LEXQjs.Protocol.parseBattleLine(line); | ||
const parsed = _chunkHYZTBSMXjs.Protocol.parseBattleLine(line); | ||
const { args, kwArgs } = parsed; | ||
@@ -841,6 +838,6 @@ return this.dispatch(args, kwArgs) ? void 0 : parsed; | ||
dispatch(args, kwArgs) { | ||
const key = _chunkK7K4LEXQjs.Protocol.key(args); | ||
const key = _chunkHYZTBSMXjs.Protocol.key(args); | ||
if (!key || !this.handler[key]) | ||
return false; | ||
if (Object.keys(kwArgs).length && !(key in _chunkK7K4LEXQjs.Protocol.ARGS_WITH_KWARGS)) | ||
if (Object.keys(kwArgs).length && !(key in _chunkHYZTBSMXjs.Protocol.ARGS_WITH_KWARGS)) | ||
return false; | ||
@@ -847,0 +844,0 @@ if (!this.handler[key](args, kwArgs)) |
{ | ||
"name": "@pkmn/protocol", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Parsing logic for Pokémon Showdown's PROTOCOL and SIM-PROTOCOL", | ||
@@ -43,4 +43,4 @@ "repository": "github:pkmn/ps", | ||
"devDependencies": { | ||
"@pkmn/dex": "^0.7.3", | ||
"@pkmn/data": "^0.7.3" | ||
"@pkmn/dex": "^0.7.4", | ||
"@pkmn/data": "^0.7.4" | ||
}, | ||
@@ -47,0 +47,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1032060
27
7857