Skip to content

Commit

Permalink
Merge pull request #237 from ben/new-location
Browse files Browse the repository at this point in the history
SF: Location scene buttons
  • Loading branch information
ben authored Mar 18, 2022
2 parents 0d72051 + 1e28efc commit f9e7a10
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## In progress

- Scene buttons generate actors in folders ([#237](https://github.com/ben/foundry-ironsworn/pull/237))

## 1.10.25

- Fix a bug where creating progress/vow items would output to chat multiple times ([#235](https://github.com/ben/foundry-ironsworn/pull/235))
Expand Down
1 change: 1 addition & 0 deletions src/module/applications/createActorDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class CreateActorDialog extends FormApplication<CreateActorDialogOptions>
type,
token: {
displayName: CONST.TOKEN_DISPLAY_MODES.ALWAYS,
disposition: CONST.TOKEN_DISPOSITIONS.NEUTRAL,
actorLink: true,
},
folder: this.options.folder || undefined,
Expand Down
59 changes: 56 additions & 3 deletions src/module/features/sceneButtons.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
import { IronswornActor } from '../actor/actor'
import { EditSectorDialog } from '../applications/sf/editSectorApp'
import { IronswornSettings } from '../helpers/settings'

function warn() {
ui.notifications?.warn('Soon™')
}

// Make sure a folder exists, e.g. ['Locations', 'Sector 05']
async function ensureFolder(...path: string[]): Promise<Folder | undefined> {
let parentFolder: Folder | undefined
let directory: Folder[] | undefined = game.folders?.contents

for (const name of path) {
if (directory === undefined) {
console.log('!!!')
ui.notifications?.warn('Actor folders not found???')
return
}
const existing = directory.find(x => x.name === name)
if (existing) {
parentFolder = existing
directory = (existing as any).children
continue
}
parentFolder = await Folder.create({ type: 'Actor', name, parent: parentFolder?.id })
directory = (parentFolder as any).children
}
return parentFolder
}

function editSector() {
const sceneId = game.user?.viewedScene
if (sceneId) {
new EditSectorDialog(sceneId).render(true)
}
}

async function newLocation(subtype: string, name: string) {
const parentFolder = await ensureFolder('Locations', game.scenes?.current?.name ?? '???')
const loc = await IronswornActor.create({
type: 'location',
name,
data: { subtype },
token: {
displayName: CONST.TOKEN_DISPLAY_MODES.ALWAYS,
disposition: CONST.TOKEN_DISPOSITIONS.NEUTRAL,
actorLink: true,
},
folder: parentFolder?.id,
})
// TODO: place it on the map
loc?.sheet?.render(true)
}

function newPlanet() {
newLocation('planet', 'New Planet')
}

function newStar() {
newLocation('star', 'New Stellar Object')
}

function newSettlement() {
newLocation('settlement', 'New Settlement')
}

export function activateSceneButtonListeners() {
if (!IronswornSettings.starforgedBeta) return

Expand All @@ -33,9 +86,9 @@ export function activateSceneButtonListeners() {
tools: [
{ name: 'edit', icon: 'fas fa-edit', title: game.i18n.localize('IRONSWORN.Edit'), onClick: editSector },
{ name: 'sector', icon: 'fas fa-globe', title: game.i18n.localize('IRONSWORN.NewSector'), onClick: warn },
{ name: 'star', icon: 'fas fa-star', title: game.i18n.localize('IRONSWORN.NewStar'), onClick: warn },
{ name: 'planet', icon: 'fas fa-globe-europe', title: game.i18n.localize('IRONSWORN.NewPlanet'), onClick: warn },
{ name: 'settlement', icon: 'fas fa-city', title: game.i18n.localize('IRONSWORN.NewSettlement'), onClick: warn },
{ name: 'star', icon: 'fas fa-star', title: game.i18n.localize('IRONSWORN.NewStar'), onClick: newStar },
{ name: 'planet', icon: 'fas fa-globe-europe', title: game.i18n.localize('IRONSWORN.NewPlanet'), onClick: newPlanet },
{ name: 'settlement', icon: 'fas fa-city', title: game.i18n.localize('IRONSWORN.NewSettlement'), onClick: newSettlement },
],
}

Expand Down
23 changes: 20 additions & 3 deletions src/module/vue/sf-locationsheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default {
const img = randomImage(subtype, klass)
await this.$actor.update({ img, data: { klass } })
// TODO: update prototype and all linked tokens
await this.updateAllTokens({ img })
},
async randomizeName() {
Expand All @@ -271,7 +271,8 @@ export default {
)
const name = CONFIG.IRONSWORN._.sample(json?.['Sample Names'] ?? [])
console.log(name)
this.$actor.update({ name })
await this.$actor.update({ name })
await this.updateAllTokens({ name })
},
async randomizeKlass() {
const table = await CONFIG.IRONSWORN.sfOracleByDataforgedId(
Expand Down Expand Up @@ -305,9 +306,25 @@ export default {
if (!drawText) return
// Append to description
const description = `${this.actor.data.description}\n<p><strong>${oracle.title}:</strong> ${drawText}</p>`
const description = `
${this.actor.data.description ?? ''}\n
<p><strong>${oracle.title}:</strong> ${drawText}</p>
`
await this.$actor.update({ data: { description } })
},
async updateAllTokens(data) {
// Prototype token
await this.$actor.data.token.update(data)
// All tokens in the scene
const activeTokens = this.$actor.getActiveTokens()
const updates = activeTokens.map((at) => ({
_id: at.data._id,
...data,
}))
await canvas.scene?.updateEmbeddedDocuments('Token', updates)
},
},
}
</script>

0 comments on commit f9e7a10

Please sign in to comment.