Skip to content

Commit 75eeba8

Browse files
committed
Add custom images
1 parent 55e3fbb commit 75eeba8

File tree

7 files changed

+93
-69
lines changed

7 files changed

+93
-69
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7-
## Unreleased
7+
## 2.8.5
88

99
### Added
10-
- Edit button to buildings that have an editor.
10+
- Edit button to buildings that have an editor (it's still rather terrible, but at least now it's more visible)
11+
- Custom image uploading for Hero patrons accessible in the settings.
1112

1213
### Changed
14+
- Fixed issue with Patreon thanks list sometimes breaking.
1315
- Modified formatting
1416
- Shifted notification down slightly so it does not collide with the header
1517
- Fixed an issue with Tippy not initialising for elements created in a table.
1618

19+
### Removed
20+
- Obsolete 'Show Sliders' setting.
21+
1722
## 2.8.5
1823

1924
### Added

lib/src/getIllustration.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
import { Town } from '../town/_common'
2-
31
type Illustration =
42
| 'general-store-illustration'
53
| 'tavern-illustration'
64
| 'town-illustration'
75
| 'city-illustration'
86

9-
export const getIllustration = (illustration: Illustration, alt: string) => {
10-
let img = '<img '
11-
img += 'id="illustration" '
12-
const path = getPath()
13-
14-
img += `src="${path}src/Resources/img/hero/${illustration}.jpg" `
15-
// If it's in production, then we can add the srcset options, otherwise we might as well omit it.
16-
if (process.env.NODE_ENV === 'production' && location.origin !== 'file://') img += `srcset="${path}src/Resources/img/hero/${illustration}-x360.jpg 360w, ${path}src/Resources/img/hero/${illustration}-x411.jpg 411w, ${path}src/Resources/img/hero/${illustration}-x500.jpg 500w, ${path}src/Resources/img/hero/${illustration}-x576.jpg 576w, ${path}src/Resources/img/hero/${illustration}-x768.jpg 768w, ${path}src/Resources/img/hero/${illustration}-x992.jpg 992w, ${path}src/Resources/img/hero/${illustration}-x1200.jpg 1200w, ${path}src/Resources/img/hero/${illustration}.jpg" `
17-
img += `alt="${alt || `An image depicting ${lib.articles.output(illustration)}, created by artist Juho Huttunen.`}" `
18-
img += '/>'
19-
return img
20-
}
21-
227
const getPath = () => {
238
if (process.env.NODE_ENV === 'production' && location.origin !== 'file://') {
249
return './'
2510
}
2611
return '../'
2712
}
2813

29-
// It would obviously be preferable to output actual <img>s instead of having it render via SugarCube.
30-
// Unfortunately, I am not a clever man, and cannot figure it out.
31-
export const getImage = (illustration: Illustration) => {
14+
const addLocalSourceSet = (illustration: Illustration, sizes: string[] = ['360', '411', '500', '576', '768', '992', '1200']) => {
15+
let img = ''
16+
const path = getPath()
17+
for (const size of sizes) {
18+
img += `${path}src/Resources/img/hero/${illustration}-x${size}.jpg ${size}w, `
19+
}
20+
return img
21+
}
22+
23+
export const getCustomImage = (url: URL) => {
24+
const img = document.createElement('img')
25+
img.id = 'illustration'
26+
img.src = url as unknown as string
27+
img.alt = 'A custom-defined image.'
28+
return img.outerHTML
29+
}
30+
31+
export const getLocalImage = (illustration: Illustration) => {
3232
const img = document.createElement('img')
3333
const path = getPath()
3434
img.id = 'illustration'
3535
img.src = `${path}src/Resources/img/hero/${illustration}.jpg`
36-
img.srcset = `${path}src/Resources/img/hero/${illustration}-x360.jpg 360w, ${path}src/Resources/img/hero/${illustration}-x411.jpg 411w, ${path}src/Resources/img/hero/${illustration}-x500.jpg 500w, ${path}src/Resources/img/hero/${illustration}-x576.jpg 576w, ${path}src/Resources/img/hero/${illustration}-x768.jpg 768w, ${path}src/Resources/img/hero/${illustration}-x992.jpg 992w, ${path}src/Resources/img/hero/${illustration}-x1200.jpg 1200w, ${path}src/Resources/img/hero/${illustration}.jpg`
36+
if (process.env.NODE_ENV === 'production' && location.origin !== 'file://') img.srcset = `${addLocalSourceSet(illustration)} ${path}src/Resources/img/hero/${illustration}.jpg`
3737
img.alt = `An image depicting ${lib.articles.output(illustration)}, created by artist Juho Huttunen.`
38-
return img
39-
}
40-
41-
export const townOrCity = (town: Town) => {
42-
if (town.type === 'city' || town.type === 'town') return 'city-illustration'
43-
return 'town-illustration'
38+
return img.outerHTML
4439
}

src/Settings/CSS/stylesheet.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ footer {
232232
padding-bottom: 20vw;
233233
}
234234
#paper {
235-
top: 15vw
235+
top: 20vw
236236
}
237237
body {
238238
font-size: 16px
@@ -252,7 +252,7 @@ footer {
252252
padding-bottom: 20vw;
253253
}
254254
#paper {
255-
top: 14vw;
255+
top: 21vw;
256256
}
257257
blockquote {
258258
margin-inline-start: 10px;
@@ -275,7 +275,7 @@ footer {
275275
padding-bottom: 25vw;
276276
}
277277
#paper {
278-
top: 13vw
278+
top: 20vw
279279
}
280280
}
281281

