-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
admin: VV atoms transform editor (#6379)
* admin: VV atoms transform editor * fix * Update nobody_wants_to_learn_matrix_math.dm * Update code/modules/admin/verbs/nobody_wants_to_learn_matrix_math.dm Co-authored-by: Antoonij <42318445+Antoonij@users.noreply.github.com> * Update code/datums/datumvars.dm Co-authored-by: Antoonij <42318445+Antoonij@users.noreply.github.com> * fix * Update tgui.bundle.js * Update code/datums/datumvars.dm Co-authored-by: Antoonij <42318445+Antoonij@users.noreply.github.com> * fix --------- Co-authored-by: Antoonij <42318445+Antoonij@users.noreply.github.com>
- Loading branch information
1 parent
e0aa0bf
commit 9393697
Showing
7 changed files
with
381 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* ## nobody wants to learn matrix math! | ||
* | ||
* More than just a completely true statement, this datum is created as a tgui interface | ||
* allowing you to modify each vector until you know what you're doing. | ||
* Much like filteriffic, 'nobody wants to learn matrix math' is meant for developers like you and I | ||
* to implement interesting matrix transformations without the hassle if needing to know... algebra? Damn, i'm stupid. | ||
*/ | ||
/datum/transform_matrix_editor | ||
var/atom/target | ||
var/matrix/testing_matrix | ||
|
||
/datum/transform_matrix_editor/New(atom/target) | ||
src.target = target | ||
testing_matrix = matrix(target.transform) | ||
|
||
/datum/transform_matrix_editor/Destroy(force, ...) | ||
QDEL_NULL(testing_matrix) | ||
target = null | ||
return ..() | ||
|
||
/datum/transform_matrix_editor/ui_state(mob/user) | ||
return GLOB.admin_state | ||
|
||
/datum/transform_matrix_editor/ui_close(mob/user) | ||
qdel(src) | ||
|
||
/datum/transform_matrix_editor/ui_interact(mob/user, datum/tgui/ui) | ||
ui = SStgui.try_update_ui(user, src, ui) | ||
if(!ui) | ||
ui = new(user, src, "MatrixMathTester") | ||
ui.open() | ||
|
||
/datum/transform_matrix_editor/ui_data() | ||
var/list/data = list() | ||
data["matrix_a"] = testing_matrix.a | ||
data["matrix_b"] = testing_matrix.b | ||
data["matrix_c"] = testing_matrix.c | ||
data["matrix_d"] = testing_matrix.d | ||
data["matrix_e"] = testing_matrix.e | ||
data["matrix_f"] = testing_matrix.f | ||
data["pixelated"] = target.appearance_flags & PIXEL_SCALE | ||
return data | ||
|
||
/datum/transform_matrix_editor/ui_act(action, list/params) | ||
. = ..() | ||
if(.) | ||
return | ||
|
||
if(!check_rights(R_VAREDIT)) | ||
return | ||
|
||
switch(action) | ||
if("change_var") | ||
var/matrix_var_name = params["var_name"] | ||
var/matrix_var_value = params["var_value"] | ||
if(!testing_matrix.vv_edit_var(matrix_var_name, matrix_var_value)) | ||
to_chat(src, "Ваше изменение было отклонено объектом. Это ошибка матричного тестера, а не ваша вина. Напишите об этом в баг репорты.", confidential = TRUE) | ||
return | ||
set_transform() | ||
if("scale") | ||
testing_matrix.Scale(params["x"], params["y"]) | ||
set_transform() | ||
if("translate") | ||
testing_matrix.Translate(params["x"], params["y"]) | ||
set_transform() | ||
if("shear") | ||
testing_matrix.Shear(params["x"], params["y"]) | ||
set_transform() | ||
if("turn") | ||
testing_matrix.Turn(params["angle"]) | ||
set_transform() | ||
if("toggle_pixel") | ||
target.appearance_flags ^= PIXEL_SCALE | ||
|
||
/datum/transform_matrix_editor/proc/set_transform() | ||
animate(target, transform = testing_matrix, time = 0.5 SECONDS) | ||
testing_matrix = matrix(target.transform) | ||
|
||
/client/proc/open_matrix_tester(atom/in_atom) | ||
if(holder) | ||
var/datum/transform_matrix_editor/matrix_tester = new(in_atom) | ||
matrix_tester.ui_interact(mob) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
import { useBackend, useLocalState } from '../backend'; | ||
import { Input, NumberInput, Section, Button, Table } from '../components'; | ||
import { toFixed } from 'common/math'; | ||
import { Window } from '../layouts'; | ||
|
||
const MatrixMathTesterInput = ( | ||
props: { value: number; varName: string }, | ||
context | ||
) => { | ||
const { act } = useBackend(context); | ||
return ( | ||
<NumberInput | ||
value={props.value} | ||
step={0.005} | ||
format={(value) => toFixed(value, 3)} | ||
width={'100%'} | ||
onChange={(e, value) => | ||
act('change_var', { var_name: props.varName, var_value: value }) | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
type MatrixData = { | ||
matrix_a: number; | ||
matrix_b: number; | ||
matrix_c: number; | ||
matrix_d: number; | ||
matrix_e: number; | ||
matrix_f: number; | ||
pixelated: boolean; | ||
}; | ||
|
||
export const MatrixMathTester = (props, context) => { | ||
const { act, data } = useBackend<MatrixData>(context); | ||
const { | ||
matrix_a, | ||
matrix_b, | ||
matrix_c, | ||
matrix_d, | ||
matrix_e, | ||
matrix_f, | ||
pixelated, | ||
} = data; | ||
const [scaleX, setScaleX] = useLocalState(context, 'scale_x', 1); | ||
const [scaleY, setScaleY] = useLocalState(context, 'scale_y', 1); | ||
const [translateX, setTranslateX] = useLocalState(context, 'translate_x', 0); | ||
const [translateY, setTranslateY] = useLocalState(context, 'translate_y', 0); | ||
const [shearX, setShearX] = useLocalState(context, 'shear_x', 0); | ||
const [shearY, setShearY] = useLocalState(context, 'shear_y', 0); | ||
const [angle, setAngle] = useLocalState(context, 'angle', 0); | ||
return ( | ||
<Window title="Transform Editor" width={290} height={270}> | ||
<Window.Content> | ||
<Section fill> | ||
<Table> | ||
<Table.Row header> | ||
<Table.Cell width={'30%'} /> | ||
<Table.Cell width={'25%'}>X</Table.Cell> | ||
<Table.Cell width={'25%'}>Y</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell header>Position(c, f)</Table.Cell> | ||
<Table.Cell> | ||
<MatrixMathTesterInput value={matrix_c} varName="c" /> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<MatrixMathTesterInput value={matrix_f} varName="f" /> | ||
</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell header>Incline(b, d)</Table.Cell> | ||
<Table.Cell> | ||
<MatrixMathTesterInput value={matrix_b} varName="b" /> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<MatrixMathTesterInput value={matrix_d} varName="d" /> | ||
</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell header>Scale(a,e)</Table.Cell> | ||
<Table.Cell> | ||
<MatrixMathTesterInput value={matrix_a} varName="a" /> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<MatrixMathTesterInput value={matrix_e} varName="e" /> | ||
</Table.Cell> | ||
</Table.Row> | ||
</Table> | ||
<Table mt={3}> | ||
<Table.Row header> | ||
<Table.Cell>Action</Table.Cell> | ||
<Table.Cell>X</Table.Cell> | ||
<Table.Cell>Y</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell> | ||
<Button | ||
icon={'up-right-and-down-left-from-center'} | ||
content={'Scale'} | ||
width={'100%'} | ||
onClick={() => act('scale', { x: scaleX, y: scaleY })} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={scaleX} | ||
step={0.05} | ||
format={(value) => toFixed(value, 2)} | ||
width={'100%'} | ||
onChange={(e, value) => setScaleX(value)} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={scaleY} | ||
step={0.05} | ||
format={(value) => toFixed(value, 2)} | ||
width={'100%'} | ||
onChange={(e, value) => setScaleY(value)} | ||
/> | ||
</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell> | ||
<Button | ||
icon={'arrow-right'} | ||
content={'Translate'} | ||
width={'100%'} | ||
onClick={() => | ||
act('translate', { x: translateX, y: translateY }) | ||
} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={translateX} | ||
step={1} | ||
format={(value) => toFixed(value, 0)} | ||
width={'100%'} | ||
onChange={(e, value) => setTranslateX(value)} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={translateY} | ||
step={1} | ||
format={(value) => toFixed(value, 0)} | ||
width={'100%'} | ||
onChange={(e, value) => setTranslateY(value)} | ||
/> | ||
</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell> | ||
<Button | ||
icon={'maximize'} | ||
content={'Shear'} | ||
width={'100%'} | ||
onClick={() => act('shear', { x: shearX, y: shearY })} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={shearX} | ||
step={0.005} | ||
format={(value) => toFixed(value, 3)} | ||
width={'100%'} | ||
onChange={(e, value) => setShearX(value)} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={shearY} | ||
step={0.005} | ||
format={(value) => toFixed(value, 3)} | ||
width={'100%'} | ||
onChange={(e, value) => setShearY(value)} | ||
/> | ||
</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell> | ||
<Button | ||
icon={'rotate-right'} | ||
content={'Rotate'} | ||
width={'100%'} | ||
onClick={() => act('turn', { angle: angle })} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<NumberInput | ||
value={angle} | ||
step={0.5} | ||
maxValue={360} | ||
minValue={-360} | ||
format={(value) => toFixed(value, 1)} | ||
width={'100%'} | ||
onChange={(e, value) => setAngle(value)} | ||
/> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<Button | ||
icon={'dog'} | ||
color={'bad'} | ||
selected={pixelated} | ||
content={'PET'} | ||
tooltip={'Pixel Enhanced Transforming'} | ||
tooltipPosition={'bottom'} | ||
width={'100%'} | ||
onClick={() => act('toggle_pixel')} | ||
/> | ||
</Table.Cell> | ||
</Table.Row> | ||
</Table> | ||
</Section> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.