Skip to content

Commit

Permalink
fix: fix parsed data
Browse files Browse the repository at this point in the history
  • Loading branch information
isuke committed Jan 7, 2024
1 parent 1775f08 commit 6b9faaf
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 78 deletions.
55 changes: 31 additions & 24 deletions lib/parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ type Rarity = "Normal" | "Magic" | "Rare" | "Unique"
type Influence = "Shaper" | "Elder" | "Crusader" | "Hunter" | "Redeemer" | "Warlord" | "None"
type GemQualityType = "Superior" | "Divergent" | "Anomalous" | "Phantasmal"
type SocketType = "R" | "G" | "B" | "W" | "A" | "D"
type SocketGroup =
| SocketType
| `${SocketType}${SocketType}`
| `${SocketType}${SocketType}${SocketType}`
| `${SocketType}${SocketType}${SocketType}${SocketType}`
| `${SocketType}${SocketType}${SocketType}${SocketType}${SocketType}`
| `${SocketType}${SocketType}${SocketType}${SocketType}${SocketType}${SocketType}`

type ColorName = "Red" | "Green" | "Blue" | "Brown" | "White" | "Yellow" | "Cyan" | "Grey" | "Orange" | "Pink" | "Purple"

Expand Down Expand Up @@ -83,23 +90,23 @@ type AdvancedBlock = {
conditions: {
Class?: { ope: MatchOperator; vals: string[] }
BaseType?: { ope: MatchOperator; vals: string[] }
Rarity?: `${MatchOperator} ${Rarity}` | Rarity
BaseDefencePercentile?: `${NumOperator} ${number}`
BaseArmour?: `${NumOperator} ${number}`
BaseEnergyShield?: `${NumOperator} ${number}`
BaseEvasion?: `${NumOperator} ${number}`
BaseWard?: `${NumOperator} ${number}`
DropLevel?: `${NumOperator} ${number}`
ItemLevel?: `${NumOperator} ${number}`
AreaLevel?: `${NumOperator} ${number}`
GemLevel?: `${NumOperator} ${number}`
Rarity?: { ope: NumOperator; val: Rarity }
BaseDefencePercentile?: { ope: NumOperator; val: number }
BaseArmour?: { ope: NumOperator; val: number }
BaseEnergyShield?: { ope: NumOperator; val: number }
BaseEvasion?: { ope: NumOperator; val: number }
BaseWard?: { ope: NumOperator; val: number }
DropLevel?: { ope: NumOperator; val: number }
ItemLevel?: { ope: NumOperator; val: number }
AreaLevel?: { ope: NumOperator; val: number }
GemLevel?: { ope: NumOperator; val: number }
TransfiguredGem?: boolean
StackSize?: `${NumOperator} ${number}`
MapTier?: `${NumOperator} ${number}`
Quality?: `${NumOperator} ${number}`
LinkedSockets?: `${NumOperator} ${number}`
Sockets?: `${NumOperator} ${number}${string}`
SocketGroup?: `${NumOperator} ${number}${string}`
StackSize?: { ope: NumOperator; val: number }
MapTier?: { ope: NumOperator; val: number }
Quality?: { ope: NumOperator; val: number }
LinkedSockets?: { ope: NumOperator; val: number }
Sockets?: { ope: NumOperator; vals: `${number}${SocketGroup}` | SocketGroup }
SocketGroup?: { ope: NumOperator; vals: `${number}${SocketGroup}` | SocketGroup }
FracturedItem?: boolean
SynthesisedItem?: boolean
Corrupted?: boolean
Expand All @@ -110,16 +117,16 @@ type AdvancedBlock = {
ElderMap?: boolean
BlightedMap?: boolean
UberBlightedMap?: boolean
Height?: `${NumOperator} ${number}`
Width?: `${NumOperator} ${number}`
CorruptedMods?: `${NumOperator} ${number}`
EnchantmentPassiveNum?: `${NumOperator} ${number}`
HasExplicitMod?: { ope: MatchOperator; vals: string[] }
Height?: { ope: NumOperator; val: number }
Width?: { ope: NumOperator; val: number }
CorruptedMods?: { ope: NumOperator; val: number }
EnchantmentPassiveNum?: { ope: NumOperator; val: number }
HasExplicitMod?: { numeric: { ope: NumOperator; val: number }; vals: string[] } | { ope: NumOperator; vals: string[] }
HasImplicitMod?: boolean
HasEaterOfWorldsImplicit?: `${NumOperator} ${number}`
HasSearingExarchImplicit?: `${NumOperator} ${number}`
HasEaterOfWorldsImplicit?: { ope: NumOperator; val: number }
HasSearingExarchImplicit?: { ope: NumOperator; val: number }
AnyEnchantment?: boolean
HasEnchantment?: { ope: MatchOperator; vals: string[] }
HasEnchantment?: { numeric: { ope: NumOperator; val: number }; vals: string[] } | { ope: NumOperator; vals: string[] }
HasInfluence?: { ope: MatchOperator; vals: Influence[] }
EnchantmentPassiveNode?: { ope: MatchOperator; vals: string[] }
Replica?: boolean
Expand Down
18 changes: 14 additions & 4 deletions src/advanced-poe-filter.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,20 @@ conditionHasCruciblePassiveTree = attr:'HasCruciblePassiveTree' __ val:condition
// Condition Values
conditionValueArray = operator:(matchOperator __)? names:names { return operator ? { ope: operator[0], vals: names } : { ope: '=', vals: names } }
conditionValueArrayOrNone = conditionValueArray / val:'None' { return val ? { ope: undefined, val: 'None' } : { ope, vals } }
conditionValueNumericAndArray = pre:((numOperator __ num __) / (matchOperator __))? names:names { return pre ? (pre.length === 4 ? { numeric: { ope: pre[0], val: pre[2] }, vals: names } : { ope: pre[0], vals: names } ) : { ope: '=', vals: names } }
conditionValueNumber = operator:numOperator __ num:num { return `${operator} ${num}` }
conditionValueSocketType = operator:(numOperator __)? num:(num)? socketType:socketType { return operator ? `${operator[0]} ${num ? num : ''}${socketType}` : `= ${num ? num : ''}${socketType}` }
conditionValueRarity = operator:(numOperator __)? rarity:rarity { return operator ? `${operator[0]} ${rarity}` : rarity }
conditionValueNumericAndArray = pre:((numOperator __ num __) / (matchOperator __))? names:names {
if (pre) {
if (pre.length === 4) {
return { numeric: { ope: pre[0], val: pre[2] }, vals: names }
} else {
return { ope: pre[0], vals: names }
}
} else {
return { ope: '=', vals: names }
}
}
conditionValueNumber = operator:numOperator __ num:num { return { ope: operator, val: num } }
conditionValueSocketType = operator:(numOperator __)? num:(num)? socketType:socketType { return operator ? { ope: operator[0], val: `${num ? num : ''}${socketType}` } : { ope: '=', val: `${num ? num : ''}${socketType}` } }
conditionValueRarity = operator:(numOperator __)? rarity:rarity { return operator ? { ope: operator[0], val: rarity } : { ope: '=', val: rarity } }
conditionValueBoolean = boolean

//
Expand Down
136 changes: 86 additions & 50 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("parse : blank and comment lines", (t) => {
activity: "Hide",
conditions: {
Class: { ope: "=", vals: ["Maps"] },
MapTier: "<= 4",
MapTier: { ope: "<=", val: 4 },
},
actions: {},
branches: [],
Expand Down Expand Up @@ -208,23 +208,23 @@ Unset "Section6"
conditions: {
Class: { ope: "=", vals: ["Maps"] },
BaseType: { ope: "=", vals: ["Sacrificial Garb"] },
DropLevel: "> 85",
ItemLevel: ">= 70",
AreaLevel: "< 30",
GemLevel: "= 10",
DropLevel: { ope: ">", val: 85 },
ItemLevel: { ope: ">=", val: 70 },
AreaLevel: { ope: "<", val: 30 },
GemLevel: { ope: "=", val: 10 },
TransfiguredGem: true,
StackSize: "< 11",
MapTier: "<= 12",
Quality: "= 15",
LinkedSockets: "= 6",
Sockets: ">= 5RGBWAD",
SocketGroup: ">= 5RGBWAD",
Rarity: "= Rare",
BaseDefencePercentile: "> 50",
BaseArmour: "> 40",
BaseEnergyShield: "> 41",
BaseEvasion: "> 42",
BaseWard: "> 43",
StackSize: { ope: "<", val: 11 },
MapTier: { ope: "<=", val: 12 },
Quality: { ope: "=", val: 15 },
LinkedSockets: { ope: "=", val: 6 },
Sockets: { ope: ">=", val: "5RGBWAD" },
SocketGroup: { ope: ">=", val: "5RGBWAD" },
Rarity: { ope: "=", val: "Rare" },
BaseDefencePercentile: { ope: ">", val: 50 },
BaseArmour: { ope: ">", val: 40 },
BaseEnergyShield: { ope: ">", val: 41 },
BaseEvasion: { ope: ">", val: 42 },
BaseWard: { ope: ">", val: 43 },
FracturedItem: false,
SynthesisedItem: false,
Corrupted: true,
Expand All @@ -235,14 +235,14 @@ Unset "Section6"
ElderMap: true,
BlightedMap: true,
UberBlightedMap: true,
Height: "> 1",
Width: "> 2",
CorruptedMods: ">= 1",
EnchantmentPassiveNum: "> 5",
Height: { ope: ">", val: 1 },
Width: { ope: ">", val: 2 },
CorruptedMods: { ope: ">=", val: 1 },
EnchantmentPassiveNum: { ope: ">", val: 5 },
HasExplicitMod: { ope: "=", vals: ["Foo", "Bar"] },
HasImplicitMod: true,
HasEaterOfWorldsImplicit: ">= 4",
HasSearingExarchImplicit: ">= 4",
HasEaterOfWorldsImplicit: { ope: ">=", val: 4 },
HasSearingExarchImplicit: { ope: ">=", val: 4 },
AnyEnchantment: true,
HasEnchantment: { ope: "=", vals: ["Foo", "Bar"] },
HasInfluence: { ope: "=", vals: ["Shaper", "Elder"] },
Expand Down Expand Up @@ -280,9 +280,9 @@ Unset "Section6"
ope: "=",
vals: ["Two-Toned Boots", "Spiked Gloves", "Gripped Gloves", "Fingerless Silk Gloves", "Bone Helmet"],
},
Sockets: "= 5RGBWAD",
SocketGroup: "= 5RGBWAD",
Rarity: "Rare",
Sockets: { ope: "=", val: "5RGBWAD" },
SocketGroup: { ope: "=", val: "5RGBWAD" },
Rarity: { ope: "=", val: "Rare" },
HasExplicitMod: { ope: "==", vals: ["Foo", "Bar"] },
HasEnchantment: { ope: "==", vals: ["Foo", "Bar"] },
HasInfluence: { ope: "==", vals: ["Shaper", "Elder"] },
Expand All @@ -307,8 +307,8 @@ Unset "Section6"
name: "Section3",
activity: "Show",
conditions: {
Sockets: "= RGBWAD",
SocketGroup: "= RGBWAD",
Sockets: { ope: "=", val: "RGBWAD" },
SocketGroup: { ope: "=", val: "RGBWAD" },
HasExplicitMod: {
numeric: { ope: ">=", val: 2 },
vals: ["Foo", "Bar"],
Expand Down Expand Up @@ -413,7 +413,7 @@ Show "Map Section"
activity: "Show",
conditions: {
Class: { ope: "=", vals: ["Maps"] },
MapTier: "> 3",
MapTier: { ope: ">", val: 3 },
},
actions: {
SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
Expand Down Expand Up @@ -450,7 +450,7 @@ Hide "Remain Section"
activity: "Hide",
conditions: {
Class: { ope: "=", vals: ["Maps"] },
MapTier: "<= 4",
MapTier: { ope: "<=", val: 4 },
},
actions: {},
branches: [],
Expand Down Expand Up @@ -508,7 +508,7 @@ Show "Map Section"
activity: "Show",
conditions: {
Class: { ope: "=", vals: ["Maps"] },
MapTier: "> 3",
MapTier: { ope: ">", val: 3 },
},
actions: {
SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
Expand All @@ -523,15 +523,19 @@ Show "Map Section"
id: "0001",
name: "Rare",
activity: "Show",
conditions: { Rarity: "Rare" },
conditions: {
Rarity: { ope: "=", val: "Rare" },
},
actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
branches: [],
},
{
id: "0002",
name: "Magic",
activity: "Hide",
conditions: { Rarity: "Magic" },
conditions: {
Rarity: { ope: "=", val: "Magic" },
},
actions: {},
branches: [],
},
Expand Down Expand Up @@ -571,7 +575,7 @@ Show "Map Section"
activity: "Show",
conditions: {
Class: { ope: "=", vals: ["Maps"] },
MapTier: "> 3",
MapTier: { ope: ">", val: 3 },
},
actions: {
SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
Expand All @@ -586,15 +590,19 @@ Show "Map Section"
id: "0001",
name: "Rare",
activity: "Show",
conditions: { Rarity: "Rare" },
conditions: {
Rarity: { ope: "=", val: "Rare" },
},
actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
branches: [],
},
{
id: "0002",
name: "Magic",
activity: "Hide",
conditions: { Rarity: "Magic" },
conditions: {
Rarity: { ope: "=", val: "Magic" },
},
actions: {},
branches: [],
},
Expand Down Expand Up @@ -651,15 +659,21 @@ Show "Map Section"
id: "0001",
name: "Rare",
activity: "Show",
conditions: { Rarity: "Rare" },
actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
conditions: {
Rarity: { ope: "=", val: "Rare" },
},
actions: {
SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 },
},
branches: [],
},
{
id: "0002",
name: "Magic",
activity: "Hide",
conditions: { Rarity: "Magic" },
conditions: {
Rarity: { ope: "=", val: "Magic" },
},
actions: {},
branches: [],
},
Expand All @@ -673,16 +687,24 @@ Show "Map Section"
id: "0003",
name: "High Tier",
activity: "Show",
conditions: { MapTier: ">= 11" },
actions: { PlayAlertSound: { id: "1", volume: 300 } },
conditions: {
MapTier: { ope: ">=", val: 11 },
},
actions: {
PlayAlertSound: { id: "1", volume: 300 },
},
branches: [],
},
{
id: "0004",
name: "Middle Tier",
activity: "Show",
conditions: { MapTier: ">= 6" },
actions: { PlayAlertSound: { id: "2", volume: 300 } },
conditions: {
MapTier: { ope: ">=", val: 6 },
},
actions: {
PlayAlertSound: { id: "2", volume: 300 },
},
branches: [],
},
],
Expand Down Expand Up @@ -738,15 +760,21 @@ Show "Map Section"
id: "0001",
name: "Rare",
activity: "Show",
conditions: { Rarity: "Rare" },
actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
conditions: {
Rarity: { ope: "=", val: "Rare" },
},
actions: {
SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 },
},
branches: [],
},
{
id: "0004",
name: "Magic",
activity: "Hide",
conditions: { Rarity: "Magic" },
conditions: {
Rarity: { ope: "=", val: "Magic" },
},
actions: {},
branches: [
{
Expand All @@ -757,16 +785,24 @@ Show "Map Section"
id: "0002",
name: "High Tier",
activity: "Show",
conditions: { MapTier: ">= 11" },
actions: { PlayAlertSound: { id: "1", volume: 300 } },
conditions: {
MapTier: { ope: ">=", val: 11 },
},
actions: {
PlayAlertSound: { id: "1", volume: 300 },
},
branches: [],
},
{
id: "0003",
name: "Middle Tier",
activity: "Show",
conditions: { MapTier: ">= 6" },
actions: { PlayAlertSound: { id: "2", volume: 300 } },
conditions: {
MapTier: { ope: ">=", val: 6 },
},
actions: {
PlayAlertSound: { id: "2", volume: 300 },
},
branches: [],
},
],
Expand Down

0 comments on commit 6b9faaf

Please sign in to comment.