Skip to content

Commit

Permalink
notekeeper!
Browse files Browse the repository at this point in the history
  • Loading branch information
FalloutFalcon committed May 29, 2024
1 parent 0b6dd1a commit ea477bf
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 54 deletions.
20 changes: 10 additions & 10 deletions code/__DEFINES/datacore.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
#define DATACORE_AGE "age"
#define DATACORE_GENDER "gender"
#define DATACORE_SPECIES "species"
#define DATACORE_FINGERPRINT "fingerprint"

#define DATACORE_APPEARANCE "character_appearance"
#define DATACORE_MINDREF "mind"
#define DATACORE_DNA_IDENTITY "identity"
#define DATACORE_DNA_FEATURES "features"
#define DATACORE_NOTES "notes"

#define DATACORE_PHYSICAL_HEALTH "p_stat"
#define DATACORE_MENTAL_HEALTH "m_stat"

#define DATACORE_BLOOD_TYPE "blood_type"
#define DATACORE_BLOOD_DNA "b_dna"
#define DATACORE_DISEASES "cdi"
#define DATACORE_DISEASES_DETAILS "cdi_d"
#define DATACORE_DISABILITIES "ma_dis"
#define DATACORE_DISABILITIES_DETAILS "ma_dis_d"
#define DATACORE_NOTES_MEDICAL "medical_note"

#define DATACORE_FINGERPRINT "fingerprint"
#define DATACORE_CRIMES "crim"
#define DATACORE_CRIMINAL_STATUS "criminal"
//#define DATACORE_CITATIONS "citation"
#define DATACORE_NOTES_SECURITY "security_note"

//Not very used
#define DATACORE_IMAGE "image"

#define DATACORE_NOTES "notes"
//#define DATACORE_NOTES_DETAILS "notes_d"
#define DATACORE_NOTES_SECURITY "security_note"
#define DATACORE_NOTES_MEDICAL "medical_note"
#define DATACORE_DNA_IDENTITY "identity"
#define DATACORE_DNA_FEATURES "features"
#define DATACORE_MINDREF "mind"

/// Keys for SSdatacore.library
#define DATACORE_RECORDS_OUTPOST "outpost"
Expand Down
11 changes: 6 additions & 5 deletions code/controllers/subsystem/datacore.dm
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,26 @@ SUBSYSTEM_DEF(datacore)
//General Record
var/datum/data/record/G = new()
G.fields[DATACORE_ID] = id
G.fields[DATACORE_NAME] = H.real_name
G.fields[DATACORE_RANK] = assignment
G.fields[DATACORE_INITIAL_RANK] = assignment
G.fields[DATACORE_NAME] = H.real_name
G.fields[DATACORE_AGE] = H.age
G.fields[DATACORE_GENDER] = person_gender
G.fields[DATACORE_SPECIES] = H.dna.species.name
G.fields[DATACORE_PHYSICAL_HEALTH] = PHYSICAL_ACTIVE
G.fields[DATACORE_MENTAL_HEALTH] = MENTAL_STABLE

G.fields[DATACORE_GENDER] = person_gender
G.fields[DATACORE_APPEARANCE] = character_appearance
G.fields[DATACORE_NOTES] = "No notes."

G.fields[DATACORE_PHYSICAL_HEALTH] = PHYSICAL_ACTIVE
G.fields[DATACORE_MENTAL_HEALTH] = MENTAL_STABLE

G.fields[DATACORE_BLOOD_TYPE] = H.dna.blood_type.name
G.fields[DATACORE_BLOOD_DNA] = H.dna.unique_enzymes
G.fields[DATACORE_DISABILITIES] = "None"
G.fields[DATACORE_DISABILITIES_DETAILS] = "No minor disabilities have been declared."
G.fields[DATACORE_DISEASES] = "None"
G.fields[DATACORE_DISEASES_DETAILS] = "No diseases have been diagnosed at the moment."
G.fields[DATACORE_NOTES_MEDICAL] = "No medical notes."
G.fields[DATACORE_NOTES_MEDICAL] = list()

G.fields[DATACORE_FINGERPRINT] = md5(H.dna.uni_identity)
G.fields[DATACORE_CRIMINAL_STATUS] = "None"
Expand Down
45 changes: 38 additions & 7 deletions code/game/machinery/computer/record/medical.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@

