Merge branch 'once' into syndromeTrigger
commit
b057a0d82a
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Export.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace DFHack {
|
||||||
|
namespace Once {
|
||||||
|
DFHACK_EXPORT bool alreadyDone(std::string);
|
||||||
|
DFHACK_EXPORT bool doOnce(std::string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
#include "modules/Once.h"
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
static unordered_set<string> thingsDone;
|
||||||
|
|
||||||
|
bool DFHack::Once::alreadyDone(string bob) {
|
||||||
|
return thingsDone.find(bob) != thingsDone.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DFHack::Once::doOnce(string bob) {
|
||||||
|
return thingsDone.insert(bob).second;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
#include "Core.h"
|
||||||
|
#include "Console.h"
|
||||||
|
#include "DataDefs.h"
|
||||||
|
#include "Export.h"
|
||||||
|
#include "PluginManager.h"
|
||||||
|
|
||||||
|
#include "modules/Once.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
using namespace df::enums;
|
||||||
|
|
||||||
|
command_result onceExample (color_ostream &out, std::vector <std::string> & parameters);
|
||||||
|
|
||||||
|
DFHACK_PLUGIN("onceExample");
|
||||||
|
|
||||||
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
||||||
|
{
|
||||||
|
commands.push_back(PluginCommand(
|
||||||
|
"onceExample", "Test the doOnce command.",
|
||||||
|
onceExample, false,
|
||||||
|
" This command tests the doOnce command..\n"
|
||||||
|
));
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
command_result onceExample (color_ostream &out, std::vector <std::string> & parameters)
|
||||||
|
{
|
||||||
|
out.print("Already done = %d.\n", DFHack::Once::alreadyDone("onceExample_1"));
|
||||||
|
if ( DFHack::Once::doOnce("onceExample_1") ) {
|
||||||
|
out.print("Printing this message once!\n");
|
||||||
|
}
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue