Documentation and stuff

Documentation, documentation, documentation.
Safety checks.
Reshuffled some code.
Modified wifi senders and receivers to both use var/id, instead of two different vars for basically the same purpose.
This commit is contained in:
Loganbacca
2015-11-23 21:46:29 +13:00
parent 012f82fe23
commit da7a4a78d8
5 changed files with 154 additions and 72 deletions
+37 -25
View File
@@ -1,16 +1,9 @@
//-------------------------------
// Doors
// Sender: sends an open/close request to all connected /door receivers. Utilises spawn_sync to trigger all doors to
// open at approximately the same time. Waits until all doors have finished opening before returning.
// Receiver: will try to open/close the parent door when activate/deactivate is called.
//-------------------------------
/datum/wifi/receiver/button/door/activate()
var/obj/machinery/door/D = parent
if(istype(D) && D.can_open())
D.open()
/datum/wifi/receiver/button/door/deactivate()
var/obj/machinery/door/D = parent
if(istype(D) && D.can_close())
D.close()
/datum/wifi/sender/door/proc/open()
var/datum/spawn_sync/S = new()
@@ -45,15 +38,23 @@
sleep(1)
return
/datum/wifi/receiver/button/door/activate()
var/obj/machinery/door/D = parent
if(istype(D) && D.can_open())
D.open()
/datum/wifi/receiver/button/door/deactivate()
var/obj/machinery/door/D = parent
if(istype(D) && D.can_close())
D.close()
//-------------------------------
// Buttons
// Sender: intended to be used by buttons, when the button is pressed it will call activate() on all connected /button
// receivers.
// Receiver: does whatever the subtype does. deactivate() by default calls activate(), so you will have to override in
// it in a subtype if you want it to do something.
//-------------------------------
/datum/wifi/receiver/button/proc/activate(mob/living/user)
/datum/wifi/receiver/button/proc/deactivate(mob/living/user)
activate(user) //override this if you want deactivate to actually do something
/datum/wifi/sender/button/proc/activate(mob/living/user)
for(var/datum/wifi/receiver/button/B in connected_devices)
B.activate(user)
@@ -62,8 +63,14 @@
for(var/datum/wifi/receiver/button/B in connected_devices)
B.deactivate(user)
/datum/wifi/receiver/button/proc/activate(mob/living/user)
/datum/wifi/receiver/button/proc/deactivate(mob/living/user)
activate(user) //override this if you want deactivate to actually do something
//-------------------------------
// Emitter
// Activates/deactivates the parent emitter.
//-------------------------------
/datum/wifi/receiver/button/emitter/activate(mob/living/user)
..()
@@ -78,6 +85,7 @@
//-------------------------------
// Crematorium
// Triggers cremate() on the parent /crematorium.
//-------------------------------
/datum/wifi/receiver/button/crematorium/activate(mob/living/user)
..()
@@ -87,6 +95,7 @@
//-------------------------------
// Mounted Flash
// Triggers flash() on the parent /flasher.
//-------------------------------
/datum/wifi/receiver/button/flasher/activate(mob/living/user)
..()
@@ -96,6 +105,7 @@
//-------------------------------
// Holosign
// Turns the parent /holosign on/off.
//-------------------------------
/datum/wifi/receiver/button/holosign/activate(mob/living/user)
..()
@@ -110,6 +120,7 @@
//-------------------------------
// Igniter
// Turns the parent /igniter on/off.
//-------------------------------
/datum/wifi/receiver/button/igniter/activate(mob/living/user)
..()
@@ -126,6 +137,7 @@
//-------------------------------
// Sparker
// Triggers the parent /sparker to ignite().
//-------------------------------
/datum/wifi/receiver/button/sparker/activate(mob/living/user)
..()
@@ -134,16 +146,10 @@
S.ignite()
//-------------------------------
// Mass Driver Button
//-------------------------------
/datum/wifi/receiver/button/mass_driver/activate(mob/living/user)
..()
var/obj/machinery/mass_driver/M = parent
if(istype(M))
M.drive()
//-------------------------------
// Mass Driver Process
// Mass Driver
// Sender: carries out a sequence of first opening all connected doors, then activating all connected mass drivers,
// then closes all connected doors. It will wait before continuing the sequence after opening/closing the doors.
// Receiver: Triggers the parent mass dirver to activate.
//-------------------------------
/datum/wifi/sender/mass_driver/proc/cycle()
var/datum/spawn_sync/S = new()
@@ -187,3 +193,9 @@
while(S.check())
sleep(1)
return
/datum/wifi/receiver/button/mass_driver/activate(mob/living/user)
..()
var/obj/machinery/mass_driver/M = parent
if(istype(M))
M.drive()
+66 -26
View File
@@ -1,12 +1,53 @@
//-------------------------------
/*
Interfaces
These are the datums that an object needs to connect via the wireless controller. You will need a /wifi/receiver to
allow other devices to connect to your device and send it instructions. You will need a /wifi/sender to send signals
to other devices with wifi receivers. You can have multiple devices (senders and receivers) if you program your
device to handle them.
Each wifi interface has one "id". This identifies which devices can connect to each other. Multiple senders can
connect to multiple receivers as long as they have the same id.
Variants are found in devices.dm
To add a receiver to an object:
Add the following variables to the object:
var/_wifi_id << variable that can be configured on the map, this is passed to the receiver later
var/datum/wifi/receiver/subtype/wifi_receiver << the receiver (and subtype itself)
Add or modify the objects initialize() proc to include:
if(_wifi_id) << only creates a wifi receiver if an id is set
wifi_receiver = new(_wifi_id, src) << this needs to be in initialize() as New() is usually too
early, and the receiver will try to connect to the controller
before it is setup.
Add or modify the objects Destroy() proc to include:
qdel(wifi_receiver)
wifi_receiver = null
Senders are setup the same way, except with a var/datum/wifi/sender/subtype/wifi_sender variable instead of (or in
addition to) a /wifi/receiver variable.
You will however need to call the /wifi/senders code to pass commands onto any connected receivers.
Example:
/obj/machinery/button/attack_hand()
wifi_sender.activate()
*/
//-------------------------------
//-------------------------------
// Wifi
//-------------------------------
/datum/wifi
var/obj/parent
var/list/connected_devices
var/id
/datum/wifi/New(var/obj/O)
/datum/wifi/New(var/new_id, var/obj/O)
connected_devices = new()
id = new_id
if(istype(O))
parent = O
@@ -18,44 +59,41 @@
return ..()
/datum/wifi/proc/connect_device(var/datum/wifi/device)
connected_devices |= device
if(connected_devices)
connected_devices |= device
else
connected_devices = new()
connected_devices |= device
/datum/wifi/proc/disconnect_device(var/datum/wifi/device)
connected_devices -= device
if(connected_devices)
connected_devices -= device
//-------------------------------
// Receiver
//-------------------------------
/datum/wifi/receiver
var/id
/datum/wifi/receiver/New(var/new_id, var/obj/O)
..(O)
id = new_id
wirelessProcess.add_device(src)
/datum/wifi/receiver/New()
..()
if(wirelessProcess)
wirelessProcess.add_device(src)
/datum/wifi/receiver/Destroy()
wirelessProcess.remove_device(src)
if(wirelessProcess)
wirelessProcess.remove_device(src)
return ..()
//-------------------------------
// Sender
//-------------------------------
/datum/wifi/sender
var/target
/datum/wifi/sender/New(var/new_target, var/obj/O)
..(O)
target = new_target
/datum/wifi/sender/New()
..()
send_connection_request()
/datum/wifi/sender/proc/set_target(var/new_target)
target = new_target
id = new_target
/datum/wifi/sender/proc/send_connection_request()
var/datum/connection_request/C = new(src, target)
var/datum/connection_request/C = new(src, id)
wirelessProcess.add_request(C)
@@ -63,17 +101,18 @@
// Connection request
//-------------------------------
/datum/connection_request
var/datum/wifi/sender/source //wifi_sender object creating the request
var/target //id tag of the target device to try to connect to
var/datum/wifi/sender/source //wifi/sender object creating the request
var/id //id tag of the target device(s) to try to connect to
/datum/connection_request/New(var/datum/wifi/sender/sender, var/receiver)
source = sender
target = receiver
if(istype(sender))
source = sender
id = receiver
//-------------------------------
// Wireless tool (temp)
//-------------------------------
/*
/obj/item/device/wireless_tool
name = "wireless tool"
desc = "Used for connecting machinery to controls for remote operation."
@@ -84,3 +123,4 @@
icon_state = "wirelesstool_on"
else
icon_state = "wirelesstool_off"
*/