var/list/records = list()
for(var/datum/data/record/target in SSdatacore.get_records(linked_ship))
var/list/notes = list()
for(var/datum/medical_note/note in target.fields[DATACORE_NOTES_MEDICAL])
notes += list(list(
author = note.author,
content = note.content,
note_ref = REF(note),
time = note.time,
))
records += list(list(
age = target.fields[DATACORE_AGE],
blood_type = target.fields[DATACORE_BLOOD_TYPE],
record_ref = REF(target),
dna = target.fields[DATACORE_BLOOD_DNA],
rank = target.fields[DATACORE_RANK],
age = target.fields[DATACORE_AGE],
name = target.fields[DATACORE_NAME],
gender = target.fields[DATACORE_GENDER],
disabilities = target.fields[DATACORE_DISABILITIES],
species = target.fields[DATACORE_SPECIES],
physical_status = target.fields[DATACORE_PHYSICAL_HEALTH],
mental_status = target.fields[DATACORE_MENTAL_HEALTH],
name = target.fields[DATACORE_NAME],
rank = target.fields[DATACORE_RANK],
species = target.fields[DATACORE_SPECIES],
blood_type = target.fields[DATACORE_BLOOD_TYPE],
dna = target.fields[DATACORE_BLOOD_DNA],
notes = notes,
))

data["records"] = records
Expand Down Expand Up @@ -65,6 +73,29 @@
return FALSE

switch(action)
if("add_note")
if(!params["content"])
return FALSE
var/content = trim(params["content"], MAX_MESSAGE_LEN)

var/datum/medical_note/new_note = new(usr.name, content)
while(length(target.fields[DATACORE_NOTES_MEDICAL]) > 5)
target.fields[DATACORE_NOTES_MEDICAL].Cut(1, 2)

target.fields[DATACORE_NOTES_MEDICAL] += new_note

return TRUE

if("delete_note")
var/datum/medical_note/old_note = locate(params["note_ref"]) in target.fields[DATACORE_NOTES_MEDICAL]
if(!old_note)
return FALSE

target.fields[DATACORE_NOTES_MEDICAL] -= old_note
qdel(old_note)

return TRUE

if("set_physical_status")
var/physical_status = params["physical_status"]
if(!physical_status || !(physical_status in PHYSICAL_STATUSES))
Expand Down
15 changes: 15 additions & 0 deletions code/modules/datacore/medical_note.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Player-written medical note.
*/
/datum/medical_note
/// Player that wrote the note
var/author
/// Details of the note
var/content
/// Station timestamp
var/time

/datum/medical_note/New(author = "Anonymous", content = "No details provided.")
src.author = author
src.content = content
src.time = station_time_timestamp()
1 change: 1 addition & 0 deletions shiptest.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,7 @@
#include "code\modules\clothing\under\jobs\Plasmaman\security.dm"
#include "code\modules\datacore\crime.dm"
#include "code\modules\datacore\library.dm"
#include "code\modules\datacore\medical_note.dm"
#include "code\modules\datacore\records.dm"
#include "code\modules\detectivework\detective_work.dm"
#include "code\modules\detectivework\evidence.dm"
Expand Down
129 changes: 129 additions & 0 deletions tgui/packages/tgui/interfaces/MedicalRecords/NoteKeeper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { useBackend, useLocalState } from 'tgui/backend';
import {
BlockQuote,
Box,
Button,
Icon,
LabeledList,
Section,
Tabs,
TextArea,
Tooltip,
} from 'tgui/components';

import { getMedicalRecord } from './helpers';
import { MedicalNote, MedicalRecordData } from './types';

/** Small section for adding notes. Passes a ref and note to Byond. */
export const NoteKeeper = (props, context) => {
const foundRecord = getMedicalRecord(props, context);
if (!foundRecord) return <> </>;

const { act } = useBackend<MedicalRecordData>(context);
const { record_ref } = foundRecord;

const [selectedNote, setSelectedNote] = useLocalState<
MedicalNote | undefined
>(context, 'selectedNote', undefined);

const [writing, setWriting] = useLocalState(context, 'note', false);

const addNote = (event, value: string) => {
act('add_note', {
record_ref: record_ref,
content: value,
});
setWriting(false);
};

const deleteNote = () => {
if (!selectedNote) return;
act('delete_note', {
record_ref: record_ref,
note_ref: selectedNote.note_ref,
});
setSelectedNote(undefined);
};

return (
<Section buttons={<NoteTabs />} fill scrollable title="Notes">
{writing && (
<TextArea
height="100%"
maxLength={1024}
onEnter={addNote}
onEscape={() => setWriting(false)}
/>
)}

{!!selectedNote && (
<>
<LabeledList>
<LabeledList.Item
label="Author"
buttons={<Button color="bad" icon="trash" onClick={deleteNote} />}
>
{selectedNote.author}
</LabeledList.Item>
<LabeledList.Item label="Time">
{selectedNote.time}
</LabeledList.Item>
</LabeledList>
<Box color="label" mb={1} mt={1}>
Content:
</Box>
<BlockQuote>{selectedNote.content}</BlockQuote>
</>
)}
</Section>
);
};

/** Displays the notes with an add tab next to. */
const NoteTabs = (props, context) => {
const foundRecord = getMedicalRecord(props, context);
if (!foundRecord) return <> </>;
const { notes } = foundRecord;

const [selectedNote, setSelectedNote] = useLocalState<
MedicalNote | undefined
>(context, 'selectedNote', undefined);
const [writing, setWriting] = useLocalState(context, 'note', false);

/** Selects or deselects a note. */
const setNote = (note: MedicalNote) => {
if (selectedNote?.note_ref === note.note_ref) {
setSelectedNote(undefined);
} else {
setSelectedNote(note);
}
};

/** Sets the note to writing mode. */
const composeNew = () => {
setWriting(true);
setSelectedNote(undefined);
};

return (
<Tabs>
{notes.map((note, index) => (
<Tabs.Tab
key={index}
onClick={() => setNote(note)}
selected={selectedNote?.note_ref === note.note_ref}
>
{index + 1}
</Tabs.Tab>
))}
<Tooltip
content={`Add a new note. Press enter or escape to exit view.`}
position="bottom"
>
<Tabs.Tab onClick={composeNew} selected={writing}>
<Icon name="plus" /> New
</Tabs.Tab>
</Tooltip>
</Tabs>
);
};
26 changes: 11 additions & 15 deletions tgui/packages/tgui/interfaces/MedicalRecords/RecordView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
PHYSICALSTATUS2DESC,
PHYSICALSTATUS2ICON,
} from './constants';
import { getMedicalRecord, getQuirkStrings } from './helpers';
import { getMedicalRecord } from './helpers';
import { NoteKeeper } from './NoteKeeper';
import { MedicalRecordData } from './types';

/** Views a selected record. */
Expand All @@ -32,21 +33,18 @@ export const MedicalRecordView = (props, context) => {
const { min_age, max_age } = data;

const {
age,
blood_type,
record_ref,
dna,
rank,
name,
age,
species,
gender,
disabilities,
physical_status,
mental_status,
name,
rank,
species,
blood_type,
dna,
} = foundRecord;

const disabilities_array = getQuirkStrings(disabilities);

return (
<Stack fill vertical>
<Stack.Item grow>
Expand Down Expand Up @@ -178,14 +176,12 @@ export const MedicalRecordView = (props, context) => {
{mental_status}
</Box>
</LabeledList.Item>
<LabeledList.Item label="Disabilities">
{disabilities_array.map((disability, index) => (
<Box key={index}>&#8226; {disability}</Box>
))}
</LabeledList.Item>
</LabeledList>
</Section>
</Stack.Item>
<Stack.Item grow>
<NoteKeeper />
</Stack.Item>
</Stack>
);
};
10 changes: 5 additions & 5 deletions tgui/packages/tgui/interfaces/MedicalRecords/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export type MedicalRecordData = {
};

export type MedicalRecord = {
record_ref: string;
rank: string;
name: string;
age: number;
gender: string;
species: string;
blood_type: string;
record_ref: string;
dna: string;
gender: string;
disabilities: string;
physical_status: string;
mental_status: string;
name: string;
notes: MedicalNote[];
rank: string;
species: string;
};

export type MedicalNote = {
Expand Down
12 changes: 6 additions & 6 deletions tgui/packages/tgui/interfaces/SecurityRecords/RecordView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ const RecordInfo = (props, context) => {
const { min_age, max_age } = data;

const {
age,
record_ref,
crimes,
fingerprint,
gender,
name,
security_note,
rank,
name,
age,
gender,
species,
crimes,
fingerprint,
wanted_status,
security_note,
} = foundRecord;

return (
Expand Down
Loading

0 comments on commit ea477bf

Please sign in to comment.