Skip to content

Commit

Permalink
[MIRROR] Refactor poster code
Browse files Browse the repository at this point in the history
  • Loading branch information
PsiOmegaDelta authored and SierraHelper committed Dec 29, 2023
1 parent b055afc commit 66038ba
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 141 deletions.
2 changes: 2 additions & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,9 @@
#include "code\game\objects\effects\decals\Cleanable\misc.dm"
#include "code\game\objects\effects\decals\Cleanable\robots.dm"
#include "code\game\objects\effects\decals\Cleanable\tracks.dm"
#include "code\game\objects\effects\decals\posters\_defines.dm"
#include "code\game\objects\effects\decals\posters\bs12.dm"
#include "code\game\objects\effects\decals\posters\posters.dm"
#include "code\game\objects\effects\fire\fire.dm"
#include "code\game\objects\effects\particles\particles.dm"
#include "code\game\objects\effects\spawners\bombspawner.dm"
Expand Down
116 changes: 1 addition & 115 deletions code/game/objects/effects/decals/contraband.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//########################## CONTRABAND ;3333333333333333333 -Agouri ###################################################

/obj/item/contraband
Expand All @@ -7,7 +6,6 @@
icon = 'icons/obj/structures/contraband.dmi'
force = 0


/obj/item/contraband/poster
name = "rolled-up poster"
desc = "The poster comes with its own automatic adhesive mechanism, for easy pinning to any vertical surface."
Expand All @@ -18,9 +16,7 @@
if(given_poster_type && !ispath(given_poster_type, /singleton/poster))
CRASH("Invalid poster type: [log_info_line(given_poster_type)]")

poster_type = given_poster_type || poster_type
if(!poster_type)
poster_type = pick(subtypesof(/singleton/poster) - list(/singleton/poster/torch, /singleton/poster/contraband_only))
poster_type = given_poster_type || poster_type || get_random_poster_type()
..()

/obj/item/contraband/poster/Initialize()
Expand Down Expand Up @@ -74,113 +70,3 @@
return TRUE

return FALSE

//############################## THE ACTUAL DECALS ###########################

/obj/structure/sign/poster
name = "poster"
desc = "A large piece of space-resistant printed paper."
icon = 'icons/obj/structures/contraband.dmi'
icon_state = "random_poster"
anchored = TRUE
var/poster_type
var/ruined = 0
var/torch_poster = FALSE //for torch-specific content

/obj/structure/sign/poster/bay_9
poster_type = /singleton/poster/bay_9

/obj/structure/sign/poster/bay_50
poster_type = /singleton/poster/bay_50

/obj/structure/sign/poster/torch
poster_type = /singleton/poster/torch
torch_poster = TRUE

/obj/structure/sign/poster/New(newloc, placement_dir = null, give_poster_type = null)
..(newloc)

if(!poster_type)
if(give_poster_type)
poster_type = give_poster_type
else
poster_type = pick(subtypesof(/singleton/poster) - typesof(/singleton/poster/torch) - typesof(/singleton/poster/contraband_only))
if(torch_poster)
poster_type = pick(subtypesof(/singleton/poster/torch))
set_poster(poster_type)

switch (placement_dir)
if (NORTH)
pixel_x = 0
pixel_y = 32
if (SOUTH)
pixel_x = 0
pixel_y = -32
if (EAST)
pixel_x = 32
pixel_y = 0
if (WEST)
pixel_x = -32
pixel_y = 0

/obj/structure/sign/poster/proc/set_poster(poster_type)
var/singleton/poster/design = GET_SINGLETON(poster_type)
SetName("[initial(name)] - [design.name]")
desc = "[initial(desc)] [design.desc]"
icon_state = design.icon_state

/obj/structure/sign/poster/use_tool(obj/item/tool, mob/user, list/click_params)
// Screwdriver - Block interaction
if (isScrewdriver(tool))
USE_FEEDBACK_FAILURE("You must use wirecutters to remove \the [src].")
return TRUE

// Wirecutters - Remove poster
if (isWirecutter(tool))
playsound(src, 'sound/items/Wirecutter.ogg', 50, TRUE)
if (ruined)
user.visible_message(
SPAN_NOTICE("\The [user] removes the remnants of \the [src] with \a [tool]."),
SPAN_NOTICE("You remove the remnants of \the [src] with \the [tool].")
)
qdel_self()
else
user.visible_message(
SPAN_NOTICE("\The [user] removes \the [src] with \a [tool]."),
SPAN_NOTICE("You remove \the [src] with \the [tool].")
)
roll_and_drop(user.loc)
return TRUE

return ..()


/obj/structure/sign/poster/attack_hand(mob/user as mob)

if(ruined)
return

if(alert("Do I want to rip the poster from the wall?","You think...","Yes","No") == "Yes")

if(ruined || !user.Adjacent(src))
return

visible_message(SPAN_WARNING("\The [user] rips \the [src] in a single, decisive motion!") )
playsound(src.loc, 'sound/items/poster_ripped.ogg', 100, 1)
ruined = 1
icon_state = "poster_ripped"
SetName("ripped poster")
desc = "You can't make out anything from the poster's original print. It's ruined."
add_fingerprint(user)

/obj/structure/sign/poster/proc/roll_and_drop(turf/newloc)
var/obj/item/contraband/poster/poster_item = new/obj/item/contraband/poster(newloc, poster_type)
transfer_fingerprints_to(poster_item)
qdel_self()

/singleton/poster
// Name suffix. Poster - [name]
var/name=""
// Description suffix
var/desc=""
var/icon_state=""
3 changes: 3 additions & 0 deletions code/game/objects/effects/decals/posters/_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var/global/const/POSTER_FLAG_NONE = EMPTY_BITFIELD
var/global/const/POSTER_FLAG_CONTRABAND = FLAG(0)
var/global/const/POSTER_FLAG_RANDOM_PICK = FLAG(1)
27 changes: 2 additions & 25 deletions code/game/objects/effects/decals/posters/bs12.dm
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@
icon_state = "poster_ripped"
name = "Contraband Poster"
desc = "You probably shouldn't be seeing this."
abstract_type = /singleton/poster/contraband_only
poster_flags = POSTER_FLAG_RANDOM_PICK | POSTER_FLAG_CONTRABAND

/singleton/poster/contraband_only/unusual_gas
icon_state = "unusual_gas"
Expand All @@ -356,28 +358,3 @@
large black gaiter with purple stripes. GAS sickles are dressed in cute little mitts of \
the same color. The entire lower right corner of the poster is occupied by a large \
inscription \"uwu\", and in the lower left it says: \"More on our site - WetSkrell.nt\"."

/singleton/poster/torch
icon_state="poster_ripped"
name = "Torch Poster"
desc = "You probably shouldn't be seeing this."

/singleton/poster/torch/event1
icon_state="bsposter_event1"
name = "Justice for Joe"
desc = "A hand-written poster demanding the release of one SCPO Joseph Tornakov from Fleet Intelligence custody. It's somewhat faded."

/singleton/poster/torch/event2
icon_state="bsposter_event2"
name = "Captain for Senate"
desc = "A poster loudly advertising the SEV Torch's captain's upcoming bid for SCG Senate. The fine print lightly suggests that failing to vote in their favor will result in an NJP."

/singleton/poster/torch/event3
icon_state="bsposter_event3"
name = "Visit E-14b Outpost"
desc = "This poster invites personnel to visit the the E-14b research outpost, built through joint Terran and Expeditionary Corps efforts. According to the poster, it's still under construction."

/singleton/poster/torch/event4
icon_state="bsposter_event4"
name = "Scientific Cooperation"
desc = "This poster depicts a Sol Expeditionary Corps captain shaking hands with a Terran Pioneer Corps officer. It appears to espouse greater scientific cooperation between the two organisations."
122 changes: 122 additions & 0 deletions code/game/objects/effects/decals/posters/posters.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/obj/structure/sign/poster
name = "poster"
desc = "A large piece of space-resistant printed paper."
icon = 'icons/obj/structures/contraband.dmi'
icon_state = "random_poster"
anchored = TRUE
var/poster_type
var/ruined = 0
var/random_poster_base_type = /singleton/poster
var/excluded_poster_flags = POSTER_FLAG_CONTRABAND

/obj/structure/sign/poster/bay_9
poster_type = /singleton/poster/bay_9

/obj/structure/sign/poster/bay_50
poster_type = /singleton/poster/bay_50

/obj/structure/sign/poster/New(newloc, placement_dir = null, given_poster_type = null)
..(newloc)

if(given_poster_type && !ispath(given_poster_type, /singleton/poster))
CRASH("Invalid poster type: [log_info_line(given_poster_type)]")

poster_type = given_poster_type || poster_type || GetRandomPosterType()
set_poster(poster_type)

switch (placement_dir)
if (NORTH)
pixel_x = 0
pixel_y = 32
if (SOUTH)
pixel_x = 0
pixel_y = -32
if (EAST)
pixel_x = 32
pixel_y = 0
if (WEST)
pixel_x = -32
pixel_y = 0

/// Returns a random poster type.
/// Uses the random_poster_base_type and excluded_poster_flags vars to limit the potential set of poster types to select from.
/obj/structure/sign/poster/proc/GetRandomPosterType()
return get_random_poster_type(random_poster_base_type, excluded_poster_flags)

/obj/structure/sign/poster/proc/set_poster(poster_type)
var/singleton/poster/design = GET_SINGLETON(poster_type)
SetName("[initial(name)] - [design.name]")
desc = "[initial(desc)] [design.desc]"
icon_state = design.icon_state

/obj/structure/sign/poster/use_tool(obj/item/tool, mob/user, list/click_params)
// Screwdriver - Block interaction
if (isScrewdriver(tool))
USE_FEEDBACK_FAILURE("You must use wirecutters to remove \the [src].")
return TRUE

