Ported homebrew, fixed explode
This commit is contained in:
parent
264bcf5425
commit
bf19e24063
5 changed files with 64 additions and 7 deletions
49
natives/homebrew.cc
Normal file
49
natives/homebrew.cc
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <Magick++.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class HomebrewWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
HomebrewWorker(Napi::Function& callback, string text)
|
||||
: Napi::AsyncWorker(callback), text(text) {}
|
||||
~HomebrewWorker() {}
|
||||
|
||||
void Execute() {
|
||||
Image image;
|
||||
image.read("./assets/images/hbc.png");
|
||||
image.textGravity(Magick::CenterGravity);
|
||||
image.font("./assets/hbc.ttf");
|
||||
image.textKerning(-5);
|
||||
image.fillColor("white");
|
||||
image.fontPointsize(96);
|
||||
image.draw(DrawableText(0, 0, text));
|
||||
image.magick("PNG");
|
||||
image.write(&blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||
}
|
||||
|
||||
private:
|
||||
string text, type;
|
||||
int delay, wordlength, i, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
Napi::Value Homebrew(const Napi::CallbackInfo &info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
string text = info[0].As<Napi::String>().Utf8Value();
|
||||
Napi::Function cb = info[1].As<Napi::Function>();
|
||||
|
||||
HomebrewWorker* explodeWorker = new HomebrewWorker(cb, text);
|
||||
explodeWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
8
natives/homebrew.h
Normal file
8
natives/homebrew.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef ESMBOT_NATIVES_HOMEBREW_H_
|
||||
#define ESMBOT_NATIVES_HOMEBREW_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Homebrew(const Napi::CallbackInfo& info);
|
||||
|
||||
#endif
|
|
@ -11,6 +11,7 @@
|
|||
#include "freeze.h"
|
||||
#include "gamexplain.h"
|
||||
#include "globe.h"
|
||||
#include "homebrew.h"
|
||||
#include "invert.h"
|
||||
#include "jpeg.h"
|
||||
#include "leak.h"
|
||||
|
@ -33,6 +34,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|||
exports.Set(Napi::String::New(env, "freeze"), Napi::Function::New(env, Freeze));
|
||||
exports.Set(Napi::String::New(env, "gamexplain"), Napi::Function::New(env, Gamexplain));
|
||||
exports.Set(Napi::String::New(env, "globe"), Napi::Function::New(env, Globe));
|
||||
exports.Set(Napi::String::New(env, "homebrew"), Napi::Function::New(env, Homebrew));
|
||||
exports.Set(Napi::String::New(env, "invert"), Napi::Function::New(env, Invert));
|
||||
exports.Set(Napi::String::New(env, "jpeg"), Napi::Function::New(env, Jpeg));
|
||||
exports.Set(Napi::String::New(env, "leak"), Napi::Function::New(env, Leak));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue