Skip to content
Permalink
Browse files

Mod loader log added.

  • Loading branch information...
mfendek committed Oct 21, 2018
1 parent 322c642 commit b0923441109815fb9694d0b9fe1f1fa7e6cec691
@@ -13,10 +13,11 @@ function sanitiseArrayJSON(array $array)
* @param string $sourcePath
* @param string $filePath
* @param string $url external source url
* @param array $files list of all mod files in use
* @return array
* @throws Exception
*/
function openDataFile($sourcePath, $filePath, $url = '')
function openDataFile($sourcePath, $filePath, $url = '', array &$files = [])
{
$path = $sourcePath . $filePath;
$file = file_get_contents($path);
@@ -28,9 +29,11 @@ function openDataFile($sourcePath, $filePath, $url = '')
// add data from external source
if ($url !== '') {
$file = @file_get_contents($url . $filePath);
$path = $url . $filePath;
$file = @file_get_contents($path);
if ($file !== false) {
$lines = array_merge($lines, explode("\n", $file));
$files[]= $path;
}
}
@@ -43,7 +46,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
error_reporting(-1);
ini_set('error_log', 'logs/oobgdw-error-' . strftime('%Y%m%d') . '.log');
$version = '2018-10-21';
$version = '2018-10-22';
// configuration
$dataPath = 'src/game_data/Data/';
@@ -182,11 +185,12 @@ function openDataFile($sourcePath, $filePath, $url = '')
$currentPage = ($currentPage > 0) ? $currentPage : 1;
if (!empty($_REQUEST['units-data'])) {
$modFiles = [];
$modUrl = (!empty($_REQUEST['mod'])) ? $_REQUEST['mod'] : '';
$modUrl = (filter_var($modUrl, FILTER_VALIDATE_URL)) ? $modUrl : '';
// process unit type specific traits
$dataFile = openDataFile($dataPath, 'classes.txt', $modUrl);
$dataFile = openDataFile($dataPath, 'classes.txt', $modUrl, $modFiles);
$currentId = '';
$typeTraits = [];
foreach ($dataFile as $line) {
@@ -223,7 +227,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
// process chassis
foreach ($climates as $climate => $climateId) {
$dataFile = openDataFile($dataPath, 'chassis' . $climateId . '.csv', $modUrl);
$dataFile = openDataFile($dataPath, 'chassis' . $climateId . '.csv', $modUrl, $modFiles);
foreach ($dataFile as $lineNumber => $line) {
$line = explode(";", $line);
$chassis = trim($line[0]);
@@ -324,7 +328,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
// process spotting
foreach ($climates as $climate => $climateId) {
$dataFile = openDataFile($dataPath, 'terrain' . $climateId . '.csv', $modUrl);
$dataFile = openDataFile($dataPath, 'terrain' . $climateId . '.csv', $modUrl, $modFiles);
foreach ($dataFile as $line) {
$line = explode(";", $line);
$name = trim($line[0]);
@@ -401,7 +405,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
}
// process units
$dataFile = openDataFile($dataPath, 'units.csv', $modUrl);
$dataFile = openDataFile($dataPath, 'units.csv', $modUrl, $modFiles);
$filterCategories = [];
$filterTypes = [];
@@ -1018,6 +1022,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
'unitsList' => $unitsOrdered,
'terrain' => $terrain,
'unitsData' => $units,
'modFiles' => $modFiles,
];
// unit data only request via AJAX

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -10,6 +10,7 @@ export const LIST_START_COMPARE = 'LIST_START_COMPARE';
export const LIST_CLEAR_COMPARE = 'LIST_CLEAR_COMPARE';
export const DATA_LOADED_SUCCESS = 'DATA_LOADED_SUCCESS';
export const DATA_LOADED_FAILURE = 'DATA_LOADED_FAILURE';
export const MOD_TOGGLE_LOG = 'MOD_TOGGLE_LOG';
export const MOD_UPDATE_URL = 'MOD_UPDATE_URL';
export const MOD_LOAD_START = 'MOD_LOAD_START';

@@ -52,6 +53,10 @@ export const dataLoadedFailure = error => ({
error,
});

export const modToggleLog = () => ({
type: MOD_TOGGLE_LOG,
});

export const modUpdateUrl = e => ({
type: MOD_UPDATE_URL,
e,
@@ -18,6 +18,7 @@ import {
listClearCompare,
dataLoadedSuccess,
dataLoadedFailure,
modToggleLog,
modUpdateUrl,
modLoad,
} from '../../actions';
@@ -37,6 +38,8 @@ class UnitNavigator extends Component {
loadFailure: false,
errorMessage: '',
modUrl: '',
modFiles: [],
modShowLog: false,
unitsData: {},
};

@@ -150,8 +153,11 @@ class UnitNavigator extends Component {

<ModLoader
url={this.props.modUrl}
showLog={this.props.modShowLog}
files={this.props.modFiles}
updateUrl={this.props.modUpdateUrl}
loadMod={this.props.modLoad}
toggleLog={this.props.modToggleLog}
/>
</div>
);
@@ -165,7 +171,10 @@ UnitNavigator.propTypes = {
startCompare: PropTypes.func.isRequired,
clearCompare: PropTypes.func.isRequired,
modUpdateUrl: PropTypes.func.isRequired,
modFiles: PropTypes.arrayOf(PropTypes.string).isRequired,
modShowLog: PropTypes.bool.isRequired,
modLoad: PropTypes.func.isRequired,
modToggleLog: PropTypes.func.isRequired,
dataLoadedSuccess: PropTypes.func.isRequired,
dataLoadedFailure: PropTypes.func.isRequired,
dataLoaded: PropTypes.bool,
@@ -227,6 +236,8 @@ const mapStateToProps = (globalState) => {
errorMessage: state.errorMessage,
dataLoaded: state.dataLoaded,
modUrl: state.modUrl,
modFiles: state.modFiles,
modShowLog: state.modShowLog,
};
};

@@ -238,6 +249,7 @@ const mapDispatchToProps = dispatch => ({
clearCompare: () => dispatch(listClearCompare()),
dataLoadedSuccess: data => dispatch(dataLoadedSuccess(data)),
dataLoadedFailure: error => dispatch(dataLoadedFailure(error)),
modToggleLog: () => dispatch(modToggleLog()),
modUpdateUrl: e => dispatch(modUpdateUrl(e)),
modLoad: () => dispatch(modLoad()),
});
@@ -5,35 +5,71 @@ import PropTypes from 'prop-types';
* Mod loader
*
* @param {string} url
* @param {boolean} showLog
* @param {array} files
* @param {function} updateUrl
* @param {function} loadMod
* @param {function} toggleLog
* @constructor
*/
const ModLoader = ({ url, updateUrl, loadMod }) => (
const ModLoader = ({ url, showLog, files, updateUrl, loadMod, toggleLog }) => (
<div className="mod-bar">
<input
type="url"
name="mod-url"
className="form-control"
value={url}
onChange={e => updateUrl(e)}
placeholder="Mod url"
/>
<button
type="button"
name="mod-load"
className="btn btn-info"
onClick={() => loadMod()}
>
Load mod
</button>
<div className="mod-bar__loader">
<input
type="url"
name="mod-url"
className="form-control"
value={url}
onChange={e => updateUrl(e)}
placeholder="Mod url"
/>
<button
type="button"
name="mod-load"
className="btn btn-primary"
onClick={() => loadMod()}
>
Load mod
</button>
<button
type="button"
name="mod-files"
className="btn btn-warning"
onClick={() => toggleLog()}
>
{(showLog) ? 'Hide log' : 'Show log'}
</button>
</div>
{
(showLog) ?
<div className="mod-bar__log">
{
(files.length > 0) ?
<ul>
{
files.map(
modFile => (
<li key={modFile}>{modFile}</li>
),
)
}
</ul>
:
<p>No mod files in use</p>
}
</div>
: ''
}
</div>
);

ModLoader.propTypes = {
url: PropTypes.string.isRequired,
showLog: PropTypes.bool.isRequired,
files: PropTypes.arrayOf(PropTypes.string).isRequired,
updateUrl: PropTypes.func.isRequired,
loadMod: PropTypes.func.isRequired,
toggleLog: PropTypes.func.isRequired,
};

export default ModLoader;
@@ -9,6 +9,7 @@ import {
LIST_CLEAR_COMPARE,
DATA_LOADED_SUCCESS,
DATA_LOADED_FAILURE,
MOD_TOGGLE_LOG,
MOD_UPDATE_URL,
MOD_LOAD_START,
} from '../actions';
@@ -125,6 +126,14 @@ const reducerUnitNavigator = (state = UnitNavigator.initialState(), action) => {
loadFailure: true,
errorMessage: action.error,
};
case MOD_TOGGLE_LOG: {
const modShowLog = !state.modShowLog;

return {
...state,
modShowLog,
};
}
case MOD_UPDATE_URL: {
const e = action.e;
const modUrl = e.target.value;
@@ -15,8 +15,7 @@ body {
text-align: center;
}

.filter-bar,
.mod-bar {
.filter-bar {
display: flex;
flex-wrap: wrap;
justify-content: center;
@@ -26,6 +25,27 @@ body {
}
}

.mod-bar {
&__loader,
&__log {
display: flex;
flex-wrap: wrap;
justify-content: center;

&> * {
margin: 0.5ex;
}
}

&__log {
background-color: $white;
border: thin solid $gray;
border-radius: 4px;
margin: 0.5ex;
padding: 0.5ex;
}
}

.form-control {
color: $black;
display: inline-block;

0 comments on commit b092344

Please sign in to comment.
You can’t perform that action at this time.