Skip to content

Commit

Permalink
Inject BEE2 and srctools FGD data into portal2.fgd
Browse files Browse the repository at this point in the history
This makes the entities able to be fixed up in instances.
  • Loading branch information
TeamSpen210 committed Aug 6, 2018
1 parent bf2cf58 commit 279e9eb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
13 changes: 6 additions & 7 deletions bee2.fgd
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// Definitions for BEE2-specific entities
@include "portal2.fgd"
// This is injected at the end of Portal2.fgd.

@BaseClass = TemplateEnt
@BaseClass = BEETemplateEnt
[
template_id(string): "Template ID" : "" : "The unique ID this template has (in the combined file)."
visgroup(string): "Visgroup" : "" : "The visgroup this brush/overlay was contained in (in the combined file)."
]

@SolidClass base(TemplateEnt) = bee2_template_world: "A set of world brushes which will be templated into a map."
@SolidClass base(BEETemplateEnt) = bee2_template_world: "A set of world brushes which will be templated into a map."
[
]

@SolidClass base(TemplateEnt) = bee2_template_detail: "A set of detail brushes which will be templated into a map."
@SolidClass base(BEETemplateEnt) = bee2_template_detail: "A set of detail brushes which will be templated into a map."
[
]

@PointClass base(TemplateEnt, info_overlay)
@PointClass base(BEETemplateEnt, info_overlay)
size(-1 -1 0, 1 1 1)
color(80 150 225)
studio("models/editor/overlay_helper.mdl")
Expand All @@ -28,7 +27,7 @@
[
]

@PointClass base(TemplateEnt) iconsprite("BEE2/editor/bee2_icon.vmt") = bee2_template_scaling:
@PointClass base(BEETemplateEnt) iconsprite("BEE2/editor/bee2_icon.vmt") = bee2_template_scaling:
"Used to store the values for a scaling template."
[
up_tex(material): "Up Texture" : "" : "Texture for the upward-pointing face."
Expand Down
1 change: 1 addition & 0 deletions src/compile_BEE2.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def copy_resource(tree):
copy_resource(tree + '/' + file)

copy_resource('BEE2.ico')
copy_resource('BEE2.fgd')
copy_resource('images/BEE2')
copy_resource('images/icons')
copy_resource('images/splash_screen')
Expand Down
61 changes: 60 additions & 1 deletion src/gameMan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import os
import shutil
import math
import re


from BEE2_config import ConfigFile, GEN_OPTS
from query_dialogs import ask_string
Expand All @@ -31,6 +33,12 @@

from typing import List, Tuple, Set, Iterable, Iterator, Dict

try:
from importlib.resources import read_text as imp_res_read_text
except ImportError:
# Backport module for before Python 3.7
from importlib_resources import read_text as imp_res_read_text


LOGGER = srctools.logger.get_logger(__name__)

Expand Down Expand Up @@ -409,6 +417,49 @@ def edit_gameinfo(self, add_line=False) -> None:
shutil.move(backup_path, item_path)
self.clear_cache()

def edit_fgd(self, add_lines: bool=False) -> None:
"""Add our FGD files to the game folder.
This is necessary so that VBSP offsets the entities properly,
if they're in instances.
Add_line determines if we are adding or removing it.
"""
fgd_path = self.abs_path('bin/portal2.fgd')
try:
with open(fgd_path, 'r', encoding='utf8') as file:
data = list(file)
except FileNotFoundError:
LOGGER.warning('No FGD file? ("{}")', fgd_path)
return

for i, line in enumerate(data):
match = re.match(
r'// BEE\W*2 EDIT FLAG\W*=\W*([01])',
line,
re.IGNORECASE | re.UNICODE,
)
if match:
if match.group(0) == '0':
return # User specifically disabled us.
# Delete all data after this line.
del data[i:]
break

with srctools.AtomicWriter(fgd_path) as file:
for line in data:
file.write(line)
if add_lines:
file.write(
'// BEE 2 EDIT FLAG = 1 \n'
'// Added automatically by BEE2. Set above to "0" to '
'allow editing below text without being overwritten.\n'
'\n\n'
)
with open('../BEE2.fgd', 'r') as bee2_fgd:
for line in bee2_fgd:
file.write(line)
file.write(imp_res_read_text(srctools, 'srctools.fgd'))

def cache_invalid(self) -> bool:
"""Check to see if the cache is valid."""
if GEN_OPTS.get_bool('General', 'preserve_bee2_resource_dir'):
Expand Down Expand Up @@ -555,7 +606,9 @@ def export(
# VBSP_config
# Instance list
# Editor models.
export_screen.set_length('EXP', len(packageLoader.OBJ_TYPES) + 4)
# FGD file
# Gameinfo
export_screen.set_length('EXP', len(packageLoader.OBJ_TYPES) + 6)

# Do this before setting music and resources,
# those can take time to compute.
Expand Down Expand Up @@ -660,6 +713,11 @@ def export(

LOGGER.info('Editing Gameinfo...')
self.edit_gameinfo(True)
export_screen.step('EXP')

LOGGER.info('Adding ents to FGD.')
self.edit_fgd(True)
export_screen.step('EXP')

LOGGER.info('Writing instance list...')
with open(self.abs_path('bin/bee2/instances.cfg'), 'w', encoding='utf8') as inst_file:
Expand Down Expand Up @@ -1358,6 +1416,7 @@ def remove_game(e=None):
)
if confirm:
selected_game.edit_gameinfo(add_line=False)
selected_game.edit_fgd(add_lines=False)

all_games.remove(selected_game)
CONFIG.remove_section(selected_game.name)
Expand Down

0 comments on commit 279e9eb

Please sign in to comment.