Skip to content

Instantly share code, notes, and snippets.

@Nishisonic
Created September 2, 2018 15:59
Show Gist options
  • Save Nishisonic/9113c8972d4aad1b81da6e54db20b364 to your computer and use it in GitHub Desktop.
Save Nishisonic/9113c8972d4aad1b81da6e54db20b364 to your computer and use it in GitHub Desktop.
const getJSON = require('get-json')
const Jimp = require(`jimp`)
const mapAreaId = process.argv[2]
const mapInfoNo = process.argv[3]
const URL = `http://203.104.209.71/kcs2/resources/map/${zeroPadding(mapAreaId, 3)}/${zeroPadding(mapInfoNo, 2)}`
const GAUGE_JSON_URL = `http://203.104.209.71/kcs2/resources/gauge/${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}.json`
const GAUGE_IMAGE_URL = `http://203.104.209.71/kcs2/resources/gauge/`
getJSON(`${URL}_info.json`, (err, resp) => {
if (err) throw err
const bg = (resp.bg || [])
const spots = (resp.spots || [])
const enemies = (resp.enemies || [])
// not used
const airbase = (resp.airbase || [])
const airbaseraid = (resp.airbaseraid || [])
getJSON(`${URL}_image.json`, (err, resp) => {
if (err) throw err
Jimp.read(`${URL}_image.png`).then(image => {
// crop
const images = Object.keys(resp.frames).map(key => {
const f = resp.frames[key].frame
const crop = image.clone().crop(f.x, f.y, f.w, f.h)
return { [key]: crop }
}).reduce((l, r) => Object.assign(l, r), {})
const background = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${bg[0]}`]
const point = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${bg[1]}`]
// point
background.composite(point, 0, 0)
// route
spots.filter(spot => spot.line !== undefined).forEach(spot => {
const suffix = spot.line.img || `route_${spot.no}`
const image = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${suffix}`]
background.composite(image, spot.x + spot.line.x, spot.y + spot.line.y)
})
// enemy
enemies.forEach(enemy => {
const image = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${enemy.img}`]
background.composite(image, enemy.x, enemy.y)
})
// gauge
getJSON(GAUGE_JSON_URL, (err, resp) => {
if(err){
background.write(`map/${zeroPadding(mapAreaId, 3)}/${zeroPadding(mapInfoNo, 2)}_full.png`)
return
}
Jimp.read(`${GAUGE_IMAGE_URL}${resp.vertical.img}.png`).then(image => {
console.log(image, resp.vertical.x, resp.vertical.y)
background.composite(image, resp.vertical.x, resp.vertical.y)
Jimp.read(`${GAUGE_IMAGE_URL}${resp.vertical.img}_light.png`).then(image => {
background.composite(image, resp.vertical.x, resp.vertical.y)
background.write(`map/${zeroPadding(mapAreaId, 3)}/${zeroPadding(mapInfoNo, 2)}_full2.png`)
})
})
// not hide
// hide process
getJSON(`${URL}_info${spots.length}.json`, (err, resp) => {
if(err) return
const bg = (resp.bg || [])
const spots = (resp.spots || [])
const enemies = (resp.enemies || [])
// not used
const airbase = (resp.airbase || [])
const airbaseraid = (resp.airbaseraid || [])
Jimp.read(`${URL}_image${spot.length}.png`).then(image => {
// crop
const images = Object.keys(resp.frames).map(key => {
const f = resp.frames[key].frame
const crop = image.clone().crop(f.x, f.y, f.w, f.h)
return { [key]: crop }
}).reduce((l, r) => Object.assign(l, r), {})
const point = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${bg[1]}`]
// point
background.composite(point, 0, 0)
// route
spots.filter(spot => spot.line !== undefined).forEach(spot => {
const suffix = spot.line.img || `route_${spot.no}`
const image = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${suffix}`]
background.composite(image, spot.x + spot.line.x, spot.y + spot.line.y)
})
// enemy
enemies.forEach(enemy => {
const image = images[`map${zeroPadding(mapAreaId, 3)}${zeroPadding(mapInfoNo, 2)}_${enemy.img}`]
background.composite(image, enemy.x, enemy.y)
})
// show hide
background.write(`map/${zeroPadding(mapAreaId, 3)}/${zeroPadding(mapInfoNo, 2)}_full3.png`)
})
})
})
}).catch(err => {})
})
})
// Kancolle main.js
// https://gist.github.com/sanaehirotaka/c177c39c37ba09b3642705a0be5e2465
function zeroPadding(t, e) {
var i = t >= 0 ? "" : "-";
t = Math.abs(t);
for (var n = t > 0 ? Math.floor(Math.log(t) * Math.LOG10E + 1) : 1, o = "", r = 0, s = e - n; r < s; r++) {
o += "0";
}
return i + o + t
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment