Skip to content

Commit

Permalink
Add more placeable information to looker mod
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Jun 17, 2023
1 parent b1a4d22 commit f4b4302
Show file tree
Hide file tree
Showing 9 changed files with 1,579 additions and 38 deletions.
Binary file modified img_src/vehicleicons.psd
Binary file not shown.
63 changes: 41 additions & 22 deletions lib/modCheckLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ class modLooker {
'vehicle.base.components.component',
'placeable.storedata.functions.function',
'placeable.colorable.colors.color',
'placeable.silo.storages.storage',
]

#xmlParser = null
Expand Down Expand Up @@ -1886,6 +1887,8 @@ class modLooker {
#parsePlace(xml) {
const storeData = xml.storedata

const fillUnit = this.#parseFillTypes(xml?.silo?.storages?.storage ?? null)
// console.log(fillUnit)
try {
return {
category : storeData?.category || null,
Expand All @@ -1896,6 +1899,25 @@ class modLooker {
name : this.#parseName(storeData?.name || 'unknown'),
price : storeData?.price || 0,
type : xml.$.TYPE,


beehive : {
exists : typeof xml.beehive !== 'undefined',
radius : xml?.beehive?.$?.ACTIONRADIUS ?? 0,
liters : xml?.beehive?.$?.LITERSHONEYPERDAY ?? 0,
},
husbandry : {
exists : typeof xml?.husbandry?.animals !== 'undefined',
type : xml?.husbandry?.animals?.$?.TYPE ?? null,
capacity : xml?.husbandry?.animals?.$?.MAXNUMANIMALS ?? 0,
},
incomePerHour : xml?.incomeperhour ?? null,
objectStorage : xml?.objectstorage?.$?.CAPACITY ?? null,
silo : {
exists : fillUnit.capacity > 0,
types : fillUnit.types,
capacity : fillUnit.capacity,
},
}
} catch {
return null
Expand All @@ -1907,35 +1929,32 @@ class modLooker {
capacity : 0,
types : [],
}
if ( typeof xml === 'undefined' ) { return returnObject }

const fillUnits = xml?.fillunitconfigurations?.fillunitconfiguration?.[0]?.fillunits?.fillunit ?? null
if ( xml === null ) { return returnObject }

if ( fillUnits !== null ) {
for ( const thisFill of fillUnits ) {
if ( thisFill?.$?.SHOWINSHOP !== false ) {
const thisTypes = thisFill?.$?.FILLTYPES?.split?.(' ') ?? null
const thisCats = thisFill?.$?.FILLTYPECATEGORIES?.split?.(' ') ?? null
for ( const thisFill of xml ) {
if ( thisFill?.$?.SHOWINSHOP !== false ) {
const thisTypes = thisFill?.$?.FILLTYPES?.split?.(' ') ?? null
const thisCats = thisFill?.$?.FILLTYPECATEGORIES?.split?.(' ') ?? null

if ( thisCats !== null ) {
for ( const thisCat of thisCats ) {
const thisCatKey = thisCat.toLowerCase()
if ( typeof this.#fillCats[thisCatKey] !== 'undefined' ) {
returnObject.types.push(...this.#fillCats[thisCatKey])
}
if ( thisCats !== null ) {
for ( const thisCat of thisCats ) {
const thisCatKey = thisCat.toLowerCase()
if ( typeof this.#fillCats[thisCatKey] !== 'undefined' ) {
returnObject.types.push(...this.#fillCats[thisCatKey])
}
}
if ( thisTypes !== null ) {
for ( const thisType of thisTypes ) {
returnObject.types.push(thisType.toLowerCase())
}
}

if ( thisTypes !== null ) {
for ( const thisType of thisTypes ) {
returnObject.types.push(thisType.toLowerCase())
}

returnObject.capacity += thisFill?.$?.CAPACITY ?? 0
}

returnObject.capacity += thisFill?.$?.CAPACITY ?? 0
}
}

return returnObject
}

Expand All @@ -1962,7 +1981,7 @@ class modLooker {
if ( typeof storeData?.bundleelements !== 'undefined' ) { return null }

try {
const theseFills = this.#parseFillTypes(xml.fillunit)
const theseFills = this.#parseFillTypes(xml?.fillunit?.fillunitconfigurations?.fillunitconfiguration?.[0]?.fillunits?.fillunit ?? null)

return {
brand : this.#parseBrand(storeData?.brand),
Expand Down
1,490 changes: 1,490 additions & 0 deletions lib/modLookerLang.json

Large diffs are not rendered by default.

Binary file added renderer/img/look/income.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added renderer/img/look/objects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion renderer/looker.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,17 @@ <h5 class="card-header">{{itemName}} <small class="fst-italic fw-normal">{{itemT
</div>
<div class="col-7 mx-auto">
<ul class="list-group list-group-flush">
<li class="list-group-item {{show_price}}"><img style="width:30px" src='img/look/price.png'> {{price}}</li>
<li class="list-group-item"><img style="width:30px" src='img/look/price.png'> {{price}}</li>
<li class="list-group-item {{show_income}}"><img style="width:30px" src='img/look/income.png'> {{income}}</li>
<li class="list-group-item {{show_hasPaint}}"><img style="width:30px" src='img/look/paintable.png'> <l10n name="look_has_paint"></l10n></li>
<li class="list-group-item {{show_hasCow}}"><img style="width:30px" src='img/fills/cow.png'> {{animalCount}}</li>
<li class="list-group-item {{show_hasPig}}"><img style="width:30px" src='img/fills/pig.png'> {{animalCount}}</li>
<li class="list-group-item {{show_hasSheep}}"><img style="width:30px" src='img/fills/sheep.png'> {{animalCount}}</li>
<li class="list-group-item {{show_hasChicken}}"><img style="width:30px" src='img/fills/chicken.png'> {{animalCount}}</li>
<li class="list-group-item {{show_hasHorse}}"><img style="width:30px" src='img/fills/horse.png'> {{animalCount}}</li>
<li class="list-group-item {{show_hasBee}}"><img style="width:30px" src='img/fills/honey.png'> {{hasBee}}</li>
<li class="list-group-item {{show_objectStore}}"><img style="width:30px" src='img/look/objects.png'> {{objectCount}}</li>
<li class="list-group-item {{show_fillUnit}}"><img style="width:30px" src='img/look/fillunit.png'> {{fillUnit}}<br />{{fillImages}}</li>
</ul>
</div>
<div class="col-12 pt-2"><p class="text-center">{{functions}}</p></div>
Expand Down
45 changes: 33 additions & 12 deletions renderer/renderJS/looker_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ window.mods.receive('fromMain_modRecord', (modCollect) => {
}
}

const maxSpeed = getDefault(thisItem?.specs?.maxspeed)
const thePower = getDefault(thisItem?.specs?.power)
const getPower = getDefault(thisItem?.specs?.neededpower)
const theWidth = getDefault(thisItem?.specs?.workingwidth, true)
const theFill = getDefault(thisItem.fillLevel)
const maxSpeed = getDefault(thisItem?.specs?.maxspeed)
const thePower = getDefault(thisItem?.specs?.power)
const getPower = getDefault(thisItem?.specs?.neededpower)
const theWidth = getDefault(thisItem?.specs?.workingwidth, true)
const theFill = getDefault(thisItem.fillLevel)
const fillImages = thisItem.fillTypes.map((thisFill) => `<img style="height: 25px" src="img/fills/${thisFill}.png">`)


storeItemsHTML.push(fsgUtil.useTemplate('vehicle_div', {
brandHIDE : shouldHide(brandImage),
Expand Down Expand Up @@ -96,16 +97,36 @@ window.mods.receive('fromMain_modRecord', (modCollect) => {
}

if ( thisItem.masterType === 'placeable' ) {
const fillImages = thisItem.silo.types.map((thisFill) => `<img style="height: 25px" src="img/fills/${thisFill}.png">`)

storeItemsHTML.push(fsgUtil.useTemplate('place_div', {
functions : thisItem.functions.join('<br>'),
iconIMG : fsgUtil.iconMaker(modCollect.opts.look?.icons?.[storeitem] || null),
itemName : thisItem.name,
itemTitle : thisItem.type,
price : Intl.NumberFormat(modCollect.currentLocale).format(thisItem.price),
show_hasPaint : shouldHide(thisItem.hasColor),
animalCount : thisItem.husbandry.capacity,
fillImages : fillImages.join(' '),
fillUnit : formatManyNumber(thisItem.silo.capacity, modCollect.currentLocale, [
{ factor : 1, precision : 0, unit : 'unit_l' },
{ factor : 0.001, precision : 1, unit : 'unit_m3' },
{ factor : 0.0353147, precision : 1, unit : 'unit_ft3' },
]),
functions : thisItem.functions.join('<br>'),
hasBee : `${formatManyNumber(thisItem.beehive.radius, modCollect.currentLocale, [{factor : 1, precision : 0, unit : 'unit_m'}])} / ${formatManyNumber(thisItem.beehive.liters, modCollect.currentLocale, [{factor : 1, precision : 0, unit : 'unit_l'}])}`,
iconIMG : fsgUtil.iconMaker(modCollect.opts.look?.icons?.[storeitem] || null),
income : thisItem.incomePerHour ?? 0,
itemName : thisItem.name,
itemTitle : thisItem.type,
objectCount : thisItem.objectStorage ?? 0,
price : Intl.NumberFormat(modCollect.currentLocale).format(thisItem.price),
show_fillUnit : shouldHide(thisItem.silo.exists),
show_hasBee : shouldHide(thisItem.beehive.exists),
show_hasChicken : shouldHide(thisItem.husbandry.type, 'CHICKEN'),
show_hasCow : shouldHide(thisItem.husbandry.type, 'COW'),
show_hasHorse : shouldHide(thisItem.husbandry.type, 'HORSE'),
show_hasPaint : shouldHide(thisItem.hasColor),
show_hasPig : shouldHide(thisItem.husbandry.type, 'PIG'),
show_hasSheep : shouldHide(thisItem.husbandry.type, 'SHEEP'),
show_income : shouldHide(thisItem.incomePerHour),
show_objectStore : shouldHide(thisItem.objectStorage),
}))
}

}

fsgUtil.byId('storeitems').innerHTML = storeItemsHTML.join('')
Expand Down
2 changes: 2 additions & 0 deletions test/langbuilder/buildLangs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const patternToInclude = [
'info_transmission_',
'fillType_',
'shopItem_',
'storeItem_',
'object_',
]

const langParser = new XMLParser({
Expand Down
6 changes: 3 additions & 3 deletions test/mod-look-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
const isFolder = false
// const fullPath = 'C:\\Users\\jtsag\\Documents\\My Games\\FarmingSimulator2022\\mods\\~test_mods\\'
const fullPath = 'C:\\Users\\jtsag\\Documents\\My Games\\FarmingSimulator2022\\mods\\fsg_realism\\'
// const modName = 'FS22_RedBarnPack'
const modName = 'FS22_RedBarnPack'
// const modName = 'FS22_Large_Pole_Barn'
// const modName = 'FS22_LimeAndSugarbeetCutProduction'
// const modName = 'FSG_eTractors_Pack'
const modName = 'FSG_Color_Pack'
// const modName = 'FSG_Color_Pack'
// const modName = 'FS22_precisionFarming'
// const modName = 'FS22_AnhydrousAmmoniaPack'
// const modName = 'FS22_AugerMaster'
Expand All @@ -39,7 +39,7 @@ const looker = new modLooker(
},
fullPath,
log,
'de',
'en',
true
)

Expand Down

0 comments on commit f4b4302

Please sign in to comment.