initial commit

This commit is contained in:
Booklordofthedings 2024-05-11 17:02:07 +02:00
commit 0e81f8608e
5 changed files with 140 additions and 0 deletions

6
BeefProj.toml Normal file
View file

@ -0,0 +1,6 @@
FileVersion = 1
[Project]
Name = "BeefBrand"
TargetType = "BeefLib"
StartupObject = "BeefBrand.Program"

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Jannis von Hagen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

BIN
example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

14
readme.md Normal file
View file

@ -0,0 +1,14 @@
# BeefBrand
This program generates .bf files that contain a hardcoded version of your assets
by using the build in Generator component from corlib
## Usage
Add the project to your Workspace.
Change your dependencies to BeefBrand.
Rightclick on your project.
Generate File.
Select BeefBrand from the dropdown.
Input the name and the path.
If relative is checked the path you input will be relative to the directory of your workspace.
![An image of the generator window](example.png)

99
src/BrandMark.bf Normal file
View file

@ -0,0 +1,99 @@
using System;
using System.IO;
namespace BeefBrand
{
class BrandMark : Compiler.Generator
{
public override String Name => "BrandMarkFile";
public override void Generate(String outFileName, String outText, ref Flags generateFlags)
{
generateFlags = .AllowRegenerate;
outFileName.Append(mParams["name"]); //Set the name of the file we created
//Calculate the path of the file
String path = scope .(); //The path of the data
path.Append(mParams["path"]);
//Load data and check for file existence
String data = scope .();
if(File.Exists(path))
data = File.ReadAllText(path,.. new String(),true);
else
Fail("The file at path doesnt exist");
String param = scope String(mParams["name"]);
String lenght = data.Length.ToString(.. scope .());
String hex = ToHex(.. scope .(),data);
//Change path
String p = scope .();
for(int i = 0; i < path.Length;i++)
{
if(path[i] == '\\')
p.Append('\\');
p.Append(path[i]);
}
if(mParams["reload"] == bool.TrueString)
{
outText.Append(
scope $"""
using System;
static
\{
extension BrandedAssets
\{
public static uint8[?] {param} = Compiler.ReadBinary("{p}");
\}
\}
"""
);
}
else
{
outText.Append(
scope $"""
static
\{
extension BrandedAssets
\{
public static uint8[{lenght}] {param} = .({hex});
\}
\}
"""
);
}
}
///Create array of hex values from data String
private void ToHex(String outText, String data)
{
for(int i = 0; i < data.Length; i++)
{
outText.Append("0x");
outText.Append(
((uint8)data[i]).ToString(.. scope .(),"X2",null)
); //Doing magic here
if(i+1 < data.Length)
outText.Append(','); //Add an , if its not the last object
}
}
public override void InitUI()
{
AddEdit("name","Object Name","Asset");
AddFilePath("path","File Path",WorkspaceDir);
AddCheckbox("reload","Autoreload",false);
}
}
}
static
{
class BrandedAssets
{
//This is where the generator will add files to
}
}