// Wirecutters - Remove poster
if (isWirecutter(tool))
playsound(src, 'sound/items/Wirecutter.ogg', 50, TRUE)
if (ruined)
user.visible_message(
SPAN_NOTICE("\The [user] removes the remnants of \the [src] with \a [tool]."),
SPAN_NOTICE("You remove the remnants of \the [src] with \the [tool].")
)
qdel_self()
else
user.visible_message(
SPAN_NOTICE("\The [user] removes \the [src] with \a [tool]."),
SPAN_NOTICE("You remove \the [src] with \the [tool].")
)
roll_and_drop(user.loc)
return TRUE

return ..()


/obj/structure/sign/poster/attack_hand(mob/user as mob)
if(ruined)
return

if(alert("Do I want to rip the poster from the wall?","You think...","Yes","No") == "Yes")
if(ruined || !user.Adjacent(src))
return

visible_message(SPAN_WARNING("\The [user] rips \the [src] in a single, decisive motion!") )
playsound(src.loc, 'sound/items/poster_ripped.ogg', 100, 1)
ruined = 1
icon_state = "poster_ripped"
SetName("ripped poster")
desc = "You can't make out anything from the poster's original print. It's ruined."
add_fingerprint(user)

/obj/structure/sign/poster/proc/roll_and_drop(turf/newloc)
var/obj/item/contraband/poster/poster_item = new/obj/item/contraband/poster(newloc, poster_type)
transfer_fingerprints_to(poster_item)
qdel_self()

/singleton/poster
// Name suffix. Poster - [name]
var/name=""
// Description suffix
var/desc=""
var/icon_state=""
var/poster_flags = POSTER_FLAG_RANDOM_PICK
abstract_type = /singleton/poster

/// Picks and returns a random (sub)type of the provided random_poster_base_type which:
/// * Is not abstract, and
/// * Has a poster_flags value with the POSTER_FLAG_RANDOM_PICK flag, and
/// * Has a poster_flags value which does not match one or more of the excluded_flags (if provided)
/proc/get_random_poster_type(random_poster_base_type = /singleton/poster, excluded_flags)
var/list/valid_posters = new()
for (var/singleton/poster/poster_type as anything in typesof(random_poster_base_type))
if (is_abstract(poster_type))
continue

var/poster_flags = initial(poster_type.poster_flags)
if ((poster_flags & POSTER_FLAG_RANDOM_PICK) && (!excluded_flags || !(poster_flags & excluded_flags)))
valid_posters += poster_type

return pick(valid_posters)
2 changes: 2 additions & 0 deletions code/unit_tests/icon_tests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
var/list/invalid_posters = list()

for(var/poster_type in subtypesof(/singleton/poster))
if (is_abstract(poster_type))
continue
var/singleton/poster/P = GET_SINGLETON(poster_type)
// [SIERRA-EDIT] - NYC_POSTERS - TAJARA
// if(!(P.icon_state in contraband_icons)) // SIERRA-EDIT - ORIGINAL
Expand Down
28 changes: 28 additions & 0 deletions maps/torch/structures/posters.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/obj/structure/sign/poster/torch
random_poster_base_type = /singleton/poster/torch

/singleton/poster/torch
icon_state="poster_ripped"
name = "Torch Poster"
desc = "You probably shouldn't be seeing this."
abstract_type = /singleton/poster/torch

/singleton/poster/torch/event1
icon_state="bsposter_event1"
name = "Justice for Joe"
desc = "A hand-written poster demanding the release of one SCPO Joseph Tornakov from Fleet Intelligence custody. It's somewhat faded."

/singleton/poster/torch/event2
icon_state="bsposter_event2"
name = "Captain for Senate"
desc = "A poster loudly advertising the SEV Torch's captain's upcoming bid for SCG Senate. The fine print lightly suggests that failing to vote in their favor will result in an NJP."

/singleton/poster/torch/event3
icon_state="bsposter_event3"
name = "Visit E-14b Outpost"
desc = "This poster invites personnel to visit the the E-14b research outpost, built through joint Terran and Expeditionary Corps efforts. According to the poster, it's still under construction."

/singleton/poster/torch/event4
icon_state="bsposter_event4"
name = "Scientific Cooperation"
desc = "This poster depicts a Sol Expeditionary Corps captain shaking hands with a Terran Pioneer Corps officer. It appears to espouse greater scientific cooperation between the two organisations."
3 changes: 2 additions & 1 deletion maps/torch/torch.dm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@

#include "robot/module_flying_surveyor.dm"

#include "structures/signs.dm"
#include "structures/closets.dm"
#include "structures/closets/closet_appearances.dm"
#include "structures/closets/command.dm"
Expand All @@ -138,6 +137,8 @@
#include "structures/closets/supply.dm"
#include "structures/closets/exploration.dm"
#include "structures/memorabilia.dm"
#include "structures/posters.dm"
#include "structures/signs.dm"

#include "loadout/_defines.dm"
#include "loadout/loadout_accessories.dm"
Expand Down

0 comments on commit 66038ba

Please sign in to comment.