-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves block definitions to yaml finally
- Loading branch information
1 parent
05bc4c4
commit ec5df93
Showing
65 changed files
with
226 additions
and
417 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Adjacencies/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Blocktest/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pucestone/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pykrete/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Renderable/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=renderables/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Smoothable/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Smoothable/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=tilemap_0027s/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,12 @@ | ||
using System.Linq; | ||
using Shared.Code.Block_System; | ||
namespace Blocktest.Block_System; | ||
|
||
public sealed class BlockSpritesManager { | ||
/// <summary> Array which stores all blocksprites instances for referencing as if they were globals. </summary> | ||
private static BlockSprites[] _allBlocksSprites; | ||
|
||
/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary> | ||
private static string[] _blockSpriteNames; | ||
|
||
/// <summary> Array which stores all blocksprites instances for referencing as if they were globals. </summary> | ||
public static BlockSprites[] AllBlocksSprites { | ||
get => _allBlocksSprites; | ||
private set => _allBlocksSprites = value; | ||
} | ||
/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary> | ||
public static string[] BlockSpriteNames { | ||
get => _blockSpriteNames; | ||
private set => _blockSpriteNames = value; | ||
} | ||
public static Dictionary<string, BlockSprites> AllBlocksSprites { get; private set; } | ||
|
||
public static void LoadBlockSprites() { | ||
AllBlocksSprites = new BlockSprites[BlockManagerShared.AllBlocks.Length]; | ||
BlockSpriteNames = new string[BlockManagerShared.AllBlocks.Length]; | ||
|
||
foreach (BlockShared block in BlockManagerShared.AllBlocks) { | ||
BlockSprites newBlockSprites = new(block); | ||
BlockSpriteNames[block.BlockId] = block.BlockName; | ||
AllBlocksSprites[block.BlockId] = newBlockSprites; | ||
} | ||
AllBlocksSprites = BlockManagerShared.AllBlocks.ToDictionary(uid => uid.Key, block => new BlockSprites(block.Value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,44 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace Shared.Code.Block_System; | ||
|
||
/// <summary> | ||
/// The BlockManager contains all of the block types in <see cref="AllBlocks">an array of blocks</see> and a | ||
/// <see cref="BlockNames">list of block names.</see> | ||
/// The BlockManager contains all of the block types in <see cref="AllBlocks">a dictionary of blocks indexed by their name</see> | ||
/// </summary> | ||
public abstract class BlockManagerShared { | ||
/// <summary> Array which stores all block instances for referencing as if they were globals. </summary> | ||
private static BlockShared[] _allBlocks; | ||
|
||
|
||
/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary> | ||
private static string[] _blockNames; | ||
|
||
/// <summary> Array which stores all block instances for referencing as if they were globals. </summary> | ||
public static BlockShared[] AllBlocks { | ||
get => _allBlocks; | ||
private set => _allBlocks = value; | ||
} | ||
|
||
/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary> | ||
public static string[] BlockNames { | ||
get => _blockNames; | ||
private set => _blockNames = value; | ||
} | ||
public static Dictionary<string, BlockShared> AllBlocks { get; private set; } | ||
|
||
|
||
/// <summary> | ||
/// Compiles all block subtypes into <see cref="AllBlocks">an array of blocks</see> and a | ||
/// <see cref="BlockNames">list of block names.</see> | ||
/// Compiles all block subtypes into <see cref="AllBlocks">a dictionary of blocks indexed by their name</see> | ||
/// </summary> | ||
public static void Initialize() { | ||
// This mess gets all subtypes of Block and puts the types in a list. | ||
Type[] allBlockTypes = ( | ||
from domainAssembly in AppDomain.CurrentDomain.GetAssemblies() | ||
from assemblyType in domainAssembly.GetTypes() | ||
where assemblyType.IsSubclassOf(typeof(BlockShared)) | ||
select assemblyType).ToArray(); | ||
|
||
AllBlocks = new BlockShared[allBlockTypes.Length]; | ||
BlockNames = new string[allBlockTypes.Length]; | ||
|
||
// For loops to populate main allBlocks array. | ||
for (int i = 0; i < allBlockTypes.Length; i++) { | ||
Type newBlockType = allBlockTypes[i]; | ||
BlockShared? newBlock = (BlockShared?)Activator.CreateInstance(newBlockType); | ||
if (newBlock == null) { | ||
Console.WriteLine($"Failed to create instance of {newBlockType}!"); | ||
var deserialize = new DeserializerBuilder().Build(); | ||
var assembly = typeof(BlockManagerShared).Assembly; | ||
var assemblyNames = assembly.GetManifestResourceNames(); | ||
var blockNames = assemblyNames.Where(x => x.StartsWith("Shared.Content.Blocks.")); | ||
|
||
AllBlocks = new Dictionary<string, BlockShared>(); | ||
foreach (string resourceName in blockNames) { | ||
using var stream = assembly.GetManifestResourceStream(resourceName); | ||
if (stream == null) { | ||
continue; | ||
} | ||
newBlock.Initialize(); | ||
if (newBlock.BlockId == -1) { | ||
newBlock.BlockId = i; | ||
using StreamReader reader = new(stream); | ||
string yaml = reader.ReadToEnd(); | ||
var block = deserialize.Deserialize<BlockShared?>(yaml); | ||
if (block == null) { | ||
continue; | ||
} | ||
if (AllBlocks[newBlock.BlockId] != null) { | ||
Console.WriteLine( | ||
$"Block {newBlock} conflicts with block {AllBlocks[newBlock.BlockId]}! (Block ID: {newBlock.BlockId})"); | ||
} else if (newBlock.BlockId > AllBlocks.Length || newBlock.BlockId < 0) { | ||
Console.WriteLine($"Block {newBlock} has invalid ID {newBlock.BlockId}! (Max ID {AllBlocks.Length})"); | ||
block.BlockUid = block.BlockName.ToLower().Replace(" ", "_"); | ||
|
||
if (!AllBlocks.TryAdd(block.BlockUid, block)) { | ||
Console.WriteLine($"File {resourceName} contains duplicate definition of block {block.BlockName}!"); | ||
} | ||
BlockNames[newBlock.BlockId] = newBlock.BlockName; | ||
AllBlocks[newBlock.BlockId] = newBlock; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.