@@ -294,7 +294,7 @@ footer {
294294
padding-bottom: 28vw;
295295
}
296296
#paper {
297-
top: 13vw
297+
top: 20vw
298298
}
299299
}
300300

@@ -313,7 +313,7 @@ footer {
313313
padding-bottom: 35vw;
314314
}
315315
#paper {
316-
top: 13.5vw
316+
top: 20vw
317317
}
318318
}
319319

@@ -332,7 +332,7 @@ footer {
332332
padding: 19vw;
333333
}
334334
#paper {
335-
top: 13vw
335+
top: 19vw
336336
}
337337
}
338338

@@ -353,7 +353,7 @@ footer {
353353
}
354354

355355
#paper {
356-
top: 14vw
356+
top: 20vw
357357
}
358358
}
359359

src/Settings/CustomImages.twee

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323
<<switch $targetType>>
2424
<<case 'buildingType'>>
2525
<label name="Select building type" for="listbox-target">
26-
<<listbox "$target" autoselect>>
27-
<<optionsfrom Object.keys(setup.buildingTypes).filter(building => {
28-
const nsfwItems = ['Brothel'];
29-
if (!settings.disableNSFW) return building;
30-
return !building.includes(nsfwItems);
31-
})>>
32-
<</listbox>>
26+
<<listbox "$target" autoselect>><<optionsfrom setup.buildingTypes>><</listbox>>
3327
</label>
3428
<<case 'building'>>
3529
<label name="Select specific building" for="listbox-target">
@@ -103,8 +97,6 @@
10397

