Skip to content

Commit

Permalink
Added notes tab to building sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
Veilza committed Jul 1, 2024
1 parent 21f70af commit 20b68c4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
4 changes: 3 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@
"building": {
"htmlFields": [
"description",
"benefits"
"benefits",
"note.public",
"note.private"
],
"objectFields": [
"trackers"
Expand Down
21 changes: 18 additions & 3 deletions module/building/building-item-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class BuildingItemSheet extends ItemSheet {
// Define the context we're using
const context = await super.getData(options)

// Generate quick references in the context for permissions levels
if (!game.user.isGM && this.item.limited) context.permissions = 'limited'
if (!game.user.isGM && this.item.observer) context.permissions = 'observer'
if (game.user.isGM || this.item.isOwner) context.permissions = 'owner'

// Manipulate any data in this context that we need to

// Tracker data from settings
Expand Down Expand Up @@ -98,9 +103,19 @@ export class BuildingItemSheet extends ItemSheet {
relativeTo: this.object
})

if (!game.user.isGM && this.item.limited) context.permissions = 'limited'
if (!game.user.isGM && this.item.observer) context.permissions = 'observer'
if (game.user.isGM || this.item.isOwner) context.permissions = 'owner'
// Private and Public notes
context.note = {
public: await TextEditor.enrichHTML(this.object.system.note.public, {
async: true,
secrets: this.object.isOwner,
relativeTo: this.object
}),
private: await TextEditor.enrichHTML(this.object.system.note.private, {
async: true,
secrets: this.object.isOwner,
relativeTo: this.object
})
}

// Return the context once we're done with our changes
return context
Expand Down
18 changes: 18 additions & 0 deletions module/building/building-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ export class BuildingModel extends foundry.abstract.TypeDataModel {
required: false
})

// Notes Tab
schema.note = new fields.SchemaField({
public: new fields.HTMLField({
required: false,
blank: true,
initial: ''
}),
private: new fields.HTMLField({
required: false,
blank: true,
initial: '',
gmOnly: true
})
},
{
label: 'settlement-sheets.Notes'
})

return schema
}
}
1 change: 1 addition & 0 deletions module/scripts/preload-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const _preloadTemplates = async function () {
// Building sheet
'modules/settlement-sheets/templates/parts/building/overview.hbs',
'modules/settlement-sheets/templates/parts/building/statistics.hbs',
'modules/settlement-sheets/templates/parts/building/notes.hbs',

// Dialog templates
'modules/settlement-sheets/templates/remove-building-dialog.hbs'
Expand Down
6 changes: 6 additions & 0 deletions templates/building-sheet-limited.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
{{!-- Tab Navigation --}}
<nav class="sheet-tabs tabs" data-group="primary">
<div class="item" data-tab="overview">{{localize "settlement-sheets.TABS.Overview"}}</div>
{{#ifeq permissions 'limited'}}
<div class="item" data-tab="notes">{{localize "settlement-sheets.TABS.Notes"}}</div>
{{/ifeq}}
</nav>

{{!-- Body --}}
<section class="sheet-body">
{{!-- Group Members Tab --}}
{{> "modules/settlement-sheets/templates/parts/building/overview.hbs"}}

{{!-- Notes Tab --}}
{{> "modules/settlement-sheets/templates/parts/building/notes.hbs"}}
</section>
</form>
8 changes: 6 additions & 2 deletions templates/building-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
<nav class="sheet-tabs tabs" data-group="primary">
<div class="item" data-tab="overview">{{localize "settlement-sheets.TABS.Overview"}}</div>
<div class="item" data-tab="statistics">{{localize "settlement-sheets.TABS.Statistics"}}</div>
<div class="item" data-tab="notes">{{localize "settlement-sheets.TABS.Notes"}}</div>
</nav>

{{!-- Body --}}
<section class="sheet-body">
{{!-- Group Members Tab --}}
{{!-- Overview Tab --}}
{{> "modules/settlement-sheets/templates/parts/building/overview.hbs"}}

{{!-- Shared Features Tab --}}
{{!-- Statistics Tab --}}
{{> "modules/settlement-sheets/templates/parts/building/statistics.hbs"}}

{{!-- Notes Tab --}}
{{> "modules/settlement-sheets/templates/parts/building/notes.hbs"}}
</section>
</form>
13 changes: 13 additions & 0 deletions templates/parts/building/notes.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="tab note" data-group="primary" data-tab="notes">
<h2>{{localize 'settlement-sheets.PublicNotes'}}</h2>
<div class="public-notes">
{{editor note.public target="system.note.public" button=true editable=editable}}
</div>

{{#ifeq permissions 'owner'}}
<h2>{{localize 'settlement-sheets.PrivateNotes'}}</h2>
<div class="private-notes">
{{editor note.private target="system.note.private" button=true editable=editable}}
</div>
{{/ifeq}}
</div>

0 comments on commit 20b68c4

Please sign in to comment.