Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Create New Microgame" option in menu #62

Merged
merged 10 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
export.cfg

export/
build/

# ignore copied example if not renamed
microgames/my_cool_microgame/

# Imported translations (automatically generated from CSV files)
*.translation
Expand Down
7 changes: 7 additions & 0 deletions addons/mg_helper/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="Microgame Helper"
description="A plugin that provides additional editor features to support microgame development."
author="izzy kestrel"
version="1.0"
script="plugin.gd"
55 changes: 55 additions & 0 deletions addons/mg_helper/plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
tool
extends EditorPlugin


const MG_EXAMPLE_PATH := "res://core/microgame/example"
const MG_EXAMPLE_NAME := "my_cool_microgame"

var dock
var active_mg_def
var new_mg_just_created : bool = false


func _enter_tree():
# Initialization of the plugin goes here.
# Load the dock scene and instance it.
# dock = preload("res://addons/my_custom_dock/my_dock.tscn").instance()

# dock.get_node("VBoxContainer/Button").connect("pressed", self, "_on_button_pressed")
add_tool_menu_item("Create New Microgame", self, "_on_button_pressed")

connect("scene_changed", self, "_on_scene_changed")

# Add the loaded scene to the docks.
# add_control_to_dock(DOCK_SLOT_LEFT_BR, dock)
# Note that LEFT_UL means the left of the editor, upper-left dock.


func _exit_tree():
remove_tool_menu_item("Create New Microgame")
# Clean-up of the plugin goes here.
# Remove the dock.
# remove_control_from_docks(dock)
# Erase the control from the memory.
# dock.free()


func _on_scene_changed(scene_root):
if new_mg_just_created:
active_mg_def = Utility.get_definition_from_microgame_scene(scene_root.filename)
active_mg_def.scene = scene_root.filename
yield(get_tree().create_timer(0.1), "timeout")
get_editor_interface().edit_resource(active_mg_def)
new_mg_just_created = false

func _on_button_pressed(_ud):
var example_dir = MG_EXAMPLE_PATH
var new_mg_dir = "res://microgames/%s/" % MG_EXAMPLE_NAME

var dir = Directory.new()
dir.make_dir(new_mg_dir)
for file in Utility.list_all_files(example_dir):
dir.copy(file, new_mg_dir + file.get_file())
get_editor_interface().get_resource_filesystem().scan()
new_mg_just_created = true
get_editor_interface().open_scene_from_path(new_mg_dir + "mg_scene.tscn")
14 changes: 10 additions & 4 deletions core/autoload/session.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
extends Node

#warning-ignore:UNUSED_SIGNAL
signal level_up_requested
#warning-ignore:UNUSED_SIGNAL
signal speed_up_requested

const GAME_MODE : Dictionary = {
"STANDARD": preload("res://modes/mode_standard.tres"),
"DEBUG": preload("res://modes/mode_debug.tres"),
}
const INTERMISSION_SCENE: PackedScene = preload("res://core/intermission/intermission.tscn")
const MENU_SCENE : PackedScene = preload("res://core/menu/menu.tscn")
const INTERMISSION_SCENE: String = "res://core/intermission/intermission.tscn"
const MENU_SCENE : String = "res://core/menu/menu.tscn"

var game_state : GameState
var microgame_pool : Array = []
Expand All @@ -17,6 +19,10 @@ var current_microgame : MicrogameDefinition


func _ready():
# hack to get PR stuff working
if OS.get_cmdline_args().size() > 0 and OS.get_cmdline_args()[0] == "-s":
return

randomize()
connect("level_up_requested", self, "_on_level_up_requested")
connect("speed_up_requested", self, "_on_speed_up_requested")
Expand Down Expand Up @@ -50,7 +56,7 @@ func start_mode(game_mode : GameState):


func _play_intermission() -> void:
get_tree().change_scene_to(INTERMISSION_SCENE)
get_tree().change_scene(INTERMISSION_SCENE)


func _on_intermission_completed() -> void:
Expand All @@ -62,7 +68,7 @@ func _on_intermission_completed() -> void:
)
else:
Scores.save_score_for(game_state.name, game_state.current_score)
get_tree().change_scene_to(MENU_SCENE)
get_tree().change_scene(MENU_SCENE)


func _on_microgame_completed(is_success : bool) -> void:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://core/microgame/metadata/mg_definition.gd" type="Script" id=1]
[ext_resource path="res://creators/iznaut.tres" type="Resource" id=3]
[ext_resource path="res://creators/iznaut.tres" type="Resource" id=1]
[ext_resource path="res://core/microgame/metadata/mg_definition.gd" type="Script" id=2]

[resource]
script = ExtResource( 1 )
script = ExtResource( 2 )
title = "My Cool Microgame"
short_hint = "Mash!"
credits = [ ExtResource( 3 ) ]
credits = [ ExtResource( 1 ) ]
input_type = 0
scene = "res://core/microgame/example/my_cool_microgame.tscn"
scene = "res://core/microgame/example/microgame.tscn"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://core/microgame/example/my_cool_microgame.gd" type="Script" id=1]
[ext_resource path="res://core/microgame/example/mg_script.gd" type="Script" id=1]

[node name="Main" type="Node"]
script = ExtResource( 1 )
Expand Down
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ window/size/resizable=false

[editor_plugins]

enabled=PoolStringArray( "res://addons/version_checker/plugin.cfg" )
enabled=PoolStringArray( "res://addons/mg_helper/plugin.cfg", "res://addons/version_checker/plugin.cfg" )

[input]

Expand Down