Skip to content

Commit

Permalink
Mod loader log added.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendek committed Oct 21, 2018
1 parent 322c642 commit b092344
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 28 deletions.
19 changes: 12 additions & 7 deletions index.php
Expand Up @@ -13,10 +13,11 @@ function sanitiseArrayJSON(array $array)
* @param string $sourcePath * @param string $sourcePath
* @param string $filePath * @param string $filePath
* @param string $url external source url * @param string $url external source url
* @param array $files list of all mod files in use
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
function openDataFile($sourcePath, $filePath, $url = '') function openDataFile($sourcePath, $filePath, $url = '', array &$files = [])
{ {
$path = $sourcePath . $filePath; $path = $sourcePath . $filePath;
$file = file_get_contents($path); $file = file_get_contents($path);
Expand All @@ -28,9 +29,11 @@ function openDataFile($sourcePath, $filePath, $url = '')


// add data from external source // add data from external source
if ($url !== '') { if ($url !== '') {
$file = @file_get_contents($url . $filePath); $path = $url . $filePath;
$file = @file_get_contents($path);
if ($file !== false) { if ($file !== false) {
$lines = array_merge($lines, explode("\n", $file)); $lines = array_merge($lines, explode("\n", $file));
$files[]= $path;
} }
} }


Expand All @@ -43,7 +46,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
error_reporting(-1); error_reporting(-1);
ini_set('error_log', 'logs/oobgdw-error-' . strftime('%Y%m%d') . '.log'); ini_set('error_log', 'logs/oobgdw-error-' . strftime('%Y%m%d') . '.log');


$version = '2018-10-21'; $version = '2018-10-22';


// configuration // configuration
$dataPath = 'src/game_data/Data/'; $dataPath = 'src/game_data/Data/';
Expand Down Expand Up @@ -182,11 +185,12 @@ function openDataFile($sourcePath, $filePath, $url = '')
$currentPage = ($currentPage > 0) ? $currentPage : 1; $currentPage = ($currentPage > 0) ? $currentPage : 1;


if (!empty($_REQUEST['units-data'])) { if (!empty($_REQUEST['units-data'])) {
$modFiles = [];
$modUrl = (!empty($_REQUEST['mod'])) ? $_REQUEST['mod'] : ''; $modUrl = (!empty($_REQUEST['mod'])) ? $_REQUEST['mod'] : '';
$modUrl = (filter_var($modUrl, FILTER_VALIDATE_URL)) ? $modUrl : ''; $modUrl = (filter_var($modUrl, FILTER_VALIDATE_URL)) ? $modUrl : '';


// process unit type specific traits // process unit type specific traits
$dataFile = openDataFile($dataPath, 'classes.txt', $modUrl); $dataFile = openDataFile($dataPath, 'classes.txt', $modUrl, $modFiles);
$currentId = ''; $currentId = '';
$typeTraits = []; $typeTraits = [];
foreach ($dataFile as $line) { foreach ($dataFile as $line) {
Expand Down Expand Up @@ -223,7 +227,7 @@ function openDataFile($sourcePath, $filePath, $url = '')


// process chassis // process chassis
foreach ($climates as $climate => $climateId) { 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) { foreach ($dataFile as $lineNumber => $line) {
$line = explode(";", $line); $line = explode(";", $line);
$chassis = trim($line[0]); $chassis = trim($line[0]);
Expand Down Expand Up @@ -324,7 +328,7 @@ function openDataFile($sourcePath, $filePath, $url = '')


// process spotting // process spotting
foreach ($climates as $climate => $climateId) { foreach ($climates as $climate => $climateId) {
$dataFile = openDataFile($dataPath, 'terrain' . $climateId . '.csv', $modUrl); $dataFile = openDataFile($dataPath, 'terrain' . $climateId . '.csv', $modUrl, $modFiles);
foreach ($dataFile as $line) { foreach ($dataFile as $line) {
$line = explode(";", $line); $line = explode(";", $line);
$name = trim($line[0]); $name = trim($line[0]);
Expand Down Expand Up @@ -401,7 +405,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
} }


// process units // process units
$dataFile = openDataFile($dataPath, 'units.csv', $modUrl); $dataFile = openDataFile($dataPath, 'units.csv', $modUrl, $modFiles);


$filterCategories = []; $filterCategories = [];
$filterTypes = []; $filterTypes = [];
Expand Down Expand Up @@ -1018,6 +1022,7 @@ function openDataFile($sourcePath, $filePath, $url = '')
'unitsList' => $unitsOrdered, 'unitsList' => $unitsOrdered,
'terrain' => $terrain, 'terrain' => $terrain,
'unitsData' => $units, 'unitsData' => $units,
'modFiles' => $modFiles,
]; ];


// unit data only request via AJAX // unit data only request via AJAX
Expand Down
2 changes: 1 addition & 1 deletion src/dist/css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/dist/js/main.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/react/js/actions/index.js
Expand Up @@ -10,6 +10,7 @@ export const LIST_START_COMPARE = 'LIST_START_COMPARE';
export const LIST_CLEAR_COMPARE = 'LIST_CLEAR_COMPARE'; export const LIST_CLEAR_COMPARE = 'LIST_CLEAR_COMPARE';
export const DATA_LOADED_SUCCESS = 'DATA_LOADED_SUCCESS'; export const DATA_LOADED_SUCCESS = 'DATA_LOADED_SUCCESS';
export const DATA_LOADED_FAILURE = 'DATA_LOADED_FAILURE'; 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_UPDATE_URL = 'MOD_UPDATE_URL';
export const MOD_LOAD_START = 'MOD_LOAD_START'; export const MOD_LOAD_START = 'MOD_LOAD_START';


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


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

export const modUpdateUrl = e => ({ export const modUpdateUrl = e => ({
type: MOD_UPDATE_URL, type: MOD_UPDATE_URL,
e, e,
Expand Down
12 changes: 12 additions & 0 deletions src/react/js/components/container/UnitNavigator.jsx
Expand Up @@ -18,6 +18,7 @@ import {
listClearCompare, listClearCompare,
dataLoadedSuccess, dataLoadedSuccess,
dataLoadedFailure, dataLoadedFailure,
modToggleLog,
modUpdateUrl, modUpdateUrl,
modLoad, modLoad,
} from '../../actions'; } from '../../actions';
Expand All @@ -37,6 +38,8 @@ class UnitNavigator extends Component {
loadFailure: false, loadFailure: false,
errorMessage: '', errorMessage: '',
modUrl: '', modUrl: '',
modFiles: [],
modShowLog: false,
unitsData: {}, unitsData: {},
}; };


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


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


Expand All @@ -238,6 +249,7 @@ const mapDispatchToProps = dispatch => ({
clearCompare: () => dispatch(listClearCompare()), clearCompare: () => dispatch(listClearCompare()),
dataLoadedSuccess: data => dispatch(dataLoadedSuccess(data)), dataLoadedSuccess: data => dispatch(dataLoadedSuccess(data)),
dataLoadedFailure: error => dispatch(dataLoadedFailure(error)), dataLoadedFailure: error => dispatch(dataLoadedFailure(error)),
modToggleLog: () => dispatch(modToggleLog()),
modUpdateUrl: e => dispatch(modUpdateUrl(e)), modUpdateUrl: e => dispatch(modUpdateUrl(e)),
modLoad: () => dispatch(modLoad()), modLoad: () => dispatch(modLoad()),
}); });
Expand Down
70 changes: 53 additions & 17 deletions src/react/js/components/presentational/ModLoader.jsx
Expand Up @@ -5,35 +5,71 @@ import PropTypes from 'prop-types';
* Mod loader * Mod loader
* *
* @param {string} url * @param {string} url
* @param {boolean} showLog
* @param {array} files
* @param {function} updateUrl * @param {function} updateUrl
* @param {function} loadMod * @param {function} loadMod
* @param {function} toggleLog
* @constructor * @constructor
*/ */
const ModLoader = ({ url, updateUrl, loadMod }) => ( const ModLoader = ({ url, showLog, files, updateUrl, loadMod, toggleLog }) => (
<div className="mod-bar"> <div className="mod-bar">
<input <div className="mod-bar__loader">
type="url" <input
name="mod-url" type="url"
className="form-control" name="mod-url"
value={url} className="form-control"
onChange={e => updateUrl(e)} value={url}
placeholder="Mod url" onChange={e => updateUrl(e)}
/> placeholder="Mod url"
<button />
type="button" <button
name="mod-load" type="button"
className="btn btn-info" name="mod-load"
onClick={() => loadMod()} className="btn btn-primary"
> onClick={() => loadMod()}
Load mod >
</button> 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> </div>
); );


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


export default ModLoader; export default ModLoader;
9 changes: 9 additions & 0 deletions src/react/js/reducers/UnitNavigator.js
Expand Up @@ -9,6 +9,7 @@ import {
LIST_CLEAR_COMPARE, LIST_CLEAR_COMPARE,
DATA_LOADED_SUCCESS, DATA_LOADED_SUCCESS,
DATA_LOADED_FAILURE, DATA_LOADED_FAILURE,
MOD_TOGGLE_LOG,
MOD_UPDATE_URL, MOD_UPDATE_URL,
MOD_LOAD_START, MOD_LOAD_START,
} from '../actions'; } from '../actions';
Expand Down Expand Up @@ -125,6 +126,14 @@ const reducerUnitNavigator = (state = UnitNavigator.initialState(), action) => {
loadFailure: true, loadFailure: true,
errorMessage: action.error, errorMessage: action.error,
}; };
case MOD_TOGGLE_LOG: {
const modShowLog = !state.modShowLog;

return {
...state,
modShowLog,
};
}
case MOD_UPDATE_URL: { case MOD_UPDATE_URL: {
const e = action.e; const e = action.e;
const modUrl = e.target.value; const modUrl = e.target.value;
Expand Down
24 changes: 22 additions & 2 deletions src/styles/scss/components/utils.scss
Expand Up @@ -15,8 +15,7 @@ body {
text-align: center; text-align: center;
} }


.filter-bar, .filter-bar {
.mod-bar {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: center; justify-content: center;
Expand All @@ -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 { .form-control {
color: $black; color: $black;
display: inline-block; display: inline-block;
Expand Down

0 comments on commit b092344

Please sign in to comment.