Forked from davidbmaier/DragBlocks.Script.txt
Last active
September 30, 2023 22:04
-
-
Save XertroV/a3bf24224bc6abf51c4888d5af3bad78 to your computer and use it in GitHub Desktop.
Drag blocks - TM2020 editor plugin by Nerpson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Nicolas 'Nerpson' Jullien | |
* @maintainer (this version) XertroV | |
* | |
* License: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) | |
* You are free to: | |
* | |
* Share — copy and redistribute the material in any medium or format | |
* Adapt — remix, transform, and build upon the material | |
* | |
* Under the following terms: | |
* | |
* Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. | |
* | |
* NonCommercial — You may not use the material for commercial purposes. | |
* | |
* ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. | |
*/ | |
#RequireContext CMapEditorPlugin | |
#Include "MathLib" as ML | |
Void Select(Int3 _From, Int3 _To) { | |
CustomSelectionCoords.clear(); | |
declare Integer FromX = ML::Min(_From.X, _To.X); | |
declare Integer FromY = ML::Min(_From.Y, _To.Y); | |
declare Integer FromZ = ML::Min(_From.Z, _To.Z); | |
declare Integer ToX = ML::Max(_From.X, _To.X); | |
declare Integer ToY = ML::Max(_From.Y, _To.Y); | |
declare Integer ToZ = ML::Max(_From.Z, _To.Z); | |
log(Now ^ "> " ^ <FromX, FromY, FromZ> ^ "\t" ^ <ToX, ToY, ToZ>); | |
for (X, FromX, ToX) { | |
for (Y, FromY, ToY) { | |
for (Z, FromZ, ToZ) { | |
CustomSelectionCoords.add(<X, Y, Z>); | |
} | |
} | |
} | |
} | |
main() { | |
declare Boolean SavedMouseLeftButton; | |
declare Integer CurrentMode = 0; | |
declare CBlockModel SavedBlockModel; | |
declare Int3 StartCoord; | |
while(True) { | |
switch (CurrentMode) { | |
case 0: { | |
if (PlaceMode == ::PlaceMode::Block) { | |
if ( | |
Input.IsKeyPressed(65) && Input.IsKeyPressed(28) | |
) { | |
CurrentMode = 1; | |
log(Now ^ "> Entering selection mode"); | |
SavedBlockModel <=> Cursor.BlockModel; | |
PlaceMode = ::PlaceMode::CustomSelection; | |
ShowCustomSelection(); | |
CustomSelectionRGB = <0., 0.5, 1.>; | |
} | |
} | |
} | |
case 1: { | |
if (Input.MouseLeftButton) { | |
if (PlaceMode != ::PlaceMode::CustomSelection) PlaceMode = ::PlaceMode::CustomSelection; | |
if (!SavedMouseLeftButton) { | |
// Starting selection. | |
StartCoord = Cursor.Coord; | |
} | |
Select(StartCoord, Cursor.Coord); | |
} else { | |
if (SavedMouseLeftButton) { | |
// Stopping selection. | |
CurrentMode = 0; | |
log(Now ^ "> Selection finished"); | |
foreach (Coord in CustomSelectionCoords) { | |
PlaceBlock(SavedBlockModel, Coord, Cursor.Dir); | |
} | |
CustomSelectionCoords.clear(); | |
HideCustomSelection(); | |
PlaceMode = ::PlaceMode::Block; | |
} else if (PlaceMode != ::PlaceMode::CustomSelection) { | |
// Abandonning selection. | |
CurrentMode = 0; | |
log(Now ^ "> Selection abandonned"); | |
} | |
} | |
} | |
} | |
SavedMouseLeftButton = Input.MouseLeftButton; | |
yield; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment