Skip to content

Commit

Permalink
conflict editor now shows a hint when the other mod has a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
TanninOne committed Jun 1, 2017
1 parent 4b38b3f commit 2ce6dca
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
4 changes: 3 additions & 1 deletion extensions/mod-dependency-manager/src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {IBiDirRule} from './types/IBiDirRule';

import { IReference } from 'modmeta-db';
import { safeCreateAction } from 'nmm-api';

Expand All @@ -18,4 +20,4 @@ export const setType = safeCreateAction('SET_MOD_RULE_TYPE');
export const setConflictInfo = safeCreateAction('SET_CONFLICT_INFO');

export const setConflictDialog = safeCreateAction('SET_CONFLICT_DIALOG',
(gameId?: string, modId?: string) => ({ gameId, modId }));
(gameId?: string, modId?: string, modRules?: IBiDirRule[]) => ({ gameId, modId, modRules }));
15 changes: 15 additions & 0 deletions extensions/mod-dependency-manager/src/util/renderReference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IReference } from 'modmeta-db';

function renderReference(ref: IReference) {
if ((ref.logicalFileName === undefined) && (ref.fileExpression === undefined)) {
return ref.fileMD5;
}

let name = ref.logicalFileName || ref.fileExpression;
if (ref.versionMatch !== undefined) {
name += ' v' + ref.versionMatch;
}
return name;
}

export default renderReference;
37 changes: 35 additions & 2 deletions extensions/mod-dependency-manager/src/views/ConflictEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { IBiDirRule } from '../types/IBiDirRule';
import { IConflict } from '../types/IConflict';
import matchReference from '../util/matchReference';
import renderModName from '../util/renderModName';
import renderReference from '../util/renderReference';

import { setConflictDialog } from '../actions';

import { IReference, IRule } from 'modmeta-db';
import { actions as nmmActions, ComponentEx, types } from 'nmm-api';
import { actions as nmmActions, ComponentEx, tooltip, types } from 'nmm-api';
import * as React from 'react';
import { Button, FormControl, ListGroup, ListGroupItem,
Modal, OverlayTrigger, Popover } from 'react-bootstrap';
Expand All @@ -16,6 +18,7 @@ interface IConnectedProps {
gameId: string;
modId: string;
conflicts: IConflict[];
modRules: IBiDirRule[];
mods: { [modId: string]: types.IMod };
}

Expand Down Expand Up @@ -46,6 +49,7 @@ class ConflictEditor extends ComponentEx<IProps, IComponentState> {
}

public componentWillReceiveProps(nextProps: IProps) {
// find existing rules for these conflicts
this.nextState.ruleType =
this.getRuleTypes(nextProps.modId, nextProps.mods, nextProps.conflicts);
}
Expand Down Expand Up @@ -87,7 +91,7 @@ class ConflictEditor extends ComponentEx<IProps, IComponentState> {
}

