Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zemnmez committed Aug 19, 2021
1 parent 4e7a9fc commit 3c03cc4
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 98 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[BUILD]
indent_style = space

[*.bzl]
indent_style = space
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ load("@rules_typescript_proto//:index.bzl", "rules_typescript_proto_dependencies

rules_typescript_proto_dependencies()

load("@npm//@bazel/labs:package.bzl", "npm_bazel_labs_dependencies")

npm_bazel_labs_dependencies()
149 changes: 87 additions & 62 deletions gen/BUILD
Original file line number Diff line number Diff line change
@@ -1,62 +1,87 @@
load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@rules_pkg//:pkg.bzl", "pkg_zip")
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")

package(default_visibility = [":__subpackages__", "//solve:__subpackages__"])

ts_project(
name="gen",
srcs=glob(["*.ts"]),
deps=[
"@npm//@types/node"
],
tsconfig="//:tsconfig"
)

nodejs_binary(
name="collate_game_core",
entry_point="collate_game_core.js"
)

genrule(
name = "gen_core",
srcs = [ "//gen/cultist_data:steam_gen_cultist_out.zip" ],
tools = [ "@bazel_tools//tools/zip:zipper" ],
exec_tools = [ ":collate_game_core" ],
outs = [ "core_en.json" ],
cmd = "$(execpath @bazel_tools//tools/zip:zipper) x $(location //gen/cultist_data:steam_gen_cultist_out.zip) -d $(location :core_en.json)_gamedir_tmp &&" +
"find $@_gamedir_tmp/CS_Data/StreamingAssets/content/core -name '*.json' | xargs ./$(execpath //gen:collate_game_core) > $@",
message = "generating collated game data"
)

proto_library (
name = "core_proto",
srcs = [ "core.proto" ],
deps = [ "//proto:cultist_proto", "@com_google_protobuf//:struct_proto" ],
)


py_proto_library (
name = "core_py_proto",
srcs = [ "core.proto" ],
deps = [ "//proto:cultist_py_proto", "@com_google_protobuf//:protobuf_python" ]
)

typescript_proto_library(
name = "core_ts_proto",
proto = ":core_proto",
)

py_library (
name = "core_py",
srcs = [ "core.py" ],
deps = ["//gen:core_py_proto"],
data = [ "//gen:core_en.json" ]
)




load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@rules_pkg//:pkg.bzl", "pkg_zip")
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")

package(default_visibility = [
":__subpackages__",
"//solve:__subpackages__",
])

ts_project(
name = "gen",
srcs = ["collate_game_core.ts"],
declaration = True,
tsconfig = "//:tsconfig",
deps = [
"@npm//@types/node",
],
)

nodejs_binary(
name = "collate_game_core",
entry_point = "collate_game_core.js",
)

genrule(
name = "gen_core",
srcs = ["//gen/cultist_data:steam_gen_cultist_out.zip"],
outs = ["core_en.json"],
cmd = "$(execpath @bazel_tools//tools/zip:zipper) x $(location //gen/cultist_data:steam_gen_cultist_out.zip) -d $(location :core_en.json)_gamedir_tmp &&" +
"find $@_gamedir_tmp/CS_Data/StreamingAssets/content/core -name '*.json' | xargs ./$(execpath //gen:collate_game_core) > $@",
exec_tools = [":collate_game_core"],
message = "generating collated game data",
tools = ["@bazel_tools//tools/zip:zipper"],
)

proto_library(
name = "core_proto",
srcs = ["core.proto"],
deps = [
"//proto:cultist_proto",
"@com_google_protobuf//:struct_proto",
],
)

py_proto_library(
name = "core_py_proto",
srcs = ["core.proto"],
deps = [
"//proto:cultist_py_proto",
"@com_google_protobuf//:protobuf_python",
],
)

py_library(
name = "core_py",
srcs = ["core.py"],
data = ["//gen:core_en.json"],
deps = ["//gen:core_py_proto"],
)


genrule(
name = "core_en_ts",
srcs = [ "core_en_types.ts", "core_en.json" ],
outs = [ "core_en_ts.ts" ],
cmd = " ".join([
"cat",
"<(echo '// @ts-nocheck')",
"$(location core_en_types.ts)",
"<(echo 'export default (')",
"$(location core_en.json)",
"<(echo ');')"
]) + " > $@"
)


ts_project(
name = "core_en_ts_js",
srcs = ["core_en_ts.ts"],
tsconfig="//:tsconfig",
declaration = True,
deps = [
"@npm//@types/node",
]
)
6 changes: 3 additions & 3 deletions gen/collate_game_core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ async function Main(files = process.argv.slice(2)) {
}
}

