46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
import { serviceDataActions } from '../actions';
|
|
import { CampaignAccessors, CampaignUtils } from '../engine/Campaign';
|
|
import { serviceDataSelectors } from '../selectors';
|
|
import { MessageManager } from './MessageManager';
|
|
export class PartyManager extends MessageManager {
|
|
constructor(params) {
|
|
super(params);
|
|
// Data Requests
|
|
this.updateSharedInventory = (shouldUpdate) => {
|
|
if (shouldUpdate) {
|
|
this.dispatch(serviceDataActions.partyInventoryRequest());
|
|
}
|
|
};
|
|
this.handleAcceptOnSuccess = (isShared, onSuccess) => {
|
|
return () => {
|
|
typeof onSuccess === 'function' && onSuccess();
|
|
if (isShared) {
|
|
const data = {};
|
|
const eventType = this.EVENT_TYPES.ITEM_SHARED_FULFILLED;
|
|
this.sendMessage({ data, eventType });
|
|
}
|
|
};
|
|
};
|
|
this.handleRejectOnError = (onError, isShared) => {
|
|
return () => {
|
|
typeof onError === 'function' && onError();
|
|
};
|
|
};
|
|
// Accessors
|
|
this.getPartyId = () => {
|
|
const partyInfo = serviceDataSelectors.getPartyInfo(this.state);
|
|
return partyInfo ? CampaignAccessors.getId(partyInfo) : null;
|
|
};
|
|
this.getPartyMemberName = (equippedEntityId) => {
|
|
const partyInfo = serviceDataSelectors.getPartyInfo(this.state);
|
|
if (partyInfo) {
|
|
return CampaignUtils.getCharacterName(partyInfo, equippedEntityId);
|
|
}
|
|
return '';
|
|
};
|
|
this.addSubscriptions({
|
|
[this.EVENT_TYPES.ITEM_SHARED_FULFILLED]: this.updateSharedInventory,
|
|
});
|
|
}
|
|
}
|