private renderConflict = (conflict: IConflict) => {
const {t, mods} = this.props;
const {t, modId, modRules, mods} = this.props;
const {ruleType} = this.state;
const popover = (
<Popover
Expand All @@ -98,6 +102,14 @@ class ConflictEditor extends ComponentEx<IProps, IComponentState> {
</Popover>
);

let reverseRule: IBiDirRule;

if (ruleType[conflict.otherMod.name] === undefined) {
reverseRule = modRules
.find(rule => matchReference(rule.reference, conflict.otherMod)
&& matchReference(rule.source, mods[modId]));
}

return (
<ListGroupItem key={conflict.otherMod.id}>
<FormControl
Expand All @@ -123,10 +135,30 @@ class ConflictEditor extends ComponentEx<IProps, IComponentState> {
}</a>
</OverlayTrigger>
</div>
{ this.renderReverseRule(reverseRule) }
</ListGroupItem>
);
}

private renderReverseRule(rule: IBiDirRule) {
const { t } = this.props;
if (rule === undefined) {
return null;
}

return (
<tooltip.Icon
id={`conflict-editor-${rule.reference.fileMD5}`}
className='pull-right'
name='exclamation-circle'
tooltip={t('{{ otherMod }} has a rule referencing {{ thisMod }}',
{ replace: {
otherMod: renderReference(rule.reference),
thisMod: renderReference(rule.source) } })}
/>
);
}

private close = () => {
const { onClose } = this.props;
onClose();
Expand Down Expand Up @@ -174,6 +206,7 @@ function mapStateToProps(state): IConnectedProps {
modId: dialog.modId,
conflicts: dialog.modId !== undefined ? state.session.dependencies.conflicts[dialog.modId] : [],
mods: dialog.gameId !== undefined ? state.persistent.mods[dialog.gameId] : {},
modRules: dialog.modRules,
};
}

Expand Down
25 changes: 8 additions & 17 deletions extensions/mod-dependency-manager/src/views/DependencyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ interface IActionProps {
onSetTarget: (id: string, pos: { x: number, y: number }) => void;
onEditDialog: (gameId: string, modId: string, reference: IReference, defaultType: string) => void;
onRemoveRule: (gameId: string, modId: string, rule: IRule) => void;
onConflictDialog: (gameId: string, modId: string) => void;
onConflictDialog: (gameId: string, modId: string, modRules: IBiDirRule[]) => void;
}

interface IComponentState {
Expand Down Expand Up @@ -282,9 +282,6 @@ class DependencyIcon extends ComponentEx<IProps, IComponentState> {
matchReference(rule.source, nextProps.mod));
}

const staticRules = util.getSafe(nextState, ['modInfo', 'rules'], undefined);
const customRules = util.getSafe(nextProps.mod, ['rules'], undefined);

if (this.props.isDragging !== nextProps.isDragging) {
let pos;
if (nextProps.isDragging) {
Expand Down Expand Up @@ -328,9 +325,6 @@ class DependencyIcon extends ComponentEx<IProps, IComponentState> {
private renderConnectorIcon(mod: types.IMod) {
const {t, connectDragSource, enabledMods} = this.props;

const staticRules = util.getSafe(this.state, ['modInfo', 'rules'], []);
const customRules = util.getSafe(mod, ['rules'], []);

const classes = ['btn-dependency'];

let anyUnfulfilled = false;
Expand All @@ -357,6 +351,9 @@ class DependencyIcon extends ComponentEx<IProps, IComponentState> {

let popover: JSX.Element;

const staticRules = util.getSafe(this.state, ['modInfo', 'rules'], []);
const customRules = util.getSafe(mod, ['rules'], []);

if ((staticRules.length > 0) || (customRules.length > 0)) {
popover = (
<Popover id={`popover-${mod.id}`} style={{ maxWidth: 500 }}>
Expand Down Expand Up @@ -466,14 +463,6 @@ class DependencyIcon extends ComponentEx<IProps, IComponentState> {
return version !== undefined ? id + ' v' + version : id;
}

private renderReference(ref: IReference) {
if (ref.fileMD5) {
return ref.fileMD5;
} else {
return (ref.logicalFileName || ref.fileExpression) + ' v' + ref.versionMatch;
}
}

private findReference(reference: IReference, mods: IModLookupInfo[]): IModLookupInfo {
return mods.find(mod => matchReference(reference, mod));
}
Expand All @@ -492,7 +481,8 @@ class DependencyIcon extends ComponentEx<IProps, IComponentState> {

private openConflictDialog = () => {
const { gameId, mod, onConflictDialog } = this.props;
onConflictDialog(gameId, mod.id);
const { modRules } = this.state;
onConflictDialog(gameId, mod.id, modRules);
}

private key = (rule: IRule) => {
Expand Down Expand Up @@ -554,7 +544,8 @@ function mapDispatchToProps(dispatch): IActionProps {
onEditDialog: (gameId, modId, reference, defaultType) =>
dispatch(setCreateRule(gameId, modId, reference, defaultType)),
onRemoveRule: (gameId, modId, rule) => dispatch(actions.removeModRule(gameId, modId, rule)),
onConflictDialog: (gameId, modId) => dispatch(setConflictDialog(gameId, modId)),
onConflictDialog: (gameId, modId, modRules) =>
dispatch(setConflictDialog(gameId, modId, modRules)),
};
}

Expand Down

0 comments on commit 2ce6dca

Please sign in to comment.