Files
Bubberstation/code/modules/library/bookcase.dm
Zonespace 8fabd54ad6 Mirrors #72354 (#18654)
* [no gbp] removes all duplicate armor datums (#72354)

closes #72348
Title

My bad

Heres the script I used this time if you want to
```cs
var baseDir = Environment.CurrentDirectory;

var allFiles = Directory.EnumerateFiles($@"{baseDir}\code", "*.dm", SearchOption.AllDirectories).ToList();
var known = new Dictionary<string, List<KeyValuePair<string, int>>>();

foreach (var file in allFiles)
{
	var fileLines = File.ReadAllLines(file);
	for (var i = 0; i < fileLines.Length; i++)
	{
		var line = fileLines[i];
		if (line.StartsWith("/datum/armor/"))
		{
			var armorName = line.Replace("/datum/armor/", "").Trim();
			if (!known.ContainsKey(armorName))
				known[armorName] = new List<KeyValuePair<string, int>>();
			var knownList = known[armorName];
			knownList.Add(new KeyValuePair<string, int>(file, i));
		}
	}
}

Console.WriteLine($"There are {known.Sum(d => d.Value.Count)} duplicate armor datums.");

var duplicates = new Dictionary<string, List<int>>();
foreach (var (_, entries) in known)
{
	var actuals = entries.Skip(1).ToList();
	foreach (var actual in actuals)
	{
		if (!duplicates.ContainsKey(actual.Key))
			duplicates[actual.Key] = new List<int>();
		duplicates[actual.Key].Add(actual.Value);
	}
}

Console.WriteLine($"There are {duplicates.Count} files to update.");

foreach (var (file, idxes) in duplicates)
{
	var fileContents = File.ReadAllLines(file).ToList();
	foreach (var idx in idxes.OrderByDescending(i => i))
	{
		string line;
		do
		{
			line = fileContents[idx];
			fileContents.RemoveAt(idx);
		}
		while (!String.IsNullOrWhiteSpace(line));
	}
	File.WriteAllLines(file, fileContents);
}
```

* modular

Co-authored-by: Zephyr <12817816+ZephyrTFA@users.noreply.github.com>
2023-01-13 18:05:12 -05:00

209 lines
6.7 KiB
Plaintext

#define BOOKCASE_UNANCHORED 0
#define BOOKCASE_ANCHORED 1
#define BOOKCASE_FINISHED 2
/obj/structure/bookcase
name = "bookcase"
icon = 'icons/obj/library.dmi'
icon_state = "bookempty"
desc = "A great place for storing knowledge."
anchored = FALSE
density = TRUE
opacity = FALSE
resistance_flags = FLAMMABLE
max_integrity = 200
armor_type = /datum/armor/structure_bookcase
var/state = BOOKCASE_UNANCHORED
/// When enabled, books_to_load number of random books will be generated for this bookcase
var/load_random_books = FALSE
/// The category of books to pick from when populating random books.
var/random_category = null
/// How many random books to generate.
var/books_to_load = 0
/datum/armor/structure_bookcase
fire = 50
/obj/structure/bookcase/Initialize(mapload)
. = ..()
if(!mapload || QDELETED(src))
return
// Only mapload from here on
set_anchored(TRUE)
state = BOOKCASE_FINISHED
for(var/obj/item/I in loc)
if(!isbook(I))
continue
I.forceMove(src)
update_appearance()
if(SSlibrary.initialized)
INVOKE_ASYNC(src, PROC_REF(load_shelf))
else
SSlibrary.shelves_to_load += src
///Loads the shelf, both by allowing it to generate random items, and by adding its contents to a list used by library machines
/obj/structure/bookcase/proc/load_shelf()
//Loads a random selection of books in from the db, adds a copy of their info to a global list
//To send to library consoles as a starting inventory
if(load_random_books)
create_random_books(books_to_load, src, FALSE, random_category)
update_appearance() //Make sure you look proper
var/area/our_area = get_area(src)
var/area_type = our_area.type //Save me from the dark
if(!SSlibrary.books_by_area[area_type])
SSlibrary.books_by_area[area_type] = list()
//Time to populate that list
var/list/books_in_area = SSlibrary.books_by_area[area_type]
for(var/obj/item/book/book in contents)
var/datum/book_info/info = book.book_data
books_in_area += info.return_copy()
/obj/structure/bookcase/examine(mob/user)
. = ..()
if(!anchored)
. += span_notice("The <i>bolts</i> on the bottom are unsecured.")
else
. += span_notice("It's secured in place with <b>bolts</b>.")
switch(state)
if(BOOKCASE_UNANCHORED)
. += span_notice("There's a <b>small crack</b> visible on the back panel.")
if(BOOKCASE_ANCHORED)
. += span_notice("There's space inside for a <i>wooden</i> shelf.")
if(BOOKCASE_FINISHED)
. += span_notice("There's a <b>small crack</b> visible on the shelf.")
/obj/structure/bookcase/set_anchored(anchorvalue)
. = ..()
if(isnull(.))
return
state = anchorvalue
if(!anchorvalue) //in case we were vareditted or uprooted by a hostile mob, ensure we drop all our books instead of having them disappear till we're rebuild.
var/atom/Tsec = drop_location()
for(var/obj/I in contents)
if(!isbook(I))
continue
I.forceMove(Tsec)
update_appearance()
/obj/structure/bookcase/attackby(obj/item/I, mob/user, params)
switch(state)
if(BOOKCASE_UNANCHORED)
if(I.tool_behaviour == TOOL_WRENCH)
if(I.use_tool(src, user, 20, volume=50))
to_chat(user, span_notice("You wrench the frame into place."))
set_anchored(TRUE)
else if(I.tool_behaviour == TOOL_CROWBAR)
if(I.use_tool(src, user, 20, volume=50))
to_chat(user, span_notice("You pry the frame apart."))
deconstruct(TRUE)
if(BOOKCASE_ANCHORED)
if(istype(I, /obj/item/stack/sheet/mineral/wood))
var/obj/item/stack/sheet/mineral/wood/W = I
if(W.get_amount() >= 2)
W.use(2)
to_chat(user, span_notice("You add a shelf."))
state = BOOKCASE_FINISHED
update_appearance()
else if(I.tool_behaviour == TOOL_WRENCH)
I.play_tool_sound(src, 100)
to_chat(user, span_notice("You unwrench the frame."))
set_anchored(FALSE)
if(BOOKCASE_FINISHED)
if(isbook(I))
if(!user.transferItemToLoc(I, src))
return
update_appearance()
else if(atom_storage)
for(var/obj/item/T in I.contents)
if(istype(T, /obj/item/book) || istype(T, /obj/item/spellbook))
atom_storage.attempt_remove(T, src)
to_chat(user, span_notice("You empty \the [I] into \the [src]."))
update_appearance()
else if(istype(I, /obj/item/pen))
if(!user.canUseTopic(src, be_close = TRUE) || !user.can_write(I))
return
var/newname = tgui_input_text(user, "What would you like to title this bookshelf?", "Bookshelf Renaming", max_length = MAX_NAME_LEN)
if(!user.canUseTopic(src, be_close = TRUE) || !user.can_write(I))
return
if(!newname)
return
else
name = "bookcase ([sanitize(newname)])"
else if(I.tool_behaviour == TOOL_CROWBAR)
if(length(contents))
to_chat(user, span_warning("You need to remove the books first!"))
else
I.play_tool_sound(src, 100)
to_chat(user, span_notice("You pry the shelf out."))
new /obj/item/stack/sheet/mineral/wood(drop_location(), 2)
state = BOOKCASE_ANCHORED
update_appearance()
else
return ..()
/obj/structure/bookcase/attack_hand(mob/living/user, list/modifiers)
. = ..()
if(.)
return
if(!istype(user))
return
if(!length(contents))
return
var/obj/item/book/choice = tgui_input_list(user, "Book to remove from the shelf", "Remove Book", sort_names(contents.Copy()))
if(isnull(choice))
return
if(!(user.mobility_flags & MOBILITY_USE) || user.stat != CONSCIOUS || HAS_TRAIT(user, TRAIT_HANDS_BLOCKED) || !in_range(loc, user))
return
if(ishuman(user))
if(!user.get_active_held_item())
user.put_in_hands(choice)
else
choice.forceMove(drop_location())
update_appearance()
/obj/structure/bookcase/deconstruct(disassembled = TRUE)
var/atom/Tsec = drop_location()
new /obj/item/stack/sheet/mineral/wood(Tsec, 4)
for(var/obj/item/I in contents)
if(!isbook(I)) //Wake me up inside
continue
I.forceMove(Tsec)
return ..()
/obj/structure/bookcase/update_icon_state()
if(state == BOOKCASE_UNANCHORED || state == BOOKCASE_ANCHORED)
icon_state = "bookempty"
return ..()
var/amount = length(contents)
icon_state = "book-[clamp(amount, 0, 5)]"
return ..()
/obj/structure/bookcase/manuals/engineering
name = "engineering manuals bookcase"
/obj/structure/bookcase/manuals/engineering/Initialize(mapload)
. = ..()
new /obj/item/book/manual/wiki/engineering_construction(src)
new /obj/item/book/manual/wiki/engineering_hacking(src)
new /obj/item/book/manual/wiki/engineering_guide(src)
new /obj/item/book/manual/wiki/robotics_cyborgs(src)
update_appearance()
/obj/structure/bookcase/manuals/research_and_development
name = "\improper R&D manuals bookcase"
/obj/structure/bookcase/manuals/research_and_development/Initialize(mapload)
. = ..()
new /obj/item/book/manual/wiki/research_and_development(src)
update_appearance()
#undef BOOKCASE_UNANCHORED
#undef BOOKCASE_ANCHORED
#undef BOOKCASE_FINISHED