@@ -69,101 +69,109 @@ function buildFile(spawnName, luaOutputData, outputPath, outputName, buildCallba
69
69
70
70
// Load spawn config
71
71
fs . readFile ( `./configs/${ spawnName } .ini` , function ( err , configData ) {
72
- if ( err ) throw err ;
73
-
74
- // Determine vocation from spawnName
75
- let vocationName = 'unknown' ;
76
- for ( let i = 0 ; i < vocationTags . length ; i ++ ) {
77
- let tag = vocationTags [ i ] ;
78
- if ( spawnName . indexOf ( tag ) !== - 1 ) {
79
- vocationName = vocationsMap [ tag ] ;
80
- break ;
81
- }
82
- }
83
-
84
- // Build script version
85
- let version ;
86
- if ( process . env . TRAVIS_TAG )
87
- version = process . env . TRAVIS_TAG ;
88
- else if ( process . env . TRAVIS_BRANCH )
89
- version = `${ process . env . TRAVIS_BRANCH } #${ process . env . TRAVIS_BUILD_NUMBER } ` ;
90
- else
91
- version = 'local' ;
92
-
93
- // Replace tokens
94
- const configHash = crypto . createHash ( 'md5' ) . update ( configData ) . digest ( 'hex' ) ;
95
- let data = luaOutputData . toString ( 'utf8' ) ;
96
-
97
- data = data . replace ( '{{VERSION}}' , version ) ;
98
- data = data . replace ( '{{SCRIPT_TOWN}}' , townName ) ;
99
- data = data . replace ( '{{SCRIPT_NAME}}' , spawnName ) ;
100
- data = data . replace ( '{{SCRIPT_SLUG}}' , outputName ) ;
101
- data = data . replace ( '{{SCRIPT_VOCATION}}' , vocationName ) ;
102
- data = data . replace ( '{{SCRIPT_CONFIG_HASH}}' , configHash ) ;
103
-
104
- // Insert config
105
- data = data . replace ( '{{CONFIG}}' , configData . toString ( 'utf8' ) . replace ( ':::::::::::::::' , `::${ configHash } ` ) ) ;
106
-
107
- // Base 64 encode lua
108
- let encodedLua = new Buffer ( data ) . toString ( 'base64' ) ;
109
- let encodedReload = new Buffer ( reloadScript ) . toString ( 'base64' ) ;
110
- let combinedWaypoints ;
111
72
112
- let developmentXML = `
113
- <panel name="Scripter">
114
- <control name="RunningScriptList">
115
- <script name=".ox.${ timestamp } .lua"><![CDATA[${ encodedLua } ]]></script>
116
- <script name=".sync.${ timestamp } .lua"><![CDATA[${ encodedReload } ]]></script>
117
- </control>
118
- </panel>` ;
119
-
120
- let productionXML = `
121
- <panel name="Scripter">
122
- <control name="RunningScriptList">
123
- <script name="${ outputName . replace ( '.xbst' , '.lua' ) } " noprompt="1"><![CDATA[${ encodedLua } ]]></script>
124
- </control>
125
- </panel>` ;
126
-
127
- // Get all the town waypoints
128
- let townPaths = glob . sync ( './waypoints/towns/*.json' ) ,
129
- townWaypoints = [ ] ;
130
-
131
- readm ( townPaths , ( err , towns ) => {
132
- if ( err ) {
133
- throw err ;
134
- }
73
+ fs . readFile ( `./configs/Prices.ini` , function ( pricesErr , pricesConfigData ) {
74
+ if ( err || pricesErr ) throw err ;
135
75
136
- // Iterate through towns
137
- towns . forEach ( ( waypoints ) => {
138
- let townData = JSON . parse ( waypoints ) ;
139
- // Iterate through waypoints in each town
140
- townData . forEach ( ( item ) => {
141
- // Add waypoint string to array
142
- townWaypoints . push ( `\n\t\t<item text="${ item . label } " tag="${ item . tag } "/>` ) ;
143
- } ) ;
144
- } ) ;
145
76
146
- // Combine waypoints
147
- townWaypoints . push ( '\n' ) ;
148
- combinedWaypoints = townWaypoints . join ( '' ) ;
77
+ // Determine vocation from spawnName
78
+ let vocationName = 'unknown' ;
79
+ for ( let i = 0 ; i < vocationTags . length ; i ++ ) {
80
+ let tag = vocationTags [ i ] ;
81
+ if ( spawnName . indexOf ( tag ) !== - 1 ) {
82
+ vocationName = vocationsMap [ tag ] ;
83
+ break ;
84
+ }
85
+ }
149
86
150
- // Combine spawn file with town waypoints
151
- let insertPoint = '<control name="WaypointList">' + os . EOL ;
152
- let xbstCombinedData = xbstData . toString ( 'utf8' ) ;
153
- xbstCombinedData = xbstCombinedData . replace ( insertPoint , insertPoint + combinedWaypoints ) ;
154
-
155
- // Inject sync script for live reloading
156
- if ( process . env . LIVE_RELOAD )
157
- xbstCombinedData += '\n' + developmentXML ;
158
- // Production lua
87
+ // Build script version
88
+ let version ;
89
+ if ( process . env . TRAVIS_TAG )
90
+ version = process . env . TRAVIS_TAG ;
91
+ else if ( process . env . TRAVIS_BRANCH )
92
+ version = `${ process . env . TRAVIS_BRANCH } #${ process . env . TRAVIS_BUILD_NUMBER } ` ;
159
93
else
160
- xbstCombinedData += '\n' + productionXML ;
94
+ version = 'local' ;
95
+
96
+ // Replace tokens
97
+ const configHash = crypto . createHash ( 'md5' ) . update ( configData ) . digest ( 'hex' ) ;
98
+ const pricesConfigHash = crypto . createHash ( 'md5' ) . update ( pricesConfigData ) . digest ( 'hex' ) ;
99
+ let data = luaOutputData . toString ( 'utf8' ) ;
100
+
101
+ data = data . replace ( '{{VERSION}}' , version ) ;
102
+ data = data . replace ( '{{SCRIPT_TOWN}}' , townName ) ;
103
+ data = data . replace ( '{{SCRIPT_NAME}}' , spawnName ) ;
104
+ data = data . replace ( '{{SCRIPT_SLUG}}' , outputName ) ;
105
+ data = data . replace ( '{{SCRIPT_VOCATION}}' , vocationName ) ;
106
+ data = data . replace ( '{{SCRIPT_CONFIG_HASH}}' , configHash ) ;
107
+ data = data . replace ( '{{PRICES_CONFIG_HASH}}' , pricesConfigHash ) ;
108
+
109
+ // Insert config
110
+ data = data . replace ( '{{CONFIG}}' , configData . toString ( 'utf8' ) . replace ( ':::::::::::::::' , `::${ configHash } ` ) ) ;
111
+ // Insert prices config
112
+ data = data . replace ( '{{PRICES_CONFIG}}' , pricesConfigData . toString ( 'utf8' ) . replace ( ':::::::::::::::' , `::${ pricesConfigHash } ` ) ) ;
113
+
114
+ // Base 64 encode lua
115
+ let encodedLua = new Buffer ( data ) . toString ( 'base64' ) ;
116
+ let encodedReload = new Buffer ( reloadScript ) . toString ( 'base64' ) ;
117
+ let combinedWaypoints ;
118
+
119
+ let developmentXML = `
120
+ <panel name="Scripter">
121
+ <control name="RunningScriptList">
122
+ <script name=".ox.${ timestamp } .lua"><![CDATA[${ encodedLua } ]]></script>
123
+ <script name=".sync.${ timestamp } .lua"><![CDATA[${ encodedReload } ]]></script>
124
+ </control>
125
+ </panel>` ;
126
+
127
+ let productionXML = `
128
+ <panel name="Scripter">
129
+ <control name="RunningScriptList">
130
+ <script name="${ outputName . replace ( '.xbst' , '.lua' ) } " noprompt="1"><![CDATA[${ encodedLua } ]]></script>
131
+ </control>
132
+ </panel>` ;
133
+
134
+ // Get all the town waypoints
135
+ let townPaths = glob . sync ( './waypoints/towns/*.json' ) ,
136
+ townWaypoints = [ ] ;
137
+
138
+ readm ( townPaths , ( err , towns ) => {
139
+ if ( err ) {
140
+ throw err ;
141
+ }
142
+
143
+ // Iterate through towns
144
+ towns . forEach ( ( waypoints ) => {
145
+ let townData = JSON . parse ( waypoints ) ;
146
+ // Iterate through waypoints in each town
147
+ townData . forEach ( ( item ) => {
148
+ // Add waypoint string to array
149
+ townWaypoints . push ( `\n\t\t<item text="${ item . label } " tag="${ item . tag } "/>` ) ;
150
+ } ) ;
151
+ } ) ;
161
152
162
- // Save XBST
163
- fs . writeFile ( outputPath , xbstCombinedData , function ( err ) {
164
- console . log ( colors . green ( spawnName ) , outputPath ) ;
165
- if ( buildCallback )
166
- buildCallback ( xbstCombinedData , timestamp ) ;
153
+ // Combine waypoints
154
+ townWaypoints . push ( '\n' ) ;
155
+ combinedWaypoints = townWaypoints . join ( '' ) ;
156
+
157
+ // Combine spawn file with town waypoints
158
+ let insertPoint = '<control name="WaypointList">' + os . EOL ;
159
+ let xbstCombinedData = xbstData . toString ( 'utf8' ) ;
160
+ xbstCombinedData = xbstCombinedData . replace ( insertPoint , insertPoint + combinedWaypoints ) ;
161
+
162
+ // Inject sync script for live reloading
163
+ if ( process . env . LIVE_RELOAD )
164
+ xbstCombinedData += '\n' + developmentXML ;
165
+ // Production lua
166
+ else
167
+ xbstCombinedData += '\n' + productionXML ;
168
+
169
+ // Save XBST
170
+ fs . writeFile ( outputPath , xbstCombinedData , function ( err ) {
171
+ console . log ( colors . green ( spawnName ) , outputPath ) ;
172
+ if ( buildCallback )
173
+ buildCallback ( xbstCombinedData , timestamp ) ;
174
+ } ) ;
167
175
} ) ;
168
176
} ) ;
169
177
} ) ;
0 commit comments