console.log(JSON.stringify(output));
console.log(JSON.stringify(output, null, 2));
}


if (require.main === module) {
Main().catch(e => {
console.error(e);

process.exitCode = process.exitCode || 1
});
}
}
3 changes: 1 addition & 2 deletions gen/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ message Core {
repeated cultist.Culture cultures = 1;
repeated cultist.Deck decks = 2;
repeated cultist.Element elements = 3;
repeated cultist.Slot slots = 4;
repeated cultist.Verb verbs = 5;
// typo to drop
repeated cultist.Legacy legcies = 6;
Expand All @@ -18,4 +17,4 @@ message Core {
repeated cultist.Recipe recipes = 9;

repeated google.protobuf.Struct endings = 10;
}
}
178 changes: 178 additions & 0 deletions gen/core_en_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import fs from 'fs';

// ts proto generation seems bad outside
// the google spaceship so this'll have to do

export interface Core {
cultures: Culture[],
decks: Deck[],
elements: Element[],
verbs: Verb[],
/** @deprecated in-game typo */
legcies: Legacy[],
legacies: Legacy[],
settings: Setting[],
recipes: Recipe[]
endings: unknown[]
}

export interface Culture {
id: string,
fontscript?: string,
released?: boolean,
endonym?: string,
exonym?: string,
uilabels?: unknown,
boldallowed?: boolean
}

export interface Deck {
id: string,
description?: string,
label?: string,
resetonexhaustion?: boolean,
spec?: string[],
draws?: number[],
defaultcard?: string,
comments?: string
drawmessages?: Record<string, string>
}

export interface Element {
id: string,
isAspect?: boolean,
isHidden?: boolean,
label?: string,
icon?: string,
unique?: boolean,
xtriggers?: {
[key: string]: unknown
},
description?: string,
aspects?: { [elementId: string]: number },
lifetime?: number,
uniquenessgroup?: string,
slots?: Slot[],
decayTo?: string,
comments?: string,
resaturate?: boolean,
lever?: string,
noartneeded?: boolean,
induces?: Induction[],
verbicon?: string,
inherits?: string
}

export interface Induction {
id: string,
chance: number
}

export interface Recipe {
id: string,
actionid?: string,
aspects?: { [elementid: string]: number },
requirements?: unknown,
description?: string,
label?: string,
warmup?: number,
craftable?: boolean,
alt?: Recipe[],
slots?: Slot[],
startdescription?: string,
comments?: string,
mutations?: Mutation[],
maxexecutions?: number,
linked?: Recipe[],
tablereqs?: { [aspect: string]: number},
effects?: { [aspect: string]: number | string},
deckeffects?: { [aspect: string]: number | string},
burnimage?: string,
extantreqs?: { [aspect: string]: number | string},
hintonly?: boolean,
ending?: string,
signalEndingFlavour?: string,
purge?: { [aspect: string]: number | string},
deleteverb?: { [aspect: string]: number | string},
haltverb?: { [aspect: string]: number | string},
chance?: number,
additional?: boolean,
expulsion?: Expulsion,
challenges?: { [kind: string]: string },
signalimportantloop?: boolean
}

export interface Mutation {
filter?: string,
level?: number,
mutate?: string,
additive?: boolean
}

export interface Expulsion {
limit?: number,
filter?: { [key: string]: number }
}

export interface Slot {
id: string,
label?: string,
description?: string,
required?: {[kind:string]: number},
forbidden?: {[kind:string]: number},
greedy?: boolean,
actionid?: string,
consumes?: boolean,
noanim?: boolean
}

export interface Verb {
id: string,
description?: string,
slots?: Slot[],
label?: string,
slot?: Slot
}

export interface Legacy {
id: string,
label?: string,
fromending?: string,
description?: string,
startdescription?: string,
effects?: { [key: string]: number},
image?: string,
startingverbid?: string,
newstart?: boolean,
availableWithoutEndingMatch?: boolean,
tablecoverimage?: string,
excludesOnEnding?: string[]
statusbarelements?: string[]
}

export interface Setting {
id: string,
tabid?: string,
hint?: string,
datatype?: string,
minvalue?: number,
maxvalue?: number,
defaultvalue?: string,
valuelabels?: Record<number, string>
}



/*
let _core: Promise<Core> | undefined;
export const core: () => Promise<Core> = async () => {
if (_core === undefined) _core = await fs.promises.readFile('core_en.json')
.then(b => JSON.parse(b.toString('utf-8')));
return _core!;
}
export default core;
*/
Loading

0 comments on commit 3c03cc4

Please sign in to comment.