Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin: VV atoms transform editor #6379

Open
wants to merge 8 commits into
base: master220
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions code/__HELPERS/matrices.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
//doesn't have an object argument because this is "Stacking" with the animate call above
//3 billion% intentional

/**
* Shear the transform on either or both axes.
* * x - X axis shearing
* * y - Y axis shearing
*/
/matrix/proc/Shear(x, y)
return Multiply(matrix(1, x, 0, y, 1, 0))

//Dumps the matrix data in format a-f
/matrix/proc/tolist()
. = list()
Expand Down
8 changes: 8 additions & 0 deletions code/datums/datumvars.dm
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@

modify_variables(D, href_list["varnameedit"], 1)

else if(href_list["matrix_tester"])

dageavtobusnick marked this conversation as resolved.
Show resolved Hide resolved
var/atom/atom = locateUID(href_list["matrix_tester"])
if(!istype(atom))
to_chat(usr, "Это можно использовать только для экземпляров типов /atom", confidential=TRUE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to_chat(usr, "Это можно использовать только для экземпляров типов /atom", confidential=TRUE)
to_chat(usr, "Это можно использовать только для экземпляров типов /atom", confidential = TRUE)

return
usr?.client.open_matrix_tester(atom)

else if(href_list["togbit"])
if(!check_rights(R_VAREDIT)) return

Expand Down
1 change: 1 addition & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons)
.["Jump to turf"] = "?_src_=holder;adminplayerobservecoodjump=1;X=[curturf.x];Y=[curturf.y];Z=[curturf.z]"
.["Add reagent"] = "?_src_=vars;addreagent=[UID()]"
.["Edit reagents"] = "?_src_=vars;editreagents=[UID()]"
.["Transform editor"] = "?_src_=vars;matrix_tester=[UID()]"
.["Trigger explosion"] = "?_src_=vars;explode=[UID()]"
.["Trigger EM pulse"] = "?_src_=vars;emp=[UID()]"

Expand Down
82 changes: 82 additions & 0 deletions code/modules/admin/verbs/nobody_wants_to_learn_matrix_math.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* ## 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/nobody_wants_to_learn_matrix_math
dageavtobusnick marked this conversation as resolved.
Show resolved Hide resolved
var/atom/target
var/matrix/testing_matrix

/datum/nobody_wants_to_learn_matrix_math/New(atom/target)
src.target = target
testing_matrix = matrix(target.transform)

/datum/nobody_wants_to_learn_matrix_math/Destroy(force, ...)
QDEL_NULL(testing_matrix)
return ..()
dageavtobusnick marked this conversation as resolved.
Show resolved Hide resolved

/datum/nobody_wants_to_learn_matrix_math/ui_state(mob/user)
return GLOB.admin_state

/datum/nobody_wants_to_learn_matrix_math/ui_close(mob/user)
qdel(src)

/datum/nobody_wants_to_learn_matrix_math/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/nobody_wants_to_learn_matrix_math/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/nobody_wants_to_learn_matrix_math/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) == FALSE)
dageavtobusnick marked this conversation as resolved.
Show resolved Hide resolved
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/nobody_wants_to_learn_matrix_math/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/nobody_wants_to_learn_matrix_math/matrix_tester = new(in_atom)
matrix_tester.ui_interact(mob)
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,7 @@
#include "code\modules\admin\verbs\mapping.dm"
#include "code\modules\admin\verbs\massmodvar.dm"
#include "code\modules\admin\verbs\modifyvariables.dm"
#include "code\modules\admin\verbs\nobody_wants_to_learn_matrix_math.dm"
#include "code\modules\admin\verbs\one_click_antag.dm"
#include "code\modules\admin\verbs\onlyone.dm"
#include "code\modules\admin\verbs\onlyoneteam.dm"
Expand Down
220 changes: 220 additions & 0 deletions tgui/packages/tgui/interfaces/MatrixMathTester.tsx
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>
);
};
34 changes: 17 additions & 17 deletions tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

Loading