Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f400ee5

Browse files
committed
refine docs, logging, help text
1 parent 06f1f53 commit f400ee5

3 files changed

Lines changed: 38 additions & 29 deletions

File tree

docs/Dev-intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ other commands).
3535

3636
Plugins can also register handlers to run on every tick, and can interface with
3737
the built-in `enable` and `disable` commands. For the full plugin API, see the
38-
example plugins or ``PluginManager.cpp``.
38+
example ``skeleton`` plugin or ``PluginManager.cpp``.
3939

4040
Installed plugins live in the ``hack/plugins`` folder of a DFHack installation,
4141
and the `load` family of commands can be used to load a recompiled plugin

plugins/examples/persistent_per_save_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) {
119119
}
120120

121121
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) {
122-
if (event == DFHack::SC_MAP_UNLOADED) {
122+
if (event == DFHack::SC_WORLD_UNLOADED) {
123123
if (is_enabled) {
124124
DEBUG(status,out).print("world unloaded; disabling %s\n",
125125
plugin_name);

plugins/examples/skeleton.cpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,37 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
9898
// Invoked with DF suspended, and always before the matching plugin_onupdate.
9999
// More event codes may be added in the future.
100100
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) {
101-
DEBUG(status,out).print("game state changed: %d\n", event);
102-
103-
if (is_enabled) {
104-
switch (event) {
105-
case SC_UNKNOWN:
106-
break;
107-
case SC_WORLD_LOADED:
108-
break;
109-
case SC_WORLD_UNLOADED:
110-
break;
111-
case SC_MAP_LOADED:
112-
break;
113-
case SC_MAP_UNLOADED:
114-
break;
115-
case SC_VIEWSCREEN_CHANGED:
116-
break;
117-
case SC_CORE_INITIALIZED:
118-
break;
119-
case SC_BEGIN_UNLOAD:
120-
break;
121-
case SC_PAUSED:
122-
break;
123-
case SC_UNPAUSED:
124-
break;
125-
}
101+
switch (event) {
102+
case SC_UNKNOWN:
103+
DEBUG(status,out).print("game state changed: SC_UNKNOWN\n");
104+
break;
105+
case SC_WORLD_LOADED:
106+
DEBUG(status,out).print("game state changed: SC_WORLD_LOADED\n");
107+
break;
108+
case SC_WORLD_UNLOADED:
109+
DEBUG(status,out).print("game state changed: SC_WORLD_UNLOADED\n");
110+
break;
111+
case SC_MAP_LOADED:
112+
DEBUG(status,out).print("game state changed: SC_MAP_LOADED\n");
113+
break;
114+
case SC_MAP_UNLOADED:
115+
DEBUG(status,out).print("game state changed: SC_MAP_UNLOADED\n");
116+
break;
117+
case SC_VIEWSCREEN_CHANGED:
118+
DEBUG(status,out).print("game state changed: SC_VIEWSCREEN_CHANGED\n");
119+
break;
120+
case SC_CORE_INITIALIZED:
121+
DEBUG(status,out).print("game state changed: SC_CORE_INITIALIZED\n");
122+
break;
123+
case SC_BEGIN_UNLOAD:
124+
DEBUG(status,out).print("game state changed: SC_BEGIN_UNLOAD\n");
125+
break;
126+
case SC_PAUSED:
127+
DEBUG(status,out).print("game state changed: SC_PAUSED\n");
128+
break;
129+
case SC_UNPAUSED:
130+
DEBUG(status,out).print("game state changed: SC_UNPAUSED\n");
131+
break;
126132
}
127133

128134
return CR_OK;
@@ -145,14 +151,17 @@ DFhackCExport command_result plugin_onupdate (color_ostream &out) {
145151
DFhackCExport command_result plugin_save_data (color_ostream &out) {
146152
DEBUG(status,out).print("save or unload is imminent; time to persist state\n");
147153

148-
// Call functions in the Persistence module here.
154+
// Call functions in the Persistence module here. If your PersistantDataItem
155+
// objects are already up to date, then they will get persisted with the
156+
// save automatically and there is nothing extra you need to do here.
149157
return CR_OK;
150158
}
151159

152160
DFhackCExport command_result plugin_load_data (color_ostream &out) {
153161
DEBUG(status,out).print("world is loading; time to load persisted state\n");
154162

155-
// Call functions in the Persistence module here.
163+
// Call functions in the Persistence module here. See
164+
// persistent_per_save_example.cpp for an example.
156165
return CR_OK;
157166
}
158167

0 commit comments

Comments
 (0)