Skip to content

Commit

Permalink
Merge pull request #1624 from crnormand/r0156
Browse files Browse the repository at this point in the history
Added support for /st + standing
  • Loading branch information
crnormand authored Sep 30, 2022
2 parents fb345fa + 407bb0e commit e930f66
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release 0.15.6

- Fixed GCS 5 import when melee attack has no level.
- Fixed GCS 5 disad calculations.
- Added support for /st + standing to allow you to clear other postures (to help supoprt TAH feature)

Release 0.15.5 9/28/2022

Expand Down
2 changes: 1 addition & 1 deletion module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ export class GurpsActor extends Actor {
let tokens = this._findTokens()
if (tokens)
for (const t of tokens) {
let id = changeData === 'standing' ? this.system.conditions.posture : changeData
let id = changeData === GURPS.StatusEffectStanding ? this.system.conditions.posture : changeData
await t.toggleEffect(GURPS.StatusEffect.lookup(id))
}
}
Expand Down
33 changes: 27 additions & 6 deletions module/chat/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Command = {
off: 'unset',
unset: 'unset',
'-': 'unset',
list: 'list',
list: 'list'
}

/** @typedef {{id: string, label: string, icon: string}} EffectData */
Expand Down Expand Up @@ -69,17 +69,30 @@ export default class StatusChatProcessor extends ChatProcessor {

let effectText = this.match.groups?.name?.trim() //this.match[3]?.trim()
let effect = !!effectText ? this.findEffect(effectText) : null
let isStanding = false
if (!effect) {
ui.notifications.warn(i18n('GURPS.chatNoStatusMatched') + " '" + effectText + "'")
return
if (!effectText) {
ui.notifications.warn(i18n('GURPS.chatNoStatusMatched'))
return
} else if (!effectText.match(new RegExp(makeRegexPatternFrom(GURPS.StatusEffectStanding), 'i')) && !effectText.match(new RegExp(makeRegexPatternFrom(i18n(GURPS.StatusEffectStandingLabel)), 'i'))) {
ui.notifications.warn(i18n('GURPS.chatNoStatusMatched') + " '" + effectText + "'")
return
}
isStanding = true
}

if (this.match.groups?.data) {
let data = JSON.parse(this.match.groups.data)
data.duration.combat = game.combats?.active?.id
mergeObject(effect, data)
}

if (isStanding) {
if (theCommand == Command.set)
for (const pid in GURPS.StatusEffect.getAllPostures()) {
await this.unset(tokens, this.findEffect(pid))
}
return // can't toggle or unset standing
}
if (theCommand == Command.toggle) return await this.toggle(tokens, effect)
else if (theCommand == Command.set) return await this.set(tokens, effect)
else if (theCommand == Command.unset) return await this.unset(tokens, effect)
Expand All @@ -94,15 +107,23 @@ export default class StatusChatProcessor extends ChatProcessor {
/** @type {EffectData[]} */
let sortedEffects = []
let effectIds = Object.values(CONFIG.statusEffects.map(it => i18n(it.id)))
effectIds.push(GURPS.StatusEffectStanding)
effectIds.sort()
for (const id of effectIds) {
let effect = CONFIG.statusEffects.find(it => it.id === id)
if (effect) sortedEffects.push(effect)
if (effect) {
effect.posture = !!GURPS.StatusEffect.getAllPostures()[id] || id == GURPS.StatusEffectStanding
sortedEffects.push(effect)
}
else if (id == GURPS.StatusEffectStanding)
sortedEffects.push({ id: id, label: GURPS.StatusEffectStandingLabel, posture: true})
}

sortedEffects.forEach(s => {
html += `<tr><td>${s.id}</td><td>'${i18n(s.label)}'</td></tr>`
let p = s.posture ? ' *' : ''
html += `<tr><td>${s.id}</td><td>'${i18n(s.label)}'${p}</td></tr>`
})
html += `<tr><td></td><td>* => ${i18n('GURPS.modifierPosture')}</td></tr>`
return html + '</table>'
}

Expand Down
2 changes: 2 additions & 0 deletions module/effects/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class StatusEffect {
this._registerSetting()

GURPS.SavedStatusEffects = CONFIG.statusEffects
GURPS.StatusEffectStanding = 'standing'
GURPS.StatusEffectStandingLabel = 'GURPS.STATUSStanding'

this.useActiveEffects = true // StatusEffect.useActiveEffects()
this._statusEffects = {}
Expand Down

0 comments on commit e930f66

Please sign in to comment.