10498
--
10599
<<button "Save">>
106-
107-
<<set $customImagesData[$targetType][$target] to $url>>
108100
<<set _outputImage to $url>>
109101
<<switch $targetType>>
110102
<<case "npc">>
@@ -117,20 +109,22 @@
117109
<<set $town.roads[$target].customImage to $url>>
118110
<<case "town">>
119111
<<set $town.customImage to $url>>
112+
<<default>>
113+
<<set $customImagesData[$targetType][$target] to $url>>
120114
<</switch>>
121115
<<run State.metadata.set('customImages', $customImagesData)>>
116+
<<update>>
122117
<</button>>
123118
<br>
124-
Great sources include:
125-
<ul>
119+
Great sources include:<ul>
126120
<li>[[ArtBreeder|https://www.artbreeder.com/create]]</li>
127121
<li>[[This gallery of watercolour concept art|https://imgur.com/gallery/5WcP9pn]]</li>
128122
</ul>
129123
<br>
130-
Loaded URL: <<idp _outputImage>>
124+
Loaded URL: <<if _outputImage>>_outputImage<</if>>
125+
<br><</liveblock>>
131126
<br>
132-
133-
<</liveblock>>
127+
<<include "ShowAllSaved">>
134128

135129
:: PrintImage [nobr]
136130
<<set $customImages to recall('customImages')>>
@@ -152,27 +146,41 @@ Loaded URL: <<idp _outputImage>>
152146
<</if>>
153147

154148
:: ShowAllSaved [nobr force-one-column]
155-
<<run console.log(State.metadata.get('customImages'))>>
149+
<details><summary>Saved Images</summary>
150+
<<liveblock>><<run console.log(State.metadata.get('customImages'))>>
156151
<<set _temp to State.metadata.get('customImages')>>
152+
<<button "Delete all">>
153+
<<run State.metadata.delete('customImages')>>
154+
<<set $customImagesData to {
155+
'deity': {},
156+
'buildingType': {},
157+
'factionType': {}
158+
}>>
159+
<<run State.metadata.set('customImages', $customImagesData)>>
160+
<<update>>
161+
<</button>> (NPCs and other specifics are flushed on restart)
157162
<table>
158163
<tr>
159164
<th>Object</th>
160165
<th>Name</th>
161166
<th>File</th>
162167
<th>Delete</th>
163168
</tr>
164-
<<for _typeKey, _type range _temp>>
169+
<<for _typeKey, _type range _temp>><<capture _typeKey, _type>>
165170
<<if Object.keys(_type).length > 0>><<set _length to Object.keys(_type).length + 1>>
166171
<tr>
167172
<th @rowspan=_length>_typeKey</th>
168173
</tr>
169-
<<for _itemKey, _item range _type>>
174+
<<for _itemKey, _item range _type>><<capture _itemKey, _item>>
170175
<tr>
171176
<td>_itemKey</td>
172177
<td>_item</td>
173-
<td>x</td>
174-
</tr>
178+
<td><<link 'x'>><<run delete _temp[_typeKey][_itemKey]>><<run State.metadata.set('customImages', _temp)>><<update>>
179+
<</link>>
180+
</td>
181+
</tr><</capture>>
175182
<</for>>
176-
<</if>>
183+
<</if>><</capture>>
177184
<</for>>
178-
</table>
185+
</table>
186+
<</liveblock>></details>

src/Settings/Setting.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ $(document).on(':dialogopened', function () {
4444
}
4545
}
4646
)
47+
setup.addSettingButton({
48+
target: 'pantheon',
49+
name: 'customImages',
50+
description: 'Add custom images.',
51+
buttonDescription: 'Open Image Importer'
52+
},
53+
() => {
54+
if (isPatron()) {
55+
setup.openDialog({
56+
header: 'Import Images',
57+
passage: 'CustomImages',
58+
rerender: true
59+
})
60+
} else {
61+
setup.openDialog({
62+
header: 'Patreon Content',
63+
passage: 'ImportPatreon',
64+
rerender: true
65+
})
66+
}
67+
}
68+
)
4769
}
4870
})
4971

@@ -72,23 +94,18 @@ Setting.addToggle('darkMode', {
7294
default: window.matchMedia('(prefers-color-scheme: dark)').matches
7395
})
7496

75-
Setting.addToggle('showCelsius', {
76-
label: 'Show celsius?'
77-
})
78-
79-
Setting.addToggle('showMetric', {
80-
label: 'Show metric?'
81-
})
82-
8397
Setting.addToggle('showBiomeGeneration', {
8498
label: 'Edit biome before generation?',
8599
desc: 'If you want to specify the biome and demographics before town creation, enable this.',
86100
onChange: settingShowBiomeGeneration
87101
})
88102

89-
Setting.addToggle('showSliders', {
90-
label: 'Show sliders?',
91-
desc: 'If you would like to change the variables of buildings, enable this. Warning: feature is in beta.'
103+
Setting.addToggle('showCelsius', {
104+
label: 'Show celsius?'
105+
})
106+
107+
Setting.addToggle('showMetric', {
108+
label: 'Show metric?'
92109
})
93110

94111
Setting.addToggle('silverStandard', {

src/Start/Start.twee

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
<<include "CreateBuilding">>
77
<span id="buildings" role="list"><<include "RoadsList">></span>
88
<<run console.log($town)>>
9-
<<include "Popup">>
10-
[[CustomImages]]
9+
<<include "Popup">>

src/Start/StoryInit.twee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<<run setup.init()>>
66

77
<<set setup.data to {
8-
versionNumber: "2.8.5",
8+
versionNumber: "2.8.6",
99
badges: {
1010
github: lib.createBadge([
1111
lib.badges.stats.githubForks,

0 commit comments

Comments
 (0)