arma-server-web-admin/lib/steam_mods.js
2021-07-10 16:17:00 +02:00

62 lines
1.2 KiB
JavaScript

var events = require('events')
var ArmaSteamWorkshop = require('arma-steam-workshop')
var SteamMods = function (config) {
this.config = config
this.armaSteamWorkshop = new ArmaSteamWorkshop(this.config.steam)
this.mods = []
}
SteamMods.prototype = new events.EventEmitter()
SteamMods.prototype.delete = function (mod, cb) {
var self = this
this.armaSteamWorkshop.deleteMod(mod, function (err) {
if (err) {
console.log(err)
} else {
self.updateMods()
}
if (cb) {
cb(err)
}
})
}
SteamMods.prototype.find = function (id) {
return this.mods.find(function (mod) {
return mod.id === id
})
}
SteamMods.prototype.download = function (workshopId, cb) {
var self = this
this.armaSteamWorkshop.downloadMod(workshopId, function (err) {
self.updateMods()
if (cb) {
cb(err)
}
})
self.updateMods()
}
SteamMods.prototype.search = function (query, cb) {
this.armaSteamWorkshop.search(query, cb)
}
SteamMods.prototype.updateMods = function () {
var self = this
this.armaSteamWorkshop.mods(function (err, mods) {
if (err) {
console.log(err)
} else {
self.mods = mods
self.emit('mods', mods)
}
})
}
module.exports = SteamMods