1 /** 2 Copyright: Copyright (c) 2015-2016 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 7 module voxelman.edit.plugin; 8 9 import std.experimental.logger; 10 11 import pluginlib; 12 import voxelman.core.config; 13 import voxelman.client.plugin; 14 import voxelman.worldinteraction.plugin; 15 16 import voxelman.eventdispatcher.plugin; 17 import voxelman.input.keybindingmanager; 18 19 shared static this() 20 { 21 pluginRegistry.regClientPlugin(new EditPlugin); 22 } 23 24 class EditPlugin : IPlugin 25 { 26 mixin IdAndSemverFrom!(voxelman.edit.plugininfo); 27 28 ClientPlugin clientPlugin; 29 WorldInteractionPlugin worldInteraction; 30 31 BlockType currentBlock = 4; 32 33 override void registerResources(IResourceManagerRegistry resmanRegistry) 34 { 35 auto keyBindingsMan = resmanRegistry.getResourceManager!KeyBindingManager; 36 keyBindingsMan.registerKeyBinding(new KeyBinding(PointerButton.PB_1, "key.mainAction", null, &onMainActionRelease)); 37 keyBindingsMan.registerKeyBinding(new KeyBinding(PointerButton.PB_2, "key.secondaryAction", null, &onSecondaryActionRelease)); 38 keyBindingsMan.registerKeyBinding(new KeyBinding(PointerButton.PB_3, "key.tertiaryAction", null, &onTertiaryActionRelease)); 39 } 40 41 override void init(IPluginManager pluginman) 42 { 43 clientPlugin = pluginman.getPlugin!ClientPlugin; 44 worldInteraction = pluginman.getPlugin!WorldInteractionPlugin; 45 } 46 47 void onMainActionRelease(string key) 48 { 49 if (clientPlugin.mouseLocked) 50 worldInteraction.placeBlock(1); 51 } 52 53 void onSecondaryActionRelease(string key) 54 { 55 if (clientPlugin.mouseLocked) 56 worldInteraction.placeBlock(currentBlock); 57 } 58 59 void onTertiaryActionRelease(string key) 60 { 61 if (clientPlugin.mouseLocked) 62 currentBlock = worldInteraction.pickBlock(); 63 } 64 }