@@ -18,7 +18,7 @@ export function open() {
1818 title : "Cultures Editor" ,
1919 resizable : false ,
2020 close : closeCulturesEditor ,
21- position : { my : "right top" , at : "right-10 top+10" , of : "svg" }
21+ position : { my : "right top" , at : "right-10 top+10" , of : "svg" }
2222 } ) ;
2323 $body . focus ( ) ;
2424}
@@ -49,7 +49,6 @@ function insertEditorHtml() {
4949 <button id="culturesEditStyle" data-tip="Edit cultures style in Style Editor" class="icon-adjust"></button>
5050 <button id="culturesLegend" data-tip="Toggle Legend box" class="icon-list-bullet"></button>
5151 <button id="culturesPercentage" data-tip="Toggle percentage / absolute values display mode" class="icon-percent"></button>
52- <button id="culturesLocate" data-tip="Click on the list first to select a culture, then click to locate it on the map" class="icon-target"></button>
5352 <button id="culturesHeirarchy" data-tip="Show cultures hierarchy tree" class="icon-sitemap"></button>
5453 <button id="culturesManually" data-tip="Manually re-assign cultures" class="icon-brush"></button>
5554 <div id="culturesManuallyButtons" style="display: none">
@@ -65,7 +64,7 @@ function insertEditorHtml() {
6564 <button id="culturesExport" data-tip="Download cultures-related data" class="icon-download"></button>
6665 <button id="culturesImport" data-tip="Upload cultures-related data" class="icon-upload"></button>
6766 <button id="culturesRecalculate" data-tip="Recalculate cultures based on current values of growth-related attributes" class="icon-retweet"></button>
68- <span data-tip="Allow culture centers, expansion and type changes to take an immediate effect">
67+ <span data-tip="Allow culture centers, expansion and type changes to take an immediate effect" style="display: inline-flex" >
6968 <input id="culturesAutoChange" class="checkbox" type="checkbox" />
7069 <label for="culturesAutoChange" class="checkbox-label"><i>auto-apply changes</i></label>
7170 </span>
@@ -83,7 +82,6 @@ function addListeners() {
8382 ensureEl ( "culturesEditStyle" ) . on ( "click" , ( ) => editStyle ( "cults" ) ) ;
8483 ensureEl ( "culturesLegend" ) . on ( "click" , toggleLegend ) ;
8584 ensureEl ( "culturesPercentage" ) . on ( "click" , togglePercentageMode ) ;
86- ensureEl ( "culturesLocate" ) . on ( "click" , locateSelectedCulture ) ;
8785 ensureEl ( "culturesHeirarchy" ) . on ( "click" , showHierarchy ) ;
8886 ensureEl ( "culturesRecalculate" ) . on ( "click" , ( ) => recalculateCultures ( true ) ) ;
8987 ensureEl ( "culturesManually" ) . on ( "click" , enterCultureManualAssignent ) ;
@@ -103,29 +101,8 @@ function refreshCulturesEditor() {
103101 drawCultureCenters ( ) ;
104102}
105103
106- function locateCulture ( cultureId ) {
107- if ( ! cults ) return ;
108- const cultureElement = cults . select ( "#culture" + cultureId ) . node ( ) ;
109- if ( ! cultureElement ) return ;
110- highlightElement ( cultureElement , 8 ) ;
111- }
112-
113- function locateSelectedCulture ( ) {
114- const selected = $body . querySelector ( "div.selected" ) ;
115- if ( ! selected ) {
116- tip ( "Select a culture first" , true ) ;
117- return ;
118- }
119- const cultureId = Number ( selected . dataset . id ) ;
120- if ( Number . isNaN ( cultureId ) ) {
121- tip ( "Select a culture first" , true ) ;
122- return ;
123- }
124- locateCulture ( cultureId ) ;
125- }
126-
127104function culturesCollectStatistics ( ) {
128- const { cells, cultures, burgs} = pack ;
105+ const { cells, cultures, burgs } = pack ;
129106 cultures . forEach ( c => {
130107 c . cells = c . area = c . rural = c . urban = 0 ;
131108 } ) ;
@@ -239,6 +216,7 @@ function culturesEditorAddLines() {
239216 <div data-tip="${ populationTip } " class="culturePopulation hide pointer"
240217 style="width: 4em">${ si ( population ) } </div>
241218 ${ getShapeOptions ( selectShape , c . shield ) }
219+ <span data-tip="Locate the culture" class="icon-target hide"></span>
242220 <span data-tip="Lock culture" class="icon-lock${ c . lock ? "" : "-open" } hide"></span>
243221 <span data-tip="Remove culture" class="icon-trash-empty hide"></span>
244222 </div>` ;
@@ -268,6 +246,7 @@ function culturesEditorAddLines() {
268246 $body . querySelectorAll ( "div > select.cultureEmblems" ) . forEach ( $el => $el . on ( "change" , cultureChangeEmblemsShape ) ) ;
269247 $body . querySelectorAll ( "div > div.culturePopulation" ) . forEach ( $el => $el . on ( "click" , changePopulation ) ) ;
270248 $body . querySelectorAll ( "div > span.icon-arrows-cw" ) . forEach ( $el => $el . on ( "click" , cultureRegenerateBurgs ) ) ;
249+ $body . querySelectorAll ( "div > span.icon-target" ) . forEach ( $el => $el . on ( "click" , cultureHighlightElement ) ) ;
271250 $body . querySelectorAll ( "div > span.icon-trash-empty" ) . forEach ( $el => $el . on ( "click" , cultureRemovePrompt ) ) ;
272251 $body . querySelectorAll ( "div > span.icon-lock" ) . forEach ( $el => $el . on ( "click" , updateLockStatus ) ) ;
273252 $body . querySelectorAll ( "div > span.icon-lock-open" ) . forEach ( $el => $el . on ( "click" , updateLockStatus ) ) ;
@@ -280,7 +259,7 @@ function culturesEditorAddLines() {
280259 togglePercentageMode ( ) ;
281260 }
282261 applySorting ( $culturesHeader ) ;
283- $ ( "#culturesEditor" ) . dialog ( { width : fitContent ( ) } ) ;
262+ $ ( "#culturesEditor" ) . dialog ( { width : fitContent ( ) } ) ;
284263}
285264
286265function getTypeOptions ( type ) {
@@ -487,7 +466,7 @@ function changePopulation() {
487466 $ ( this ) . dialog ( "close" ) ;
488467 }
489468 } ,
490- position : { my : "center" , at : "center" , of : "svg" }
469+ position : { my : "center" , at : "center" , of : "svg" }
491470 } ) ;
492471}
493472
@@ -538,7 +517,7 @@ function removeCulture(cultureId) {
538517 cults . select ( "#culture" + cultureId ) . remove ( ) ;
539518 debug . select ( "#cultureCenter" + cultureId ) . remove ( ) ;
540519
541- const { burgs, states, cells, cultures} = pack ;
520+ const { burgs, states, cells, cultures } = pack ;
542521
543522 burgs . filter ( b => b . culture == cultureId ) . forEach ( b => ( b . culture = 0 ) ) ;
544523 states . forEach ( s => {
@@ -558,6 +537,11 @@ function removeCulture(cultureId) {
558537 refreshCulturesEditor ( ) ;
559538}
560539
540+ function cultureHighlightElement ( ) {
541+ const cultureId = + this . parentNode . dataset . id ;
542+ highlightElement ( cults . select ( "#culture" + cultureId ) . node ( ) , 4 ) ;
543+ }
544+
561545function cultureRemovePrompt ( ) {
562546 if ( customization ) return ;
563547
@@ -612,7 +596,7 @@ function cultureCenterDrag() {
612596 const y0 = + tr [ 1 ] - d3 . event . y ;
613597
614598 function handleDrag ( ) {
615- const { x, y} = d3 . event ;
599+ const { x, y } = d3 . event ;
616600 this . setAttribute ( "transform" , `translate(${ x0 + x } ,${ y0 + y } )` ) ;
617601 const cell = findCell ( x , y ) ;
618602 if ( pack . cells . h [ cell ] < 20 ) return ; // ignore dragging on water
@@ -643,7 +627,7 @@ function togglePercentageMode() {
643627 const totalPopulation = + ensureEl ( "culturesFooterPopulation" ) . dataset . population ;
644628
645629 $body . querySelectorAll ( ":scope > div" ) . forEach ( function ( el ) {
646- const { cells, area, population} = el . dataset ;
630+ const { cells, area, population } = el . dataset ;
647631 el . querySelector ( ".cultureCells" ) . innerText = rn ( ( + cells / totalCells ) * 100 ) + "%" ;
648632 el . querySelector ( ".cultureArea" ) . innerText = rn ( ( + area / totalArea ) * 100 ) + "%" ;
649633 el . querySelector ( ".culturePopulation" ) . innerText = rn ( ( + population / totalPopulation ) * 100 ) + "%" ;
@@ -659,14 +643,14 @@ async function showHierarchy() {
659643 const HeirarchyTree = await import ( "../hierarchy-tree.js?v=1.120.5" ) ;
660644
661645 const getDescription = culture => {
662- const { name, type, rural, urban} = culture ;
646+ const { name, type, rural, urban } = culture ;
663647
664648 const population = rural * populationRate + urban * populationRate * urbanization ;
665649 const populationText = population > 0 ? si ( rn ( population ) ) + " people" : "Extinct" ;
666650 return `${ name } culture. ${ type } . ${ populationText } ` ;
667651 } ;
668652
669- const getShape = ( { type} ) => {
653+ const getShape = ( { type } ) => {
670654 if ( type === "Generic" ) return "circle" ;
671655 if ( type === "River" ) return "diamond" ;
672656 if ( type === "Lake" ) return "hexagon" ;
@@ -706,7 +690,7 @@ function enterCultureManualAssignent() {
706690 culturesEditor . querySelectorAll ( ".hide" ) . forEach ( el => el . classList . add ( "hidden" ) ) ;
707691 culturesFooter . style . display = "none" ;
708692 $body . querySelectorAll ( "div > input, select, span, svg" ) . forEach ( e => ( e . style . pointerEvents = "none" ) ) ;
709- $ ( "#culturesEditor" ) . dialog ( { position : { my : "right top" , at : "right-10 top+10" , of : "svg" } } ) ;
693+ $ ( "#culturesEditor" ) . dialog ( { position : { my : "right top" , at : "right-10 top+10" , of : "svg" } } ) ;
710694
711695 tip ( "Click on culture to select, drag the circle to change culture" , true ) ;
712696 viewbox
@@ -720,6 +704,7 @@ function enterCultureManualAssignent() {
720704}
721705
722706function selectCultureOnLineClick ( i ) {
707+ if ( customization !== 4 ) return ;
723708 const previous = $body . querySelector ( "div.selected" ) ;
724709 if ( previous ) previous . classList . remove ( "selected" ) ;
725710 this . classList . add ( "selected" ) ;
@@ -811,7 +796,7 @@ function exitCulturesManualAssignment(close) {
811796 culturesEditor . querySelectorAll ( ".hide" ) . forEach ( el => el . classList . remove ( "hidden" ) ) ;
812797 culturesFooter . style . display = "block" ;
813798 $body . querySelectorAll ( "div > input, select, span, svg" ) . forEach ( e => ( e . style . pointerEvents = "all" ) ) ;
814- if ( ! close ) $ ( "#culturesEditor" ) . dialog ( { position : { my : "right top" , at : "right-10 top+10" , of : "svg" } } ) ;
799+ if ( ! close ) $ ( "#culturesEditor" ) . dialog ( { position : { my : "right top" , at : "right-10 top+10" , of : "svg" } } ) ;
815800
816801 debug . select ( "#cultureCenters" ) . style ( "display" , null ) ;
817802 restoreDefaultEvents ( ) ;
@@ -875,9 +860,9 @@ function downloadCulturesCsv() {
875860 const headers = `Id,Name,Color,Cells,Expansionism,Type,Area ${ unit } ,Population,Namesbase,Emblems Shape,Origins` ;
876861 const lines = Array . from ( $body . querySelectorAll ( ":scope > div" ) ) ;
877862 const data = lines . map ( $line => {
878- const { id, name, color, cells, expansionism, type, area, population, emblems, base} = $line . dataset ;
863+ const { id, name, color, cells, expansionism, type, area, population, emblems, base } = $line . dataset ;
879864 const namesbase = nameBases [ + base ] . name ;
880- const { origins} = pack . cultures [ + id ] ;
865+ const { origins } = pack . cultures [ + id ] ;
881866 const originList = origins . filter ( origin => origin ) . map ( origin => pack . cultures [ origin ] . name ) ;
882867 const originText = '"' + originList . join ( ", " ) + '"' ;
883868 return [ id , name , color , cells , expansionism , type , area , population , namesbase , emblems , originText ] . join ( "," ) ;
@@ -910,7 +895,7 @@ async function uploadCulturesData() {
910895 namesbase : d . Namesbase
911896 } ) ) ;
912897
913- const { cultures, cells} = pack ;
898+ const { cultures, cells } = pack ;
914899 const shapes = Object . keys ( COA . shields . types )
915900 . map ( type => Object . keys ( COA . shields [ type ] ) )
916901 . flat ( ) ;
@@ -934,7 +919,7 @@ async function uploadCulturesData() {
934919 culture . i
935920 ) ;
936921 } else {
937- current = { i : cultures . length , center : ra ( populated ) , area : 0 , cells : 0 , origins : [ 0 ] , rural : 0 , urban : 0 } ;
922+ current = { i : cultures . length , center : ra ( populated ) , area : 0 , cells : 0 , origins : [ 0 ] , rural : 0 , urban : 0 } ;
938923 cultures . push ( current ) ;
939924 }
940925
0 commit comments