Skip to content

Commit

Permalink
Multiple downloads work, pushing to v0.5.3-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamYG committed Jun 20, 2019
1 parent 42d1067 commit 7da1504
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 197 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sc2-campaign-manager",
"version": "0.5.2-alpha",
"version": "0.5.3-alpha",
"description": "A Campaign Manager for StarCraft II. ",
"main": "main.js",
"build": {
Expand Down
2 changes: 2 additions & 0 deletions src/classes/Campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ICampaign {
"patchNotes":Array<IPatchNote>,
"screenshots":Array<IScreenshot>,
"videos"?:Array<string>,
"state"?:string,
[key: string]: string|number|object|boolean|ISC2Map|ISC2Mod
};

Expand Down Expand Up @@ -148,6 +149,7 @@ export default class Campaign {

static downloadCampaign = (campaign:ICampaign) => {
const installDir = Campaign.getCampaignsInstallDir();

Downloader.pushCampaign(campaign);
//ipcRenderer.send(msg.DOWNLOAD_CAMPAIGN, {...campaign, installDir:Campaign.getCampaignsInstallDir()});

Expand Down
46 changes: 39 additions & 7 deletions src/classes/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ interface IDownloadSet {
[key: string]: IDownload;
}

const getCampaignFromStore = (campaignId:string) => {
const campaigns = store.getState().campaignState.campaigns;
const campaignIndex = campaigns.findIndex(c => c.id === campaignId);
return campaigns[campaignIndex]

}

const setCampaignInStore = (campaignId:string,campaign:ICampaign) => {
const campaigns = store.getState().campaignState.campaigns;
const campaignIndex = campaigns.findIndex(c => c.id === campaignId);
store.dispatch(setCampaign(campaign,campaignIndex));
}

export default class Downloader {
static downloads: IDownloadSet;
static progress: number = 0;

static pushCampaign(campaign: ICampaign) {

console.log("pushCampaign");
let sourcesbyKey: { [key: string]: ISource } = {};

const mods: Array<ISC2Component> = [...campaign.mods, ...campaign.maps];
const sources = _.uniqWith<ISource>(
mods.map(
Expand All @@ -60,11 +75,24 @@ export default class Downloader {
);
Promise.all(promises).then(data => {
console.log("downloads have finished for", campaign.id);
const newCampaign:ICampaign = {
...getCampaignFromStore(campaign.id),
installed:Campaign.isCampaignInstalled(getCampaignFromStore(campaign.id)),
progress:0,
state:"ready"
};
setCampaignInStore(newCampaign.id,newCampaign)
});

const newCampaign:ICampaign = {
...getCampaignFromStore(campaign.id),
state:"downloading"
};
setCampaignInStore(newCampaign.id,newCampaign)

}
static async downloadSource(source: ISource, index: number) {
let timer = Date.now();

const tempPath = path.join(
app.getPath("temp"),
app.getName(),
Expand All @@ -87,6 +115,12 @@ export default class Downloader {
} else {
this.copyMaps(source.files[0], tempFullName);
}
const newCampaign:ICampaign = {
...getCampaignFromStore(source.campaignId),
installed:Campaign.isCampaignInstalled(getCampaignFromStore(source.campaignId)),
state:"ready"
};
setCampaignInStore(newCampaign.id,newCampaign)
});
dl.pipe(ws);
})
Expand Down Expand Up @@ -192,12 +226,10 @@ export default class Downloader {
[campaignId]: download
};
console.log(campaignId, download.progress);
const campaigns = store.getState().campaignState.campaigns;
const campaignIndex = campaigns.findIndex(c => c.id === campaignId);
const campaign = {
...campaigns[campaignIndex],
const newCampaign:ICampaign = {
...getCampaignFromStore(campaignId),
progress:download.progress
};
store.dispatch(setCampaign(campaign,campaignIndex));
setCampaignInStore(campaignId,newCampaign)
}
}
Loading

0 comments on commit 7da1504

Please sign in to comment.